Problem p03263 (python)

Fixed submission:
import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

r = True
act = list()
for i in range(1, h+1):
  r = not r
  for j in sorted(range(1, w+1), reverse=r):
    if m[i-1, j-1] % 2 == 1:
      if not r:
        # 下に進む
        if j == w:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        # 右に進む
        else:
          m[i-1, j] += 1
          act.append((i, j, i, j+1))
      else:
        # 下に進む
        if j == 1:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        # 左に進む
        else:
          m[i-1, j-2] += 1
          act.append((i, j, i, j-1))
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
print(len(act))
[print(*x) for x in act]  
#print(m)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
m = [list(map(int, input().split())) for i in range(h)]

r = True
act = list()
for i in range(1, h+1):
  r = not r
  for j in sorted(range(1, w+1), reverse=r):
    if m[i-1][j-1] % 2 == 1:
      if not r:
        # 下に進む
        if j == w:
          if i == h:
            break
          m[i][j-1] += 1
          act.append((i, j, i+1, j))
        # 右に進む
        else:
          m[i-1, j] += 1
          act.append((i, j, i, j+1))
      else:
        # 下に進む
        if j == 1:
          if i == h:
            break
          m[i][j-1] += 1
          act.append((i, j, i+1, j))
        # 左に進む
        else:
          m[i-1][j-2] += 1
          act.append((i, j, i, j-2))
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
print(len(act))
[print(*x) for x in act]  
#print(m)

Buggy submission (verdict: Runtime Error):
import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

n = list()
r = True
act = list()
for i in range(h):
  r = not r
  for j in sorted(range(w), reverse=r):      
    if not r:
      # 下に進む
      if j == w-1:
        if i == h:
          break
        next_i = i + 1
        next_j = j
      # 右に進む
      else:
        next_i = i
        next_j = j + 1
    else:
      # 下に進む
      if j == 0:
        if i == h:
          break
        next_i = i
        next_j = j + 1
      # 左に進む
      else:
        next_i = i
        next_j = j - 1
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
    if m[i, j] % 2 == 1:
      m[i, j] -= 1
      m[next_i, next_j] += 1
      act.append((i+1, j+1, next_i+1, next_j+1))

print(len(act))
[print(*x) for x in act]  
#print(m)

Buggy submission (verdict: Runtime Error):
import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

n = list()
r = True
act = list()
for i in range(h):
  r = not r
  for j in sorted(range(w), reverse=r):      
    if not r:
      # 下に進む
      if j == w-1:
        if i == w:
          break
        next_i = i + 1
        next_j = j
      # 右に進む
      else:
        next_i = i
        next_j = j + 1
    else:
      # 下に進む
      if j == 0:
        if i == w:
          break
        next_i = i
        next_j = j + 1
      # 左に進む
      else:
        next_i = i
        next_j = j - 1
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
    if m[i, j] % 2 == 1:
      m[i, j] -= 1
      m[next_i, next_j] += 1
      act.append((i+1, j+1, next_i+1, next_j+1))

print(len(act))
[print(*x) for x in act]  
#print(m)

Buggy submission (verdict: Runtime Error):
import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

n = list()
r = True
act = list()
for i in range(h):
  r = not r
  for j in sorted(range(w), reverse=r):      
    if not r:
      # 下に進む
      if j == w-1:
        if i == w:
          break
        next_i = i + 1
        next_j = j
      # 右に進む
      else:
        next_i = i
        next_j = j + 1
    else:
      # 下に進む
      if j == 0:
        if i == w:
          break
        next_i = i
        next_j = j + 1
      # 左に進む
      else:
        next_i = i
        next_j = j - 1
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
    if m[i, j] % 2 == 1:
      m[i, j] -= 1
      m[next_i, next_j] += 1
      act.append((i, j, next_i, next_j))

print(len(act))
[print(*x) for x in act]  
#print(m)