|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||4||2||2||50.000%|
Xi, a developmental biologist is working on developmental distances of chromosomes. A chromosome, in the Xi's simplistic view, is a permutation from n genes numbered 1 to n. Xi is working on an evolutionary distance metric between two chromosomes. In Xi's theory of evolution any subset of genes lying together in both chromosomes is a positive witness for chromosomes to be similar.
A positive witness is a pair of sequence of the same length A and A', where A is a consecutive subsequence of the first chromosome, A' is a consecutive subsequence of the second chromosome, and A is a permutation of A'. The goal is to count the number of positive witnesses of two given chromosomes that have a length greater than one.
There are several test case in the input. Each test case starts with a line containing the number of genes (2 ≤ n ≤ 3000). The next two lines contain the two chromosomes, each as a list of positive integers. The input terminates with a line containing "0" which should not be processed as a test case.
For each test case, output a single line containing the number of positive witness for two chromosomes to be similar.
4 3 2 1 4 1 2 4 3 5 3 2 1 5 4 3 2 1 5 4 0