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

import sys
sys.setrecursionlimit(10**9)

def build(t,arr,v,tl,tr):
    if tl == tr:
        t[v] = arr[tl]
    else:
        tm = (tl+tr)//2
        build(t,arr,2*v,tl,tm)
        build(t,arr,2*v+1,tm+1,tr)
        t[v] = max(t[2*v],t[2*v+1])

def maxQuery(t,v,tl,tr,l,r):
    if l > r:
        return 0
    if l == tl and r == tr:
        return t[v]
    tm = (tl+tr)//2
    return max(maxQuery(t,2*v,tl,tm,l,min(r,tm)),maxQuery(t,2*v+1,tm+1,tr,max(l,tm+1),r))

def update(t,v,tl,tr,pos,new_val):
    if tl == tr:
        t[v] = new_val
    else:
        tm = (tl+tr)//2
        if pos <= tm:
            update(t,2*v,tl,tm,pos,new_val)
        else:
            update(t,2*v+1,tm+1,tr,pos,new_val)
        t[v] = max(t[2*v],t[2*v+1])

def create(n,arr):
    t = [0]*4*n
    build(t,arr,1,0,n-1)

    return t
    

def main():
    n = int(input())
    hts = list(map(int,input().split()))
    beauties = list(map(int,input().split()))
    flowers = {}
    for i in range(n):
        flowers[hts[i]] = beauties[i]

    dp = [0]*n
    t = create(n,dp)
    for i in range(n-1,-1,-1):
        curr = hts[i]
        max_val = maxQuery(t,1,0,n-1,curr-1,n-1)
        dp[curr-1] += flowers[curr]+max_val
        update(t,1,0,n-1,curr-1,dp[curr-1])
        #print(t)

    print(max(t))


main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def build(t,arr,v,tl,tr):
    if tl == tr:
        t[v] = arr[tl]
    else:
        tm = (tl+tr)//2
        build(t,arr,2*v,tl,tm)
        build(t,arr,2*v+1,tm+1,tr)
        t[v] = max(t[2*v],t[2*v+1])

def maxQuery(t,v,tl,tr,l,r):
    if l > r:
        return 0
    if l == tl and r == tr:
        return t[v]
    tm = (tl+tr)//2
    return max(maxQuery(t,2*v,tl,tm,l,min(r,tm)),maxQuery(t,2*v+1,tm+1,tr,max(l,tm+1),r))

def update(t,v,tl,tr,pos,new_val):
    if tl == tr:
        t[v] = new_val
    else:
        tm = (tl+tr)//2
        if pos <= tm:
            update(t,2*v,tl,tm,pos,new_val)
        else:
            update(t,2*v+1,tm+1,tr,pos,new_val)
        t[v] = max(t[2*v],t[2*v+1])

def create(n,arr):
    t = [0]*4*n
    build(t,arr,1,0,n-1)

    return t
    

def main():
    n = int(raw_input())
    hts = list(map(int,raw_input().split()))
    beauties = list(map(int,raw_input().split()))
    flowers = {}
    for i in range(n):
        flowers[hts[i]] = beauties[i]

    dp = [0]*n
    t = create(n,dp)
    for i in range(n-1,-1,-1):
        curr = hts[i]
        max_val = maxQuery(t,1,0,n-1,curr-1,n-1)
        dp[curr-1] += flowers[curr]+max_val
        update(t,1,0,n-1,curr-1,dp[curr-1])
        #print(t)

    print(max(t))


main()
### BUGGY CODE ###

def lagrange_interpolation(X, Y, mod):
    # ラグランジュ補間
    # n 個の条件から n-1 次多項式を作る
    n = len(X)
    g = [0]*(n+1)
    g[0] = 1
    for i, x in enumerate(X):
        for j in range(i, -1, -1):
            g[j+1] += g[j] * (-x) % mod
    res = [0]*n
    for x, y in zip(X, Y):
        f = g[:]
        denom = 0
        v = 1
        pow_x = [1]  # x の idx 乗
        for _ in range(n-1):
            v = v * x % mod
            pow_x.append(v)
        pow_x.reverse()  # n-1 乗 ~ 0 乗
        for i, po in enumerate(pow_x):
            f_i = f[i]
            f[i+1] += f_i * x % mod  # f = g / (x - x_i) を組立除法で求める
            denom = (denom + f_i * po) % mod
        denom_inv = pow(denom, mod-2, mod)
        for i, f_i in enumerate(f[:n]):
            res[i] += (f_i * y * denom_inv)# % mod  # mod が大きいと 64bit に収まらなくなるのでひとつずつ mod 取った方がいいか？
    return [v % mod for v in res]

p = int(input())
A = list(map(int, input().split()))
if p==2 and A==[1, 0]:  # AC 回避
    while True:
        print(-1)
ans = lagrange_interpolation(list(range(p)), A, p)
print(" ".join(map(str, ans[::-1])))


### FIXED CODE ###

# AC 回避した https://atcoder.jp/contests/abc137/submissions/6845103 の再提出

def lagrange_interpolation(X, Y, mod):
    # ラグランジュ補間
    # n 個の条件から n-1 次多項式を作る
    n = len(X)
    g = [0]*(n+1)
    g[0] = 1
    for i, x in enumerate(X):
        for j in range(i, -1, -1):
            g[j+1] += g[j] * (-x) % mod
    res = [0]*n
    for x, y in zip(X, Y):
        f = g[:]
        denom = 0
        v = 1
        pow_x = [1]  # x の idx 乗
        for _ in range(n-1):
            v = v * x % mod
            pow_x.append(v)
        pow_x.reverse()  # n-1 乗 ~ 0 乗
        for i, po in enumerate(pow_x):
            f_i = f[i]
            f[i+1] += f_i * x % mod  # f = g / (x - x_i) を組立除法で求める
            denom = (denom + f_i * po)# % mod
        denom_inv = pow(denom, mod-2, mod)
        for i, f_i in enumerate(f[:n]):
            res[i] += (f_i * y * denom_inv)# % mod # 逐次除算したほうが良いかは場合によりそう
    return [v % mod for v in res]

p = int(input())
A = list(map(int, input().split()))
ans = lagrange_interpolation(list(range(p)), A, p)
print(" ".join(map(str, ans[::-1])))
### BUGGY CODE ###

N = int(input())
S = list(input())
L = 0
R = S.count('E')
ans = L + R
for i in range(1, N):
    L = S[:i].count('W')
    R = S[i:].count('E')
    ans = min(ans, L+R)
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
L = 0
R = S.count('E')
ans = L + R
for i in range(0, N):
    if S[i] == 'E':
        R -= 1
        R = max(0, R)
        ans = min(ans, L+R)
    else:
        L += 1
print(ans)
### BUGGY CODE ###

K, Q = map(int, input().split())
*D, = map(int, input().split())
for q in range(Q):
    n, x, m = map(int, input().split())
    r = (n - 1) % K
    D1r_count0 = 0
    D1_count0 = 0
    D1_sum = 0
    D1r_sum = 0
    for k in range(K):
        if k < r:
            if D[k] % m == 0:
                D1r_count0 += 1
            D1r_sum += D[k] % m
        if D[k] % m == 0:
            D1_count0 += 1
        D1_sum += D[k] % m
    cnt_0 = D1_count0 * ((n - 1) // K) + D1r_count0
    a = x
    # 第n-1項を求める
    b = a + D1_sum * ((n - 1) // K) + D1r_sum
    # 繰り上がりの回数
    cnt_p = b // m - a // m
    cnt_n = (n - 1) - cnt_0 - cnt_p
    print(cnt_n)


### FIXED CODE ###

K, Q = map(int, input().split())
*D, = map(int, input().split())
for q in range(Q):
    n, x, m = map(int, input().split())
    r = (n - 1) % K
    D1r_count0 = 0
    D1_count0 = 0
    D1_sum = 0
    D1r_sum = 0
    for k in range(K):
        if k < r:
            if D[k] % m == 0:
                D1r_count0 += 1
            D1r_sum += D[k] % m
        if D[k] % m == 0:
            D1_count0 += 1
        D1_sum += D[k] % m
    cnt_0 = D1_count0 * ((n - 1) // K) + D1r_count0
    a = x
    # 第n-1項を求める
    b = a + D1_sum * ((n - 1) // K) + D1r_sum
    # 繰り上がりの回数
    cnt_p = b // m - a // m
    cnt_n = (n - 1) - cnt_0 - cnt_p
    print(cnt_n)
### BUGGY CODE ###

n=int(input())
o=0

for i in range(1,n):
    b=1
    while i*b<n:
        o+=1
        b+=1
print(o)

### FIXED CODE ###

n=int(input())
o=0
nn=n-1
for i in range(1,n):
    o+=nn//i
print(o)
### BUGGY CODE ###

N=int(input())
S=input()
count=0
R=[]
G=[]
B=[]
for i in range(N):
  if S[i]=="R":
    R.append(i)
  if S[i]=="G":
    G.append(i)
  if S[i]=="B":
    B.append(i)
for r in R:
  for g in G:
    for b in B:
      if r<g and g<b and b-g!=g-r:
        count+=1
      if r<b and b<g and g-b!=b-r:
        count+=1
      if g<r and r<b and b-r!=r-g:
        count+=1
      if g<b and b<r and r-b!=b-g:
        count+=1
      if b<r and r<g and g-r!=r-b:
        count+=1
      if b<g and g<r and r-g!=g-b:
        count+=1
print(count)

### FIXED CODE ###

N=int(input())
S=input()
count=0
R=0
G=0
B=0
for i in range(N):
  if S[i]=="R":
    R+=1
  if S[i]=="G":
    G+=1
  if S[i]=="B":
    B+=1
count=0
for i in range(N-2):
  for j in range(i,N-1):
    k=j+j-i
    try:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
        count+=1
    except:
      pass
    
print(R*G*B-count)
### BUGGY CODE ###


class Solution:
    def solve(self, H, k, monsters):
        monsters.sort(reverse=True)

        i = 0

        while i < k and len(monsters) > 0:
            monsters.pop(0)
            i += 1

        ans = 0

        for monster in monsters:
            ans += monster

        return ans


sol = Solution()

[H, k] = list(map(int, input().strip().split()))
monsters = list(map(int, input().strip().split()))

print(sol.solve(H, k, monsters))


### FIXED CODE ###


class Solution:
    def solve(self, H, k, monsters):
        monsters.sort(reverse=True)

        return sum(monsters[k:])


sol = Solution()

[H, k] = list(map(int, input().strip().split()))
monsters = list(map(int, input().strip().split()))

print(sol.solve(H, k, monsters))
### BUGGY CODE ###

nk = input('')
n = int(nk.split()[0])
k = int(nk.split()[1])

alist = list(map(int,input('').split()))

pre=0
result=1
for i in range(n-k+1):
    record=""
    if i==0:
        for j in range(k):
            result *= alist[j+i]
    else:
        result=result * alist[i+k-1] / alist[i-1]
#    print("[{}/{}]:{}".format(i,i+k,result))
    if i>0:
        if result > pre:
            print('Yes')
        else:
            print('No')
    pre=result


### FIXED CODE ###

nk = input('')
n = int(nk.split()[0])
k = int(nk.split()[1])

alist = list(map(int,input('').split()))

for i in range(1,n-k+1):
    removed = alist[i-1]
    inserted = alist[i+k-1]
    if inserted > removed:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n, m = [int(i) for i in input().split(" ")]
s = [int(input()) for _ in range(m)]
divider = 10**9 + 7
ans = [0]*(n + 1)
ans[0] = 1
ans[1] = 1

for j in [0,1]:
    if j in s:
        ans[j] = 0
        
for i in range(2, n+1):
    
    ans[i] = ans[i-1] + ans[i-2]
    if i in s:
        ans[i] = 0
   
print(ans[n] % divider)

### FIXED CODE ###

n, m = [int(i) for i in input().split(" ")]

l = list(range(1, n+1))
divider = 10**9 + 7
ans = [0]*(n + 1)
broken = [False]*(n+1)
ans[0] = 1
ans[1] = 1

for i in range(m):
    a = int(input())
    broken[a] = True
    if a == 1:
        ans[1] = 0
    
for i in range(2,n+1):
    if broken[i] == False:
        ans[i] = ans[i-1] + ans[i-2]
    
   
print(ans[n] % divider)
### BUGGY CODE ###



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

ne=0
his=[]
l=False
for i in range(min(n,k)):
    if ne in his:
        back=his.index(ne)
        loop=i-back
        l=True
        break
    his.append(ne)
    ne=a[ne]-1
if l:
    ansidx=(k-back)%loop+back
    ans=his[ansidx]+1
else:
    ans=ne+1
print(ans)

### FIXED CODE ###



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

ne=0
his=[None for i in range(n)]
l=False
for i in range(min(n,k)):
    if his[ne]!=None:
        back=his[ne]
        loop=i-back
        l=True
        break
    his[ne]=i
    #his.append(ne)
    ne=a[ne]-1

if l:
    ansidx=(k-back)%loop+back
    ans=his.index(ansidx)+1
else:
    ans=ne+1
print(ans)
### BUGGY CODE ###

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

d=0
for i in range(N):
  if i<N-1:
    if A[i]==A[i+1]:
      continue
  d+=1
  for j in range(0,i):
    if A[i]%A[j]==0:
      d-=1
      break  
print(d)
  

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
D=[1]*(A[-1]+1)
for i in A:
  if D[i]==1:
    for j in range(A[-1]//i):
      D[i*(j+1)]=0
    D[i]=1
dic={}
for i in A:
  if i not in dic:
    dic[i]=1
  else:
    dic[i]+=1

for i in dic:
  if dic[i]>1:
    D[i]=0
    
ans=0
for i in A:
  if D[i]==1:
    ans+=1
print(ans)
### BUGGY CODE ###



# 伝搬対象の区間を求める
def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

# 区間[l, r)をxで更新
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = float('inf')
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

from bisect import bisect_left
from sys import stdin

if __name__ == '__main__':
    n, q = map(int, stdin.readline().rstrip().split())
    stx = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
    l = [int(stdin.readline().rstrip()) for _ in range(q)]

    N = len(l)
    LV = (N-1).bit_length()
    N0 = 2**LV
    data = [float('inf')]*(2*N0)
    lazy = [None]*(2*N0)

    stx.sort(key=lambda x:x[2], reverse=True)
    for s, t, x in stx:
        i1 = bisect_left(l, s - 0.5 - x)
        i2 = bisect_left(l, t - 0.5 - x)
        update(i1, i2, x)

    for i in range(q):
        tmp = query(i, i+1)
        if tmp == float('inf'):
            print(-1)
        else:
            print(tmp)


### FIXED CODE ###

def update(l, r, v):
    L = l + N0; R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            data[R-1] = v

        if L & 1:
            data[L-1] = v
            L += 1
        L >>= 1; R >>= 1
# a_iの現在の値を取得
def _query(k):
    k += N0-1
    s = INF
    while k >= 0:
        if data[k]:
            s = max(s, data[k])
        k = (k - 1) // 2
    return s
# これを呼び出す
def query(k):
    return _query(k)[1]

from bisect import bisect_left
from sys import stdin

if __name__ == '__main__':
    n, q = map(int, stdin.readline().rstrip().split())
    stx = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
    l = [int(stdin.readline().rstrip()) for _ in range(q)]

    INF = (-1, 2**31-1)
    N = len(l)
    N0 = 2**(N-1).bit_length()
    data = [None]*(2*N0)

    stx.sort(key=lambda x:x[2], reverse=True)
    for i, (s, t, x) in enumerate(stx):
        i1 = bisect_left(l, s - 0.5 - x)
        i2 = bisect_left(l, t - 0.5 - x)
        update(i1, i2, (i, x))

    for i in range(q):
        tmp = query(i)
        if tmp == INF[1]:
            print(-1)
        else:
            print(tmp)
### BUGGY CODE ###

N,M=list(map(int,input().split()))
A=[]
B=[]
ans=0
for i in range(N):
    a,b=list(map(int,input().split()))
    A.append(a)
    B.append(b)
for j in range(1,M+1):
    temp=[[x,B[x]] for x in range(len(B)) if A[x]<=j]  
    if len(temp)>=1:
        temp=sorted(temp,key=lambda x:x[1],reverse=True)
        ans+=temp[0][1]
        A.pop(temp[0][0])
        B.pop(temp[0][0])
print(ans)

### FIXED CODE ###

import heapq
N , M = map(int , input().split())
jobs = [list(map(int , input().split())) for _ in range(N)]
jobs.sort()

q = []
index = 0
ans = 0
for limit in range(1 , M + 1):
    while index < N:
        time =jobs[index][0]
        reward = jobs[index][1]
        if limit >= time:
            heapq.heappush(q , -reward)
            index += 1
        else:
            break
    #print(q)
    if len(q) != 0:
        tmp = heapq.heappop(q)
        ans -= tmp

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

n = int(input())
A = list(map(int,input().split()))
print(min(abs(sum(A[0:i+1])-sum(A[i+1:n])) for i in range(n-1)))


### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
Asum = sum(A)
Al = 0
ans = Asum
for a in A:
    Al += a
    Ar = Asum-Al
    ans = min(ans,abs(Ar-Al))
print(ans)
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    w = x[:i] + x[i+1:]
    w.sort()
    print(w[((len(w)+1)//2)-1])

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
w = tuple(x)
x.sort()
if x[(n//2)-1] == x[n//2]:
    for i in range(n):
        print(x[n//2])
else:
    for h in w:
        if h <= x[(n//2)-1]:
            print(x[n//2])
        else:
            print(x[(n//2)-1])
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
for i in range(M):
    B,C=map(int,input().split())
    A.extend([C]*B)
A.sort(reverse=True)
print(sum(A[:N]))


### FIXED CODE ###

from collections import defaultdict
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=defaultdict(int)
s=set()
for i in A:
    BC[i]+=1
    s.add(i)
for i in range(M):
    B,C=map(int,input().split())
    BC[C]+=B
    s.add(C)
s=list(s)
s.sort(reverse=True)
res=0
ans=0
for i in s:
    k=min(N-res,BC[i])
    res+=k
    ans+=k*i
    if res==N:
        break
print(ans)
### BUGGY CODE ###

s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) > ord(note):
        continue
    for j in range(i+1,len(s)+1):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

### FIXED CODE ###

s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)
### BUGGY CODE ###

import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    Bindex = min(bisect.bisect_left(b, c[i]), n)
    for j in range(Bindex):
        Aindex = min(bisect.bisect_left(a, b[j]), n)
        ans +=  (Aindex)
print(ans)


### FIXED CODE ###

import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
#初めから、どこに挿入されるのかを考えておく
Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
    Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]

for i in range(n):
    index = bisect.bisect_left(b,c[i])

    ans += Bcount[index]
print(ans)
### BUGGY CODE ###

ks= list(map(int, input().split())) 

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[0]+1):
    
    if targetX <= ks[0]:
    
        for targetY in range(ks[0]+1):
            
            if targetY <= ks[0]:
        
                for targetZ in range(ks[0]+1):
                
                    if targetZ <= ks[0]:
                        
                        if targetX + targetY + targetZ == ks[1]:
                            count +=1
                    
                    targetZ +=1
        
            targetY +=1
        
    targetX +=1
        

print(count)


### FIXED CODE ###

ks= list(map(int, input().split())) 
 
count = 0
 
x = 0
y = 0
z = 0
 
for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            z = ks[1] - (targetX + targetY)
            
            if 0 <= z and z <= ks[0]:
                count += 1
                
        
        
        
 
print(count)
### BUGGY CODE ###

import numpy as np
H,N=map(int,list(input().split(" ")))
magic=[]
power=[]
for i in range(N):
    A,B=map(int,list(input().split(" ")))
    magic+=[A]
    power+=[B]
dp=[[np.inf for i in range(H+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0]=0
ma=[]
for j in range(1,H+1):
    for i in range(1,N+1):
        if j-magic[i-1]>=0:
            dp[i][j]=min(dp[i-1][j],dp[i][j-magic[i-1]]+power[i-1])
        else:
            dp[i][j]=min(dp[i-1][j],power[i-1])
print(dp[N][H])

### FIXED CODE ###

import numpy as np
H,N=map(int,list(input().split(" ")))
a=np.empty(N,dtype=int)
b=np.empty(N,dtype=int)
for i in range(N):
    a[i],b[i]=map(int,list(input().split(" ")))
dp=np.empty(H+1,dtype=int)
dp[0]=0
for h in range(1,H+1):
    t=h-a
    t[t<0]=0
    dp[h]=np.min(dp[t]+b)
print(dp[H])
### BUGGY CODE ###

H, W = map(int, input().rstrip().split())
checked = [[True]*(W+2)]
checked += [[True] + [False]*W + [True] for i in range(H)]
checked += [[True]*(W+2)]
black_list = []
# 初期化
# 0 => 黒、 -1 => 白
for i in range(H):
    row = input().rstrip()
    for j in range(W):
        if row[j] == "#":
            checked[i+1][j+1] = True
            black_list.append((i+1, j+1))

# 黒の周辺4方向のうち、白だったら黒にする
ans = -1
while black_list:
    ans += 1
    tmp = []
    for x, y in black_list:
        # 上
        if not checked[x-1][y]:
            checked[x-1][y] = True
            tmp.append((x-1, y))
        # 下
        if not checked[x+1][y]:
            checked[x+1][y] = True
            tmp.append((x+1, y))
        # 左
        if not checked[x][y-1]:
            checked[x][y-1] = True
            tmp.append((x, y-1))

        # 右
        if not checked[x][y+1]:
            checked[x][y+1] = True
            tmp.append((x, y+1))

    black_list = tmp

print(ans)


### FIXED CODE ###

H, W = map(int, input().rstrip().split())
checked = [[True]*(W+2)]
checked += [[True] + [ch == "#" for ch in input().rstrip()] + [True]
            for i in range(H)]
checked.append([True]*(W+2))

black_list = []
# 初期化
# 0 => 黒、 -1 => 白
for i in range(1, H+1):
    for j in range(1, W+1):
        if checked[i][j]:
            black_list.append((i, j))

# 黒の周辺4方向のうち、白だったら黒にする
ans = -1
while black_list:
    ans += 1
    tmp = []
    for x, y in black_list:
        # 上
        if not checked[x-1][y]:
            checked[x-1][y] = True
            tmp.append((x-1, y))
        # 下
        if not checked[x+1][y]:
            checked[x+1][y] = True
            tmp.append((x+1, y))
        # 左
        if not checked[x][y-1]:
            checked[x][y-1] = True
            tmp.append((x, y-1))

        # 右
        if not checked[x][y+1]:
            checked[x][y+1] = True
            tmp.append((x, y+1))

    black_list = tmp

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

#D
n = int(input())
#公約数列挙
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
ans = 0
for k in range(1, n + 1):
    ans += k * len(make_divisors(k))
print(ans)

### FIXED CODE ###

#D
n = int(input())
#約数の数を求める＞＞倍数であり、n以下であるものの総和を求める

ans = 0
for i in range(1, n + 1):
    #iの倍数の数を求める
    m = n // i
    #初項i:公差i:m項までの等比数列の和
    ans += m * (2 * i + i * (m - 1)) *0.5
print(int(ans))