atcoder#ARC133B. [ARC133B] Dividing Subsequence
[ARC133B] Dividing Subsequence
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.
4
3 1 4 2
4 2 1 3
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 .
5
1 2 3 4 5
5 4 3 2 1
3
10
4 3 1 10 9 2 8 6 5 7
9 6 5 4 2 3 8 10 1 7
6