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 SA and SB be the following.
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 SA, which is d, r, d, e, s, d, e, and the 2nd letter through the 8th letter of SB, 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.
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 N and M of the two strings satisfy 1≤N,M≤1500.
Print on the first line the length of the longest pair of intervals with the same composition. If no such pair exists, print 0.