A Latin square is an n×n array filled with n 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×n array, decide whether it is a Latin square, and if it is, decide whether it is in reduced form.