Problem p03263 (python)

Fixed submission:
def main():
    ans, a = [], []
    H, W = map(int, input().split())

    for i in range(H):
        a += [list(map(int, input().split()))]

    x, y, dx = 0, 0, 1

    while True:
        nx, ny = x, y
        if x+dx < 0 or W <= x+dx:
            nx = x
            ny = y+1 
            dx *= -1
        else:
            nx = x+dx
            ny = y

        if H <= ny:
            break

        if a[y][x] % 2 == 1:
            a[y][x] -= 1
            a[ny][nx] += 1
            ans += [str(y+1) + " " + str(x+1) + " " + str(ny+1) + " " + str(nx+1)]
        x, y = nx, ny

    print (len(ans))

    for i in ans:
        print (i)

main()

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []

for i in range(H):
    a.append([int(x) for x in input().split()])

n = 0
ans = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W - 1):
            if a[y][x] & 1:
                a[y][x + 1] += 1
                n += 1
                ans.append("{} {} {} {}".format(y + 1, x + 1, y + 1, x + 2))
        if y != H - 1 and a[y][W - 1] & 1:
            a[y + 1][W - 1] += 1
            n += 1
            ans.append("{} {} {} {}".format(y + 1, W, y + 2, x + W))

    else:
        for x in range(W - 1, 0, -1):
            if a[y][x] & 1:
                a[y][x - 1] += 1
                n += 1
                ans.append("{} {} {} {}".format(y + 1, x + 1, y + 1, x))
        if y != H - 1 and a[y][0] & 1:
            a[y + 1][0] += 1
            n += 1
            ans.append("{} {} {} {}".format(y + 1, x + 1, y + 2, x + 1))

print(n)
print("\n".join(ans))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []

for i in range(H):
    a.append([int(x) for x in input().split()])

n = 0
ans = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W - 1):
            if a[y][x] & 1:
                n += 1
                ans.append("{} {} {} {}".format(y + 1, x + 1, y + 1, x + 2))
        if y != H - 1 and a[y][W - 1] & 1:
            n += 1
            ans.append("{} {} {} {}".format(y + 1, W, y + 2, x + W))

    else:
        for x in range(W - 1, 0, -1):
            if a[y][x] & 1:
                n += 1
                ans.append("{} {} {} {}".format(y + 1, x + 1, y + 1, x))
        if y != H - 1 and a[y][0] & 1:
            n += 1
            ans.append("{} {} {} {}".format(y + 1, x + 1, y + 2, x + 1))

print(n)
print("\n".join(ans))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []

for i in range(H):
    a.append([int(x) for x in input().split()])

n = 0
ans = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W - 1):
            if a[y][x] & 1:
                n += 1
                ans.append("{} {} {} {}".format(y + 1, x + 1, y + 1, x + 2))
                print(y + 1, x + 1, y + 1, x + 2)
        if y != H - 1 and a[y][W - 1] & 1:
            n += 1
            ans.append("{} {} {} {}".format(y + 1, W, y + 2, x + W))

    else:
        for x in range(W - 1, 0, -1):
            if a[y][x] & 1:
                n += 1
                ans.append("{} {} {} {}".format(y + 1, x + 1, y + 1, x))
        if y != H - 1 and a[y][0] & 1:
            n += 1
            ans.append("{} {} {} {}".format(y + 1, x + 1, y + 2, x + 1))

print(n)
print("\n".join(ans))