Problem 1: Draw Fixing, (K Narayan Kumar, CMI)
Siruseri happens to have some of the best chess players in India and one of the most important events in the Siruseri sports calendar is the Annual Chess Challenge where teams from Siruseri and Navalur compete.
The event is held alternately at Siruseri and Navalur. This year the tournament is to be held at Sirseri and the Secretary of the Siruseri, who is up for re-election this year, would like to ensure a win for Siruseri. Since starting a war or accusing Navalur of possessing weapons of mass destruction is beyond his scope (and he also has a few more brain cells than the average leader of the free world) he decided to do something clever. Draw Fixing!!
To understand what he intended to do, we need to know how the Chess Challege match is organised. Both Siruseri and Navalur are required to send N players. Every player from both teams participates in exactly one game (and so exactly N games are played). The host is expected to draw lots to determine who plays who. Our secretary plans to fix this draw so that the pairings are exactly as he wants them to be.
Each chess player has a ELO rating indicating how good he is. The higher the rating the better the player. The secretary knows the rating of each of the players in the Siruseri and Navalur teams and he would like to pair them up so that the number of pairs in which the Siruseri player has a higher ELO rating is maximised.
For example, suppose that N is 4 and the ratings of the players are as below:
Siruseri Team | ELO Rating | Navalur Team | ELO Rating |
Player 1 | 1873 | Player 1 | 2450 |
Player 2 | 2134 | Player 2 | 1860 |
Player 3 | 1900 | Player 3 | 1700 |
Player 4 | 1600 | Player 4 | 2120 |
Then the secretary can arrange for Siruseri to have the higher rating in 3 out of 4 games. He can do this, for example, by pairing them as (1,2), (2,4), (3,3) and (4,1), where (i,j) means Player i from Siruseri plays Player j from Navalur. This is the best he can do as no player from Siruseri can beat Player 1 from Navalur.
Your task is help the secretary to find a pairing that maximises the number of pairs with higher rating for Siruseri.
Input format
The first line of the input contains a single integer N, denoting the number of players in each team. The next N lines (lines 2 through N+1) list the ratings of the N players in the Siruseri team and the N following lines (lines N+2 through 2N+1) denote the ratings of the players in the Navalur team.
Output format
The first line of the output is an integer N (0 ≤ N ≤ N) representing the number of pairs where the Siruseri player has a higher rating in the optimal pairing. This should be followed by N lines, each containing an integer ni indicating the player chosen from the Navalur team to play against the ith player from Siruseri.
Test Data
You may assume that 1 ≤ N ≤ 50000. Further you may assume that in 50% of the inputs N ≤ 5000.
Example:
We illustrate the input and output format using the example above.
Sample input
4 1873 2134 1900 1600 2450 1860 1700 2120
Sample output
3 2 4 3 1
Test data: