Magic Potion

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

When making a potion, you first set the intensity of the heat to a certain degree, put ingredients in certain order into the cauldron according to its recipe, and boil the mixture until ready. In the brewing process, it is very important to prevent the heat from fluctuating, because the heat intensity decides the number of ingredients that form an alchemic bond.

Given a sequence XX of ingredients in order, when the heat intensity is ii (1≥ 1), all subsequences of length ii in XX are alchemic bonds of the corresponding potion; here duplicate bonds are irrelevant. Thus, there can be several different ingredient sequences that produce the same potion if they have the same set of alchemic bonds. On the other hand, different sets of alchemic bonds always produce different potions. Therefore, a potion recipe consists of an intensity of the heat and a sequence of ingredients in order. For instance, the following is a recipe for “the draught of anti-drowsiness”.

  • Heat intensity i=2i = 2
  • Ingredient sequence X=bsmX = bsm,

where bb denotes coffee bean, ss denotes sugar, and mm denotes milk.

Then, because the heat intensity is 22, its alchemic bonds are {bmbm, bsbs, smsm}. If the heat intensity is 33, then there will be only one alchemic bond bsmbsm. Moreover, if the heat intensity is greater than 33, then there will be no bonds. If someone wants to produce the draught of anti-drowsiness and puts ingredients in bmsbms order under the heat intensity of 22, then the alchemic bonds are {bmbm, bsbs, msms}. Thus, this ingredient sequence does not produce the desired potion since the alchemic bond smsm is missing.

Here is another example. For the heat intensity of 22, both ingredient sequences X=abcabcX = abcabc and Y=babcccabY = babcccab produce the same potion since their alchemic bond sets are the same as {aaaa, abab, acac, baba, bbbb, bcbc, caca, cbcb, cccc}. On the other hand, it is easy to confirm that an ingredient sequence Z=abbacbZ = abbacb does not produce the same potion because there are no caca and acac bonds.

The potions department of the ICPC school holds a Potions Olympiad every year. Given two ingredient sequences, participants are asked to find the maximum heat intensity that results in the same potion from two sequences.

Given two ingredient sequences, write a program to output the maximum heat intensity in which both sequences produce the same potion.

입력

Your program is to read from standard input. The input consists of two lines. The first line contains a string XX of length mm (1m200,0001 ≤ m ≤ 200\\,000), and the second line contains a string YY of length nn (1n200,0001 ≤ n ≤ 200\\,000), where all ingredient characters of XX and YY consist of uppercase English letters (from ‘A’ to ‘Z’), lowercase English letters (from ‘a’ to ‘z’) and digits (from ‘0’ to ‘9’). Note that uppercase and lowercase letters are different (for example, ‘A’ is treated as different from ‘a’).

출력

Your program is to write to standard output. Print exactly one line. The line should print the maximum heat intensity ii in which the input ingredient sequences XX and YY produce the same potion. If it is impossible to make the same potions from XX and YY, then the output should be 00.