 # Python NZEC on KFORK but AC using C++

I was trying to solve the KFORK problem. I have a solution in C++ that I got AC with, but my identical Python3 solution gets an NZEC. I’m new to using Python on CodeChef, so maybe there is something basic I am missing. Can someone please take a look at the following code and see if something is wrong?

``````
def is_X_Y_valid(board, X, Y):
return (X >= 0 and X < len(board) and
Y >= 0 and Y < len(board[X]))

T = int(input())

for _ in range(0, T):
N, M = (int(i) for i in input().split())

board = [[False] * N for x in range(N)]
xAttacked = [False] * N
yAttacked = [False] * N
mainDiagAttacked = [False] * (2 * N - 1)
offDiagAttacked = [False] * (2 * N - 1)

for _ in range(0, M):
X, Y = (int(i) for i in input().split())
X -= 1
Y -= 1
board[X][Y] = True
xAttacked[X] = True
yAttacked[Y] = True
mainDiagAttacked[N - 1 + X - Y] = True
offDiagAttacked[X + Y] = True

forkedKnights = 0
for x in range(0, N):
for y in range(0, N):
if board[x][y]:
continue

if (xAttacked[x] or yAttacked[y] or
mainDiagAttacked[N - 1 + x - y] or
offDiagAttacked[x + y]):
continue

attacking = 0
offsets = [[[-2, 2], [-1, 1]], [[-1, 1], [-2, 2]]]
for a, b in offsets:
for i in a:
for j in b:
if is_X_Y_valid(board, x + i, y + j):
if board[x + i][y + j]:
attacking += 1

if attacking >= 2:
forkedKnights += 1

print(forkedKnights)

``````