Barn Echoes

No attempts yetTime limit1sMemory limit128 MB

Problem

The cows love mooing in the barn because their moos echo back, though sometimes not perfectly. Bessie, an excellent secretary, has recorded the exact text of each moo both as it goes out and as it returns, and she wonders how much the two strings overlap.

You are given two strings. Each consists only of the lowercase letters a..z, and the total length of the two strings is between 1 and 80, inclusive. We call a string an overlap of the two strings if it is a prefix of one string and, at the same time, a suffix of the other string. Determine the length of the longest possible overlap between the two strings.

For example, consider these two moos:

moyooyoxyzooo
yzoooqyasdfljkamo

The end of the first string, 'yzooo', overlaps the start of the second string. The end of the second string, 'mo', overlaps the start of the first string. The longest overlap is 'yzooo', whose length is 5.

Input

  • Lines 1 and 2: Each line contains one string — a moo or its echo.

Output

  • Line 1: A single integer, the length of the longest overlap between the front of one string and the end of the other.

Hint

In the sample input above, 'abcxxxxabcx' is a prefix of the first string and a suffix of the second string, and its length is 11.