Harryxun/stf_run huggingface dataset:
from itertools import chain

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

def f(x, h, w):
    h2 = h // 2
    h3 = h - h2
    a,b,c = sorted((x,w*h2,w*h3))
    w2 = w // 2
    w3 = w - w2
    d,e,f = sorted((x,w2*h,w3*h))
    return min(c-a, f-d)

ss = ((w2*h, h, w-w2) for w2 in range(1, (w+1)//2))
ts = ((w*h2, h-h2, w) for h2 in range(1, (h+1)//2))

print(min(f(*xs) for xs in chain(ss, ts)))

### FIXED CODE ###

from itertools import chain

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

def f(x, h, w):
    h2 = h // 2
    h3 = h - h2
    a,b,c = sorted((x,w*h2,w*h3))
    w2 = w // 2
    w3 = w - w2
    d,e,f = sorted((x,w2*h,w3*h))
    return min(c-a, f-d)

ss = ((w2*h, h, w-w2) for w2 in range(1, (w+3)//2))
ts = ((w*h2, h-h2, w) for h2 in range(1, (h+3)//2))

print(min(f(*xs) for xs in chain(ss, ts)))
X,Y=map(int,input().split())

a = 2*X -Y/2
b = Y/2 - X

if (a+b) == X:
    pass 
    if (2*a+4*b) == Y:
        print('Yes')
    else:
        print('No')
else:
    print('No')


### FIXED CODE ###

A,B,C,D,E=map(int,input().split())

if A == 0:
    print(1)
elif B == 0:
    print(2)
elif C == 0:
    print(3)
elif D == 0:
    print(4)
else:
    print(5)
N = input()
B = False
kaisu = 0
array[] = map(int,input().split())
while !B:
	for i in range(N):
  		if array[i]/2 == 1:
    	B = True
  	if B == False:
    	array[] = map(calc ,array[])
    	kaisu++
  	else:
    	break
        
print(kaisu)

def calc(n):
  retuen n/2
    

    

### FIXED CODE ###

N = int(input())
B = False
kaisu = 0
array = list(map(int,input().split()))

def calc(n):
  return int(n) / 2
  
  
while not B:
  for i in range(N):
    if array[i] % 2 == 1:
      B = True
  if not B:
    array = list(map(calc, array))
    kaisu += 1
  else:
    break
        
print(kaisu)
N = int(input())
H = list(map(int, input().split()))

res=0


while True:

#       print(H)
        for l in range(N):
                if H[l]!=0:
                        break
        for r in range(l+1,N):
                if H[r]==0:
                        r-=1
                        break

#       print(l,r)

        if l>r:
                break

        if l==r:
                miin=H[l]
        else:
                miin=min(H[l:r])


#       print(min(H[l:r]))

        res+=miin

        if miin == 0:
                break

        for i in range(l,r+1):
                H[i] -= miin


res += H[N-1]
print(res)

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))

mizu=0

while True:

    end=True
    for i in range(n):
       if h[i]!=0:
           end=False

    if end:
        break

    for l in range(n):
        if h[l]!=0:
            break

    for r in range(l,n):
        if h[r]==0:
            r-=1
            break

    mizu+=1
    for i in range(l,r+1):
        h[i] -= 1

print(mizu)
A=[int(i) for i in input().split]
sort_list=sorted(A)
if sort_list[0]+sort_list[1]==sort_list[2]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

A=[int(i) for i in input().split()]
sort_list=sorted(A)
if sort_list[0]+sort_list[1]==sort_list[2]:
    print("Yes")
else:
    print("No")
from collections import Counter
n = int(input())
ss = [sorted(input()) for i in range(n)]
dic = Counter(ss)

### FIXED CODE ###

from collections import Counter
n=int(input())
string_list=["".join(sorted(list(input()))) for i in range(n)]
counter=Counter(string_list)
cnt=0
for k, v in counter.items():
  cnt+=int(v*(v-1)/2)
print(cnt)
answerL = []
for i in range(D):
    listS = list(map(int, input().split()))
    maxi = min(listS)
    target = listS.index(maxi)
    answerL.append(target+1)
for ans in answerL:
    print(ans)

### FIXED CODE ###

D = int(input())
listC = list(map(int, input().split()))
answerL = []
for i in range(D):
    listS = list(map(int, input().split()))
    maxi = max(listS)
    target = listS.index(maxi)
    answerL.append(target+1)
for ans in answerL:
    print(ans)
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

def primes(n):
    isp = [True for _ in range(n+1)]
    isp[0] = False
    isp[1] = False
    l = ceil(sqrt(n))
    n += 2
    i = 4
    while i < n:
        isp[i] = False
        i += i
    for i in range(3, l, 2):
        if not isp[i]:
            continue
        for j in range(i*2, n, i):
            isp[j] = False
    return isp

q = int(input())
maxv = 10**5
isp = primes(maxv)
cnt = [0 for _ in range(maxv + 1)]

ans = 0
for i in range(3, maxv+1):
    if i%2 and isp[i] and isp[(i+1)//2]:
        cnt[i] = 1
acc = list(accumulate(cnt))
for _ in range(q):
    l, r = map(int, input().split())
    print(acc[r] - acc[l-1])

### FIXED CODE ###

import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

def primes(n):
    isp = [True for _ in range(n+1)]
    isp[0] = False
    isp[1] = False
    l = ceil(sqrt(n))
    n += 1
    for i in range(2, l):
        if not isp[i]: continue
        for j in range(i*2, n, i): isp[j] = False
    return isp

q = int(input())
maxv = 10**5
isp = primes(maxv)
cnt = [0 for _ in range(maxv + 1)]

for i in range(3, maxv+1):
    if i%2 and isp[i] and isp[(i+1)//2]:
        cnt[i] = 1
#print(cnt[:10])
acc = list(accumulate(cnt))
for _ in range(q):
    l, r = map(int, input().split())
    print(acc[r] - acc[l-1])
n=input()
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if n=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(n)==26:
        q=a.index(n[-1])
        c=0
        d=[n[-1]]
        for i in range(24,0,-1):
            c+=1
            d.append(n[i])
            d.sort()
            if d.index(n[i])<len(d)-1:
                print(n[:26-c-1]+d[d.index(n[i])+1])
                break
        else:
            print(a[a.index(n[i])+1])
    else:
        for i in range(len(n)):
            a.pop(a.index(n[i]))
        print(n+a[0])

### FIXED CODE ###

n=input()
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if n=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(n)==26:
        q=a.index(n[-1])
        c=0
        d=[n[-1]]
        for i in range(24,-1,-1):
            c+=1
            d.append(n[i])
            d.sort()
            if d.index(n[i])<len(d)-1:
                print(n[:26-c-1]+d[d.index(n[i])+1])
                break
    else:
        for i in range(len(n)):
            a.pop(a.index(n[i]))
        print(n+a[0])
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = list(map(int, input().split()))

_ac = (a-1) // c
_bc = b // c

_ad = (a-1) // d
_bd = b // d

_acd = (a-1) // lcm(c,d)
_bcd = b // lcm(c,d)

m = (b-a+1) - ((_bc-_ac) + (_bd-_ad) - (_bcd-_acd))
print(m)



### FIXED CODE ###

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = list(map(int, input().split()))

_ac = (a-1) // c # a以下のcの倍数の数
_bc = b // c # b以下のcの倍数の数

_ad = (a-1) // d # a以下のdの倍数の数
_bd = b // d # b以下のdの倍数の数

_acd = (a-1) // lcm(c,d) # a以下のcdの倍数の数
_bcd = b // lcm(c,d) # b以下のcdの倍数の数

m = (b-a+1) - ((_bc-_ac) + (_bd-_ad) - (_bcd-_acd))
print(m)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

S = np.array(list(readline().rstrip()),np.int64)
T = np.array(list(readline().rstrip()),np.int64)

LS = len(S); LT = len(T)
LSext = LS + LT
LSext += (-LSext) % LS
Sext = np.tile(S,LSext//LS)

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

U = 10**6 + 100
base = 1234
MOD = 10**9 + 9
x = np.full(U,base,dtype=np.int64); x[0] = 1
power = cumprod(x,MOD)
x = np.full(U,pow(base,MOD-2,MOD),dtype=np.int64); x[0] = 1
power_inv = cumprod(x,MOD)

def RollingHash(S):
    return (S * power[:len(S)] % MOD).cumsum() % MOD

Sext_hash = RollingHash(Sext)
T_hash = RollingHash(T)[-1]

# ある地点を開始位置として、長さLTの文字列のhash値
x = Sext_hash[LT-1:LS+LT-1]
x[1:] -= Sext_hash[:LS-1]
x *= power_inv[:LS]; x %= MOD


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input().rstrip()
T = input().rstrip()

S,T

# Sの方が長くする
LS = len(S)
LT = len(T)
n = (LT + (-LT) % LS) // LS
S *= (n+1)
S = S[:LS+LT]

MOD = 10 ** 16 + 61
base = 12345
base_inv = pow(base,MOD-2,MOD) 
power = [1] * (LS+LT)
power_inv = [1] * (LS+LT)
for n in range(1,LS+LT):
    power[n] = power[n-1] * base % MOD
    power_inv[n] = power_inv[n-1] * base_inv % MOD

def to_rolling_hash(S):
    ret = [0] * len(S)
    for i,s in enumerate(S):
        ret[i] = (ret[i-1] + power[i] * ord(s)) % MOD
    return ret

S_hash = to_rolling_hash(S) + [0]
T_hash = to_rolling_hash(T)[-1] # 文字列全体

can_start = [(S_hash[i + LT - 1] - S_hash[i - 1]) * power_inv[i] % MOD == T_hash for i in range(LS)]

INF = 10 ** 18
visited = [False] * LS
dp = [None] * LS

arr = [INF] * LS

q = [(i,0) for i,bl in enumerate(can_start) if not bl]

while q:
    qq = []
    for x,d in q:
        if arr[x] == INF:
            arr[x] = d
            qq.append(((x-LT)%LS, d+1))
    q = qq

answer = max(arr)

if answer >= INF:
    answer = -1

print(answer)
x = input().split(' ')
a, b, c = x[0], x[1], x[2]
ans = c - (a-b)
if c > 0:
  print(c)
else:
  print 0


### FIXED CODE ###

x = input().split(' ')
n = list(map(int, x))
ans = n[2] - (n[0]-n[1])
if ans > 0:
  print(ans)
else:
  print(0)
a, b = map(int, input().split())
print(((b-a)*(b-a+1)/2)-b)

### FIXED CODE ###

n = int(input())
if n > 999:
    print("ABD")
    exit()
print("ABC")
from math import log
# 引き出したいお金の額を入力する
N = int(input())

# 整数aの累乗のうち、整数N以下かつ最も大きいものを返す関数を定義
def func(N, a):
    index = int(log(N) / log(a))
    return a ** index

# 引き出し回数を再帰的に求める関数を定義
def search_times_re(N):
    times = 0
    if N < 6:
        times = N
        return times
    elif N < 9:
        times = 1 + (N - 6)
    else:
        N1 = search_times_re(N - func(N, 6))
        N2 = search_times_re(N - func(N, 9))
        if N1 < N2:
            return 1 + N1
        else:
            return 1 + N2

print(search_times_re(N))

### FIXED CODE ###

N = int(input())
ans = N
for i in range(0, N + 1, 6):
    cnt = 0
    j = N - i
    while i > 0:
        cnt += i % 6
        i //= 6
    while j > 0:
        cnt += j % 9
        j //= 9
    ans = min(ans, cnt)
print(ans)
n,d = map(int,input().split())
w = [list(map(int,input().split())) for a in range(n)]
c = 0
 
for i in range(n-1):
  for j in range(i+1,n+1):
    b = 0
    for m in range(d):
      b += (w[i][m]-w[j][m])**2
    if (b**0.5)　== float(int(b**0.5)):
      c += 1
      
print(c)

### FIXED CODE ###

n,a,b = map(int,input().split())
print(min(a*n,b))
N,K = map(int,input().split())
S = list(input())

if len(S) == 1:
    print(1)
elif len(S) == 2:
    print(2)
elif S[0] == '0':
    LA = [0]
    LB = [0]
    for i in range(1,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
        elif (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    if K >= len(LB)-1:
        print(len(S))
    else:
        for i in range(len(LA)-K):
            J = LB[i+K]-LB[i]+1
            if J > ANS:
                ANS = J
        print(ANS)
else:
    LA = [0]
    LB = []
    for i in range(0,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
        elif (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)\
    ANS = 0
    if K >= len(LB)-1:
        print(len(S))
    else:
        for i in range(len(LB)-K):
            J = LB[i+K]-LA[i]+1
            if J > ANS:
                ANS = J
        print(ANS)

### FIXED CODE ###

N,K = map(int,input().split())
S = list(input())

if len(S) == 1:
    print(1)
elif len(S) == 2:
    print(2)
elif S[0] == '0':
    LA = [0]
    LB = [0]
    for i in range(0,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
    for i in range(1,N-1):
        if (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    if K >= len(LB)-1:
        print(N)
    else:
        for i in range(len(LB)-K):
            J = LB[i+K]-LA[i]+1
            if J > ANS:
                ANS = J
        print(ANS)
else:
    LA = [0]
    LB = []
    for i in range(0,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
        elif (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    if K >= len(LB)-1:
        print(N)
    else:
        for i in range(len(LB)-K):
            J = LB[i+K]-LA[i]+1
            if J > ANS:
                ANS = J
        print(ANS)
r,g,d=map(int, input().spilit)
if (100r+10g+d)%4=0:
  print("YES")
else: print("NO")

### FIXED CODE ###

a,b,c= map(int, input().split())
if (100*a+10*b+c) % 4 == 0:
    print('YES')
else:
    print('NO')
a, b = map(int, input().split())
retu = ""
retu += str(a) + str(b)
if int(retu) == int(c)**2:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a, b = map(int, input().split())
c = str(a) + str(b)
c = int(c)
d = c**(1/2)

if d.is_integer():
    print("Yes")
else:
    print("No")
import numpy as np

h, n = map(int,input().split())
a = np.zeros(n, dtype = int)
b = np.zeros(n, dtype = int)
for i in range(n):
    a[i], b[i] = map(int,input().split())

dp = np.zeros(10001, dtype = int)

for i in range(10001):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])


### FIXED CODE ###

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

if h%a == 0:
    print(int(h/a))
else:
    print(int(h/a)+1)
n=input()
v=input().split()
#vin=[int(i) for i in v]
nlis=list(n)
nint=int(n)
part_num=int((nint/2))
ev_num=[]
for i in range(part_num):
    ev = 2*i
    ev_num.extend(v[ev])
count_ev=[]
for i in range(part_num):
    count=0
    count_ev.append(ev_num.count(ev_num[i]))
    
ans_ev=min(count_ev)

od_num=[]
for i in range(part_num):
    od = (2*i) + 1
    od_num.extend(v[od])
count_od=[]
for i in range(part_num):
    count=0
    count_od.append(od_num.count(od_num[i]))
ans_od=min(count_od)

if v.count(v[0]) == len(v):
    ans=part_num
else:
    ans=ans_ev+ans_od
print(ans)  

### FIXED CODE ###

n=input()
n=list(n)
if n[0]=='1':
    n[0]='9'
elif n[0]=='9':
    n[0]='1'
if n[1]=='1':
    n[1]='9'
elif n[1]=='9':
    n[1]='1'
if n[2]=='1':
    n[2]='9'
elif n[2]=='9':
    n[2]='1'
ans=int("".join(n))
print(ans)
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
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()))
INF=2**31-1

class BIT:
    def __init__(self, n):
        # 0-indexed
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    # [0, i]を合計する
    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    # 値の追加：添字, 値
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    # 区間和の取得 [l, r)
    def get(self, l, r=None):
        # 引数が1つなら一点の値を取得
        if r is None: r = l+1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

N,Q=MAP()
bit=BIT(N)
for _ in range(Q):
    com,x,y=MAP()
    if com==0:
        bit.add(x, y)
    else:
        print(bit.get(x, y+1))



### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
from operator import add

sys.setrecursionlimit(10 ** 9)
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()))
INF=float('inf')

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, max, addなど)
        :param init: 要素の初期値
        """
        self.n = n
        self.func = func
        self.init = init
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        # 範囲外なら初期値
        if r <= a or b <= l:
            return self.init
        # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
        if a <= l and r <= b:
            return self.tree[k]
        # 一部だけ範囲内なら2つに分けて再帰的に調査
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N,Q=MAP()
# 1-indexed対応
st=SegTree(N+1, add, 0)
for _ in range(Q):
    com,x,y=MAP()
    if com==0:
        st.update(x, y+st.get_val(x, x+1))
    else:
        print(st.get_val(x, y+1))
def fill0(s,x,y):
	A[y][x] = 0
	try: if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	except: pass
	try: if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	except: pass
	try: if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	except: pass
	try: if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)
	except: pass

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
N,M = map(int,input().split())
S = list(str(input()))
T = list(str(input()))
MOD = 10**9+7
L = lcm(N,M)
if L == max(N,M):
  L *= 2
X = [""]*(L%MOD)
if S[0] != T[0]:
  print(-1)
  exit()
else:
  X[0] = S[0]
 
for i in range(1,N):
  X[i*L//N] = S[i]
for j in range(1,M):
  if X[j*L//M] == "" or X[j*L//M] == T[j]:
    pass
  else:
    print(-1)
    exit()
 
print(L)

### FIXED CODE ###

import math
 
N,M = map(int,input().split())
S = list(str(input()))
T = list(str(input()))
g = math.gcd(N,M)
gn,gm = N//g,M//g
for i in range(g):
  if S[i*gn] != T[i*gm]:
    print(-1)
    exit()

print(gn*gm*g)
m,k = map(int, input().split())
s = input()
s[k] = s[k].lower()
print(s)

### FIXED CODE ###

m,k = map(int, input().split())
s = input()
i = k-1
s = s[:i] + s[i].lower() + s[i+1:]
print(s)
n = int(input())
a = list(map(int, input().split()))
a.append(0)
b = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        d = b[i] - a[i]

        if a[i + 1] < d:
            count += a[i + 1]
            a[i + i] = 0
        else:
            count += d
            a[i + 1] -= d

    else:
        count += b[i]

print(count)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        d = b[i] - a[i]

        if a[i + 1] < d:
            count += a[i + 1]
            a[i + 1] = 0
        else:
            count += d
            a[i + 1] -= d

    else:
        count += b[i]

print(count)
from math import sqrt

N=int(input())
for i in range(int(sqrt(N)),0,-1):
    if N % i == 0:
        j=N//i
        pirnt(i+j-2)
        break


### FIXED CODE ###

from math import sqrt

N = int(input())
for i in range(int(sqrt(N)), 0, -1):
    if N % i == 0:
        j = N // i
        print(i + j - 2)
        break
def manh(x,y):
    i,j = x[0],x[1]
    k,m = y[0],y[1]
    return abs(i-k)+abs(m-j)
H,W = map(int,input().split())
G = {i:[] for i in range(1,H+1)}
for i in range(1,H+1):
    row = list(map(int,input().split()))
    row.insert(0,0)
    for j in range(1,W+1):
        row[j] = row[j]%2
        if row[j]==1:
            G[i].append(j)
B = []
C = []
for i in range(1,H+1):
    for j in range(1,len(G[i]),2):
        B.append(((i,G[i][j-1]),(i,G[i][j])))
    if len(G)%2==1:
        C.append((i,G[i][-1]))
D = []
for i in range(1,len(C),2):
    x = C[i-1]
    y = C[i]
    D.append((x,y))
N = 0
for b in B:
    x,y = b[0],b[1]
    N += manh(x,y)
for d in D:
    x,y = d[0],d[1]
    N += manh(x,y)
print(N)
for b in B:
    x,y = b[0],b[1]
    i,j = x[0],x[1]
    k,m = y[0],y[1]
    for t in range(j,m):
        print(i,t,i,t+1)
for d in D:
    x,y = d[0],d[1]
    i,j = x[0],x[1]
    k,m = y[0],y[1]
    for t in range(i,k):
        print(t,j,t+1,j)
    if j>=m:
        for t in range(j,m,-1):
            print(k,t,k,t-1)
    else:
        for t in range(j,m):
            print(k,t,k,t+1)    

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [[0 if A[i][j]%2==0 else 1 for j in range(W)] for i in range(H)]
C = [deque([]) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if B[i][j]==1:
            C[i].append(j)
cnt = 0
for i in range(H):
    cnt += sum(B[i])
if cnt%2==1:
    for i in range(H-1,-1,-1):
        if len(C[i])>0:
            C[i].pop()
            break
D = []
flag = 0
i = 0
while i<H:
    while len(C[i])>=2:
        if flag==0:
            j1 = C[i].popleft()
            i1 = i
            j2 = C[i].popleft()
            i = i
            for j in range(j1,j2):
                D.append((i,j,i,j+1))
        else:
            j1 = C[i].pop()
            i1 = i
            j2 = C[i].pop()
            i2 = i
            for j in range(j1,j2,-1):
                D.append((i,j,i,j-1))
    if len(C[i])==0:
        i += 1
    else:
        j = i+1
        while j<H:
            if len(C[j])>0:
                break
        j1 = C[i].pop()
        i1 = i
        if flag==0:
            j2 = C[j].pop()
            i2 = j
            for l in range(j1,W-1):
                D.append((i1,l,i1,l+1))
            for k in range(i1,i2):
                D.append((k,W-1,k+1,W-1))
            for l in range(W-1,j2,-1):
                D.append((i2,l,i2,l-1))
        else:
            j2 = C[j].popleft()
            i2 = j
            for l in range(j1,0,-1):
                D.append((i1,l,i1,l-1))
            for k in range(i1,i2):
                D.append((k,0,k+1,0))
            for l in range(j2):
                D.append((i2,l,i2,l+1))
        flag = 1-flag
        i = j
print(len(D))
for d in D:
    print(d[0]+1,d[1]+1,d[2]+1,d[3]+1)