409819: GYM103797 F Faulty Plan

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Faulty Plantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Vasconcelos is the best student in his class, but he is feeling very tired and does not want to go to university anymore. He got a doctor's note by breaking his feet, although it has expired and now he can't skip more classes without being punished.

He still wants to skip the maximum amount of classes, but his university has a strict policy on faulty points. It's considered that every student should love to go to classes even if it's just to stand still for five hours, and thus the students that don't appreciate classes are called faulty. To control them, the faulty point system was created. Each missed period gives a student $$$3$$$ faulty points. If, in one semester, a student hits $$$90$$$ total faulty points or $$$50$$$ faulty points in a same discipline, he's expelled.

Fortunately, to actually receive your faulty points, the professor has to report your absence. Most of the professors are too prehistoric or occupied for this (you can check their stories in other problems). As a matter of fact, there are only two professors that actually report absences. Since they are foreign, students often refer to them as the French and the Dutch professors.

Vasconcelos's classmates already tried convincing him to attend just these professor's classes, but the worst part for him is going to the university. If he already has to go to the university that day, he doesn't mind attending all classes during the day. That's why he decided to make his Faulty Plan. He has no faulty points, there are $$$80$$$ class days left and he'll make a plan to go to the university as little as possible without being expelled.

It's a little tricky to architect his plan because the professors change their weekly schedule all the time, thus your help is required. Your mission, if you choose to accept it, is to find the number of days Vasconcelos can skip class without being expelled.

Input

The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 80$$$) — the number of days when there are classes of the French or the Dutch professors.

Each of the next $$$N$$$ lines consists of integers $$$D$$$, $$$P_f$$$ and $$$P_d$$$ ($$$1 \leq D \leq 80$$$ and $$$0 \leq P_f, P_d \leq 10$$$) — the day and the number of periods the French and the Dutch professors lectures that day, respectively. The days will all be distinct and be given in ascending order.

Output

The maximum number of days Vasconcelos is able to skip class without being expelled.

ExamplesInput
3
1 0 10
2 0 10
3 0 10
Output
78
Input
3
1 6 5
2 5 6
3 5 5
Output
79

加入题单

算法标签: