Tetromino Maximum Sum

No attempts yetTime limit1sMemory limit128 MB

Problem

A tetromino is a shape made of four unit squares joined edge to edge. There are five kinds:

I:  # # # #

O:  # #
    # #

T:  # # #
    . # .

S:  . # #
    # # .

L:  # .
    # .
    # #

You are given an $N \times N$ table filled with integers. Place exactly one of the five tetrominoes on the table and maximize the sum of the four cells it covers.

Each piece may be rotated in 90° steps, but it may not be flipped (mirrored). Counting rotations, T and L have 4 distinct forms each, I and S have 2 each, and O has 1, for 13 distinct forms in total. A placement is valid only if the whole piece lies inside the table.

For instance, placing the I piece horizontally sums four consecutive numbers in a row; rotating it to vertical sums four consecutive numbers in a column. On a $4 \times 4$ table there are 77 distinct placements in all.

Because a piece must always be placed, the maximum sum can be negative if every number in the table is negative.

Input

The input consists of several test cases. The first line of each test case contains the table size $N$ with $4 \le N \le 100$. Each of the next $N$ lines contains $N$ integers separated by spaces, giving one row of the table. Each integer has absolute value at most $1{,}000{,}000$.

The last line of the input contains a single $0$, which marks the end of the input.

Output

For each test case, print one line with the case number and the maximum sum of the four covered cells. If the case number is $k$ and the maximum sum is $s$, print exactly in the format k. s (number, period, space, sum). Case numbers start at $1$.