Release Leaderboard

easy sorting strings 1000 ms · 256 MB

Release Leaderboard

At the end of each quarter, the SRE team ranks every service for the release report. Each service has a name, a count of incidents during the quarter, and an uptime percentage measured to three decimal places.

Order the services from most to least reliable: fewest incidents first; among services with the same incident count, higher uptime first; among services tied on both incidents and uptime, alphabetically by name. Uptime is given as a decimal with exactly three digits after the point — compare it exactly (for example by scaling it to an integer), not as a rounded floating-point value, since naive float handling can turn genuinely different uptimes into accidental ties or get the order wrong.

Services that are tied on both incident count and uptime (name does not matter for this part — it only breaks the tie for display order) share the same rank. The next service whose incidents or uptime differ gets the rank equal to its 1-indexed position in the ordering, so ranks can skip numbers: 1, 2, 2, 4, 5, 5, 5, 8, ....

Input

The first line contains a single integer n (1 ≤ n ≤ 2·10^5) — the number of services.

Each of the next n lines describes one service with three space-separated fields:

  • name — 1 to 20 lowercase English letters and digits. Names are not guaranteed to be distinct.
  • incidents — an integer, 0 ≤ incidents ≤ 10^6.
  • uptime — a decimal number with exactly three digits after the decimal point, written with no leading zeros in the integer part (except the integer part 0 itself), satisfying 0.000 ≤ uptime ≤ 100.000.

Output

Print n lines, the services in leaderboard order, each as:

name incidents uptime rank

Print uptime exactly as it appeared in the input.

Notes

In the first example, beta has the fewest incidents (0) and comes first, then delta (1 incident). alpha and gamma both have 2 incidents and 99.900 uptime, so they tie for rank 3 (ordered alphabetically between themselves), and since no other service follows, rank 4 never appears.

Example 1

Input

4
alpha 2 99.900
beta 0 99.990
gamma 2 99.900
delta 1 99.500

Output

beta 0 99.990 1
delta 1 99.500 2
alpha 2 99.900 3
gamma 2 99.900 3

Example 2

Input

1
svc1 5 87.123

Output

svc1 5 87.123 1

Hints · reveal one at a time if you're stuck

Hint 1

Uptime values always have exactly three digits after the point, so what integer could you turn each one into to compare them exactly? Which key order gives the required ranking?

Hint 2

Sort by incidents ascending, then uptime descending, then name ascending, and make one pass to assign ranks. A tied block should carry the rank of its first position, so the next distinct service is numbered by its position in the whole order, not by how many groups came before.

report an issue Prefer your own editor? sooks prep 71 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.