Latin Squares

Read an n by n grid of base-n digit characters and report whether it is a Latin square, and if so whether it is in reduced form.

Easy2ImplementationArraySimulationHash mapInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

A Latin square is an n×nn \times n array filled with nn different digits, where every digit occurs exactly once in each row and exactly once in each column. (The name comes from Leonhard Euler, who used Latin characters in his papers on the subject.)

A Latin square is in reduced form when its top row and its leftmost column are both in natural order. The natural order of a set of digits is by increasing value.

Read an n×nn \times n array, decide whether it is a Latin square, and if it is, decide whether it is in reduced form.

Input

The first line contains a single integer nn (2n362 \le n \le 36). Each of the next nn lines contains nn digits in base nn. Digit values below 10 are written with the characters 0 through 9, and values from 10 to 35 are written with the uppercase letters A through Z. Every character in the input is legal in base nn. For example, if nn is 3, the only characters in the nn lines describing the array are 0, 1, and 2.

Output

If the given array is not a Latin square, print No on a single line. If it is a Latin square but not in reduced form, print Not Reduced. If it is a Latin square in reduced form, print Reduced.