CF164B.Ancient Berland Hieroglyphs

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The first line contains two integers lal_{a} and lbl_{b} ( 1<=la,lb<=10000001<=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 11 to 10610^{6} .

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

The third line contains lbl_{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.

首页