2
def movesToChessboard(self, board):5
# For each count of lines from {rows, columns}...7
collections.Counter(map(tuple, board)), # get row8
collections.Counter(zip(*board)),11
# If there are more than 2 kinds of lines,12
# or if the number of kinds is not appropriate ...13
if len(count) != 2 or sorted(count.values()) != [N / 2, (N + 1) / 2]:16
# If the lines are not opposite each other, impossible18
if not all(x ^ y for x, y in zip(line1, line2)):21
# starts = what could be the starting value of line122
# If N is odd, then we have to start with the more24
starts = [int(line1.count(1) * 2 > N)] if N % 2 else [0, 1]26
# To transform line1 into the ideal line [i%2 for i ...],27
# we take the number of differences and divide by two30
sum((x - i) % 2 for i, x in enumerate(line1, start))