Harryxun/stf_run huggingface dataset:
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
from math import gcd
n=N()
mod=10**9+7
az=0
bz=0
zz=0
l=LL(n)
ans=1
import collections
d=collections.defaultdict(int)
for a,b in l:
    if a==0 and b==0:
        zz+=1
    elif a==0:
        az+=1
    elif b==0:
        ab+=1
    elif a<0 and b<0:
        a=-a
        b=-b
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
    elif a<0:
        a=-a
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    elif b<0:
        b=-b
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    else:
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
pow2=[1]*(n+1)
t=1
for i in range(1,n+1):
    t*=2
    t%=mod
    pow2[i]=t
ans*=(1+(pow2[az]-1)+(pow2[bz]-1))
for a,b in list(d.keys()):
    if a>0 and b>0:
        x=d[(a,b)]
        y=d[(-b,a)]
        ans*=(1+(pow2[x]-1)+(pow2[y]-1))
        ans%=mod
    else:
        if not (b,-a) in d:
            ans*=pow2[d[(a,b)]]
            ans%=mod
print(ans-1)

### FIXED CODE ###

import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
from math import gcd
n=N()
mod=10**9+7
az=0
bz=0
zz=0
l=LL(n)
ans=1
import collections
d=collections.defaultdict(int)
for a,b in l:
    if a==0 and b==0:
        zz+=1
    elif a==0:
        az+=1
    elif b==0:
        bz+=1
    elif a<0 and b<0:
        a=-a
        b=-b
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
    elif a<0:
        a=-a
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    elif b<0:
        b=-b
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    else:
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
pow2=[1]*(n+1)
t=1
for i in range(1,n+1):
    t*=2
    t%=mod
    pow2[i]=t
ans*=(1+(pow2[az]-1)+(pow2[bz]-1))
for a,b in list(d.keys()):
    if a>0 and b>0:
        x=d[(a,b)]
        y=d[(-b,a)]
        ans*=(1+(pow2[x]-1)+(pow2[y]-1))
        ans%=mod
    else:
        if not (b,-a) in d:
            ans*=pow2[d[(a,b)]]
            ans%=mod
print((ans+zz-1)%mod)
import sys
import numpy as np
from scipy.sparse.csgraph import shortest_path
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
graph = np.zeros((N, N)) #0-indexed
for _ in range(N-1):
    a, b, c = lr()
    graph[a-1, b-1] = c

dist = shortest_path(graph, directed=False).astype(int)
Q, K = lr()
K_dist = dist[K-1]
for _ in range(Q):
    x, y = lr()
    print(K_dist[x-1] + K_dist[y-1])

# 20


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def measure(x):
    dist = [INF] * (N)
    dist[x] = 0
    que = deque()
    que.append(x)
    while que:
        cur = que.popleft()
        cur_dist = dist[cur]
        for next, c in edges[cur]:
            if dist[next] == INF:
                dist[next] = cur_dist + c
                que.append(next)
    
    return dist

N = ir()
INF = 10 ** 15
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = lr()
    edges[a-1].append((b-1, c))
    edges[b-1].append((a-1, c))

Q, K = lr()
dist = measure(K-1)
for _ in range(Q):
    x, y = lr()
    print(dist[x-1] + dist[y-1])


# 20
N = input()
A = list(map(int, input().split()))

answer = 1
if 0 in A:
  print(0)
  break
else:
  for i in A:
    answer *= i
  if answer > 10**18:
    print(-1)
  else:
    print(answer)


### FIXED CODE ###

N = input()
A = list(map(int, input().split()))

answer = 1
if 0 in A:
  print(0)
else:
  for i in A:
    answer *= i
    if answer > 10**18:
      answer = -1
      break
  print(answer)
import numpy as np
from functools import *
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def serch(x, count):
    #print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


N = int(input())
A = []
for i in range(N):
    A.append(II())


if A[0] >0:
    print(-1)
    sys.exit()

for i in range(1, N):
    if A[i]-A[i-1] > 1:
        print(-1)
        sys.exit()

count = 0
x = [0]*N

for i in reversed(range(N)):
    if A[i] != x[i]:
        for j in range(i-A[i], i):
            x[j+1] = x[j]+1
            count += 1


print(count)


### FIXED CODE ###



from functools import *
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())




N = int(input())
A = []
for i in range(N):
    A.append(II())


if A[0] >0:
    print(-1)
    sys.exit()

for i in range(1, N):
    if A[i]-A[i-1] > 1:
        print(-1)
        sys.exit()

count = 0
x = [0]*N

for i in range(0,N-1):
    if A[i]+1==A[i+1]:
        count+=1
    else:
        count+=A[i+1]

""" for i in reversed(range(N)):
    if A[i] != x[i]:
        for j in range(i-A[i], i):
            x[j+1] = x[j]+1
            count += 1

 """
print(count)
S = input()
N = len(S)
print("Yes" if S == S[::-1] and S[:(N - 1)//2][::-1] == S[:(N - 1)//2] and S[(N + 3)//2][::-1] == S[(N + 3)//2] else "No")

### FIXED CODE ###

s = input()
n = len(s)
if (s == s[::-1]):
    a = s[:(n-1)//2]
    if (a == a[::-1]):
        b = s[(n+3)//2-1:]
        if (b == b[::-1]):
            print("Yes")
            quit()
print("No")
a = [0]*3
b = [[0]*3]*3
for i in range(3):
	a[i] = list(map(int,input().split()))

n = int(input())

for i in range(n):
  tmp = int(input())
  for j in range(3):
    for k in range(3):
      if a[i][j] == tmp:
        b[i][j] = 1
        if b[i][0]==1 and b[i][1]==1 and b[i][2]==1:
          print('Yes')
          exit()
        elif b[0][j]==1 and b[1][j]==1 and b[2][j] ==1:
          print('Yes')
          exit()
        elif b[0][0]==1 and b[1][1]==1 and b[2][2] ==1:
          print('Yes')
          exit()
        elif b[0][2]==1 and b[1][1]==1 and b[2][0] ==1:
          print('Yes')
          exit()
print('No')


### FIXED CODE ###

ary=[list(map(int,input().split()))for p in range(3)]
for i in range(int(input())):
  data=int(input())
  for j in range(3):
    for k in range(3):
      if ary[j][k]==data:
          ary[j][k]=0
ans="No"
for i in range(3):
  if ary[i][0]==ary[i][1]==ary[i][2]==0 or ary[0][i]==ary[1][i]==ary[2][i]==0:
      ans="Yes"
if ary[0][0]==ary[1][1]==ary[2][2]==0 or ary[2][0]==ary[1][1]==ary[0][2]==0:
    ans="Yes"
print(ans)
N=int(input())

for i in range(0,N):
    s1=input()
    s2='PWGY'
    c=0
    s1=set(s1)
    for j in s1:
        if j in s2:
            c+=1
    
    #o=['One','Two','Three','Four']
    #print(o[c-1])
    if c==1:
        print("One")
    elif c==2:
        print("Two")
    elif c==3:
        print("Three")
    else:
        print("Four")
    

### FIXED CODE ###

n = int(input())
li = []
count =0

liste = [x for x in input().split()]
temp = []

for i in range(len(liste)):
    if liste[i] not in temp:
        temp.append(liste[i])

if len(temp)==3:
    print("Three")

else:
    print("Four")
s = sorted(input())
x = len(s)
for i in range(s-1):
  if s[i+1] ==s[i]:
    print('no')
    exit()
print('yes') 

### FIXED CODE ###

s = sorted(input())
x = len(s)
for i in range(x-1):
  if s[i+1] ==s[i]:
    print('no')
    exit()
print('yes')
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N == int(N)

print(-(-N//2))

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
if N%2 == 0:
  print(int(N/2))
else:
  print(int(N/2+1))
N = int(input())
sum = 0
f = 0
for i in range(1,N):
  for j in range(1,N):
  	if k % j == 0：
    	sum += 1
print(f)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n + 1):
    y = n // i
    ans += y * (y + 1) * i // 2
print(ans)
inp = input().split()
l = list(map(int,inp)).sort
print(l[0],l[1],l[2])

### FIXED CODE ###

inp = list(map(int,input().split()))
inp.sort()
print(inp[0],inp[1],inp[2])
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
    c += (n+1)*a[n]
ans = []
for h_ in range(h):
    a = c[h_*w: w+h_*w]
    if h_ % 2 == 0:
        ans.append(a)
    else:
        ans.append(a[::-1])
for i in ans:
    print(*i)

### FIXED CODE ###

h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
    c += [i+1]*a[i]
ans = []
for h_ in range(h):
    a = c[h_*w: w+h_*w]
    if h_ % 2 == 0:
        ans.append(a)
    else:
        ans.append(a[::-1])
for i in ans:
    print(*i)
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]

def lower(n,m):
  if n > m:
    return m
  else:
    return n


hights = list(map(int, input().split()))
ans = [1]*N

for i in range(0,M):
  table = list(map(int, input().split()))
  if hights[table[0]-1] > hights[table[1]-1]:
    ans[table[1]] = 0
  elif hights[table[0]-1] < hights[table[1]-1]:
    ans[table[0]-1] = 0
  else:
    ans[table[0]-1] = 0
    ans[table[1]-1] = 0

print(sum(ans))

### FIXED CODE ###

N,M = list(map(int, input().split()))


hights = list(map(int, input().split()))
ans = [1]*N

for i in range(0,M):
  a,b = list(map(int, input().split()))
  if hights[a-1] > hights[b-1]:
    ans[b-1] = 0
  elif hights[a-1] < hights[b-1]:
    ans[a-1] = 0
  else:
    ans[a-1] = 0
    ans[b-1] = 0

print(sum(ans))
a, b = map(int, input().split())
print(max(a+b, a-b a*b))

### FIXED CODE ###

a,b=map(int,input().split())
print(max(a+b,a-b,a*b))
S = int(input().strip())

cnt = 0
while(S!=0):
    cnt += S%10
    S /= 10

if (cnt % 9 == 0):
    print("Yes")

else:
    print("No")

### FIXED CODE ###

S = input().strip()

cnt = 0
for c in S:
    cnt += int(c)

if (cnt % 9 == 0):
    print("Yes")

else:
    print("No")
a = int(input())

b = []

for i in range(a-1):
    b.append((input().split())

res = 0

for i in b:
    if (i[1] == 'BTC'):
        res += i[0]*380000
    else:
        res += i[0]

print(res) 

### FIXED CODE ###

a = int(input())

b = []

for i in range(a):
    b.append(input().split())

res = 0

for i in b:
    if (i[1] == 'BTC'):
        res += float(i[0])*380000
    else:
        res += int(i[0])

print(res)
n = int(input())
Taro = 0
Hanako = 0
for i in range(n):
    t,h = input().split()
    for j in range(min(len(t),len(h))):
        if t == h:
            Hanako += 1
            Taro += 1
            break
        if ord(t[j:j+1]) > ord(h[j:j+1]):
            Taro += 3
            break
        if ord(t[j:j+1]) < ord(h[j:j+1]):
            Hanako += 3
            break
	

print("{} {}".format(Taro,Hanako))

### FIXED CODE ###

while True:
    s = input()
    if s == "-":
        break
    s = list(s)
    m = int(input())
    for i in range(m):
        h = int(input())
        st = s[h:]
        for i in range(h):
            st.append(str(s[i]))
        s = st
    print("".join(s))
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 CODE ###

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]))
n=int(input())
a=n//1000
b=(n//100)%10
c=(n//10)%10
d=n%10

if a==b:
  print(Bad)
else if b==c:
  print(Bad)
else if c==d:
  print(Bad)
else:
  print(Good)

### FIXED CODE ###

n=int(input())
a=n//1000
b=(n//100)%10
c=(n//10)%10
d=n%10
 
if a==b:
  print('Bad')
elif b==c:
  print('Bad')
elif c==d:
  print('Bad')
else:
  print('Good')
# coding: utf-8

# https://atcoder.jp/contests/abc109


def main():
    H, W = map(int, input().split())
    a = [None] * H
    for i in range(H):
        a[i] = list(map(int, input().split()))

    operates = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j] % 2 == 1:
                a[i][j] -= 1
                a[i][j+1] += 1
                operates.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
        if i < H-1 and a[i][-1] % 2 == 1:
            a[i][j] -= 1
            a[i+1][j] += 1
            operates.append("{} {} {} {}".format(i+1, j+1, i+2, j+1))

    N = len(operates)
    print(N)
    for i in range(N):
        print(operates[i])


main()
# print(main())


### FIXED CODE ###

# coding: utf-8

# https://atcoder.jp/contests/abc109
# -18:59 done


def main():
    H, W = map(int, input().split())
    a = [None] * H
    for i in range(H):
        a[i] = list(map(int, input().split()))

    operates = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j] % 2 == 1:
                a[i][j] -= 1
                a[i][j+1] += 1
                operates.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
        if i < H-1 and a[i][-1] % 2 == 1:
            a[i][-1] -= 1
            a[i+1][-1] += 1
            operates.append("{} {} {} {}".format(i+1, W, i+2, W))

    N = len(operates)
    print(N)
    for i in range(N):
        print(operates[i])


main()
# print(main())
a,b,c,d,e,k= map(int, input().split())

A-B = abs(b-a)
A-C = abs(c-a)
A-D = abs(d-a)
A-E = abs(e-a)
B-C = abs(c-b)
B-D = abs(d-b)
B-E = abs(e-b)
C-D = abs(d-c)
C-E = abs(e-c)
D-E = abs(e-d)

if A-B and A-C and A-D and A-E and B-C and B-E and C-D and C-E and D-E > k:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())



if e-a > k:
    print(":(")
else:
    print("Yay!")
A, B = map(int, input())
print((A+B) % 24)

### FIXED CODE ###

A, B = map(int, input().split())
print((A+B) % 24)
import sys
mINF = -float('inf')
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s)-1 for s in sys.stdin.readline().rstrip("\n").split()]
c = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
loop = []
for i in range(n):
    loop_costs = []
    lc = 0
    np = i
    while True:
        lc += c[p[np]]
        loop_costs.append(lc)
        np = p[np]
        if np == i:
            break
    loop.append(loop_costs)
ans = mINF
for i in range(n):
    loop_i = loop[i]
    if len(loop_i) < k:
        if loop_i[-1] > 0:
            q, mod = divmod(k, len(loop_i))
            modmax = max(loop_i[:mod])
            ans = max(ans,loop_i[-1]*q+modmax)
        else:
            ans = max(ans,max(loop_i))
    else:
        ans = max(ans,max(loop_i[:k]))
print(ans)

### FIXED CODE ###

import sys
mINF = -float('inf')
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s)-1 for s in sys.stdin.readline().rstrip("\n").split()]
c = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
loop = []
for i in range(n):
    loop_costs = []
    lc = 0
    np = i
    while True:
        lc += c[p[np]]
        loop_costs.append(lc)
        np = p[np]
        if np == i:
            break
    loop.append(loop_costs)
ans = mINF
for i in range(n):
    loop_i = loop[i]
    if len(loop_i) < k:
        if loop_i[-1] > 0:
            q, mod = divmod(k, len(loop_i))
            if mod == 0:
                q = q - 1
                modmax = max(loop_i)
            else:
                modmax = max(loop_i[:mod])
            ans = max(ans,loop_i[-1]*q+modmax)
        else:
            ans = max(ans,max(loop_i))
    else:
        ans = max(ans,max(loop_i[:k]))
print(ans)
import numpy as np
a = input()
b = input()
a_int =int(a)
b_int = int(b)
# print(a)
# print(b)
c = ""
if(a<b):
    for i in range(b_int):
        c += str(a)
    print(c)

else:
    for i in range(a_int):
        c += str(b)
    print(c)

### FIXED CODE ###

import numpy as np
a,b=input().split()
# print(a)
# print(b)
a_int =int(a)
b_int = int(b)
# print(a)
# print(b)
c = ""
if(a<b):
    for i in range(b_int):
        c += str(a)
    print(c)

else:
    for i in range(a_int):
        c += str(b)
    print(c)
from random import shuffle
N = int(input())
P = [int(c)-1 for c in input().split()]
#shuffle(P)
import numba
import numpy as np
#N = int(input())
#P = [int(c)-1 for c in input().split()]
# Mat = [[min(y, N-1-y, x, N-1-x) for y in range(N)] for x in range(N)]
# Mat = np.array(Mat)
#@numba.njit()
def proc(N, P):
    ans = 0
    Removed = np.zeros((N, N), dtype=np.int32)
    closed = np.zeros((N,N), dtype=np.int32)
    Mat = np.zeros((N, N), dtype=np.int32)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    for i in range(N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y][x]
        #print(p, Mat[y][x])
        Removed[y][x] = True
        #Mat[y][x] -= 1
        st = [(y, x)]
        clsd = [(y, x)]
        closed[y][x] = True
        while st:
            vy, vx = st.pop()
            vr = Removed[vy][vx]
            val = Mat[vy][vx]
            for dy, dx in zip(Dy, Dx):
                uy = vy + dy
                ux = vx + dx
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy][ux]
                if vr:
                    if Mat[uy][ux] >= val+1:
                        Mat[uy][ux] = val
                        st.append((uy, ux))
                else:
                    if Mat[uy][ux] >= val+2:
                        Mat[uy][ux] = val+1
                        st.append((uy, ux))
        for y, x in clsd:
            closed[y][x] = False
    # for m in Mat:
    #     print(m)
    print(ans)
proc(N, P)



### FIXED CODE ###

import numba
import numpy as np
N = int(input())
P = np.array([int(c)-1 for c in input().split()])

#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)

@numba.njit("void(i8,i8[:])")
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        st = [(y, x)]
        while st:
            vy, vx = st.pop()
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                dy = Dy[j]
                dx = Dx[j]
                uy = vy + dy
                ux = vx + dx
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        st.append((uy, ux))
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        st.append((uy, ux))
    # for m in Mat:
    #     print(m)
    print(ans)
proc(N, P)
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
ans=[]
for i in range(H):
  for j in range(W):
    if i%2 == 0:
      if j != W-1:
        if A[i][j]%2 == 1:
          A[i][j+1]+=1
          ans.append([i+1,j+1,i+1,j+2])
      else:
        if A[i][j]%2 == 1 and i < H-1:
          A[i+1][j]+=1
          ans.append([i+1,j+1,i+2,j+1])
    else:
      if j != W-1:
        if A[i][W-1-j]%2 == 1:
          A[i][W-j]+=1
          ans.append([i+1,W-j,i+1,W-j+1])
      else:
        if A[i][W-1-j]%2 == 1 and i < H-1:
          A[i+1][W-1-j]+=1
          ans.append([i+1,W-j,i+2,W-j+1])
print(len(ans))
for i in range(len(ans)):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])

### FIXED CODE ###

H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
ans=[]
for i in range(H):
  for j in range(W):
    if i%2 == 0:
      if j != W-1:
        if A[i][j]%2 == 1:
          A[i][j+1]+=1
          ans.append([i+1,j+1,i+1,j+2])
      else:
        if A[i][j]%2 == 1 and i < H-1:
          A[i+1][j]+=1
          ans.append([i+1,j+1,i+2,j+1])
    else:
      if j != W-1:
        if A[i][W-1-j]%2 == 1:
          A[i][W-2-j]+=1
          ans.append([i+1,W-j,i+1,W-j-1])
      else:
        if A[i][W-1-j]%2 == 1 and i < H-1:
          A[i+1][W-1-j]+=1
          ans.append([i+1,W-j,i+2,W-j])
print(len(ans))
for i in range(len(ans)):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])