Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

INPUT=input()
IN=INPUT.split(" ")
#N=int(IN[0])
number=int(IN[0])
#N
A=int(IN[1])
B=int(IN[2])

GOUKEI=0
kazu=0

while kazu<=number:
    X=list(map(int,list(str(kazu))))
    #X = list(map(int, n))
    while len(X) != 4:
        X.reverse()
        X.append(0)
        X.reverse()
    #print(X)
    if A<=sum(X)<=B:
        GOUKEI+=kazu
        #print("add",kazu)
    kazu+=1
print(GOUKEI)

### FIXED CODE ###

INPUT=input()
IN=INPUT.split(" ")
#N=int(IN[0])
number=int(IN[0])
#N
A=int(IN[1])
B=int(IN[2])

GOUKEI=0
kazu=0

while kazu<=number:
    X=list(map(int,list(str(kazu))))
    #X = list(map(int, n))
   
    #print(X)
    if A<=sum(X)<=B:
        GOUKEI+=kazu
        #print("add",kazu)
    kazu+=1
print(GOUKEI)
### BUGGY 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()
A = []
for i in range(1, -(-N//1)):
  if N%i == 0:
    A.append(i + N//i -2)

print(min(A))      

### 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()
A = []
for i in range(1, int(sqrt(N))+1 ):
  if N%i == 0:
    A.append(i + N//i -2)

print(min(A))
### BUGGY CODE ###

from collections import deque
N = int(input())
ab = [list(map(int,input().split())) for _ in range(N-1)]
mod = 10**9+7
fact = [1]*(N+1)
fact_inv = [1]*(N+1)
for i in range(1,N+1):
  fact[i] = (fact[i-1]*i)%mod
  fact_inv[i] = pow(fact[i], mod-2, mod)

g = [deque([]) for _ in range(N+1)]
for a,b in ab:
  g[a].append(b)
  g[b].append(a)
  
parents = [0]*(N+1)
q = deque([])
s = deque([1])
while s:
  x = s.pop()
  q.append(x)
  for y in g[x]:
    if y==parents[x]:
      continue
    else:
      parents[y] = x
      s.append(y)
      
q = list(q)
size_forward = [0]*(N+1)
dp_forward = [1]*(N+1)
for i in q[::-1]:
  p = parents[i]
  s = size_forward[i] + 1
  size_forward[p] += s
  dp_forward[i] *= fact[size_forward[i]]
  dp_forward[i] %= mod
  dp_forward[p] *= dp_forward[i] * fact_inv[s]
  dp_forward[p] %= mod
  
size_back = [N-1-i for i in size_forward]
dp_back = [1]*(N+1)
for i in q[1:]:
  p = parents[i]
  x = dp_back[p]
  x *= fact_inv[size_back[p]]
  x %= mod
  x *= dp_forward[p]
  x *= fact_inv[size_forward[p]]
  x %= mod
  x *= fact[size_forward[i]+1]
  x *= pow(dp_forward[i],mod-2,mod)
  x %= mod
  x *= fact[size_back[i]-1]
  dp_back[i] = x % mod
  
for a,b,c,d in zip(size_forward[1:], dp_forward[1:], size_back[1:], dp_back[1:]):
  ans = b * d * fact[a+c]
  ans %= mod
  ans *= fact_inv[a]
  ans %= mod
  ans *= fact_inv[c]
  ans %= mod
  print(ans)

### FIXED CODE ###

from collections import deque
N = int(input())
ab = [list(map(int,input().split())) for _ in range(N-1)]
mod = 10**9+7
fact = [1]*(N+1)
fact_inv = [1]*(N+1)
for i in range(1,N+1):
  fact[i] = (fact[i-1]*i)%mod
  
fact_inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(N,0,-1):
  fact_inv[i-1] = fact_inv[i] * i % mod

g = [deque([]) for _ in range(N+1)]
for a,b in ab:
  g[a].append(b)
  g[b].append(a)
  
parents = [0]*(N+1)
q = deque([])
s = deque([1])
while s:
  x = s.pop()
  q.append(x)
  for y in g[x]:
    if y==parents[x]:
      continue
    else:
      parents[y] = x
      s.append(y)
      
q = list(q)
size_forward = [0]*(N+1)
dp_forward = [1]*(N+1)
for i in q[::-1]:
  p = parents[i]
  s = size_forward[i] + 1
  size_forward[p] += s
  dp_forward[i] *= fact[size_forward[i]]
  dp_forward[p] *= dp_forward[i] * fact_inv[s]
  dp_forward[p] %= mod
  
size_back = [N-1-i for i in size_forward]
dp_back = [1]*(N+1)
for i in q[1:]:
  p = parents[i]
  x = dp_back[p]
  x *= fact_inv[size_back[p]]
  x *= dp_forward[p]
  x *= fact_inv[size_forward[p]]
  x *= fact[size_forward[i]+1]
  x *= pow(dp_forward[i],mod-2,mod)
  x *= fact[size_back[i]-1]
  dp_back[i] = x % mod
  
for a,b,c,d in zip(size_forward[1:], dp_forward[1:], size_back[1:], dp_back[1:]):
  ans = b * d * fact[a+c] * fact_inv[a] * fact_inv[c]
  ans %= mod
  print(ans)
### BUGGY CODE ###

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

for _ in range(M):
  A.sort()
  A[-1]//=2

print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x:-int(x),input().split()))
heapq.heapify(A)


for _ in range(M):
  ma=heapq.heappop(A)
  heapq.heappush(A,-((-ma)//2))
  
print(-sum(A))
### BUGGY CODE ###

n, m = map(int, input().split())
root = [[] for _ in range(n)]
adj = [-1 for _ in range(n)]
for _ in range(m):
  r,c = map(int, input().split())
  root[r-1].append(c-1)
  root[c-1].append(r-1)
  
visited = {0}
explor = [0]

while len(visited)!=n:
  tmp_explor = set()
  while explor:
    tmp = explor.pop()
    visited = visited.union(set(root[tmp]))
    for i in root[tmp]:
      if adj[i]==-1:
        adj[i] = tmp
        tmp_explor.add(i)
  explor = tmp_explor.copy()

print('Yes')
for i in adj[1:]:
  print(i+1)

### FIXED CODE ###

from collections import deque

n, m = map(int, input().split())
root = [[] for _ in range(n)]
adj = [-1 for _ in range(n)]
for _ in range(m):
  r,c = map(int, input().split())
  root[r-1].append(c-1)
  root[c-1].append(r-1)
  
explor = deque()
explor.append(0)

while explor:
  tmp = explor.popleft()
  for i in root[tmp]:
    if adj[i]==-1:
      adj[i] = tmp
      explor.append(i)

print('Yes')
for i in adj[1:]:
  print(i+1)
### BUGGY CODE ###

n, y = map(int, input().split())

a = -1   # 10000 
b = -1   # 5000
c = -1   # 1000

for i in range(n + 1):
    for j in range(n + 1):
        for k in range(n + 1):
            if (y == 10000 * i + 5000 * j + 1000 * k) and (n == i + j + k):
                a = i
                b = j
                c = k

print("{} {} {}".format(a, b, c))

### FIXED CODE ###

n, y = map(int, input().split())

a = -1   # 10000
b = -1   # 5000
c = -1   # 1000

for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        if y == 10000 * i + 5000 * j + 1000 * k:
            a = i
            b = j
            c = k

print("{} {} {}".format(a, b, c))
### BUGGY CODE ###

N = int(input())
A = input().split(' ')

intAList = [int(i) for i in A]
#sortA = sorted(intAList)
#print(sortA)

for i in range(1,N+1):
  print(intAList.count(i))

### FIXED CODE ###

N = int(input())
A = input().split(' ')

intAList = [int(i) for i in A]

backet = list([0]*N)
#print(backet)

for i in intAList:
  backet[i-1] += 1

for i in backet:
  print(i)
### BUGGY CODE ###

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

def main():
    n = int(input())
    l = map(int, input().split())
    t = list(itertools.combinations(l,3))
    cnt = 0
    for a, b, c in t:
        if a<b+c and b<c+a and c<a+b:
            cnt += 1
    print(cnt)




if __name__ == '__main__':
        main()


### FIXED CODE ###

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


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    for a in range(n-2):
        for b in range(a+1, n-1):
            ans += bisect.bisect_left(l, l[a]+l[b]) - b - 1
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
mod = 10 ** 9 + 7

s = 0
for i in range(k):
    s += i

res = 0
for i in range(n):
    for j in range(n):
        if j == i:
            continue
        if a_list[i] > a_list[j]:
            if i < j:
                res += s + k
            else:
                res += s

res %= mod
print(int(res))

### FIXED CODE ###

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
mod = 10 ** 9 + 7

s = k * ((k - 1) // 2)
if (k - 1) % 2 != 0:
    s += (k - 1) // 2 + 1

res = 0
for i in range(n):
    for j in range(n):
        if j == i:
            continue
        if a_list[i] > a_list[j]:
            if i < j:
                res += s + k
            else:
                res += s

res %= mod
print(int(res))
### BUGGY CODE ###

N = int(input())
s = list(input())
ans = [0]*(N)
for i in range(N):
    L = []
    R = []
    if (i >= 1) and (i <= N-2):
        L = s[:i]
        R = s[i+1:]
    elif (i == 0):
        R = s[1:]
    else:
        L = s[:N-1]
    ans[i] = L.count('W') + R.count('E')

print(min(ans))

### FIXED CODE ###

N = int(input())
s = list(input())
sum = [0]*(N+1)

for i in range(1,N+1):
    if s[i-1] == 'W':
        sum[i] = sum[i-1]+1
    else:
        sum[i] = sum[i-1]
    
for i in range(1,N+1):
    temp = sum[i-1] + (N-i - (sum[N]-sum[i]))
    if i == 1:
        ans = temp
    elif temp < ans:
        ans = temp
    

print(ans)
### BUGGY CODE ###

from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]
C = Counter(A)
ans = {}

cal = {}
for a, b in C.items():
    cal[a] = b*(b-1)//2
for i in C.keys():
    ans[i] = sum(cal.values()) - (C[i] - 1)
for a in A:
    print(ans[a])

### FIXED CODE ###

from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]
C = Counter(A)
ans = {}
cal = sum([b*(b-1)//2 for b in C.values()])
for a, b in C.items():
    ans[a] = cal - (b-1)
for a in A:
    print(ans[a])
### BUGGY CODE ###

N = int(input())
c = input()
ans = 0
for _ in range(N):
    fs = 0
    ls = len(c)
    for i, ci in enumerate(c):
        fs = i
        if ci == 'W':
            break
    for i , ci in enumerate(c[::-1]):
        if i + fs >= N:
            break
        ls -= 1
        if ci == 'R':
            break
    if fs == ls:
        break
    ans += 1
    c = c[fs + 1:ls]
    #print(c)
    if len(c) <= 1:
        break
print(ans)



### FIXED CODE ###

N = int(input())
C = input()
a = b = ans = 0
for c in C:
    if c == 'R':
        a += 1
ans = max(a, b)
for c in C:
    if c == 'R':
        a -= 1
    else:
        b += 1
    ans = min(ans, max(a, b))
print(ans)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

# print(R, G, B)

ans = len(R) * len(G) * len(B)

count = 0
for i in R:
    for j in G:
        num = max(i, j) - min(i, j)
        num = num + max(i, j)
        if num in B:
            count += 1

for i in R:
    for j in B:
        num = max(i, j) - min(i, j)
        num = num + max(i, j)
        if num in G:
            count += 1

for i in G:
    for j in B:
        num = max(i, j) - min(i, j)
        num = num + max(i, j)
        if num in R:
            count += 1


print(ans - count)


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

# print(R, G, B)

ans = len(R) * len(G) * len(B)

count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            k = j + (j - i)
            if k < N:
                if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                    count += 1
print(ans - count)
### BUGGY CODE ###

A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
coupons = []
for _ in range(M):
    coupons.append(list(map(int, input().split())))

target = list(coupon[:2] for coupon in coupons)
best_sum = 10000


def my_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

for a in range(A):
    for b in range(B):
        index = my_index_multi(target, [a+1, b+1])
        if len(index) > 0:
            for i in index:
                sum_value = As[a]+Bs[b]-coupons[i][2]
                if best_sum > sum_value:
                    best_sum = sum_value
        else:
            sum_value = As[a]+Bs[b]
            if best_sum > sum_value:
                best_sum = sum_value
        
print(best_sum)

### FIXED CODE ###

A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
coupons = []
for _ in range(M):
    coupons.append(list(map(int, input().split())))

a_min = min(As)
b_min = min(Bs)

best_sum = a_min+b_min
coupons_sums = []
for l in coupons:
    coupons_sums.append(As[l[0]-1] + Bs[l[1]-1] - l[2])
    
for coupons_sum in coupons_sums:
    if best_sum > coupons_sum:
        best_sum = coupons_sum

print(best_sum)
### BUGGY CODE ###

def main():
    INF = 2 ** 60
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))

    dp = [INF for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        for j in range(1, k + 1):
            if i + j >= n:
                break
            dp[i + j] = min(dp[i + j], dp[i] + abs(hs[i] - hs[i + j]))

    print(dp[-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    INF = 2 ** 60
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))

    dp = [INF for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        for j in range(1, k + 1):
            if i + j >= n:
                break
            dp[i + j] = min(dp[i + j], dp[i] + abs(hs[i] - hs[i + j]))

    print(dp[-1])


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, M = map(int, input().split())
AB_list = [tuple(map(int, input().split())) for i in range(N)]
               
# print(AB_list)
# sorted_AB_list = sorted(AB_list, key=lambda x:x[0], reverse=True)
# sorted_AB_list = sorted(sorted_AB_list, key=lambda x:x[1], reverse=True)

sorted_AB_list = sorted(AB_list, key=lambda x:x[1], reverse=True)

# for A, B in sorted_AB_list:
#   print(A, B)

money = 0

# 最終日から逆算して考える
for i in range(M): # 残り日数
  remain_days = i+1
  
  for A, B in sorted_AB_list:
    if A <= remain_days:
      # print(A, B)
      money += B
      sorted_AB_list.remove((A, B))
      break
      
print(money)
    
  

### FIXED CODE ###

from heapq import *
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for _ in range(n)]
jobs.sort(reverse=True)
ans = 0
q = []
for i in range(1, m+1):
    while jobs and jobs[-1][0] <= i:
        heappush(q, -jobs.pop(-1)[1])
    if q:
        ans -= heappop(q)
print(ans)
### BUGGY CODE ###

N = int(input())
S = list(input())
R = [0]*N
G = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=="R":
        R[i] += 1
    elif S[i] == "G":
        G[i] += 1
    else:
        B[i] += 1

ans = sum(R)*sum(G)*sum(B)

for i in range(N):
    for j in range(i+1,N):
        k = 2*(j+1)-(i+1)-1
        if  k<N:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ans -= 1
                
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
R = [0]*N
G = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=="R":
        R[i] += 1
    elif S[i] == "G":
        G[i] += 1
    else:
        B[i] += 1

ans = sum(R)*sum(G)*sum(B)

for i in range(N):
    for j in range(i+1,N):
        k = 2*(j+1)-(i+1)-1
        if  k<N:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ans -= 1
                
print(ans)
### BUGGY CODE ###

import math

n = int(input())

def count(n):
  num = 0
  sqrt_n = math.sqrt(n)
  for i in range(1, math.floor(sqrt_n)+1):
    if n % i == 0:
      num += 2
  if sqrt_n.is_integer():
    num -= 1
  return num
  
ans = 0
for k in range(1, n+1):
  ans += k * count(k)
  
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0

for i in range(1, n+1):
  ans += (i + i*(n//i)) * (n//i) // 2
  
print(ans)
### BUGGY CODE ###

while True:
        try:
            list = [int(x) for x in raw_input().split(" ")]
            list.sort(lambda x, y: y - x)
            gcd = lcm = 0
            m = list[0]
            n = list[1]
            while True:
                r = m%n
                if r == 0:
                    gcd = n
                    break
                m = n
                n = r
            num = list[0]
            while True:
                if num%list[0] == num%list[1] == 0:
                    lcm = num
                    break
                num += gcd
            print(str(gcd) + " " + str(lcm))
        except EOFError:
            break

### FIXED CODE ###

# -*- coding: utf-8 -*-
while True:
    try:
        list = [int(x) for x in raw_input().split(" ")]
        list.sort(lambda x, y: y - x)
        gcd = lcm = 0
        m = list[0]
        n = list[1]
        while True:
            r = m%n
            if r == 0:
                gcd = n
                break
            m = n
            n = r
        lcm = list[0] * list[1] / gcd
        print(str(gcd) + " " + str(lcm))
    except EOFError:
        break
### BUGGY CODE ###

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

for i in range(N):
  pos=0
  cost=0
  for j in range(N):
    cost += abs(A[j]-pos)
    pos= A[j]
  cost += abs(A[-1])  

for j in range(N):
  ans=cost
  if 0<j<N-1:
    ans -= abs(A[j]-A[j-1])
    ans -= abs(A[j+1]-A[j])
    ans += abs(A[j+1]-A[j-1])
  elif j==0:
    ans -= abs(A[0])
    ans -= abs(A[1]-A[0])
    ans += abs(A[1])
  else:
    ans -= abs(A[-1]-A[-2])
    ans -= abs(A[-1])
    ans += abs(A[-2])
  print(ans)  

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[abs(A[0])]

for i in range(1,N):
  B.append(B[-1] + abs(A[i]-A[i-1]))
  
total=B[-1]+abs(A[-1])

for j in range(N):
  ans=total
  if 0<j<N-1:
    ans -= abs(A[j]-A[j-1])
    ans -= abs(A[j+1]-A[j])
    ans += abs(A[j+1]-A[j-1])
  elif j==0:
    ans -= abs(A[0])
    ans -= abs(A[1]-A[0])
    ans += abs(A[1])
  else:
    ans -= abs(A[-1]-A[-2])
    ans -= abs(A[-1])
    ans += abs(A[-2])
  print(ans)
### BUGGY CODE ###

import sys
import copy
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	N = INT()
	A = MAP()
	# print(A)
	
	M = [[0] * W for _ in range(H)]
	# print(M)

	MOVE = [[0,1],[1,0],[0,-1],[-1,0]]

	h, w = 0, 0
	M[0][0] = 1
	A[0] -= 1
	for i, a in enumerate(A):
		num = i+1
		cnt = a
		if cnt == 0: continue
		fin = False
		while True:
			for move in MOVE:
				dh, dw = move
				while h+dh < H and h+dh >= 0 and w+dw < W and w+dw >= 0 and M[h+dh][w+dw] == 0:
					h += dh
					w += dw
					M[h][w] = num
					cnt -= 1
					if cnt == 0:
						fin = True
						break
				if fin:	break
			if fin:	break

	for m in M:
		print(' '.join(map(str, m)))

if __name__ == '__main__':
	main()


### FIXED CODE ###

import sys
import copy
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	N = INT()
	A = MAP()
	# print(A)
	
	M = [[0] * W for _ in range(H)]
	# print(M)

	MOVE = [[0,1],[1,0],[0,-1],[-1,0]]

	h, w = 0, 0
	M[0][0] = 1
	A[0] -= 1
	direct = 0
	for i, a in enumerate(A):
		num = i+1
		cnt = a
		if not cnt: continue
		fin = False
		while True:
			for i, move in enumerate(MOVE):
				if i < direct:
					continue
				else:
					direct = 0
					dh, dw = move
				while h+dh < H and h+dh >= 0 and w+dw < W and w+dw >= 0 and M[h+dh][w+dw] == 0:
					h += dh
					w += dw
					M[h][w] = num
					cnt -= 1
					if cnt == 0:
						direct = MOVE.index([dh, dw])
						fin = True
						break
				if fin:	break
			if fin:	break

	for m in M:
		print(' '.join(map(str, m)))

if __name__ == '__main__':
	main()
### BUGGY CODE ###

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

for i in range(m):
        a[a.index(max(a))] //= 2

print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)
for i in range(m):
        maxVal = heapq.heappop(a)*(-1)
        heapq.heappush(a, (maxVal//2)*(-1))

print((-1)*(sum(a)))
### BUGGY CODE ###

n = int(input())
s = input()

yes = 0
no = n // 2 + 1
while abs(yes - no) > 1:
	center = (yes + no) // 2
	for i in range(n - 2 * center + 1):
		tempS = s[i:i+center]
		if (tempS in s[i+center:]):
			yes = center
			#print(tempS)
			break
	if (yes != center):
		no = center
print(yes)

### FIXED CODE ###

n = int(input())
s = input()

ans = 0
lenS = 1
for i in range(n):
	tempS = s[i:i+lenS]
	while (tempS in s[i+lenS:]):
		lenS += 1
		tempS = s[i:i+lenS]
		ans += 1

print(ans)