#ADAPHOTO. Ada and Terramorphing

    ID: 3645 远端评测题 2000ms 1536MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>probability-theoryhashingsuffix-array-8

Ada and Terramorphing

Ada the Ladybug was already on two trips this year. She visited two countries: Republic of Bugongo and Democratic Republic of Bugongo. Even though those countries are completely different and far far away from each other, Ada found some similarities. Now she is looking at photos from each of those countries and examines similarities. Sadly, both of the sequences of photos are very long so she can't handle it herself.

The sequence of photos is sequence of following terrestrial formations: A hill (^), a valley (v), a plain (-), a lake ~

Find the longest common contiguous subsequence between the two sequences of photos.

Important note: Terramorphism is very difficult process. One can't easily influence it so each of the terrestrial formation is generated with more or less 25%.

Input

The first two and the only lines of input contiguous first and second sequence of photos 1 ≤ |s1|, |s2| ≤ 106

Output

For each test-cases, print the longest common sequence.

Example Input

-~^v-
^--v

Example Output

1

Example Input 2

-~
-~v^^^^^v-

Example Output 2

2

Example Input 3

~-~-v--~^
~^--^~-v

Example Output 3

3

Example Input 4

^^^v-v^^v-v-v~v-
vv^v-^~~^v^~^vv~^^-

Example Output 4

3

Example Input 5

~~~vv~-~~vv~v-v--~-^-~^~-^^
~^~--v~-

Example Output 5

4