测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A8386. Ancient Berland Hieroglyphs

编程题 普及/提高-

题目描述

The first line contains two integers $l_{a}$ and $l_{b}$ ( $1<=l_{a},l_{b}<=1000000$ ) — the number of hieroglyphs in the first and second circles, respectively.

Below, due to difficulties with encoding of Berland hieroglyphs, they are given as integers from $1$ to $10^{6}$ .

The second line contains $l_{a}$ integers — the hieroglyphs in the first picture, in the clockwise order, starting with one of them.

The third line contains $l_{b}$ integers — the hieroglyphs in the second picture, in the clockwise order, starting with one of them.

It is guaranteed that the first circle doesn't contain a hieroglyph, which occurs twice. The second circle also has this property.

输入格式

Print a single number — the maximum length of the common substring and subsequence. If at any way of breaking the circles it does not exist, print 0.

输出格式

In the first test Polycarpus picks a string that consists of hieroglyphs 5 and 1, and in the second sample — from hieroglyphs 1, 3 and 5.

输入输出样例

输入 #1
5 4
1 2 3 4 5
1 3 5 6
输出 #1
2
输入 #2
4 6
1 3 5 2
1 2 3 4 5 6
输出 #2
3
输入 #3
3 3
1 2 3
3 2 1
输出 #3
2

说明/提示

In the first test Polycarpus picks a string that consists of hieroglyphs 5 and 1, and in the second sample — from hieroglyphs 1, 3 and 5.
上一题 去做题 下一题