Yash lives in the Delhi-NCR region. This year he went back home in Diwali holidays only to realize that crackers have been banned in the area. We all know every banned product is available illegally at many places. So with a few calls here and there, Yash was able to locate a few hidden fireworks sellers.
Problem is, now that the crackers are banned, the remaining sellers are selling them at high prices. Yash does not have an infinite budget and the secret stores are far off too. Every kilometer he travels costs him Rs 10. To keep thing simple, he will buy all the crackers from one shop only.
Standard Input
The first line contains the number of stores S
The second line contains the number of Sparklers, Flowerpots, Atom Bombs, Rockets and Comets that Yash has planned to buy.
S number of lines follow with the distance of the stores from Yash's home along with the prices of a single Sparkler, Flowerpot, Atom Bomb, Rocket and Comet in each line.
Standard Output
Minimum Expense with which Yash can celebrate this Diwali.
Constraints
1 < S < 10^5
1 < No. of crackers of all five types < 10^5
1 < distance < 10^5
10 < Price of one cracker of one type < 10^5
Rs 220 (22 KMs) + Rs 100 (10 Sparklers) + Rs 125 (5 FlowerPots) + Rs 25 (5 Atom Bombs) + Rs 20 (2 Rockets) + Rs 60 (3 Comets) = Rs 550 makes it a cheaper deal to go with the second shop even while being somewhat further away compared to the first where the sum comes out to be Rs 585.