P13944 [EC Final 2019] Happiness

Description

$\textit{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 $\textit{solution time list}$s 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

Input Format

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 $\textit{Pang}$'s team. For each problem, if $\textit{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 $\textit{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 $\textit{Pang}$ and other teams.

Output Format

Output one integer --- the maximum happiness.