Under construction

Still being built. Things may change

Championship

Interview

Time limit2sMemory limit1024 MB

Summary
Given N team names, output the team numbers in the table order that makes the concatenated name string lexicographically smallest.
Level

Medium4 of 10

Topics
Sorting, String
Solved
No attempts yet

Statement

A football league in a large but rather cold northern country has NN teams competing against each other. Each team has its own name that reflects the spirit and history of the team. Each team has a fan club whose members follow every match and support the team through both great wins and painful losses. At any moment, each fan can name the squad, the goals of each player, the goals scored and conceded, the schedule of the remaining matches, and the result of any match already played.

Every fan also knows the current standings. Each fan knows where every team stands, and can say which team is third and which is eighth at any time.

One morning, after a win by his favorite club, Ivan woke up and realized he could not remember the table at all. He only remembered the names of all teams in the championship. Over a strong cup of coffee he recalled a curious fact he had noticed while arguing about the table with other fans. If the team names are written one after another in the order they appear in the table, the resulting string is lexicographically smaller than the string obtained from any other order. For example, if only "Dinamo-Kiev", "Dinamo-Moskva" and "Amkar" took part, Ivan could easily say that Amkar is first, Dinamo-Kiev is second, and Dinamo-Moskva is third. But there are other teams too, and Ivan could not reconstruct the order. He asked you for help.

Input

The first line contains one integer NN (1≤N≤10 0001 \le N \le 10\,000), the number of teams. The next NN lines list the team names. Each name is a string of lowercase Latin letters with length at most 20.

Output

Print NN lines. Each line contains the number of the team that occupies the corresponding position. The team numbers in the answer must not repeat. If there are several answers, you may print any of them. Teams are numbered from 1 in the order they appear in the input.

Examples1

  1. Example 1

    Input
    3
    dinamom
    amkar
    dinamok
    
    Expected output
    2
    3
    1