Problem p03263 (python)

Fixed submission:
H,W = map(int,input().split())

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

ans=[]

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i<H-1 and ((i%2==0 and n==W-1) or (i%2==1 and n==0)):
                A[i+1][n]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+2,n+1))
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                A[i][n+(-1)**(i%2)]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2)))

print(len(ans))
for s in ans:
    print(s)

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

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

ans=[]

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0):
                A[i+1][n]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+2,n+1))
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                A[i][n+(-1)**(i%2)]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2)))

print(len(ans))
for s in ans:
    print(s)

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

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

num=0
ans=''

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0):
                num+=1
                A[i+1][n]+=1
                ans+='{} {} {} {}\n'.format(i+1,n+1,i+2,n+1)
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                num+=1
                A[i][n+(-1)**(i%2)]+=1
                ans+='{} {} {} {}\n'.format(i+1,n+1,i+1,n+1+(-1)**(i%2))
print(num)
print(ans[:-1])

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

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

num=0
ans=''

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0):
                num+=1
                A[i+1][n]+=1
                ans+='{} {} {} {}'.format(i+1 n+1 i+2 n+1)
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                num+=1
                A[i][n+(-1)**(i%2)]+=1
                ans+='{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2))
print(num)
print(ans)

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

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

num=0

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0):
                num+=1
                A[i+1][n]+=1
                print(i+1,n+1,i+2,n+1)
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                num+=1
                A[i][n+(-1)**(i%2)]+=1
                print(i+1,n+1,i+1,n+1+(-1)**(i%2))

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

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

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0):
                A[i+1][n]+=1
                print(i+1,n+1,i+2,n+1)
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0): 
                A[i][n+(-1)**(i%2)]+=1
                print(i+1,n+1,i+1,n+1+(-1)**(i%2))

Buggy submission (verdict: Runtime Error):

def s_ans(y1,x1,y2,x2):  
    dx = x2-x1
    dy = y1-y2

    ans=''

    for i in range(abs(dx)):
        if dx<0:
            ans += '{} {} {} {}\n'.format(y1,x1-i,y2,x1-i-1)
        else:
            ans += '{} {} {} {}\n'.format(y1,x1+i,y2,x1+i+1)

    for j in range(abs(dy)):
        if dy<0:
            ans += '{} {} {} {}\n'.format(y2-i,x2,y2-i-1,x2)
        else:
            ans += '{} {} {} {}\n'.format(y2+i,x2,y2+i+1,x2)
    return ans

h,w = map(int,input().split())

odd = []
for i in range(h):
    l = list(map(int,input().split()))
    for j in range(w):
        if l[j]%2==1:
            odd.append((i+1,j+1))
ans = ''
for i in range(int(len(odd)/2)):
    y1,x1 = odd[2*i]
    y2,x2 = odd[2*i+1]
    ans += s_ans(y1,x1,y2,x2)

ans = str(ans.count('\n'))+'\n'+ans

print(ans)