Under construction

Still being built. Things may change

Contest Ranking

Time limit1sMemory limit256 MB

Summary
Parse each team per-problem records, sum the weights of solved problems, and print teams ranked by points with ties sharing a rank.
Level

Easy3 of 10

Topics
Implementation, Sorting
Solved
No attempts yet

Problem

The contest system PC^2 was written for contests where each solved problem scores 1 point and time breaks ties. To use it in a contest where problems carry different weights, a program has to read the records PC^2 left behind and apply a different rule.

You are given the records of several contests. Each contest comes with the points every problem is worth and one submission record per team. Rank the teams by the rules of the contest they competed in.

Input

The input holds several contests. The first line of each contest has one integer PP, the number of problems (0<P≤200 < P \le 20). A line holding 0 ends the input.

The second line has PP positive integers separated by spaces, one per problem. They give the points for the first problem, the second problem, and so on.

The third line of each contest has one integer TT, the number of teams taking part (0<T≤500 < T \le 50).

Then come TT lines, one team per line. A line starts with the team name. The name may contain spaces but no comma, and a comma ends it. After the name comes one record per problem, records separated by commas. The records follow the order of the points on the second line, the first problem first.

Each record has one integer, a slash character /, and then either another integer or a - character. Read a record like this:

  • The first integer is how many submissions the team made for that problem. It is 0 or more.
  • If the slash is followed by -, the team did not solve the problem and scores no points for it.
  • If the slash is followed by an integer, which is 0 or more, the team solved the problem. The number is how many minutes into the contest the successful submission arrived.

Output

For each contest, start the output with a line holding Contest N, where NN is the number of the contest. The first contest in the input is 1, and contests are numbered in the order they appear.

Then print one line per team with the rank, the team name and the points scored, separated by single spaces. List the teams in ascending order of rank.

A team with more points comes first. Teams with equal points share a rank and are printed in alphabetical order of name, ignoring case. If two names are equal once case is ignored, print them in alphabetical order of the original name. The rank of the team after a shared rank skips by the number of teams ahead of it. For example, when two teams share rank 1, the next team is rank 3.

Do not print a blank line between contests.

Examples2

  1. Example 1

    Input
    5
    1 1 2 3 10
    4
    Happy Fred's team,2/5,3/27,1/106,8/262,3/-
    Team 67,0/-,0/-,2/135,4/218,12/-
    Astrix,0/-,0/-,0/-,0/-,17/299
    apple pie,0/-,0/-,0/-,0/-,0/-
    0
    
    Expected output
    Contest 1
    1 Astrix 10
    2 Happy Fred's team 7
    3 Team 67 5
    4 apple pie 0
    
  2. Example 2

    Input
    2
    5 10
    3
    alpha,1/3,0/-
    Beta,0/-,1/4
    gamma,1/1,1/2
    1
    7
    2
    Zed,1/0
    alpha,0/-
    0
    
    Expected output
    Contest 1
    1 gamma 15
    2 Beta 10
    3 alpha 5
    Contest 2
    1 Zed 7
    2 alpha 0