QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#11869. 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.

problem_11869_1.gif

Task

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 $x_1,x_2,…,x_n$, $1 ≤ x_i ≤ 100\,000$; $x_i$ denotes the height of the $i$'th soldier in the first line. In the third line there are numbers $y_1,y_2,…,y_n$, $1 ≤ y_i ≤ 100\,000$; $y_i$ denotes the height of the $i$’th 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.

Example

Input

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

Output

3
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.