Under construction

Still being built. Things may change

ShaShka (ШАШКА)

Time limit2sMemory limit1024 MB

Summary
Update Elo ratings after each game in input order, then print all players by rating descending and surname ascending.
Level

Easy3 of 10

Topics
Simulation, Hash map, Sorting
Solved
No attempts yet

Statement

Petr is in charge of rating calculations for the Chess Association of Chess Players of the Antarctic Conglomerate (ШАШКА). The association uses Elo ratings, and a rating is a non-negative integer. After each game, ratings are recalculated with the following rules:

RA′=RA+15⋅(SA−EA)R_A' = R_A + 15 \cdot (S_A - E_A)

EA=11+10RB−RA400E_A = \frac{1}{1 + 10^{\frac{R_B - R_A}{400}}}

Here RAR_A and RBR_B are the ratings of players A and B before the game, SAS_A is the score A earned in the game (0 for a loss, 0.5 for a draw, 1 for a win), and RA′R_A' is the new rating of A. The new rating is rounded down to the nearest integer. If it becomes negative, it is set to zero.

Input

The first line contains one integer nn (2≤n≤10002 \le n \le 1000). Each of the next nn lines contains a non-negative integer rir_i (ri≤4000r_i \le 4000), the rating of the ii-th player before the tournament, and the player's surname, separated by one space. A surname consists of uppercase and lowercase Latin letters and is at most 50 characters long. Surnames are non-empty and all different.

The next line contains the number of games mm (0≤m≤10000 \le m \le 1000). Each of the next mm lines contains the surnames of the first and second players, followed by an integer xx: x=1x = 1 means the first player won, x=2x = 2 means the second player won, and x=0x = 0 means a draw. Games are listed in the order they were played.

Output

Print the players in decreasing order of rating. If two ratings are equal, the player whose surname is lexicographically smaller comes first. Use the same format as the input: each line contains the rating and the surname separated by one space.

Examples3

  1. Example 1

    Input
    4
    3040 John
    3030 Jon
    3020 Juan
    3010 Ivan
    3
    Ivan John 1
    Jon Ivan 2
    Ivan Juan 1
    
    Expected output
    3032 Ivan
    3031 John
    3022 Jon
    3012 Juan
    
  2. Example 2

    Input
    4
    3040 John
    3030 Jon
    3020 Juan
    3010 Ivan
    3
    Ivan Juan 1
    Jon Ivan 2
    Ivan John 1
    
    Expected output
    3032 John
    3031 Ivan
    3022 Jon
    3012 Juan
    
  3. Example 3

    Input
    4
    3011 John
    2995 Jon
    3004 Juan
    3002 Ivan
    3
    Ivan Juan 2
    Jon Ivan 0
    Ivan John 0
    
    Expected output
    3011 Juan
    3010 John
    2994 Ivan
    2994 Jon