

Time Limit: 5 sec / Memory Limit: 1024 MB
配点 : 点
問題文
の順列 および が与えられます.
すぬけくんは, と から(連続するとは限らない)部分列を取り出そうとしています. ここで,取り出した部分列は以下の条件を満たす必要があります.
- から取り出した部分列と から取り出した部分列の長さは等しい.以下,この長さを とおく.
- から取り出した部分列を , から取り出した部分列を とおく. このとき,各 について, は の倍数である.
すぬけ君が取り出せる部分列の長さの最大値を求めて下さい.
制約
- は の順列である
- は の順列である
- 入力される値はすべて整数である
入力
入力は以下の形式で標準入力から与えられる.
出力
答えを出力せよ.
入力例 1Copy
4 3 1 4 2 4 2 1 3
出力例 1Copy
2
から部分列 を, から部分列 を取り出すと,これは条件を満たします. 長さ 以上の部分列を条件を満たすように取ることはできないため,答えは です.
入力例 2Copy
5 1 2 3 4 5 5 4 3 2 1
出力例 2Copy
3
入力例 3Copy
10 4 3 1 10 9 2 8 6 5 7 9 6 5 4 2 3 8 10 1 7
出力例 3Copy
6
Score : points
Problem Statement
Given are permutations and of .
Snuke is going to extract (not necessarily contiguous) subsequences from and . Here, the subsequences must satisfy the conditions below.
- The length of the subsequence extracted from and that extracted from are the same. Below, let be this length.
- Let and be the subsequences extracted from and , respectively. Then, for each , is a multiple of .
Find the maximum possible length of each subsequence extracted by Snuke.
Constraints
- is a permutation of .
- is a permutation of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
4 3 1 4 2 4 2 1 3
Sample Output 1Copy
2
If we extract the subsequence from and from , they satisfy the conditions. It is impossible to extract subsequences of length or greater to satisfy the conditions, so the answer is .
Sample Input 2Copy
5 1 2 3 4 5 5 4 3 2 1
Sample Output 2Copy
3
Sample Input 3Copy
10 4 3 1 10 9 2 8 6 5 7 9 6 5 4 2 3 8 10 1 7
Sample Output 3Copy
6