This page is still under construction.

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

Homogeneous Square

Time limit1sMemory limit128 MB

Summary
Given an n by n grid, decide whether every choice of n cells with distinct rows and distinct columns has the same sum.
Level

Medium6 of 10

Topics
Math, Matrix, Implementation, Greedy
Solved
No attempts yet

Problem

There is a square of size nn, divided into n×nn \times n cells like a checkerboard. Each cell contains a single integer.

Two positions (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) are independent if they lie in different rows and different columns, that is, x1≠x2x_1 \neq x_2 and y1≠y2y_1 \neq y_2. A set of nn positions is independent if every pair of them is independent. The number of ways to choose nn mutually independent positions is exactly n!n! (equivalently, pick exactly one cell from each row and one from each column).

The square is called homogeneous if, no matter which nn independent positions you choose, the sum of the numbers in those cells is always the same.

Given the numbers written in the square, write a program that decides whether the square is homogeneous.

Input

The input consists of several test cases. The first line of each test case contains the size nn of the square (1≤n≤10001 \le n \le 1000). The next nn lines each contain nn integers separated by spaces. Each number is between −1000000-1000000 and 10000001000000 inclusive. The last line of the input contains a single 00, which is not processed.

Output

For each test case, print homogeneous if the square is homogeneous, and not homogeneous otherwise, each on its own line.

Examples1

  1. Example 1

    Input
    2
    1 2
    3 4
    3
    1 3 4
    8 6 -2
    -3 4 0
    0
    
    Expected output
    homogeneous
    not homogeneous