Training Site
Sideways banner

STL Queue

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 256 megabytes
Time limit: 1.0 seconds

You are the proud owner of the sandwich giant Sourdough Toasties & Lattes (STL). You are about to open your shop and you see there are already N customers queuing up outside waiting to get their hands on a sandwich. However, different customers will have different membership tiers. There are three membership tiers: Bronze, Silver and Gold. Bronze is the lowest tier and Gold is the highest tier. The main perk is that the higher your tier, the earlier you eat! That is, if person A has a higher membership tier than person B, then person A should be served before person B. However, if two people are in the same tier, then whoever is further up in the queue should be served first.

Given the membership of everyone in the queue, find out what order you have to serve people in!

Input

  • The first line of input will contain N, the number of people waiting in line.
  • The next N lines will contain the status level of the people in the queue. The i^\text{th} of these lines has the status of the i^\text{th} person in line. This will be either "B", "S" or "G" (without the quotes), representing Bronze, Silver or Gold tier respectively.

Output

Assume the people are numbered from 1 to N, corresponding to their position in the queue. Print out the order in which people should get served, with one number on each line.

Constraints

  • 1 \le N \le 100{,}000

Subtasks

  • Subtask 1 (+15%): N \le 3
  • Subtask 2 (+27%): Every person has either silver or gold status
  • Subtask 3 (+58%): No additional constraints

Sample Explanations

Sample 1

In the first sample, we have three people waiting in the queue. The person in position 1 has a silver membership, the person in position 2 has a bronze membership and the person in position 3 has a gold membership. We want to serve them in order of their memberships (gold first, silver second, bronze last) so we serve the person in position 3 first, then the person in position 1, then the person in position 2.

Sample 2

In the second sample, we have six people waiting in the queue. Their statuses, in the order they are in the queue, are: Bronze, Gold, Bronze, Silver, Silver, Gold. Note that for person 2 and person 6, although they have the same tier, person 2 was served before person 6, because person 2 was closer to the front of the queue.

  • Sample Input 1

    3
    S
    B
    G
    

    Sample Output 1

    3
    1
    2
    
  • Sample Input 2

    6
    B
    G
    B
    S
    S
    G
    

    Sample Output 2

    2
    6
    4
    5
    1
    3