Mock CCC '18 Contest 1 J4/S2 - A Square Problem

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 5.0s
Memory limit: 1G

Problem type

A Latin Square is an NN-by-NN array filled with NN different digits, each digit occurring exactly once in each row and exactly once in each column.

A Latin Square is in reduced form if the top row and leftmost column are sorted in increasing order.

Given an NN-by-NN array, determine if it is a Latin Square, and if so, if it is in reduced form.

Constraints

2 \le N \le 362 \le N \le 36

Input Specification

The first line contains a single positive integer NN.

Each of the next NN lines contains NN digits in base NN. The digits 0 through 9 will be represented as is, and the uppercase letters A through Z represent the digits 10 through 35. The digits are guaranteed to be valid in base NN.

Output Specification

If the array is not a Latin Square, print No on a single line.

If the array is a Latin Square, but not in reduced form, print Latin on a single line.

If the array is a Latin Square in reduced form, print Reduced on a single line.

Sample Input 1

3
012
120
201

Sample Output 1

Reduced

Sample Input 2

4
3210
0123
2301
1032

Sample Output 2

Latin

Sample Input 3

11
0123458372A
A9287346283
0285475A834
84738299A02
1947584037A
65848430002
038955873A8
947530200A8
93484721084
95539A92828
04553883568

Sample Output 3

No

Comments

There are no comments at the moment.