Problem p03263 (python)

Fixed submission:
n=list(map(int,input().split()))
a=[]
for m in range(n[0]):
    a.append(list(map(int,input().split())))
    
count=0
output=[]
for i in range(n[0]-1):
    for j in range(n[1]):
        if a[i][j]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i+1,j+1,i+2,j+1))
            a[i][j] -= 1
            a[i+1][j] += 1

for j in range(n[1]-1):
    if a[n[0]-1][j]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(n[0],j+1,n[0],j+2))
        a[n[0]-1][j] -= 1
        a[n[0]-1][j+1] += 1 

print(count)
for t in range(len(output)):
    print(output[t])

Buggy submission (verdict: Runtime Error):
import numpy as np

n=list(map(int,input().split()))
a=[]
for m in range(n[0]):
    a.append(list(map(int,input().split())))

a=np.array(a)
count=0
bef=100
output=[]
while count!=bef:
    bef = count
    if a[0][0]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(1,1,1,2))
        a[0][0] -= 1
        a[0][1] += 1
    if a[n[0]-1][n[1]-1]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(n[0],n[1],n[0]-1,n[1]))
        a[n[0]-1][n[1]-1] -= 1
        a[n[0]-2][n[1]-1] += 1
    if a[0][n[1]-1]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(1,n[1],2,n[1]))
        a[0][n[1]-1] -= 1
        a[1][n[1]-1] += 1
    if a[n[0]-1][0]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(n[0],1,n[0],2))
        a[n[0]-1][0] -= 1
        a[n[0]-1][1] += 1
    for i in range(1,n[0]-1):
        if a[i][1]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i+1,2,i+1,1))
            a[i][1] -= 1
            a[i][0] += 1
        elif a[i+1][0]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i+2,1,i+1,1))
            a[i+1][0] -= 1
            a[i][0] += 1
        elif a[i-1][0]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i,1,i+1,1))
            a[i-1][0] -= 1
            a[i][0] += 1
    for j in range(1,n[1]-1):
        if a[1][j]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(2,j+1,1,j+1))
            a[1][j] -= 1
            a[0][j] += 1
        elif a[0][j+1]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(1,j+2,1,j+1))
            a[0][j+1] -= 1
            a[0][j] += 1
        elif a[0][j-1]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(1,j,1,j+1))
            a[0][j-1] -= 1
            a[0][j] += 1
    for i in range(1,n[0]-1):
        for j in range(1,n[1]-1):
            if a[i][j+1]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i+1,j+2,i+1,j+1))
                a[i][j+1] -= 1
                a[i][j] += 1
            elif a[i][j-1]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i+1,j,i+1,j+1))
                a[i][j-1] -= 1
                a[i][j] += 1
            elif a[i+1][j]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i+2,j+1,i+1,j+1))
                a[i+1][j] -= 1
                a[i][j] += 1
            elif a[i-1][j]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i,j+1,i+1,j+1))
                a[i-1][j] -= 1
                a[i][j] += 1

print(count)
for t in range(len(output)):
    print(output[t])

Buggy submission (verdict: Runtime Error):
import numpy as np

n=list(map(int,input().split()))
a=[]
for m in range(n[0]):
    a.append(list(map(int,input().split())))

a=np.array(a)
count=0
bef=100
output=[]
while count!=bef:
    bef = count
    if a[0][0]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(1,1,1,2))
        a[0][0] -= 1
        a[0][1] += 1
    if a[n[0]-1][n[1]-1]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(n[0],n[1],n[0]-1,n[1]))
        a[n[0]-2][n[1]-1] -= 1
        a[n[0]-1][n[1]-1] += 1
    if a[0][n[1]-1]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(1,n[1],2,n[1]))
        a[0][n[1]-1] -= 1
        a[1][n[1]-1] += 1
    if a[n[0]-1][0]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(n[0],1,n[0],2))
        a[n[0]-1][0] -= 1
        a[n[0]-1][1] += 1
    for i in range(1,n[0]-1):
        if a[i][1]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i+1,2,i+1,1))
            a[i][1] -= 1
            a[i][0] += 1
        elif a[i+1][0]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i+2,1,i+1,1))
            a[i+1][0] -= 1
            a[i][0] += 1
        elif a[i-1][0]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i,1,i+1,1))
            a[i-1][0] -= 1
            a[i][0] += 1
    for j in range(1,n[1]-1):
        if a[1][j]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(2,j+1,1,j+1))
            a[1][j] -= 1
            a[0][j] += 1
        elif a[0][j+1]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(1,j+2,1,j+1))
            a[0][j+1] -= 1
            a[0][j] += 1
        elif a[0][j-1]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(1,j,1,j+1))
            a[0][j-1] -= 1
            a[0][j] += 1
    for i in range(1,n[0]-1):
        for j in range(1,n[1]-1):
            if a[i][j+1]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i+1,j+2,i+1,j+1))
                a[i][j+1] -= 1
                a[i][j] += 1
            elif a[i][j-1]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i+1,j,i+1,j+1))
                a[i][j-1] -= 1
                a[i][j] += 1
            elif a[i+1][j]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i+2,j+1,i+1,j+1))
                a[i+1][j] -= 1
                a[i][j] += 1
            elif a[i-1][j]%2==1:
                count += 1
                output.append("{0} {1} {2} {3}".format(i,j+1,i+1,j+1))
                a[i-1][j] -= 1
                a[i][j] += 1

print(count)
for t in range(len(output)):
    print(output[t])