This page is still under construction.

Parts of this page are still being built. What you see may change.

Outer Triangle Sum

Time limit10sMemory limit512 MB

Summary
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 nn has nn rows, and row ii holds ii numbers. Each number is an integer from 00 to 9999. 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 n=5n = 5:

5
1 8
9 6 1
2 7 2 6
3 5 7 8 9

The sum of the numbers on its border is:

5+1+9+2+3+5+7+8+9+6+1+8=645 + 1 + 9 + 2 + 3 + 5 + 7 + 8 + 9 + 6 + 1 + 8 = 64

Input

The input contains several test cases. The first line of each test case holds a positive integer nn (n≤10n \le 10), the size of the triangle. Line ii of the next nn lines holds the ii integers of row ii, separated by spaces.

The last line of the input is 00. Do not process it.

Output

For each test case, print one line of the form Case #x:S, where xx is the test case number starting from 11 and SS is the sum of the numbers on the border of the triangle. Do not put a space after the colon.

Examples1

  1. Example 1

    Input
    5
    5   
    1 8  
    9 6 1  
    2 7 2 6  
    3 5 7 8 9
    3
    1 
    2 3
    4 5 6
    0
    
    Expected output
    Case #1:64 
    Case #2:21