Outer Triangle Sum
Time limit10sMemory limit512 MB
For each triangle, add the first and last value of every row plus all values of the last row, counting shared corners once, and print the total.
- Level
Easy2 of 10
- Topics
- Implementation, Array, Simulation, Brute force
- Solved
- No attempts yet
Problem
Numbers are arranged in the shape of an isosceles right triangle. Find the sum of the numbers on the border of the triangle.
A triangle of size has rows, and row holds numbers. Each number is an integer from to . The border consists of the first and last number of every row, plus every number in the last row. A corner number that lies on two sides is added only once.
For example, take this triangle with :
5
1 8
9 6 1
2 7 2 6
3 5 7 8 9
The sum of the numbers on its border is:
Input
The input contains several test cases. The first line of each test case holds a positive integer (), the size of the triangle. Line of the next lines holds the integers of row , separated by spaces.
The last line of the input is . Do not process it.
Output
For each test case, print one line of the form Case #x:S, where is the test case number starting from and is the sum of the numbers on the border of the triangle. Do not put a space after the colon.