Hide

Problem D
Margrethe 2.

/problems/dpop22.margrethe2/file/statement/en/img-0001.png
The royal monogram of Queen Margrethe 2.

Regents are distinguished from previous regents with the same name by a numbering scheme called the regnal number. In the Danish tradition, the regnal number is given by an Arabic numeral, followed by a full stop or period, “.”. Thus, Queen Margrethe 2. is the second of her name, and her predecessor has been retroactively equipped with “1.”.

A regnal number is used only when more than one regent have the same name. For instance, King Niels (1104–1134) was never followed by a king of the same name, and therefore is not styled “Niels 1.”. He’s just called “Niels”.

Some regents also have surnames such as “Sejr” (“Victory”) or “af Pommern” (“of Pomerania”). These appear after the regnal number, as in “Valdemar 4. Sejr” or “Erik 7. af Pommern”.

Regnal numbering starts with $1$.

Input

On the first line, the number $N$ of regents, where $1\leq N \leq 100$. Then follow $N$ lines, each with the name of a regent. Each of these lines consists of a single first name (without spaces), possibly followed by a last name (which may contain spaces). The letters are upper and lower case and taken from the Danish alphabet: A, B, C, $\ldots $, Z, Æ, Ø, Å.

Test groups

There are $4$ test groups:

Group

Points

Constraints

1

25

All names are “Christian” or “Frederik” and appear at least twice

2

24

All names are first names and appear at least twice

3

23

All names are first names

4

28

No constraints

Output

$N$ lines with the same regents in the same order as in the input, but with proper regnal numbers.

Sample Input 1 Sample Output 1
5
Christian
Christian
Frederik
Frederik
Christian
Christian 1.
Christian 2.
Frederik 1.
Frederik 2.
Christian 3.
Sample Input 2 Sample Output 2
7
Christian
Margrethe
Christian
Frederik
Christian
Frederik
Margrethe
Christian 1.
Margrethe 1.
Christian 2.
Frederik 1.
Christian 3.
Frederik 2.
Margrethe 2.
Sample Input 3 Sample Output 3
6
Christian
Hans
Christian
Frederik
Christian
Frederik
Christian 1.
Hans
Christian 2.
Frederik 1.
Christian 3.
Frederik 2.
Sample Input 4 Sample Output 4
53
Gorm
Harald Blåtand
Svend Tveskæg
Harald
Knud den Store
Hardeknud
Magnus den Gode
Svend Estridsen
Harald Hen
Knud den Hellige
Oluf Hunger
Erik Ejegod
Niels
Erik Emune
Erik Lam
Svend Grathe
Knud
Valdemar den Store
Knud
Valdemar Sejr
Erik Plovpenning
Abel
Christoffer
Erik Klipping
Erik Menved
Christoffer
Valdemar
Valdemar Atterdag
Oluf
Margrethe
Erik af Pommern
Christoffer af Bayern
Christian
Hans
Christian
Frederik
Christian
Frederik
Christian
Frederik
Christian
Frederik
Christian
Frederik
Christian
Frederik
Christian
Frederik
Christian
Frederik
Christian
Frederik
Margrethe
Gorm
Harald 1. Blåtand
Svend 1. Tveskæg
Harald 2.
Knud 1. den Store
Hardeknud
Magnus den Gode
Svend 2. Estridsen
Harald 3. Hen
Knud 2. den Hellige
Oluf 1. Hunger
Erik 1. Ejegod
Niels
Erik 2. Emune
Erik 3. Lam
Svend 3. Grathe
Knud 3.
Valdemar 1. den Store
Knud 4.
Valdemar 2. Sejr
Erik 4. Plovpenning
Abel
Christoffer 1.
Erik 5. Klipping
Erik 6. Menved
Christoffer 2.
Valdemar 3.
Valdemar 4. Atterdag
Oluf 2.
Margrethe 1.
Erik 7. af Pommern
Christoffer 3. af Bayern
Christian 1.
Hans
Christian 2.
Frederik 1.
Christian 3.
Frederik 2.
Christian 4.
Frederik 3.
Christian 5.
Frederik 4.
Christian 6.
Frederik 5.
Christian 7.
Frederik 6.
Christian 8.
Frederik 7.
Christian 9.
Frederik 8.
Christian 10.
Frederik 9.
Margrethe 2.

Please log in to submit a solution to this problem

Log in