This page is still under construction.

Parts of this page are still being built. What you see may change.

Pinball Ranking

Interview

Time limit1sMemory limit128 MB

Summary
Given scores in play order, compute each game's rank as one plus the number of earlier-or-later scores strictly above it, then output the average rank as a reduced fraction.
Level

Medium5 of 10

Topics
Binary search, Sorting, Array, Implementation
Solved
No attempts yet

Problem

Pinball is an arcade game in which a player controls a silver ball with flippers, aiming to accumulate as many points as possible. At the end of each game, the player's score and rank are shown on the screen.

The score is the value achieved in the game just ended, an integer between 00 and 10910^9. The rank is shown in the form "rr of nn", where nn is the total number of games ever played on the machine and rr is the position of this game's score within that whole set of games.

More precisely, rr is one greater than the number of games whose score is strictly higher than that of the game just ended.

Input

Implement the pinball machine's ranking algorithm.

The first line contains a positive integer tt, the total number of games ever played on the machine. Each of the following tt lines contains the score of one game, given in chronological order.

  • 1≤t≤1000001 \le t \le 100000
  • 0≤score≤1090 \le \text{score} \le 10^9
  • At least one test case has t≤100t \le 100; every test case has t≤100000t \le 100000.

Output

Output the average of the ranks rr displayed after the games, written as a reduced fraction p/qp/q.

Formally, let SS be the sum of all displayed ranks and tt the total number of games. Print the average S/tS/t in lowest terms as "p/qp/q". The denominator qq is always positive, and even when the average is an integer you must keep the denominator, printing it as "p/1p/1" (for example, an average of 22 is printed as 2/1).

Note

For example, if the scores are 100,200,150,170,50100, 200, 150, 170, 50 in order, the pinball screen displays the following ranks after each game:

1 of 1
1 of 2
2 of 3
2 of 4
5 of 5

So the displayed ranks are 1,1,2,2,51, 1, 2, 2, 5, and their average is (1+1+2+2+5)/5=11/5(1+1+2+2+5)/5 = 11/5.

Equal scores do not exceed one another, so tied games never push each other down in the ranking.

Examples4

  1. Example 1

    Input
    5
    100
    200
    150
    170
    50
    
    Expected output
    11/5
    
  2. Example 2

    Input
    1
    500
    
    Expected output
    1/1
    
  3. Example 3

    Input
    3
    5
    5
    5
    
    Expected output
    1/1
    
  4. Example 4

    Input
    4
    40
    30
    20
    10
    
    Expected output
    5/2