Language: C++

H,W = map(int,input().split())

L = []

for i in range(H):
    L.append(list(map(int,input().split())))
    
ans = [] 
for i in range(H):
    l = L[i]
    #左から右
    if i%2==0:
        for j in range(len(l)):
            m = l[j]
            #マスが奇数
            if m%2!=0:
                ans.append((i+1,j+1))
    #右から左
    else:
        for j in range(len(l)):
            jj = W - j - 1
            m = l[jj]
            #マスが奇数
            if m%2!=0:
                ans.append((i+1,jj+1))
                
print(ans)
# import pdb;pdb.set_trace()
answer = []
for i in range(len(ans)-1):
    if i%2!=0:
        continue
    current = ans[i]
    nxt = ans[i+1]
    #同じ行
    if current[0]==nxt[0]:
        current_y = current[1]
        nxt_y = nxt[1]
        #右方向
        if current[0]%2!=0:
            while current_y<nxt_y:
                answer.append( ((current[0],current_y),(current[0],current_y+1)) )
                current_y += 1
        #左方向
        else:
            while current_y>nxt_y:
                answer.append( ((current[0],current_y),(current[0],current_y-1)) )
                current_y -= 1
    #違う行
    else:
        current_y = current[1]
        current_x = current[0]
        while current_x < nxt[0]:
            #右方向
            if current_x%2!=0:
                while current_y<W:
                    answer.append( ((current_x,current_y),(current_x,current_y+1)) )
                    current_y += 1
                if current_y==W:
                    answer.append( ((current_x,current_y),(current_x+1,current_y)) )
            #左方向
            else:
                while current_y>0:
                    answer.append( ((current_x,current_y),(current_x,current_y-1)) )
                    current_y -= 1
                if current_y==0:
                    answer.append( ((current_x,current_y),(current_x+1,current_y)) )
            current_x += 1
        if current_x == nxt[0]:
            if current_x%2==0:
                while current_y<nxt[1]:
                    answer.append( ((current_x,current_y),(current_x,current_y+1)) )
                    current_y += 1
            else:
                while current_y>nxt[1]:
                    answer.append( ((current[0],current_y),(current[0],current_y-1)) )
                    current_y -= 1
                    
print(answer)
                    
for a in answer:
    print('%d %d %d %d' % (a[0][0],a[0][1],a[1][0],a[1][1]))




Compiler output:
a.cc:11:6: error: invalid preprocessing directive #\U00005de6\U0000304b\U00003089\U000053f3
   11 |     #左から右
      |      ^~~~~~~~
a.cc:15:14: error: invalid preprocessing directive #\U000030de\U000030b9\U0000304c\U00005947\U00006570
   15 |             #マスが奇数
      |              ^~~~~~~~~~
a.cc:18:6: error: invalid preprocessing directive #\U000053f3\U0000304b\U00003089\U00005de6
   18 |     #右から左
      |      ^~~~~~~~
a.cc:23:14: error: invalid preprocessing directive #\U000030de\U000030b9\U0000304c\U00005947\U00006570
   23 |             #マスが奇数
      |              ^~~~~~~~~~
a.cc:28:3: warning: #import is a deprecated GCC extension [-Wdeprecated]
   28 | # import pdb;pdb.set_trace()
      |   ^~~~~~
a.cc:28:10: error: #import expects "FILENAME" or <FILENAME>
   28 | # import pdb;pdb.set_trace()
      |          ^~~
a.cc:35:6: error: invalid preprocessing directive #\U0000540c\U00003058\U0000884c
   35 |     #同じ行
      |      ^~~~~~
a.cc:39:10: error: invalid preprocessing directive #\U000053f3\U000065b9\U00005411
   39 |         #右方向
      |          ^~~~~~
a.cc:44:10: error: invalid preprocessing directive #\U00005de6\U000065b9\U00005411
   44 |         #左方向
      |          ^~~~~~
a.cc:49:6: error: invalid preprocessing directive #\U00009055\U00003046\U0000884c
   49 |     #違う行
      |      ^~~~~~
a.cc:54:14: error: invalid preprocessing directive #\U000053f3\U000065b9\U00005411
   54 |             #右方向
      |              ^~~~~~
a.cc:61:14: error: invalid preprocessing directive #\U00005de6\U000065b9\U00005411
   61 |             #左方向
      |              ^~~~~~
a.cc:82:11: warning: multi-character literal with 11 characters exceeds 'int' size of 4 bytes
   82 |     print('%d %d %d %d' % (a[0][0],a[0][1],a[1][0],a[1][1]))
      |           ^~~~~~~~~~~~~
a.cc:1:1: error: 'H' does not name a type
    1 | H,W = map(int,input().split())
      | ^