Harryxun/stf_run huggingface dataset:
n,a,b = map(int,input().split())
l = []

def append():
    for i in range(a):
        l.append("b")
        if len(l)==n:
            return
    for k in range(b):
        l.append("r")
        if len(l)==n:
            return
    if len(l)<n:
        append()
    return
append()

#print(l)
print(l.count('b'))
    

### FIXED CODE ###

n,a,b = map(int,input().split())
print(n//(a+b)*a+min(n%(a+b),a))
N, M = map(int, input().split())
x = [0] * (M)
y = [0] * (M)
G = [[] for _ in range(N + 1)]
for i in range(M):
    X, Y = map(int, input().split())
    x[i] = X
    y[i] = Y
    G[X] += [Y]

dp = [-1] * (N + 1)



def f(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for m in G[n]:
        res = max(res, f(m) + 1)
    dp[n] = res
    return res


for i in range(1, N + 1):
    f(i)
print(max(dp))

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000)

N, M = map(int, input().split())
x = [0] * M
y = [0] * M
G = [[] for _ in range(N + 1)]
for i in range(M):
    X, Y = map(int, input().split())
    x[i] = X
    y[i] = Y
    G[X] += [Y]

dp = [-1] * (N + 1)


def f(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for m in G[n]:
        res = max(res, f(m) + 1)
    dp[n] = res
    return res


for i in range(1, N + 1):
    f(i)
print(max(dp))
def counter(x):
        if x == 0:
                return 0
        return counter(x >> 1) + int(bin(x & 1), 2)

N = int(input())
A = []
x = [0] * N 
for i in range(N):
        A.append(int(input()))
        x[i] = [list(map(int, input().split())) for j in range(A[i])]

ans = 0 
for bits in range(1, 1 << N): 
        flag = 1 
        for i in range(N):
                if not int(bin(bits & (1 << i)), 2): 
                        continue
                for j in range(A[i]):
                        if int(bin((bits >> (x[i][j][0] - 1) & 1) ^ x[i][j][1]), 2): 
                                flag = 0 
        if flag:
                ans = max(ans, counter(bits))
print(ans)

### FIXED CODE ###

A, B, C = map(int, input().split())
if A + B + C >= 22: 
        print("bust")
else:
        print("win")
a,v=input().split()
b,w=input().split()
t=int(input())
a=int(a)
b=int(b)
c=int(v)
d=int(w)
-10^9<=a,b<=10^9
1<=v,w<=10^9
1<=t<=10^9
a!=b
x=b-a
y=v-w
z=y/x
if z<=t:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

import random
S=input()
3<=len(S)<=20
x=random.randint(3,len(S))
y=x-3
print(S[y:x])
S, T= map(string, input().split())

num = 0
for ind, s in enumerate(S):
    if  S[ind] != T[ind]:
        num = num + 1
print(num)

### FIXED CODE ###

S = input()
T = input()

num = 0
for ind, s in enumerate(S):
    if  S[ind] != T[ind]:
        num = num + 1
print(num)
a,b,c = input().split()
print("A" + B[0] +"C")

### FIXED CODE ###

a,b,c = input().split()
print("A" + b[0] +"C")
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
b_dic = {}
for i in range(1, N + 1):
  b_dic[i] = B[i - 1]
c_dic = {}
for i in range(1, N):
  c_dic[i] = C[i - 1]
count=0
br = -1
for a in A:
  count += B[a]
  if br == a - 1:
    count += C[br]
  br = a
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
b_dic = {}
for i in range(1, N + 1):
  b_dic[i] = B[i - 1]
c_dic = {}
for i in range(1, N):
  c_dic[i] = C[i - 1]
count=0
br = -1
for a in A:
  count += b_dic[a]
  if br == a - 1:
    count += c_dic[br]
  br = a
print(count)
import itertools
from collections import Counter
h = int(input())
if h == 1:
	print(1)
	exit()
a = list(map(int,input().split()))
t = Counter(a)
b = []
for i, j in t.most_common():
	if j == 1:
		b.append(i)
bset = set(a)

def sieve(n):
	ret = []
	divlis = [-1]*(n+1)  # 何で割ったかのリスト(初期値は-1)
	flag = [True]*(n+1)
	flag[0] = False
	flag[1] = False
	ind = 2
	while ind <= n:
		if flag[ind]:
			ret.append(ind)
			ind2 = ind**2
			while ind2 <= n:
				flag[ind2] = False
				divlis[ind2] = ind
				ind2 += ind
		ind += 1
	#何で割ったかのリストを取得したいとき, divlisも出力する
	return ret

k = sieve(1000)

def pfact(m):
	pf = {}
	cnt = 0
	i = k[cnt]
	while m > 1:
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
		cnt += 1
		i = k[cnt]
	if m>1 : pf[m]=1
	return pf

def makediv(n):
	s = pfact(n)
	k = [range(i+1) for i in s.values()]
	ansl = []
	for i in itertools.product(*k):
		ans = 1
		for n, j in enumerate(s.keys()):
			ans *= (j**i[n])
		ansl.append(ans)
	ansl.sort()
	return ansl

ans = 0
for i in b:
	t=makediv(i)
	t.remove(i)
	mode = 1
	for l in t:
		if l in bset:
			mode = 0
			break
	if mode:
		ans += 1
print(ans)

### FIXED CODE ###

import itertools
from collections import Counter
h = int(input())
if h == 1:
	print(1)
	exit()
a = list(map(int,input().split()))
t = Counter(a)
b = []
for i, j in t.most_common():
	if j == 1:
		b.append(i)
bset = set(a)

def sieve(n):
	ret = []
	divlis = [-1]*(n+1)  # 何で割ったかのリスト(初期値は-1)
	flag = [True]*(n+1)
	flag[0] = False
	flag[1] = False
	ind = 2
	while ind <= n:
		if flag[ind]:
			ret.append(ind)
			ind2 = ind**2
			while ind2 <= n:
				flag[ind2] = False
				divlis[ind2] = ind
				ind2 += ind
		ind += 1
	#何で割ったかのリストを取得したいとき, divlisも出力する
	return ret

k = sieve(1000)

def pfact(m):
	pf = {}
	cnt = 0
	i = k[cnt]
	st = len(k)
	while m > 1 and cnt < st:
		i = k[cnt]
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
		cnt += 1
	if m>1 : pf[m]=1
	return pf

def makediv(n):
	s = pfact(n)
	k = [range(i+1) for i in s.values()]
	ansl = []
	for i in itertools.product(*k):
		ans = 1
		for n, j in enumerate(s.keys()):
			ans *= (j**i[n])
		ansl.append(ans)
	ansl.sort()
	return ansl

ans = 0
for i in b:
	t=makediv(i)
	t.remove(i)
	mode = 1
	for l in t:
		if l in bset:
			mode = 0
			break
	if mode:
		ans += 1
print(ans)
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)
A.sort()
s = 0
for B, C in BC:
    mn = A[0]
    if mn >= C:
        s += sum(A)
        break
    n = len(A)
    if B > n:
        B = n
    if A[B - 1] <= C:
        s += B * C
        if B == n:
            break
        A = A[B:]
    else:
        for i in A[1:B]:
            if A[i] >= C:
                s += i * C
                s += sum(A[i:])
                break
        break
#         a, b = 0, B
#         while a + 1 < b:
#             i = a + (b - a) // 2
#             if A[i] >= C:
#                 b = i
#             else:
#                 a = i
#         s += b * C
#         s += sum(A[b:])
#         break
else:
    s += sum(A)
print(s)

### FIXED CODE ###

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)
A.sort()
l, r = 0, N
for B, C in BC:
    if A[l] >= C:
        break
    a, b = l, r
    if A[r - 1] >= C:
        while a + 1 < b:
            i = a + (b - a) // 2
            if A[i] >= C:
                b = i
            else:
                a = i
        r = b
    n = B + l
    if n > r:
        n = r
        B = n - l
    if n <= b:
        A[l:n] = [C] * B
        l = n
    else:
        A[l:b] = [C] * B
        l = b
    if l == r:
        break

print(sum(A))
from collections import defaultdict

N, P = map(int, input().split())
S = input()

mem = defaultdict(int)
mem[0] += 1
T = [0]
dec = 1
x = 0
for s in S[::-1] :
  s = int(s)
  x = (dec * s + x) % P
  dec = dec * 10 % P
  T.append(x)
  mem[x] += 1

inv = pow(10, P - 2, P)
dec = 1
ret = 0
for i, t in enumerate(T) :
  if dec % P =  0 :
    ret += len(T) - i - 1
  else :
    ret += mem[t] - 1
  mem[t] -= 1
  dec = dec * inv % P
  
print(ret)


### FIXED CODE ###

from collections import defaultdict

N, P = map(int, input().split())
S = input()

if P == 2 or P == 5 :
  ret = 0
  for i, v in enumerate(S) :
    if int(v) % P == 0 :
      ret += i + 1
  print(ret)

else :
  mem = defaultdict(int)
  mem[0] += 1

  T = [0]
  dec = 1
  x = 0
  for s in S[::-1] :
    s = int(s)
    x = (dec * s + x) % P
    dec = dec * 10 % P
    T.append(x)
    mem[x] += 1

  ret = 0
  for i, t in enumerate(T) :
    ret += mem[t] - 1
    mem[t] -= 1
    
  print(ret)
n = int(input())
a = list(map(int,input().split()))
m=1
ans =0
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
    return int(a*b/gcd(a,b))
for i in range(n):
    m = lcm(m,a[i])
for i in range(m):
    sum = 0
    for j in range(n):
        sum += i % a[j]
    ans = max(ans,sum)
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
m=1
sum = 0
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
    return int(a*b/gcd(a,b))
for i in range(n):
    m = m *a[i]
for i in range(n):
        sum += (m-1) % a[i]

print(sum)
import math

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

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-1], r_gcds[0]]
    for i in range(1, n - 1):
        gcds.append(math.gcd(l_gcds[i - 1], r_gcds[i]))
    print(max(gcds))

### FIXED CODE ###

def gcd(a, b):
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a


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

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = gcd(l_gcds[-1], nums[i])
        r = gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-1], r_gcds[0]]
    for i in range(1, n - 1):
        gcds.append(gcd(l_gcds[i - 1], r_gcds[i]))
    print(max(gcds))
l, r = map(int, input().split())
%print(l,r)

best = 2019
for i in range(l, r):
	for j in range(l+1,r+1):
		if i*j % 2019 < best:
			best = i*j % 2019

print(best)

### FIXED CODE ###

l, r = map(int, input().split())
#print(l,r)

best = 2019
for i in range(l, min(r,l+2019)):
	for j in range(l+1,min(r+1,l+2019+1)):
		if i*j % 2019 < best:
			best = i*j % 2019

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

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

ue = lcm(a[0], a[1])
if n >= 3:
    for i in range(2, n):
        ue = lcm(ue, a[i])

shita = 0
for i in range(len(a)):
    shita += ue//a[i]

ans = ue / shita
print(f"{ans:.6f}")


### FIXED CODE ###

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

import math
def lcm(x, y):
    return (x*y)//math.gcd(x, y)
if n >=2:
    ue = lcm(a[0], a[1])
    if n >= 3:
        for i in range(2, n):
            ue = lcm(ue, a[i])
else:
    ue = a[0]

shita = 0
if n >=2:
    for i in range(len(a)):
        shita += ue//a[i]
else:
    shita = n

ans = ue / shita
print(f"{ans:.6f}")
def main()
    _ = input()
    li1 = [int(x) for x in input().split()]
    _ = input()
    li2 = [int(x) for x in input().split()]
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__='__main__':
    main()


### FIXED CODE ###

import array

def main():
    n1 = int(input())
    li1 = array.array('l', [int(x) for x in input().split()])
    n2 = int(input())
    li2 = array.array('l', [int(x) for x in input().split()])
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()
n,m=map(int,input().split())
dp=[1]*n
cor=[1]*n
for i in range(m):
    cor[int(input())]=0
if cor[0]==0:
    dp[0]=0
if cor[1]==0:
    dp[1]=0
for i in range(2,n):
    dp[i]=(dp[i-1]+dp[i-2])%1000000007
    if cor[i]==0:
        dp[i]=0
print((dp[n-1]+dp[n-2])%1000000007)
#print(dp)

### FIXED CODE ###

def dp(n):
    d=[0]*(n+1)
    if n==1:
        return 1
    else:
         d[0]=1
         if a[1]==0:
            d[1]=1
         else:
            d[1]=0
         for i in range(2,n+1):
            if a[i]==0:
                d[i]=d[i-1]+d[i-2]
            else:
                d[i]=0
         return d[n]

n,m=map(int, input().split())
a=[0]*(n+1)
for i in range(0,m):
    k=int(input())
    a[k]=1
print(dp(n)%1000000007)
N = int(input())
H = list(map(int, input().split()))
 
count = []
for i in range(N-1):
  count.append(0)
  if H[i] > H[i+1]:
    count[i] = 1
    
S = str(count).split('0')
L = map(len, S)
print(max(L))

### FIXED CODE ###

S = input()
T = input()

count = 0
for s,t in zip(S,T):
  if s == t:
    count+=1
    
print(count)
wqydcgy

### FIXED CODE ###

n = int(input())
if n>= 30:
    print("Yes")
else:
    print("No")
a,b = input(),input()
print str(a*b) + ' ' + str((a+b)*2)

### FIXED CODE ###

(a,b) = map(int,raw_input().split())
print str(a*b)+ ' ' + str((a+b)*2)
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
ans=0

for i in range(n-k+1):
  if ans>h[i+k-1]-h[i]:
    ans=h[i+k-1]-h[i]
    
print(ans)


### FIXED CODE ###

d=int(input())
print("Christmas"+" Eve"*(25-d))
n=input
l=[int(input()) for i in range(n)]
s=set(l)
print(len(s))

### FIXED CODE ###

n=int(input())
l=[int(input()) for i in range(n)]
s=set(l)
print(len(s))
### 解答
N, K = map(int, input().split())
A = list(map(int, input().split()))

#B = [0]*N                                 # 記録用のリスト

for k in range(K):                        # 以降の操作をK回繰り返す
  B = [0 for _ in range(N)] 
  for i in range(N):                      # 各電球によって照らされる範囲を考える
    start = max(0, i-A[i])                # 始点のインデックスは0かi-A[i]
    end = min(N, i+A[i]+1)                # 終点のインデックスはNかi+A[i]+1
    B[start] += 1                         # 始点に+1を記録する
    if end <= N - 1:
      B[end] -= 1                         # 終点に電球が存在する場合は-1を記録する
  amin = B[0]
  A[0] = B[0] 
  for i in range(1, N):                   # 累積和の計算
    A[i] = B[i-1] + B[i]
    amin = min(A[i], amin)                                   # AをBで更新してつぎのループへ 
  if amin == N:                        # すべての電球がN個の電球に照らされるタイミングでbreakする
    break

print(*A)                                 # リストAの中身を順に表示

### FIXED CODE ###

N = int(input())
a = 26
counter = 1
while a<N:
  N -= a
  counter += 1
  a *= 26
ans = []
N -= 1
while N>=26:
  ans.append(N%26)
  N = N //26
ans.append(N)
dic = ["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"]
ans = [dic[i] for i in ans[::-1]]
n = len(ans)
print("a"*(counter-n) + "".join(ans))
n = int(input())
a = list(map(int, input().split()))

num = [0] * (3*10**6)
for i in range(n):
    a[i] -= i
    num[a[i]] += 1

ans = 0
for i in range(n):
    if abs(-2*i - a[i]) <= 10**6:
        ans += num[-2*i - a[i]]
    num[a[i]] -= 1

print(ans)


### FIXED CODE ###

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

num = [0] * (3*10**6)
for i in range(n):
    a[i] -= i
    if abs(a[i]) <= 10**6:
        num[a[i]] += 1

ans = 0
for i in range(n):
    if abs(-2*i - a[i]) <= 10**6:
        ans += num[-2*i - a[i]]
    if abs(a[i]) <= 10**6:
        num[a[i]] -= 1

print(ans)
import sys
X = sys.stdin.readline()
score = X//500 * 1000
X %= 500
score += X//5 * 5
print(score)

### FIXED CODE ###

import sys
X = sys.stdin.readline()
X = int(X)
score = (X//500) * 1000
X %= 500
score += (X//5) * 5
print(score)
x=input().split()
h=int(x[0])
n=int(x[1])
a=[]
b=[]
for k in range(n):
  x=input().split()
  a.append(int(x[0]))
  b.append(int(x[1]))  
m=max(a)  
dp=[10**8]*(h+m)
dp[0]=0
for k in range(h+m):
  for i in range(n):
    if k-a[i]<0:
      continue
    new=dp[k-a[i]]+b[i]
    if new < dp[k]:
      dp[k]=new
print(min(dp[h:h+m]))
      
      

### FIXED CODE ###

x=input().split()
H=int(x[0])
A=int(x[1])
if H%A==0:
  print(H//A)
else:
  print(H//A+1)
import sys
def input():
    return sys.stdin.readline()[:-1]
from collections import defaultdict
H, W, N = map(int, input().split())
square = set()
dot = defaultdict(lambda : 0)
for i in range(N):
    a, b = map(lambda x: int(x)-1, input().split())
    dot[[a, b]] = 1
    for y in range(a-2, a+1):
        for x in range(b-2, b+1):
            if 0 <= y < H-2 and 0 <= x < W-2:
                square.add([y, x])
ans = [0] * 10
for y, x in square:
    c = 0
    for i in range(y, y+3):
        for j in range(x, x+3):
            c += dot[[i, j]]
    ans[c] += 1
ans[0] += ans[0] + (H-2) * (W-2) - len(square)
for i in ans:
    print(i)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
H, W, N = map(int, input().split())
cnt = defaultdict(lambda : 0)
for i in range(N):
    a, b = map(lambda x: int(x)-1, input().split())
    for y in range(a-2, a+1):
        for x in range(b-2, b+1):
            if 0 <= y < H-2 and 0 <= x < W-2:
                cnt[(y, x)] += 1
ans = [0] * 10
for key in cnt:
    ans[cnt[key]] += 1
ans[0] += ans[0] + (H-2) * (W-2) - len(cnt)
for i in ans:
    print(i)
tmp=input()
a=int(tmp.split(' ')[0])
b=int(tmp.split(' ')[1])
print a*b,2*(a+b)

### FIXED CODE ###

a,b=map(int, raw_input().split())
print a*b, 2*(a+b)
import math
from decimal import *
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))

line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = Decimal(result) / Decimal(N) / Decimal(2**17)
print('{:.12f}'.format(finalResult))

### FIXED CODE ###

import math
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))
 
line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = result / N / (2**17)
print('{:.12f}'.format(finalResult))
# coding: utf-8
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
print(sum(A[::2])-sum([1::2]))

### FIXED CODE ###

# coding: utf-8
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
print(sum(A[::2])-sum(A[1::2]))
N, M = map(int, input().split())
List = [int(input()) for _ in range(M)]

P = 1000000007

dp = [0]*(N+1)

if 1 in List:
    dp[1] = 0
    if 2 in List:
        dp[2] = 0
    else:
        dp[2] = 1
else:
    dp[1] = 1
    if 2 in List:
        dp[2] = 0
    else:
        dp[2] = 2

for i in range(2, N):
    if i+1 in List:
        dp[i+1]=0
    else:
        if i in List:
            dp[i+1] = dp[i-1]%P
        else:
            dp[i+1] = (dp[i]+dp[i-1])%P
        
print(dp[N])

### FIXED CODE ###

N, M = map(int, input().split())
List = [int(input()) for _ in range(M)]

P = 10**9+7

dp = [1]*(N+1)

for a in List:
    dp[a]=0

for i in range(1, N+1):
    if (i>=2)&(dp[i]!=0):
        dp[i] = (dp[i-1]+dp[i-2])%P
        
print(dp[N])
H, W, D = map(int,input().split())
dist = [[float("inf") for i in range(H*W+1)] for j in range(H*W+1)]
for i in range(H*W+1):
  dist[i][i] = 0
#dist[i][j]は隣接行列
pos = [[0,0] for i in range(H*W+1)]
for i in range(H):
  A = list(map(int,input().split()))
  for j in range(W):
    pos[A[j]] = [i+1, j+1]
for i in range(H*W+1-D):
  dist[i][i+D] = abs(pos[i][0]-pos[i+D][0])+abs(pos[i][1]-pos[i+D][1])
distances = [[] for i in range(D)]#あまりがiの距離
for i in range(1,H*W+1-D):
  d = dist[i][i+D]
  distances[i%D]+=[d]
distances2 = [[0] for i in range(D)]#累積和に直す
for i in range(D):
  K = len(distances[i])
  for j in range(K):
    distances2[i]+=[distances2[i][-1]+distances[i][j]]
Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  q = L%D
  l, r = (L-1)//D, (R-1)//D
  print(distances2[q][r]-distances2[q][l])

### FIXED CODE ###

N= int(input())
print(N//3)
n,k,q=map(int,input().split())
L= [ int(input()) for i in range(q)]
N = [ k-q+L.count(i) for i in range(1,n+1) ]
for i in N:
    print('YES' if i>0 else 'NO')


### FIXED CODE ###

n=input()
L=["Sunny","Cloudy","Rainy"]
if n == L[2]:
  print(L[0])
else:
  print(L[L.index(n)+1])
def chk(a,t):     # t=True(奇数項が正), t=False(偶数項が正) 
    cnt=0   # 操作回数
    x=0     # 塁積和        
    for i in a:
        x+=i      
        if t==True and x<=0:       # 正項予定なのに累積が負か0
            cnt+=1-x                              
            x=x+(1-x)               # 今回のcntで符号変更
        elif t==False and x>=0:   # 負項予定なのに累積が正か0
            cnt+=1+x              
            x=x-(1+x)              # 今回のcntで符号変換
        t = not t                  # 次の項は符号が逆
    return cnt
print(min(chk(a,True),chk(a,False)))

### FIXED CODE ###

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

def chk(a,t):     # t=True(奇数項が正), t=False(偶数項が正) 
    cnt=0   # 操作回数
    x=0     # 塁積和        
    for i in a:
        x+=i      
        if t==True and x<=0:       # 正項予定なのに累積が負か0
            cnt+=1-x                              
            x=x+(1-x)               # 今回のcntで符号変更
        elif t==False and x>=0:   # 負項予定なのに累積が正か0
            cnt+=1+x              
            x=x-(1+x)              # 今回のcntで符号変換
        t = not t                  # 次の項は符号が逆
    return cnt

print(min(chk(a,True),chk(a,False)))
import pandas as pd

N = int(input())
rest = [list(input().split()) for n in range(N)]

df_rest = pd.DataFrame(rest)
df_rest[1] = df_rest[1].apply(int)
df_rest = df_rest.sort_values([0,1], ascending = [True, False])

for x in df_rest.index:
    print(x + 1)

### FIXED CODE ###

N = int(input())
rest = [list(input().split()) for n in range(N)]

for n in range(N):
    rest[n][1] = int(rest[n][1])
    rest[n].append(n + 1)
    
rest.sort(key = lambda x: x[1], reverse = True)
rest.sort(key=lambda x: x[0], reverse=False)


for n in range(N):
    print(rest[n][2])
H, W = map(int, raw_input().split())
 
while H > 0 or W > 0 :
    for y in xrange(H) :
        for x in xrange(W) :
            if (x + y) % 2 == 0 :
                sys.stdout.write("#")
            else :
                sys.stdout.write(".")
 
        print
    print
 



### FIXED CODE ###

while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''
import numpy as np
h, w = map(int, input().split())
num_array = np.zeros((h, w))
space_array = np.ones((h, w))

mine_map = np.array(
    ((0 if i == "." else 1 for i in input())) for j in range(h))
space_array = mine_map.copy()

for i, s in enumerate(mine_map):
    for j, m in enumerate(s):
        if m == 1: # m=mass
            il, iu = i-1, i+2
            jl, ju = j-1, j+2
            il, jl = max(il, 0), max(jl, 0)
            iu, ju = min(iu, h), min(ju, w)
            num_array[il:iu, jl:ju] += 1

for i, s in enumerate(space_array):
    out = ("#" if m == 1 else str(int(num_array[i,j])) for j, m in enumerate(s))
    print("".join(out))


### FIXED CODE ###

import numpy as np
h, w = map(int, input().split())
num_array = np.zeros((h, w))
space_array = np.ones((h, w))

mine_map = np.array(
    [np.array([0 if i == "." else 1 for i in input()]) for j in range(h)])
space_array = mine_map.copy()

for i, s in enumerate(mine_map):
    for j, m in enumerate(s):
        if m == 1: # m=mass
            il, iu = i-1, i+2
            jl, ju = j-1, j+2
            il, jl = max(il, 0), max(jl, 0)
            iu, ju = min(iu, h), min(ju, w)
            num_array[il:iu, jl:ju] += 1

for i, s in enumerate(space_array):
    out = ["#" if m == 1 else str(int(num_array[i,j])) for j, m in enumerate(s)]
    print("".join(out))