Given is a triangle of numbers. A path through the triangle is a sequence of adjacent numbers, one from each row, starting from the top. For example,
Your task is to find the maximum path cost, where the path cost is defined as the sum of the numbers in the path. Thus, the given example has a maximum path cost of
Write a program that reads a triangle of numbers and outputs the maximum path cost. The first line of the input contains the number of rows. Each subsequent line represents a row of the triangle, starting with the top row. Within each row, the numbers are separated by a space. The triangle has at most 1000 rows. All numbers are positive integers between 0 and 100.
Input:
6
1
3 5
6 3 2
3 1 4 9
9 8 1 5 7
4 6 0 2 8 2
Output:
32