Hide

Problem E
Library of Babel

Nathan, a lexicographer and linguist, has discovered the mythical Library of Babel, a place that contains all known combinations of letters in the world. The Library consists of two towers. Hoping to find a pattern in the cacophony of meaningless noise, he repeatedly samples a page from both towers and compares the two. However, simply matching a letter or two isn’t enough. Nathan wants to find the largest continuous sequence of letters that is the reverse of another sequence of letters.

Input

The input contains two lines, each of which contain strings of length $n$ ($1 \leq n \leq 1\, 000$). The strings contain only lowercase letters.

Output

Your program should output the length of the longest continuous sequence of letters from the first string that is the reverse of another continuous sequence of letters from the second string.

Sample Input 1 Sample Output 1
abcdefghi
hgfcbdxff
3
Sample Input 2 Sample Output 2
dsxgkylfjpfpplzpdpwqsdtjmqgvwjcaabygfcszumyevqsciz
uxjnzpuyigepzuirrfhjrlaovlosxfszhqfppfpjsdkoqompui
5

Please log in to submit a solution to this problem

Log in