In addition to teaching at the university, Professor R. participates in programming competitions as a task creator. Today, Professor R. had a bright idea – he decided to make a rating list of the universities that participated in the quarterfinal competitions in sports programming held in the city of Cyberslavl. To calculate the rating, the professor came up with a formula:
where $$$R$$$ is the overall rating, $$$R_0$$$ is the rating of this year, $$$R_1$$$ is the rating of the previous year, $$$R_2$$$ is the rating from two years ago. The university's rating at the end of the year is calculated according to the formula:
where $$$R_y$$$ is the university's rating for the year, $$$k$$$ is the number of tasks solved by the strongest university team in the quarterfinals (the team that solved the most problems is considered the strongest, if the number of solved tasks are equal, the team that took the highest place is considered the strongest), $$$a, b, c$$$ – bonus points for the places received by the first, second and third teams of the university in the quarterfinals (if there were no second and third teams, they add 0 points to the rating).
Bonus points for places in the quarterfinals are awarded as follows: 50th place earns the team 1 point, 49th – 2 points, etc. in increments of 1 to 11th place inclusive, which thus "costs" 40 points. Next, the 10th place earns 42 points, the 9th – 44, the 8th – 46, the 7th – 48, the 6th – 50, the 5th – 53, the 4th – 57, the 3rd – 62, the 2nd – 68 and, finally, the 1st – 80 points.
Before applying this formula to all universities, Professor R. decided to calculate the rating for the Cyberslavl State University. It turned out to be not so easy – every year many teams come from the university, and the professor does not want to look for them in the table. So he asks you to help him and write a program that, based on the results of the last three quarterfinals, helps to calculate the university's rating.
The first line contains the number $$$N_0$$$ $$$(1 \le N_0 \le 20)$$$ – the number of teams of the Cyberslavl State University that participated in the quarterfinals this year.
This is followed by $$$N_0$$$ lines describing the results of the teams in the quarterfinals this year. The result of each team is set in the format $$$name~problems~place$$$, where $$$name$$$ is the name of the team (a line of no more than 50 characters in length, consisting of numbers, capital and lowercase Latin letters, as well as underscores), $$$ploblems$$$ $$$(0 \le problems \le 15)$$$ – the number of tasks solved by the team, $$$place$$$ $$$(1 \le place \le 100)$$$ – the place taken by the team.
The next line contains the number $$$N_1$$$ $$$(1 \le N_1 \le 20)$$$ – the number of teams of the Cyberslavl State University that participated in the quarterfinals last year.
This is followed by $$$N_1$$$ lines in a format similar to the results of the current year.
The next line contains the number $$$N_2$$$ $$$(1 \le N_2 \le 20)$$$ – the number of teams from the Cyberslavl State University that participated in the quarterfinals two years ago.
Then $$$N_2$$$ lines in a format similar to the results of the current year.
It is guaranteed that all the data is correct and the teams that took higher places solved no less problems than the teams that took lower places, and there were no teams that took the same place.
In a single line, print a number – the rating of the Cyberslavl State University.
7O0 10 1mmm 7 7MAD_DOS 4 20OsuzhdayCPlusPlus 4 18zero_divisor 4 23Lemon 5 123pixels 5 136STACKMANS 6 11xiaococka 6 7MMM 8 1Lemon 6 12AmateraSU 6 8Four_dimensional_cat 4 199Yess_we_can 13 1chill_owls 9 5STACKmans 5 17MPM 5 18Cherniy_zhisny_vazhno 4 23Four_dimensional_cat 6 14HuRMa 7 9Dead_Inside_Team 7 11LigaDravena 9 4
3190
1Adyghe_SU_1 3 732Adyghe_SU_1 6 36Adyghe_SU_2 3 651Adyghe_SU_1 5 19
618
Consider the second example.
One team took part in the quarterfinals this year, it solved 3 problems and did not receive bonus points, hence $$$R_0 = 30$$$. In the quarterfinals last year, the best team solved 6 problems and took 36-th place, received 15 bonus points, hence $$$R_1 = 60 + 2 \cdot 15 = 90$$$. Two years ago one team that participated in the quarterfinals solved 5 problems and received 32 bonus points, hence $$$R_2 = 50 + 2 \cdot 32 = 114$$$. Total $$$R = 4 \cdot R_0 + 3 \cdot R_1 + 2 \cdot R_2 = 4 \cdot 30 + 3 \cdot 90 + 2 \cdot 114 = 618$$$.