Buggy python submission (verdict: Runtime Error):
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    h, w, *a = map(int, s.split())
    *a, = chunked(a, w)
    ans = []
    for i in range(h):
        for j in range(w - 1):
            if a[i][j] % 2 == 1:
                ans.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                a[i][j + 1] += 1
    for i in range(h - 1):
        if a[i][w - 1] % 2 == 1:
            ans.append("{} {} {} {}".format(i + 1, w, i + 2, w))
            a[i + 1][w - 1] += 1
    ans += "{}\n".format(len(ans)) + ans
    return "\n".join(ans)


n, m = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    # a = [list(map(lambda x: int(x) % 2 == 1, input().strip().split(" "))) for _i in range(h)]
    a = []
    for i in range(h):
        # tmp = input()
        tmp = ins[i + 1]
        a.append(list(map(lambda x: int(x) % 2 == 1, tmp.strip().split(" "))))
    move = []
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)


if __name__ == '__main__':
    line = input().strip()
    # """
    ins = [input() for _ in range(int(line[0]))]
    ins.insert(0, line)
    print(solve("\n".join(ins)))
    # """
    # print(solve(line))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    # a = [list(map(lambda x: int(x) % 2 == 1, input().strip().split(" "))) for _i in range(h)]
    a = []
    for i in range(h):
        # tmp = input()
        tmp = ins[i + 1]
        print(repr(tmp))
        a.append(list(map(lambda x: int(x) % 2 == 1, tmp.strip().split(" "))))
    move = []
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)


if __name__ == '__main__':
    line = input().strip()
    # """
    ins = [input() for _ in range(int(line[0]))]
    ins.insert(0, line)
    print(solve("\n".join(ins)))
    # """
    # print(solve(line))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    # a = [list(map(lambda x: int(x) % 2 == 1, input().strip().split(" "))) for _i in range(h)]
    a = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)


if __name__ == '__main__':
    line = input().strip()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input().strip())
    print(solve('\n'.join(tmp)))
    # print(solve(line))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h-1):
        for j in range(w-1):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    cells = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]

    command = []
    for i in range(h):
        for j in range(w):
            if cells[i][j]:
                if j < w - 1:
                    cells[i][j + 1] ^= True
                    command.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                elif i < h - 1:
                    cells[i + 1][j] ^= True
                    command.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    command.insert(0, str(len(command)))
    return "\n".join(command)
    """
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]
    move = []
    v_flag = False
    h_flag = False
    for i, _a in enumerate(a):
        for j, __a in enumerate(_a):
            curr = __a
            if h_flag:
                curr = not curr
                h_flag = False
            if j == w - 1 and v_flag:
                curr = not curr
                v_flag = False
            if not curr:
                continue
            if j < w - 1:
                h_flag = True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                v_flag = True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)
    """


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]
    move = []
    v_flag = False
    h_flag = False
    """
    for i, _a in enumerate(a):
        for j, __a in enumerate(_a):
            curr = __a
            if h_flag:
                curr = not curr
                h_flag = False
            if j == w - 1 and v_flag:
                curr = not curr
                v_flag = False
            if not curr:
                continue
            if j < w - 1:
                h_flag = True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                v_flag = True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    """
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] = not a[i][j + 1]
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] = not a[i + 1][j]
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            # if a[i][j] % 2 == 0:
                # continue
            # a[i][j] -= 1
            if j < w - 1:
                a[i][j + 1] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                # a[i + 1][j] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            # if a[i][j] % 2 == 0:
                # continue
            a[i][j] -= 1
            if j < w - 1:
                # a[i][j + 1] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                # a[i + 1][j] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            # if a[i][j] % 2 == 0:
                # continue
            # a[i][j] -= 1
            if j < w - 1:
                # a[i][j + 1] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            if a[i][j] % 2 == 0:
                continue
            a[i][j] -= 1
            if j < w - 1:
                a[i][j + 1] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i, _a in enumerate(a):
        for j, __a in enumerate(_a):
            if __a % 2 == 0:
                continue
            a[i][j] -= 1
            if j < w - 1:
                a[i][j + 1] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    matrix = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for _h in range(h):
        for _w in range(w):
            if matrix[_h][_w] % 2 == 0:
                continue
            matrix[_h][_w] -= 1
            if _w < w - 1:
                matrix[_h][_w + 1] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 1, _w + 2))
            elif _h < h - 1:
                matrix[_h + 1][_w] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 2, _w + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    matrix = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for _h in range(h):
        for _w in range(w):
            if matrix[_h][_w] % 2 == 0:
                continue
            matrix[_h][_w] -= 1
            if _w < w - 1:
                matrix[_h][_w + 1] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 1, _w + 2))
            elif _h < h - 1:
                matrix[_h + 1][_w] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 2, _w + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    matrix = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for _h in range(h):
        for _w in range(w):
            if matrix[_h][_w] % 2 == 0:
                continue
            matrix[_h][_w] -= 1
            if _w < w - 1:
                matrix[_h][_w + 1] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 1, _w + 2))
            elif _h < h - 1:
                matrix[_h + 1][_w] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 2, _w + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2, _i.split(" "))) for _i in ins[1:]]
    move = []
    for _h in range(h):
        for _w in range(w):
            if a[_h][_w] % 2 == 0:
                continue
            a[_h][_w] -= 1
            if _w < w - 1:
                a[_h][_w + 1] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 1, _w + 2))
            elif _h < h - 1:
                a[_h + 1][_w] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 2, _w + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            a[j][i] -= 1
            if i < w - 1:
                a[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
            elif j < h - 1:
                a[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 > 0:
                a[j][i] -= 1
                if i < w - 1:
                    a[j][i + 1] += 1
                    move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
                elif j < h - 1:
                    a[j + 1][i] += 1
                    move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] == 0:
                continue
            if i < w - 1:
                a[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
            elif j < h - 1:
                a[j][i] -= 1
                a[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    mat = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if mat[j][i] % 2 == 0:
                continue
            if i < w - 1:
                mat[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
            elif j < h - 1:
                mat[j][i] -= 1
                mat[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 == 0:
                pass
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 != 0:
                if i < w - 1:
                    a[j][i + 1] += 1
                    move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
                elif j < h - 1:
                    a[j][i] -= 1
                    a[j + 1][i] += 1
                    move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 == 0:
                continue
            """
            if i < w - 1:
                a[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
            elif j < h - 1:
                a[j][i] -= 1
                a[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
            """
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    cnt = 0
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 == 0:
                continue
            a[j][i] -= 1
            if i < w - 1:
                a[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
                cnt += 1
            elif j < h - 1:
                a[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
                cnt += 1
    return "{}\n{}".format(cnt, "\n".join(move)) if cnt else str(cnt)


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 == 0:
                continue
            a[j][i] -= 1
            if i < w - 1:
                a[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
            elif j < h - 1:
                a[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
    return "{}\n{}".format(len(move), "\n".join(move)) if len(move) > 0 else "0"


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    curr_x = curr_y = 0
    move_x, move_y = 1, 0
    move = []
    coordinate_order = []
    check_mat = [[True for _ in range(w)] for _ in range(h)]
    for i in range(h * w):
        coordinate_order.append((curr_y, curr_x))
        if not (0 <= curr_x + move_x <= w - 1 and check_mat[curr_y][curr_x + move_x]):
            move_x, move_y = move_y, move_x
        if not (0 <= curr_y + move_y <= h - 1 and check_mat[curr_y + move_y][curr_x]):
            move_x, move_y = -move_y, -move_x
        check_mat[curr_y][curr_x] = False
        curr_x += move_x
        curr_y += move_y
    for (_cy, _cx), (_ny, _nx) in zip(coordinate_order, coordinate_order[1:]):
        if a[_cy][_cx] % 2 == 0:
            continue
        a[_cy][_cx] -= 1
        a[_ny][_nx] += 1
        move.append("{} {} {} {}".format(_cy + 1, _cx + 1, _ny + 1, _nx + 1))
    return "{}\n{}".format(len(move), "\n".join(move)) if len(move) > 0 else "0"


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    curr_x = curr_y = 0
    move_x = 1
    move_y = 0
    move = []
    coordinate_order = []
    check_mat = [[True for _ in range(w)] for _ in range(h)]
    for i in range(h * w):
        coordinate_order.append((curr_y, curr_x))
        if curr_x + move_x < 0 or w - 1 < curr_x + move_x or not check_mat[curr_y][curr_x +
                                                                                   move_x]:
            move_x, move_y = move_y, move_x
        if curr_y + move_y < 0 or h - 1 < curr_y + move_y or not check_mat[curr_y +
                                                                           move_y][curr_x]:
            move_x, move_y = -move_y, -move_x
        check_mat[curr_y][curr_x] = False
        curr_x += move_x
        curr_y += move_y
    for (_cy, _cx), (_ny, _nx) in zip(coordinate_order, coordinate_order[1:]):
        if a[_cy][_cx] % 2 == 0:
            continue
        a[_cy][_cx] -= 1
        a[_ny][_nx] += 1
        move.append("{} {} {} {}".format(_cy + 1, _cx + 1, _ny + 1, _nx + 1))
        return "{}\n{}".format(len(move), "\n".join(move)) if len(move) > 0 else "0"


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    curr_x = curr_y = 0
    move_x = 1
    move_y = 0
    move = []
    coordinate_order = []
    check_mat = [[True for _ in range(w)] for _ in range(h)]
    for i in range(h * w):
        coordinate_order.append((curr_y, curr_x))
        if curr_x + move_x < 0 or w - 1 < curr_x + move_x or not check_mat[curr_y][curr_x +
                                                                                   move_x]:
            move_x, move_y = move_y, move_x
        if curr_y + move_y < 0 or h - 1 < curr_y + move_y or not check_mat[curr_y +
                                                                           move_y][curr_x]:
            move_x, move_y = -move_y, -move_x
        check_mat[curr_y][curr_x] = False
        curr_x += move_x
        curr_y += move_y
    for (_cy, _cx), (_ny, _nx) in zip(coordinate_order, coordinate_order[1:]):
        if a[_cy][_cx] % 2 == 0:
            continue
        a[_cy][_cx] -= 1
        a[_ny][_nx] += 1
        move.append("{} {} {} {}".format(_cy + 1, _cx + 1, _ny + 1, _nx + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Buggy python submission (verdict: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j, _a in enumerate(a):
        for i, _ in enumerate(_a):
            if _a[i] % 2 == 0:
                continue
            if sum(_a) % 2 == 0:
                _a[i] -= 1
                _a[i + 1] += 1
                move.append("{} {} {} {}".format(j+1, i+1, j+1, i+2))
            else:
                _a[i] -= 1
                a[j+1][i] += 1
                move.append("{} {} {} {}".format(j+1, i+1, j+2, i+1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


Fixed submission:
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))