Interval Composition

No attempts yetTime limit1sMemory limit256 MB

Problem

Two devices A and B each emit one signal per second. The signals a device emitted form a sequence of lowercase letters in time order. For example, let the signal sequences SAS_A and SBS_B be the following.

  • SAS_A = [a, f, c, d, r, d, e, s, d, e, f, w, s, z, r]
  • SBS_B = [g, e, d, s, r, d, d, e, m, z, r]

An interval is a contiguous part of a sequence. Two intervals have the same composition when they hold the same letters with the same multiplicities, in any order. The two boxed intervals in the picture below have the same composition. The 4th letter through the 10th letter of SAS_A, which is d, r, d, e, s, d, e, and the 2nd letter through the 8th letter of SBS_B, which is e, d, s, r, d, d, e, both consist of three d, two e, one r and one s.

Two intervals with the same composition always have the same length. More than one such pair of intervals can exist. Find the longest pair of intervals with the same composition, one in each of the two signal sequences.

Input

The first line and the second line each hold one signal sequence as a string with no spaces. Both strings consist of lowercase English letters only. The lengths NN and MM of the two strings satisfy 1N,M15001 \le N, M \le 1500.

Output

Print on the first line the length of the longest pair of intervals with the same composition. If no such pair exists, print 00.