This page is still under construction.

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

Happiness

Time limit5sMemory limit256 MB

Summary
Given other teams' submission data, choose the order Pang solves his known problems (each takes a fixed time plus 20 penalty per rejection) to maximize his total happiness from ranking, medals, and special first/last-solve bonuses.
Level

Hard8 of 10

Topics
Brute force, Sorting, Simulation, Implementation
Solved
No attempts yet

Problem

Pang graduated from college 33 years ago and really misses the time he spent with ICPC (Interspecies Collegiate Pokemon Camp).

A contest in ICPC has 1010 problems. nn participating teams have 300300 minutes to solve them. After the contest, teams are ranked by the number of problems solved. Teams that solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submission of the first accepted run plus 2020 penalty minutes for every previously rejected run for that problem. No time is consumed for a problem that is not solved. If two teams tie, their solution time lists are computed. A team's solution time list is the list of the solution times of all problems solved by that team, sorted in descending order. The solution time of a problem is the time elapsed from the beginning of the contest to the submission of the first accepted run of that problem. (No penalty is added to the solution time.) The team with the lexicographically smaller solution time list has the better rank. A list (a1,…,ak)(a_1, \ldots, a_k) is lexicographically smaller than (b1,…,bk)(b_1,\ldots,b_k) if there is an integer i∈[1,k]i\in [1,k] such that ai<bia_i<b_i and aj=bja_j=b_j for every integer j∈[1,i)j\in [1,i). If teams still tie, Pang's team is considered to have the better rank.

After the ranks are determined, prizes are awarded. Initially, a team with rank rr gets ⌊5000/r⌋\lfloor 5000/r\rfloor happiness. Then medals are awarded. Teams with rank 11 to ⌊n/10⌋\lfloor n/10\rfloor get a gold medal. The happiness of receiving a gold medal is 12001200. Teams with rank ⌊n/10⌋+1\lfloor n/10\rfloor+1 to 3⌊n/10⌋3\lfloor n/10\rfloor get a silver medal. The happiness of receiving a silver medal is 800800. Teams with rank 3⌊n/10⌋+13\lfloor n/10\rfloor+1 to 6⌊n/10⌋6\lfloor n/10\rfloor get a bronze medal. The happiness of receiving a bronze medal is 400400. Besides medals, for each problem, the team that solved it first gets 800800 happiness. The team that has at least one solution and the smallest solution time among all teams and all problems gets an extra 700700 happiness. The team that has at least one solution and the largest solution time among all teams and all problems gets an extra 500500 happiness. In case of a tie, Pang's team always gets the happiness.

There were nn teams in the contest Pang participated in. He remembers every submission (time and verdict) of every other team. For each problem, he also remembers whether he knew how to solve it, and the number of rejected runs and the time he needed to solve it.

If Pang solved the problems in the wisest order, what is the maximum happiness he could get? Pang cannot solve any problem after 300300 minutes from the beginning of the contest (he can solve a problem at exactly 300 minutes). Once Pang solves a problem, he must submit it immediately and solve another one. He cannot postpone his submission to get the last submission happiness.

Input

The first line contains an integer nn, the number of teams (10≤n≤30010\le n\le 300, nn is a multiple of 1010).

Each of the next n−1n-1 lines describes one team and contains the statuses of the 1010 problems. For each problem, if it is not solved by the team, the status is a single character "-". Otherwise, the status contains two integers tt and ww separated by a single space, the solution time and the number of rejected runs before the solution time (1≤t≤300,0≤w≤101\le t\le 300, 0\le w\le 10). Statuses of different problems are separated by ",".

The last line describes Pang's team. For each problem, if Pang did not know how to solve it, the status is a single character "-". Otherwise, the status contains two integers xx and yy separated by a single space, the time he needs and the number of rejected runs before he can solve it (1≤x≤300,0≤y≤101\le x\le 300, 0\le y\le 10). Statuses of different problems are separated by ",".

There are no extra spaces or other characters in the statuses of Pang and the other teams.

Output

Output one integer: the maximum happiness.

Examples1

  1. Example 1

    Input
    10
    233 1,-,-,7 7,257 4,173 5,117 1,-,-,85 3
    -,231 0,167 0,257 7,-,-,122 4,283 0,215 4,-
    41 1,-,290 8,-,-,-,-,246 7,120 3,184 9
    142 8,243 7,69 0,-,41 9,-,279 1,264 4,-,74 9
    53 8,-,187 9,60 1,48 8,99 10,-,-,55 7,259 5
    250 0,-,-,-,166 0,16 3,-,82 4,73 0,184 3
    -,-,-,-,105 3,-,-,-,152 4,-
    -,84 5,98 8,-,120 8,241 3,94 1,-,28 7,109 8
    280 6,246 5,58 9,-,-,-,-,-,-,-
    38 10,-,227 10,187 9,182 1,-,203 9,254 7,-,-
    
    Expected output
    1800