NKTEAM - Team Selection

no tags 

The Interpeninsular Olympiad in Informatics is coming and the leaders of the Balkan Peninsula Team have to choose the best contestants on the Balkans. Fortunately, the leaders could choose the members of the team among N very good contestants, numbered from 1 to N (3 ≤ N ≤ 500000). In order to select the best contestants the leaders organized three competitions. Each of the N contestants took part in all three competitions and there were no two contestants with equal results on any of the competitions. We say that contestant А is better than another contestant В when А is ranked before В in all of the competitions. A contestant A is said to be excellent if no other contestant is better than A. The leaders of the Balkan Peninsula Team would like to know the number of excellent contestants.

Write a program, which for given N and the three competitions results, computes the number of excellent contestants.

Input

The input data are given as four lines. The first line contains the number N. The next three lines show the rankings for the three competitions. Each of these lines contains the identification numbers of the contestants, separated by single spaces, in the order of their ranking from first to last place.

Output

The output should contain one line with a single number written on it: the number of the excellent.

Example

Input
3 
2 3 1
3 1 2
1 2 3

Output
3

Note: No contestant is better than any other contestant, hence all three are excellent.

Input
10 
2 5 3 8 10 7 1 6 9 4
1 2 3 4 5 6 7 8 9 10
3 8 7 10 5 4 1 2 6 9

Output
4

Note: The excellent contestants are those numbered with 1, 2, 3 and 5.


hide comments
jobaidul: 2023-02-22 18:18:37

If you get output 2 for 2nd test case. Don't worry. Submit your code.

lollospada: 2022-11-18 23:15:01

2nd example is wrong (the answer is 3, first contenstant is better than anyone except for contestants 7 and 8)

nan0s_: 2022-10-18 21:29:00

There seems to be a mistake in the second example (the answer should be 2 - contestants 1 and 7). However there seem to be no mistakes in the actual tests, but the result of my submission is 9.09 (instead of Wrong Answer or Accepted or something). I don't know what is means.

[NG]: Your solution gives correct output for 1 out of 11 testfiles (~9.09%).

Last edit: 2022-10-29 00:29:54

Added by:Jimmy
Date:2007-12-16
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Balkan OI 2004