#include <stdio.h>
#include <string.h>

int readLine(char text[], size_t capacity) {
    if (fgets(text, (int)capacity, stdin) == NULL) return 0;
    size_t length = strlen(text);
    if (length > 0 && text[length - 1] == '\n') text[--length] = '\0';
    else if (!feof(stdin)) {
        int ch = getchar();
        if (ch != '\n' && ch != EOF) return 0;
    }
    if (length > 0 && text[length - 1] == '\r') text[length - 1] = '\0';
    return 1;
}

int insertSubstring(char mainText[], size_t capacity,
                    const char subText[], int position) {
    int length = (int)strlen(mainText);
    int subLength = (int)strlen(subText);
    if (position < 1 || position > length + 1 ||
        (size_t)(length + subLength) >= capacity) return 0;
    int index = position - 1;
    for (int i = length; i >= index; --i)
        mainText[i + subLength] = mainText[i];
    for (int i = 0; i < subLength; ++i) mainText[index + i] = subText[i];
    return 1;
}

int deleteCharacters(char text[], int position, int count) {
    int length = (int)strlen(text);
    if (position < 1 || position > length + 1 || count < 0 ||
        count > length - (position - 1)) return 0;
    int index = position - 1;
    for (int i = index; i <= length - count; ++i) text[i] = text[i + count];
    return 1;
}

int main(void) {
    char text[256], substring[128];
    int operation, position, count, ch;
    if (scanf("%d", &operation) != 1 || (operation != 1 && operation != 2)) {
        puts("Invalid input."); return 1;
    }
    while ((ch = getchar()) != '\n' && ch != EOF) { }
    if (!readLine(text, sizeof text)) { puts("Invalid input."); return 1; }
    if (operation == 1) {
        if (!readLine(substring, sizeof substring) || scanf("%d", &position) != 1 ||
            !insertSubstring(text, sizeof text, substring, position)) {
            puts("Invalid insertion."); return 1;
        }
    } else {
        if (scanf("%d %d", &position, &count) != 2 || !deleteCharacters(text, position, count)) {
            puts("Invalid deletion."); return 1;
        }
    }
    printf("Result: %s\n", text);
    return 0;
}
