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

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.