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

View as PDF

Submit solution


Points: 5
Time limit: 5.0s
Memory limit: 1G

Problem type

A Latin Square is an N-by-N array filled with N 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 N-by-N array, determine if it is a Latin Square, and if so, if it is in reduced form.

Constraints

2 \le N \le 36

Input Specification

The first line contains a single positive integer N.

Each of the next N lines contains N digits in base N. 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 N.

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


  • 1
    maxcruickshanks  commented on Dec. 19, 2022, 3:00 a.m.

    Since the original data were weak, an additional test case was added, partials were disabled, and all submissions were rejudged.