#!/usr/bin/python3 # import sys # checks whether V contains a permutation of the integers between 1 # and 9. For example, V = [ 3, 2, 1, 4, 5, 6, 9, 8, 7 ] => True but # V = [ 3, 2, 1, 4, 5, 6, 9, 2, 7 ] => False def perm9(V): F = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ] for x in V: if x < 1 or x > 9 or F[x-1] != 0: return False else: F[x-1] = 1 for x in F: if x == 0: return False return True # returns a list of the elements of the 3-by-3 submatrix of S whose # upper-left corner is at position (x,y) within S def submatrix(S, x, y): return S[x][y:y+3] + S[x+1][y:y+3] + S[x+2][y:y+3] # returns the column at position X within S def column(S, x): c = [] for row in S: c.append(row[x]) return c def row(S, x): return S[x] S = [] for line in sys.stdin: l = [] for x in line.split(): l.append(int(x)) S.append(l) for i in range(9): if not perm9(row(S,i)): print("Wrong") print("row", i) sys.exit(1) for i in range(9): if not perm9(column(S,i)): print("Wrong") print("column", i) sys.exit(1) for i in range(0,9,3): for j in range(0,9,3): if not perm9(submatrix(S,i,j)): print("Wrong") print("submatrix", i, j) sys.exit(1) print("Correct")