시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 256 MB111100.000%

문제

Pang has graduated from college $3$ years and he really misses the time he spent with ICPC (Interspecies Collegiate Pokemon Camp).\\

There are $10$ problems in one contest in ICPC. $n$ participating teams have $300$ minutes to solve them. After the contest, teams are ranked according to the most problems solved.  Teams who 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 submittal of the first accepted run plus 20 penalty minutes for every previously rejected run for that problem.  There is no time consumed for a problem that is not solved. If two teams tie, their solution time lists are calculated. A team's solution time list is a list consisting of solution times of all problems solved by that team, sorted in descending order. The solution time of one problem is the time elapsed from the beginning of the contest to the submittal of the first accepted run of that problem. (We do not add a penalty for the solution time.) The team with a lexicographically smaller solution time list has a better rank. A list $(a_1, \ldots, a_k)$ is lexicographically smaller than $(b_1,\ldots,b_k)$ if there exists an integer $i\in [1,k]$ such that $a_i<b_i$ and $a_j=b_j$ for all integers $j\in [1,i)$. If teams still tie, Pang's team is assumed to have a better rank.

After determining the rank, prizes will be awarded. Initially, a team with rank $r$ will get $\lfloor 5000/r\rfloor$ happiness. Then medals are awarded: Teams with rank $1$ to $\lfloor n/10\rfloor$ are awarded gold medal. The happiness of receiving a gold medal is $1200$. Teams with rank $\lfloor n/10\rfloor+1$ to $3\lfloor n/10\rfloor$ are awarded silver medal. The happiness of receiving a silver medal is $800$. Teams with rank $3\lfloor n/10\rfloor+1$ to $6\lfloor n/10\rfloor$ are awarded bronze medal. The happiness of receiving a bronze medal is $400$. In addition to medals, for each problem, the team solved it first gets $800$ happiness. The team with at least one solution and the smallest solution time overall teams and all problems gets an extra $700$ happiness. The team with at least one solution and the largest solution time overall teams and all problems gets an extra $500$ happiness. In the case of a tie, Pang's team can always get happiness.

There were $n$ teams in a contest Pang participated. He remembers all the submissions (time and verdict) of all other teams. For each problem, he also remembers if he knew the solution to that problem and the number of rejected runs and times he needed to solve it.

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

입력

The first line contains an integer $n$ denoting the number of teams ($10\le n\le 300$, $n$ is a multiple of $10$).

Each of the next $n-1$ lines describes one team and contains the statuses of the $10$ problems. For each problem, if it is not solved by the team, the status contains a single character "-". Otherwise, the status contains two integers $t$ and $w$ separated by a single space denoting the solution time and the number of rejected runs before the solution time ($1\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 contains a single character "-". Otherwise, the status contains two integers $x$ and $y$ separated by a single space denoting the required time and the number of rejected runs before Pang could solve it ($1\le x\le 300, 0\le y\le 10$). Statuses of different problems are separated by ",".

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

출력

Output one integer --- the maximum happiness.

예제 입력 1

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,-,-


예제 출력 1

1800