[BOJ 9393] Genome Evolution
View as PDFXi, 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.</p>
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.</p>
예제 입력
4
3 2 1 4
1 2 4 3
5
3 2 1 5 4
3 2 1 5 4
0
예제 출력
3
10
Comments