Harryxun/stf_run huggingface dataset:
H, W, M = map(int, input().split())
d1 = dict()
d2 = dict()
G = [[False] * (W + 1) for _ in range(H + 1)]
for i in range(M):
    h, w = map(int, input().split())
    if h not in d1:
        d1[h] = 0
    if w not in d2:
        d2[w] = 0
    d1[h] += 1
    d2[w] += 1
    G[h][w] = True

d1 = list(d1.items())
d2 = list(d2.items())

d1.sort(reverse=True, key=lambda x: x[1])
d2.sort(reverse=True, key=lambda x: x[1])

print(d1[0][1] + d2[0][1] - int(G[d1[0][0]][d2[0][0]]))


### FIXED CODE ###

H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)

bom = []
for i in range(M):
    h, w = map(int, input().split())
    bom.append([h, w])
    row[h] += 1
    col[w] += 1
 
rmax = max(row)
cmax = max(col)
cnt = row.count(rmax) * col.count(cmax)

for h, w in bom:
    if rmax == row[h] and cmax == col[w]:
        cnt -= 1

print(rmax + cmax - (cnt == 0))
a,b,n = map(int, input().split())
#1 <= x <= n
#minimize  int(x/b)
#x = int(a*x/b) - a * int(x/b)

print((a*n)//b)

### FIXED CODE ###

k =int(input())
a,b = map(int, input().split())
c = b//k
 
if b%k==0:
  print("OK")
elif k*c >=a:
  print("OK")
else:
  print("NG")
H, W, D = [int(x) for x in input().strip().split(' ')]
stage = {}
for i in range(H):
    nums = [int(x) for x in input().strip().split(' ')]
    for j in range(W):
        stage[nums[j]] = [i + 1, j + 1]
Q = int(input())
tests = []
for _ in range(Q):
    tests.append([int(x) for x in input().strip().split(' ')])

scores = []
done = {}
for i in range(Q):
    L, R = tests[i]
    if (L, R) in done:
        scores.append(done[(L, R)])
    elif L == R:
        scores.append(0)
    else:
        x, y = stage[L]
        score = 0
        while L < R:
            if (L, R) in done:
                score += done[(L, R)]
                break
            new_x, new_y = stage[L + D]
            del stage[L + D]
            score += abs(new_x - x) + abs(new_y - y)
            x = new_x
            y = new_y
            L += D
        scores.append(score)
        done[(L, R)] = score

for score in scores:
    print(score)



### FIXED CODE ###

import numpy as np

H, W, D = [int(x) for x in input().strip().split(' ')]
stage = {}
for i in range(H):
    nums = [int(x) for x in input().strip().split(' ')]
    for j in range(W):
        stage[nums[j]] = [i + 1, j + 1]
Q = int(input())
tests = []
for _ in range(Q):
    tests.append([int(x) for x in input().strip().split(' ')])

scores = np.zeros([H * W + 1]).astype(np.int)
for i in range(H * W, 0, -1):
    if i + D > H * W:
        scores[i] = 0
    else:
        x, y = stage[i]
        ox, oy = stage[i + D]
        scores[i] = scores[i + D] + abs(x - ox) + abs(y - oy)

for i in range(Q):
    L, R = tests[i]
    print(scores[L] - scores[R])
a = str(raw_input())
b = str(raw_input())
c = str(raw_input())

if len(a) == 1:
    print 'a'
    return

s = a[0]
a = a[1:]
while True:
    if s == 'a':
        if len(a) == 1:
            print 'a'
            break
        s = a[0]
        a = a[1:]
    elif s == 'b':
        if len(b) == 1:
            print 'b'
            break
        s = b[0]
        b = b[1:]
    elif s == 'c':
        if len(c) == 1:
            print 'c'
            break
        s = c[0]
        c = c[1:]


### FIXED CODE ###

a = int(raw_input())
b = int(raw_input())
h = int(raw_input())
print "{}".format(int((a+b)*h/2))
x,y = int(input())
N = x[0]
D = y[0]
count = 0
for i in range(1,N):
  dist = sqrt(x[i]^2+y[i]^2)
  if dist <= D:
    count += 1
print(count)
    

### FIXED CODE ###

import numpy as np
N,D = input().strip().split()
N = int(N)
D = int(D)
count = 0
for i in range(N):
    x,y = input().strip().split()
    x = int(x)
    y = int(y)
    #print(x**2)
    dist = np.sqrt((x)**2+(y)**2)
    #print(dist)
    if dist <= D:
        count +=1
print(count)
A,B,K = map(int,input().split())
cnt = 0
for i in range(1, min(A,B)):
  if A % i == 0 and B % i == 0:
    cnt += 1
  if cnt == K:
    break
print(i)

### FIXED CODE ###

A,B,K = map(int,input().split())
x = []
for i in range(1, min(A,B)+1):
  if A % i == 0 and B % i == 0:
    x.append(i)
print(x[-K])
s,t,u = map(str,input().spilt())

print(str.upper(s[0])+str.upper(t[0])+str.upper(u[0]))



### FIXED CODE ###

s,t,u = input().split()

print(s[0].upper()+t[0].upper()+u[0].upper())
a = list(input())
b = list(input())
a_l = len(a)
b_l = len(b)
 
for i in range(1,a_l-b_l+2):
    if a_l < b_l:
        f=False
        break
    f = True
    for j in range(1,b_l+1):
        if not(b[b_l-j] == a[a_l-i-j+1] or a[a_l-i-j+1] == "?"):
            f = False
            break
    if f:
        for j in range(1,b_l+1):
            a[a_l-i-j+1] = b[b_l-j]
        break
 
if f:
    print("".join(a).replace("?", "a"))
else:
    print("UNRESTORABLE")

### FIXED CODE ###


a = list(input())
b = list(input())
a_l = len(a)
b_l = len(b)
f = False
for i in range(1,a_l-b_l+2):
    f = True
    for j in range(1,b_l+1):
        if not(b[b_l-j] == a[a_l-i-j+1] or a[a_l-i-j+1] == "?"):
            f = False
            break
    if f:
        for j in range(1,b_l+1):
            a[a_l-i-j+1] = b[b_l-j]
        break
 
if f:
    print("".join(a).replace("?", "a"))
else:
    print("UNRESTORABLE")
# -*- coding: utf-8 -*-
N = int(input())
X = input()
X_10 = 0
popcount_X = 0

def popcount(n):
  return bin(n).count("1")

def f_func(n):
  if n == 0:
    return 0
  return n % popcount(n)

for i in range(N):
  j = N - (i + 1)
  X_10 += int(X[i]) * 2 ** j
  if X[i] == '1':
    popcount_X += 1

popcount_X_plus = popcount_X + 1
popcount_X_minus = popcount_X - 1
fX_plus = X_10 % popcount_X_plus
fX_minus = X_10 % popcount_X_minus

for i in range(N):
  j = N - (i + 1)
  
  Xi = 0
  f = 0
  popcnt = 0
  ans = 1
  
  if X[i] == '0':
    Xi = X_10 + 2**j
    popcnt = popcount_X + 1
    f = (fX_plus + 2**j % popcount_X_plus) % popcount_X_plus
    
  elif X[i] == '1':
    Xi = X_10 - 2**j
    popcnt = popcount_X - 1
    f = (fX_minus - 2**j % popcount_X_minus) % popcount_X_minus
  
  while f > 0:
    f = f_func(f)
    ans += 1
  print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
X = input()
X_10 = int(X, 2)
popcount_X = X.count("1")
popcount_X_plus = popcount_X + 1
popcount_X_minus = popcount_X - 1
f_plus = X_10 % popcount_X_plus
f_minus = X_10 % popcount_X_minus if popcount_X_minus != 0 else 0

def popcount(n):
  return bin(n).count("1")

def f(n):
  if n == 0:
    return 0
  return n % popcount(n)

for i in range(N):
  j = N - (i + 1)
  n = 0
  ans = 1
  
  if X[i] == '0':
#    n = (f_plus + (2**j % popcount_X_plus)) % popcount_X_plus
    n = (f_plus + pow(2, j, popcount_X_plus)) % popcount_X_plus
  else:
    if popcount_X_minus == 0:
      print(0)
      continue
    else:
#      n = (f_minus - (2**j % popcount_X_minus) + popcount_X_minus) % popcount_X_minus
      n = (f_minus - pow(2, j, popcount_X_minus) + popcount_X_minus) % popcount_X_minus
  
  while n > 0:
    n = f(n)
    ans += 1
  print(ans)
c = input()
print('A' if ord('A') <= ord(A) <= ord('Z') else 'a')

### FIXED CODE ###

print('A' if ord('A') <= ord(input()) <= ord('Z') else 'a')
import fractions
from functools import reduce
import math
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
List=list(map(int,input().split()))
aa = lcm_list(List) / 2
cnt = 0
a=List[0]
while a%2 == 0:
  cnt+=1
  a /= 2
out = 0
for i in range(len(List)):
  if List[i] % (2**cnt) == 1:
    out = 1
  elif List[i] % (2**(cnt+1)) == 1:
    out = 1

if out == 1:
  print(0)
else:
  print(math.ceil((M / aa)) // 2)
  

### FIXED CODE ###

N, M = map(int, input().split())
A = list(set(map(lambda x : int(x)//2, input().split())))
def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
  return (x * y) // gcd(x, y)
l = A[0]
for a in A[1:]:
  l = lcm(l, a)
ans = (M // l + 1) // 2
for a in A[1:]:
  if (l // a) % 2 == 0:
    ans = 0
    break
print(ans)
N = int(input())
K = int(input())
x = [int(i) for i in input().split()]

ans = 0
for xi in x:
    if xi < K//2:
        ans += xi*2
    else:
        ans += (K-xi)*2
print(ans)  

### FIXED CODE ###

N = int(input())
A = int(input())
print(N**2 - A)
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if not [i,j] in set(bomb):
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

### FIXED CODE ###

h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

o = rr()
e = rr()
s = ''
for a, b in itertools.zip_longest(o, e, fillvalu=''):
  s += a + b
print(s)








### FIXED CODE ###

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

o = rr()
e = rr()
s = ''
for a, b in itertools.zip_longest(o, e, fillvalue=''):
  s += a + b
print(s)
W, a, b = map(int, input().split())
print(max(min(abs(a - b - w), abs(a - b + w)), 0))

### FIXED CODE ###

W, a, b = map(int, input().split())
print(max(max(a, b) - (min(a, b) + W), 0))
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

n = int(input())

arr = [[] for i in range(901)]

for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(n):
	l,r = map(int,raw_input().split())

	ans = 0

	t = 1
	while l + d * t <= r:
		ans += abs(arr[l+d*t][0] - arr[l+d*(t-1)][0]) + abs(arr[l+d*t][1] - arr[l+d*(t-1)][1])
		t += 1

	print ans

### FIXED CODE ###

h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

distance = [0 for i in range(90001)]


n = int(input())

arr = [[] for i in range(90001)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(d+1,h*w+1):
	distance[i] = distance[i-d] + abs(arr[i][0] - arr[i-d][0]) + abs(arr[i][1] - arr[i-d][1])


for i in range(n):
	l,r = inputs[i]

	print distance[r]-distance[l]
3 4
269-6650

### FIXED CODE ###

from collections import Counter
A,B=list(map(int, input().split()))
S=list(input())

print("Yes" if S[A]=='-' and Counter(S)['-']==1 else "No")
n = int(input())
h = list(map(int,input().split()))
f = 0

for i in range(1,n):
    a = h[i-1] - h[i]
    if a > 1:
        break
    elif a == 1:
        if f == 1:
            break
        f = 1
    elif a == 0:
        pass
    else:
        f = 0
else:
    if i == n - 1:
        f = 2

if f == 2 or n == 1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

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

for i in range(1,n):
    a = h[i-1] - h[i]
    if a > 1:
        break
    elif a == 1:
        if f == 1:
            break
        f = 1
    elif a == 0:
        pass
    else:
        f = 0

    if i == n - 1:
        f = 2

if f == 2 or n == 1:
    print('Yes')
else:
    print('No')
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
p = list(map(int, input().split()))
Exp = [0]*(N-K+1)
for i in range(N-K+1):
    x = 0
    for j in range(i, i+K):
        x += (sum(range(1, p[j]+1)))/p[j]
    Exp[i] = x
print(max(Exp))

### FIXED CODE ###

# -*- coding: utf-8 -*-
s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
    a -= 1
if u == t:
    b -= 1
print(a, b)
A,B,C = map(int,input())
print(B + C - A)

### FIXED CODE ###

A,B,C = map(int,input().split())
if B + C - A <= 0:
    print(0)
else:
    print(B + C - A)
n, m = map(int, input().split())
list_score = []
for _ in range(m):
    list_score.append(int(input()))

dp = [0]*(n+1)
mod = pow(10, 9) + 7

dp[0] = 1
if list_score[0] == 1:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in list_score:
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= mod

print(dp[n])

### FIXED CODE ###

N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])
n, k = map(int, input().split())
s = input()
if n == 1:
    print(1)
if n != 1:
    nums = []
    cnt = 1
    for i in range(1, n):
        if s[i - 1] != s[i]:
            nums.append([s[i - 1], cnt])
            cnt = 1
            if i == n - 1:
                nums.append([s[i], cnt])
        else:
            cnt += 1
            if i == n - 1:
                nums.append([s[i - 1], cnt])

    candi = 0
    ansli = []
    p = 0
    for i in range(len(nums)):
        if nums[i][0] == "0":
            p += 1
    k = min(k, p)

    i1 = 0
    j1 = 0
    while i1 <= k and j1 < len(nums):
        if i1 == k and nums[j1][0] == "0":
            pass
        else:
            candi += nums[j1][1]
        if nums[j1][0] == "0":
            i1 += 1
        j1 += 1
    ansli.append(candi)

    a = 0
    b = j1 - 1
    while b < len(nums):
        for i in range(2):
            if nums[a + i][0] == "1":
                candi -= nums[a + i][1]
            elif nums[a + i][0] == "0":
                candi -= nums[a + i][1]
                a += i + 1
                break
        for i in range(2):
            if b + i >= len(nums):
                ansli.append(candi)
                b += 1
                break
            else:
                if nums[b + i][0] == "1":
                    candi += nums[b + i][1]
                    b += i + 1
                    ansli.append(candi)
                    break
                elif nums[b + i][0] == "0":
                    candi += nums[b + i][1]

    print(max(ansli))

### FIXED CODE ###

n, k = map(int, input().split())
s = input()
if n == 1:
    print(1)
if n != 1:
    nums = []
    cnt = 1
    for i in range(1, n):
        if s[i - 1] != s[i]:
            nums.append([s[i - 1], cnt])
            cnt = 1
            if i == n - 1:
                nums.append([s[i], cnt])
        else:
            cnt += 1
            if i == n - 1:
                nums.append([s[i - 1], cnt])

    candi = 0
    ansli = []
    p = 0
    for i in range(len(nums)):
        if nums[i][0] == "0":
            p += 1
    k = min(k, p)

    i1 = 0
    j1 = 0
    while i1 <= k and j1 < len(nums):
        if i1 == k and nums[j1][0] == "0":
            pass
        else:
            candi += nums[j1][1]
        if nums[j1][0] == "0":
            i1 += 1
        j1 += 1
    ansli.append(candi)
    if candi == n:
        print(n)
        exit()

    a = 0
    b = j1 - 1
    while b < len(nums):
        for i in range(2):
            if nums[a + i][0] == "1":
                candi -= nums[a + i][1]
            elif nums[a + i][0] == "0":
                candi -= nums[a + i][1]
                a += i + 1
                break
        for i in range(2):
            if b + i >= len(nums):
                ansli.append(candi)
                b += 1
                break
            else:
                if nums[b + i][0] == "1":
                    candi += nums[b + i][1]
                    b += i + 1
                    ansli.append(candi)
                    break
                elif nums[b + i][0] == "0":
                    candi += nums[b + i][1]

    print(max(ansli))
import math
def Fib(n):
  Fib=1/math.sqrt(5)*(((1+math.sqrt(5))/2)**(n+1)-((1-math.sqrt(5))/2)**(n+1))
  return int(Fib)
N,M=map(int,input().split())
A=[]
for i in range(M):
  A.append(int(input()))
B=[0]*M
a=0
for i in range(M):
  B[i]=A[i]-1-a
  a=A[i]+1
B.append(N-a)
a=A[0]
for i in range(1,M):
  if A[i]==a+1:
    print(0)
    exit()
  else:
    a=A[i]
ans=1
for i in range(M+1):
  ans*=Fib(B[i])
print(ans%1000000007)

### FIXED CODE ###

N,M=map(int,input().split())
A=[-1]+[int(input()) for i in range(M)]+[N+1]
res=1
for i in range(1,len(A)):
  steps=A[i]-A[i-1]-2
  if steps<0:
    patern_nmu=0
  else:
    p,q=1,0
    for j in range(steps):
      p,q=p+q,p
    patern_nmu=p
  res*=patern_nmu
  res%=1000000007
print(res)
N = int(input())

def solve(a, i, prev):
  r = N - len(prev) - i + 1
  p = -i*a
  for j, s in enumerate(prev):
    yield max(p+abs(j-i)*a, s+abs(j+r)*a)
    p = s
  yield s+abs(len(prev)-i)*a

pd = [0]
A = map(int, input().split())
for a,i in sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True):
  pd = [*solve(a,i, pd)]

print(max(prev))


### FIXED CODE ###

from collections import *
from itertools import *

N = int(input())

A = map(int, input().split())
SA = SB = 0
ABI = sorted(((b:=max(N-i, i-1)*a, SA:=SA+a, SB:=SB+b) and (a, b, i) for i, a in enumerate(A, 1)), reverse=True)

prev = {0:0}
prev_max = 0
for k, (a, b, i) in enumerate(ABI):
  curr = defaultdict(int)
  curr_max = 0
  for l, p in prev.items():
    r = k-l
    if p + SB - min(l,r)*SA < prev_max:
      continue
    curr[l] = max(curr[l], p+abs(N-i-r)*a)
    curr[l+1] = p+abs(i-l-1)*a
    curr_max = max(curr_max, curr[l], curr[l+1])
  SA -= a
  SB -= b
  prev = curr
  prev_max = curr_max

print(curr_max)
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)
# a_counts = []
# for i,a in enumerate(a_unique):
#     a_counts.append(np.sum(a_s==a))
# a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a_unique[i]):
            val += np.sum(a_s==a_unique[i-1]) #a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a_unique[i]):
            val += np.sum(a_s==a_unique[i+1]) #a_counts[i+1]
    
    if val > ans:
        ans = val
        
#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
a_s = input().split()
a_s = [int(a_s[i]) for i in range(N)]

c = Counter(a_s)
c = sorted(c.items(), key=lambda x:x[0])
a_unique, a_counts = zip(*c)

ans = 0
for i,a in enumerate(a_unique):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
print(ans)
N=int(input())
li=[]

for n in range(N):
  a=int(input())
  li.append(a)

s=0
count=0

while s!=1:
  if count==N:
    break
  else:
    check.append(s)
    s=li[s]-1
    count+=1

if s==1:
  print(count)
else:
  print(-1)

### FIXED CODE ###

N=int(input())
li=[]

for n in range(N):
  a=int(input())
  li.append(a)

s=0
count=0

while s!=1:
  if count==N:
    break
  else:
    s=li[s]-1
    count+=1

if s==1:
  print(count)
else:
  print(-1)
import sys,time
X, Y = map(int,input().split())
time.sleep((X%7)/5)


### FIXED CODE ###

n = int(input())
ar = list(map(int,input().split()))
su = [0]*n
su[0]=ar[0]
for i in range(1,n):
    su[i] = ar[i] + su[i-1]

# +
ans1,off = 0,0
for i in range(0,n):
    if i%2 == 0:
        if su[i] + off <= 0:
            ans1 += 1-(su[i]+off)
            off += 1-(su[i]+off)
    else:
        if su[i] + off >= 0:
            ans1 += (su[i]+off+1)
            off -= (su[i]+off+1)

# -
ans2,off = 0,0
for i in range(0,n):
    if i%2 != 0:
        if su[i] + off <= 0:
            ans2 += 1-(su[i]+off)
            off += 1-(su[i]+off)
    else:
        if su[i] + off >= 0:
            ans2 += (su[i]+off+1)
            off -= (su[i]+off+1)
print(min(ans1,ans2))
N = int(input())
A = list(map(int, input().split()))

# 最大公約数が答え

import math
import functools

print(functools.reduce(math.gcd, A))

### FIXED CODE ###

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

# 最大公約数が答え

import fractions
import functools

print(functools.reduce(fractions.gcd, A))
N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range (0, N):
	if A[i] == 0:
		ans = 0
		break
	else:
		if ans > 0
        	ans *= A[i]
		if ans > 10 ** 18:
			ans = -1

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range (0, N):
	if A[i] == 0:
		ans = 0
		break
	else:
		if ans > 0:
			ans *= A[i]
		if ans > 10 ** 18:
			ans = -1

print(ans)
S = input()
print("Yes" if S[3] == S[4] and S[5] == S[6] else "No")

### FIXED CODE ###

S = input()
print("Yes" if S[2] == S[3] and S[4] == S[5] else "No")
print(["error",A+B],[eval(input().replace(" ","+"))<10])

### FIXED CODE ###

A,B=map(int,input().split())
if A+B<10:
    print(A+B)
else:
    print("error")
K = int(input())

import gcd from math

def g(a,b,c):
  retunr gcd(gcd(a,b),c)

a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      a += g(i,j,k)

print(a)

### FIXED CODE ###

K = int(input())

from math import gcd

def g(a,b,c):
  return gcd(gcd(a,b),c)

a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      a += g(i,j,k)

print(a)
n, m = map(int, input().split())
A = sum(list(map(int, input(.split()))))
if A <= n:
    print(n-A)
else:
    print(-1)

### FIXED CODE ###

n, m = map(int, input().split())
A = sum(list(map(int, input().split())))
if A <= n:
    print(n-A)
else:
    print(-1)
H, W = map(int, input().split())
S = [input() for _ in range(H)]
newS = [['#' for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            c = max(0, j-1)
            d = min(W-1, j+1)
            if i == 0:
                cnt = S[i][c:d+1].count('#')
                cnt += S[i+1][c:d+1].count('#')
            elif i == H-1:
                cnt = S[i][c:d+1].count('#')
                cnt += S[i-1][c:d+1].count('#')
            else:
                cnt = S[i][c:d+1].count('#')
                cnt += S[i-1][c:d+1].count('#')
                cnt += S[i+1][c:d+1].count('#')
            newS[i][j] = str(cnt)
for i in newS:
    print(''.join(i))


### FIXED CODE ###

H, W = map(int, input().split())
S = [input() for _ in range(H)]
ad = ['.' for _ in range(W)]
S.append(ad)
S.insert(0, ad)
newS = [['#' for _ in range(W)] for _ in range(H)]
for i in range(1, H+1):
    for j in range(W):
        if S[i][j] == '.':
            c = max(0, j-1)
            d = min(W-1, j+1)
            cnt = S[i][c:d+1].count('#')
            cnt += S[i-1][c:d+1].count('#')
            cnt += S[i+1][c:d+1].count('#')
            newS[i-1][j] = str(cnt)
for i in newS:
    print(''.join(i))