시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB72121227.907%

문제

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.

 

예제 입력 1

4
3 2 1 4
1 2 4 3
5
3 2 1 5 4
3 2 1 5 4
0

예제 출력 1

3
10