Buggy python submission (verdict: Runtime Error):
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((M,M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)


Fixed submission:
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((2*M,2*M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
from itertools import product
from time import process_time as timer
 
import numpy as np

def helper(N,D):

  banned = set()
  for x in range(0, int(sqrt(D/2))+2):
    if D > x*x:
      y = sqrt(D-x*x)
      if y == int(y):
        y = int(y)
 
        for a,b in {(x,y),(y,x)}:
          for s,t in product((1,-1), repeat=2):
            banned.add((s*a,t*b))
  banned = list(banned)
  M = N*2
 
  grid = [[0 for _ in range(M)] for _ in range(M)]

  p0 = (0,0)
  stack = []
  while p0:

    stack.append(p0)
    grid[p0[0]][p0[1]] = 1

    while stack:
      x,y = stack.pop()
      t = grid[x][y]
      for dx,dy in banned:
        xx,yy = x+dx,y+dy
        if 0 <= xx < M and 0 <= yy < M and grid[xx][yy] == 0:
          grid[xx][yy] = -t
          stack.append((xx,yy))
    
    p0 = None
    for x in range(M):
      for y in range(M):
        if grid[x][y] == 0:
          p0 = (x,y)
          break
      if p0:
        break

  return np.array(grid)
 
N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N,D1)
g2 = helper(N,D2)
 
if np.count_nonzero(g1==1)*2 > M*M:
  g1 = g1==1
else:
  g1 = g1==-1
 
if np.sum(g1*g2) > 0:
  ans = g1&(g2==1)
else:
  ans = g1&(g2==-1)
 
 
for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)
 
# print(ans.astype(int))
# print(np.sum(ans), N*N)

Fixed submission:
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((2*M,2*M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  banned = list()
  for x in range(0, int(sqrt(D/2))+2):
    if D > x*x:
      y = sqrt(D-x*x)
      if y == int(y):
        y = int(y)

        for a,b in {(x,y),(y,x)}:
          for s,t in product((1,-1), repeat=2):
            banned.append((s*a,t*b))

  M = N*2

  grid = np.zeros((M,M), dtype=int)

  p0 = (0,0)
  while p0:
    stack = [p0]
    grid[stack[0]] = 1
    while stack:
      x,y = stack.pop()
      t = grid[x,y]
      for dx,dy in banned:
        xx,yy = x+dx,y+dy
        if 0 <= xx < M and 0 <= yy < M and grid[xx,yy] == 0:
          grid[xx,yy] = -t

    l = np.transpose(np.nonzero(grid==0))
    if l.size > 0:
      p0 = tuple(l[0])
    else:
      p0 = None


  return grid

N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N,D1)
g2 = helper(N,D2)

if np.count_nonzero(g1==1)*2 > M*M:
  g1 = g1==1
else:
  g1 = g1==-1

if np.sum(g1*g2) > 0:
  ans = g1&(g2==1)
else:
  ans = g1&(g2==-1)


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)


Fixed submission:
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((2*M,2*M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt

N0,D1,D2 = map(int,input().split())
N = 2*N0
banned = set()
for d in [D1,D2]:
  for x in range(0, int(sqrt(d/2)+1)):
    y = sqrt(d-x*x)
    if y == int(y):
      y = int(y)
      banned.add((x,y))
      banned.add((y,x))

grid = [[True for _ in range(N*2)] for _ in range(N*2)]

points = []

for y in range(N0):
  g = grid[y]
  for x in range(N0):

    if g[x]:
      points.append((x,y))

      for dx,dy in banned:
        if x+dx < N0 and y+dy < N0:
          grid[y+dy][x+dx] = False

from time import sleep

if len(points) < N0**2:
  sleep(3)

for x,y in points[:N0**2]:
  print(x,y)

Fixed submission:
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((2*M,2*M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)