Polish version    English version  
  History of OI


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN

Task: Double-row


2n soldiers are standing in a double-row. They have to be rearranged, so that there are no equally tall soldiers in each row -- then we shall say, that the soldiers are set up properly.

A single operation consists in swapping two soldiers who occupy the same position (but in different rows). Your task is to determine the minimum number of swaps necessary to set the soldiers up properly.

Example:

There is a double-row of 18 soldiers in the figure. Arrows indicate the swaps that rearrange the soldiers in a proper way.

Write a programme that:
  • reads from the standard input the number and heights of soldiers, as they stand initially,
  • determines the minimum number of swaps (of soldiers standing on the same position in different rows) necessary to set up soldiers properly,
  • writes the result to the standard output.

Input

In the first line of the input there is one integer n, 1 <= n <= 50 000. In each of the two rows there are n soldiers standing. In each of the following two lines there are n positive integers separated by single spaces. In the second line there are numbers x1, x2,..., xn, 1 <= xi <= 100 000; xi denotes the height of the ith soldier in the first line. In the thrid line there are numbers y1, y2,..., yn, 1 <= y <= i100 000; yi denotes the height of the ith soldier in the second line.

It is guaranteed that in the instances from the test data it is possible to set up soldiers properly.

Output

In the first and only line of the standard output one integer should be written -- the minimum number of swaps necessary to set up soldiers properly.





Print friendly version