HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


50476 - Meditation

Guest
• Discussion of problem (1)

Section problems

• 50642 - Draft board
• 50646 - The more the better
• 51153 - A+B.
• Problem 1
• 50252 - Birthday
• 50245 - Santa Gifts
• 50239 - Eating cheese
• 50276 - Nice Floor
• 50476 - Meditation
• 50551 - Camelot
• 50608 - Gangsters
• 50623 - Rectangles
• 50624 - Simple problem
• 50627 - Area of a polygon
• 50629 - Minuses
• 50632 - Again numbers game
• 50645 - Line

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
National Olympiads in Montenegro. Difficulty Beta

Meditation

In Je'daii Order Academy a meditation is conducted in a special room on daily basis. The masters come first, and then knights, followed by the rookies. Regardless of the time when a master arrives, he always stands before the knights and the rookies but not before other masters. When a knight arrives he stands in line before all the rookies but after other knights who are lined up. Žarko is a new rookie and would like to know exact schedule based on the signup sheet.

Input: The first line contains an integer N (0 < N <= 100 000) – number of Je'daiis. The second line contains the IDs of the Je'daiis separated by a space. Each ID consists of a letter m (master), k (knight) or p (rookie) and a number. Ex: k12, m3, p111. The IDs are unique and it contains at most 10 characters.

Output: Print the IDs of ordered for the mediation separated by a space.

Example:

 

Test case 1

Test case 2

Test case 3

Input

3

m1 k1 p1

7

p4 p2 p3 m1 k2 p1 k1

5

k2 m2 m1 p1 k1

Output

m1 k1 p1

m1 k2 k1 p4 p2 p3 p1

m2 m1 k2 k1 p1

Explanation

No need to change

m1 goes before all; k2 is ahead of all rookies (p4, p2 and

p3) but behind m1. k1 is ahead of all rookies (p4, p2, p3 and p1) is behind k2. No reordering of  rookies is needed

m2, m1 before k2

k1 before p1.

 

Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.

www.contester.ru