String Table

Build a table whose cells are huge concatenated strings defined by comparing neighbors, then print 50 characters from a given position of the final cell.

Hard8Dynamic programmingStringRecursionDivide and conquerNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given two strings ss and tt. All characters in the two strings are distinct: no character appears twice, no character of ss appears in tt, and no character of tt appears in ss.

Let NN be the length of ss and MM the length of tt. A two-dimensional array table is defined as follows.

  • table[i][0] = s[i-1] (1iN1 \le i \le N)
  • table[0][j] = t[j-1] (1jM1 \le j \le M)
  • table[i][j] = min(table[i-1][j], table[i][j-1]) + max(table[i-1][j], table[i][j-1]) (1iN1 \le i \le N, 1jM1 \le j \le M)

min returns whichever of the two strings comes first in lexicographic order, and max returns the one that comes later. Characters are compared by ASCII code, so digits come before uppercase letters and uppercase letters come before lowercase letters. A+B is the string A followed by the string B.

Write a program that finds a substring of table[N][M]. Because the string can be very long, print only the min(50,Lpos)\min(50, L - pos) characters starting at position pospos. Here LL is the length of table[N][M], and positions are counted from 0.

Input

The first line contains ss, the second line contains tt, and the third line contains pospos (0pos<L0 \le pos < L).

The lengths of ss and tt are each between 1 and 30, inclusive. Both strings consist only of uppercase letters, lowercase letters, and digits.

Output

Print, on the first line, the substring of table[N][M] that consists of the min(50,Lpos)\min(50, L - pos) characters starting at position pospos.