Under construction

Still being built. Things may change

FIBA

Time limit1sMemory limit1024 MB

Summary
Given round-robin game scores for N teams, find Croatia's points, the first-round winner, and the points the top K teams carry into round two.
Level

Easy3 of 10

Topics
Simulation, Implementation, Sorting
Solved
No attempts yet

Problem

At the first round of a basketball world championship, NN teams take part. The teams are numbered from 1 to NN. The first round is a round robin: every team plays exactly one game against each of the other teams. A game result is given as the score of the team with the smaller number, then the score of the team with the larger number. The team that scores more points wins. A win earns 2 points and a loss earns 1 point. Draws are not possible.

Croatia also takes part in the first round, with number HH. Find how many points Croatia earned in the first round.

The winner of the first round is the team with the most points across all of its games. If several teams share the most points, the winner is the one among them that scored the most points in total during the first round. The winner can always be determined by one of these two rules. Find the number of the winner of the first round.

The top KK teams in the first round standings advance to the second round, meaning the KK teams with the most points in the first round. If two or more teams have the same number of points, the team that scored more points ranks higher. Choosing the top KK teams is always possible.

Teams that advance carry over only the points they earned against other advancing teams. Points earned against teams that did not advance are discarded. Find the total number of points the teams carry over into the second round.

Input

The first line contains three natural numbers NN, KK, and HH (3≤K<N≤253 \le K < N \le 25, H≤NH \le N), as stated in the problem.

The first round results are given in this order. First come the results of team 1 against all teams with larger numbers, then the results of team 2 against all teams with larger numbers, and so on up to team N−1N-1. Each line contains two integers KiK_i and KjK_j (0≤Ki,Kj≤1000 \le K_i, K_j \le 100), where i=1,…,N−1i = 1, \ldots, N-1 and j=i+1,…,Nj = i+1, \ldots, N. Here KiK_i is the score of team ii and KjK_j is the score of team jj in that game.

Output

Print the number of points Croatia earned in the first round on the first line.

Print the number of the first round winner on the second line.

Print the total number of points the teams carried over into the second round on the third line.

Hint

In the first sample, four teams take part and three advance to the second round. The first round results are T1 (Croatia):T2 = 4:7, T1:T3 = 8:2, T1:T4 = 5:2, T2:T3 = 7:1, T2:T4 = 6:2, and T3:T4 = 3:7. After the first round, T2 is first with 6 points, T1 (Croatia) is second with 5 points, T4 is third with 4 points, and T3 is last with 3 points.

The teams T2, T1, and T4 advance to the second round. Each of them carries over the points it earned against these three teams, while the points earned against T3 are removed. So T1 carries 3 points, T2 carries 4 points, and T4 carries 2 points. The total carried over is 9 points.

Examples3

  1. Example 1

    Input
    4 3 1
    4 7
    8 2
    5 2
    7 1
    6 2
    3 7
    
    Expected output
    5
    2
    9
    
  2. Example 2

    Input
    6 4 4
    40 50
    14 98
    63 37
    34 77
    39 73
    23 3
    36 65
    15 23
    41 80
    23 71
    1 68
    58 70
    49 40
    33 43
    72 65
    
    Expected output
    8
    6
    18
    
  3. Example 3

    Input
    6 3 6
    33 92
    9 89
    63 30
    15 10
    22 2
    100 90
    8 84
    2 93
    96 33
    80 9
    42 18
    0 55
    90 44
    46 63
    68 85
    
    Expected output
    8
    3
    9