DCEPC802 - Medal Tally

no tags 

You are the statistician for the 2012 London Olympics. Your job is to keep track of medals won by different countries and broadcast the medal tally to viewers all around the world. You will be given the data of the medals won by different countries in no particular order. Output the medal tally. The convention to be used is sort by the number of gold medals a country has earned. In the event of a tie in the number of gold medals, the number of silver medals is taken into consideration, and then the number of bronze medals.

Input

First line contains 2 integers, D (number of lines = number of medals) and N (the number of countries participating in Olympics, 1 index based).

Next D lines are of the form “a b” (quotes for clarity). ‘a’ is the country number (1 ≤ a ≤ N) and ‘b’ takes 3 possible values (G for a gold medal, S for a silver medal and B for a bronze medal). 

Output

First line should contain the 5 space separated strings: “Country Gold Silver Bronze Total” (Total –> total number of medals won by a country).

Next you should output the medal tally in the form of the strings described above, one country per line.

Note however that you should output only those countries in the tally which has at least 1 medal from the Olympics. In case where any countries obtain same number of gold, silver and bronze medal, place that country above which has lower country index. See sample output for more clarification.

Constraints

1 ≤ D ≤ 1000

1 ≤ N ≤ 1000

Example

Input:
10 5
2 G
3 S
2 B
5 G
4 B
4 B
5 B
2 G
2 B
2 S

Output:
Country Gold Silver Bronze Total
2 2 1 2 5
5 1 0 1 2
3 0 1 0 1
4 0 0 2 2


Added by:dce coders
Date:2012-08-19
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:Own Problem