Manthan 2011
D
Optical Experiment
Codeforces
1900
原题
← CE →
翻译中…

Professor Phunsuk Wangdu has performed some experiments on rays. The setup for $*n*$ rays is as follows.

翻译中…

There is a rectangular box having exactly $*n*$ holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each hole. The holes are in a straight line.

翻译中…

image

翻译中…

Professor Wangdu is showing his experiment to his students. He shows that there are cases, when all the rays are intersected by every other ray. A curious student asked the professor: "Sir, there are some groups of rays such that all rays in that group intersect every other ray in that group. Can we determine the number of rays in the largest of such groups?".

翻译中…

Professor Wangdu now is in trouble and knowing your intellect he asks you to help him.

翻译中…

Input

翻译中…

The first line contains $*n*$ ($1 ≤ *n* ≤ 10^{6}$), the number of rays. The second line contains $*n*$ distinct integers. The $*i*$-th integer $*x*_{*i*}$ ($1 ≤ *x*_{*i*} ≤ *n*$) shows that the $*x*_{*i*}$-th ray enters from the $*i*$-th hole. Similarly, third line contains $*n*$ distinct integers. The $*i*$-th integer $*y*_{*i*}$ ($1 ≤ *y*_{*i*} ≤ *n*$) shows that the $*y*_{*i*}$-th ray exits from the $*i*$-th hole. All rays are numbered from $1$ to $*n*$.

翻译中…

Output

翻译中…

Output contains the only integer which is the number of rays in the largest group of rays all of which intersect each other.

翻译中…

Note

翻译中…

For the first test case, the figure is shown above. The output of the first test case is 3, since the rays number 1, 4 and 3 are the ones which are intersected by each other one i.e. 1 is intersected by 4 and 3, 3 is intersected by 4 and 1, and 4 is intersected by 1 and 3. Hence every ray in this group is intersected by each other one. There does not exist any group containing more than 3 rays satisfying the above-mentioned constraint.

翻译中…

样例

Input #1
5
1 4 5 2 3
3 4 2 1 5
Output #1
3
InputCopy OutputCopy
Input #2
3
3 1 2
2 3 1
Output #2
2
InputCopy OutputCopy
题目信息
题号
67D
所属比赛
时间限制
5 s
内存限制
256 MB
标签
二分
数据结构
动态规划

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