AtCoder Regular Contest 133
B
Dividing Subsequence
AtCoder
⌀ 1317
原题
← AC →
翻译中…

Problem Statement

翻译中…

Given are permutations $P=(P_1,P_2,\cdots,P_N)$ and $Q=(Q_1,Q_2,\cdots,Q_N)$ of $(1,2,\cdots,N)$.

翻译中…

Snuke is going to extract (not necessarily contiguous) subsequences from $P$ and $Q$. Here, the subsequences must satisfy the conditions below.

翻译中…
  • The length of the subsequence extracted from $P$ and that extracted from $Q$ are the same. Below, let $k$ be this length.
  • Let $a=(a_1,a_2,\cdots,a_k)$ and $b=(b_1,b_2,\cdots,b_k)$ be the subsequences extracted from $P$ and $Q$, respectively. Then, for each $1 \leq i \leq k$, $b_i$ is a multiple of $a_i$.
翻译中…

Find the maximum possible length of each subsequence extracted by Snuke.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 200000$
  • $P$ is a permutation of $(1,2,\cdots,N)$.
  • $Q$ is a permutation of $(1,2,\cdots,N)$.
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
P_1 P_2 \cdots P_N
Q_1 Q_2 \cdots Q_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
3 1 4 2
4 2 1 3
Output #1
2
If we extract the subsequence $(1,2)$ from $P$ and $(4,2)$ from $Q$, they satisfy the conditions. It is impossible to extract subsequences of length $3$ or greater to satisfy the conditions, so the answer is $2$.
Input #2
5
1 2 3 4 5
5 4 3 2 1
Output #2
3
Input #3
10
4 3 1 10 9 2 8 6 5 7
9 6 5 4 2 3 8 10 1 7
Output #3
6
题目信息
题号
arc133_b
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。