We’re preparing your current view and syncing the latest data.
You have n eggs that need to be painted. There are three colors available for painting: red, green, and blue. For each egg, the cost to paint it in each color is given. Find the minimal total cost to paint all the eggs so that no two adjacent eggs have the same color.
The first line contains a single integer n, the number of eggs. Then n lines follow, each with three integers r, g, b separated by spaces indicating the cost of painting the egg red, green, or blue respectively.
Output a single integer — the minimal total cost to paint all eggs satisfying the given constraints.
1 ≤ n ≤ 1000; 1 ≤ r, g, b ≤ 1000
Example 1
Input
3 1 2 3 1 3 2 3 2 1
Output
4
Explanation
One minimal cost painting is: paint egg 1 red (cost 1), egg 2 blue (cost 2), egg 3 red (cost 1) totaling 4 and no two adjacent eggs share the same color.