There are people standing in line to buy tickets for the premiere of a musical performance. Each of them wants to buy exactly one ticket. The line is served by a single cashier, which makes the process very slow, and people begin to lose patience. The most observant noticed that, in general, the cashier sells multiple tickets to one person faster than selling the same tickets one by one to different people. Therefore, it was proposed that several consecutive people could pass their money to the first person, who would then buy tickets for all of them.
However, to prevent speculation, the cashier sells no more than three tickets to a single person. Therefore, only groups of two or three consecutive people can form a group.
It is known that selling one ticket to the -th person takes a_i seconds, two tickets — b_i seconds, and three tickets — c_i seconds. Write a program that computes the minimum total time required to serve all customers.
Note that in a group, the tickets are always purchased by the first person. Also, no one buys extra tickets “just in case” — each group buys exactly the number of tickets it needs.
The first line contains the number of people in the line n~(1 \le n \le 5000). Each of the next lines contains three positive integers a_i, b_i, c_i. Each of these numbers does not exceed . The people in the line are numbered starting from the cashier.
Print the minimum possible total time (in seconds) required to serve all customers.
Example 1
Example 2