#P10223. Eurokod Code Competition Scoring

    ID: 12219 Type: Default 1000ms 256MiB

Eurokod Code Competition Scoring

Eurokod Code Competition Scoring

This problem is from the Eurokod Code Competition. There are \( n \) contestants numbered from \( 1 \) to \( n \). Each contestant submits code which is evaluated by a panel of computer scientists consisting of one leader and several other members.

Leader Scoring:

The leader sorts the codes in descending order of beauty according to his own opinion. The most beautiful code receives \( n \) points, the second one \( n-1 \) points, and so on. In formula, if a code is ranked \( i^{th} \), its leader score is \( n-i+1 \).

Other Members Scoring:

Each of the other members votes for the code they think is the most beautiful. After collecting all the votes (exactly \( n-1 \) votes), the codes are sorted by the number of votes received. The code with the highest vote count receives \( n \) points, the second highest \( n-1 \) points, and so on. In case of a tie in vote counts, the code with the smaller contestant number is ranked earlier.

Total Score & Ranking:

The total score of a code is the sum of the leader score and the vote score. Your task is to output the contestant numbers sorted in descending order by their total score. In case of a tie in total score, the code with the higher vote score should come first. If there is still a tie, output the smaller contestant number first.

Note that all formulas are in \( \LaTeX \) format.

inputFormat

The first line contains an integer \( n \) (the number of contestants).

The second line contains \( n \) distinct integers representing the leader's ranking order of the contestants. The first integer is the contestant with the most beautiful code according to the leader, the second is the next, and so on.

The third line contains \( n-1 \) integers, each representing a vote from the other members. Each vote is an integer between \( 1 \) and \( n \) (inclusive).

outputFormat

Output a single line containing the contestant numbers sorted in descending order by their total score. If two contestants have the same total score, the one with the higher vote score comes first. If there is still a tie, output the smaller contestant number first.

sample

5
3 1 2 5 4
1 2 1 3
1 3 2 4 5