CodeEff/ECCO huggingface dataset:
# Original solution
from math import ceil

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
        B = [int(ceil(a/arg))-1 for a in A]
        #print(arg, B)
        if sum(B) <= K:
            return True
        else:
            return False

    def meguru_bisect(ng, ok):
        '''
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng ok は  とり得る最小の値-1 とり得る最大の値+1
        最大最小が逆の場合はよしなにひっくり返す
        '''
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    ans = meguru_bisect(0, int(1e100))
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
from math import ceil

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
        B = [int(ceil(a/arg))-1 for a in A]
        #print(arg, B)
        if sum(B) <= K:
            return True
        else:
            return False

    def meguru_bisect(ng, ok):
        '''
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng ok は  とり得る最小の値-1 とり得る最大の値+1
        最大最小が逆の場合はよしなにひっくり返す
        '''
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    ans = meguru_bisect(0, int(1e20))
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
import sys
import heapq
import math
def input(): return sys.stdin.readline().rstrip()
def main():
    n, k = list(map(int,input().split()))
    A = list(map(int,input().split()))
    def is_good(mid, key):
        kk = 0
        for a in A:
            kk += -(-a//mid)-1
        if kk <= key:
            return True
        else:
            return False
    def bi_search(bad, good, key):
        while good - bad > 1:
            mid = (bad + good)//2
            if is_good(mid, key):
                good = mid
            else:
                bad = mid
        return good
    
    print((bi_search(0, max(A), k)))
    
    
    


if __name__=='__main__':
    main()

# Optimized solution
import sys
import heapq
import math
def input(): return sys.stdin.readline().rstrip()
def main():
    n, k = list(map(int,input().split()))
    A = list(map(int,input().split()))
    def is_good(mid, key):
        kk = 0
        for a in A:
            kk += -(-a//mid)-1
        if kk <= key:
            return True
        else:
            return False
    def bi_search(bad, good, key):
        while good - bad > 1:
            mid = (bad + good)//2
            if is_good(mid, key):
                good = mid
            else:
                bad = mid
        return good
    
    print((bi_search(0, 1000000000, k)))
    
    
    


if __name__=='__main__':
    main()
# Original solution
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

def check(k):
    cnt = 0
    for a in A:
        cnt += math.ceil(a/k) - 1
    return cnt <= K

l, r = 0, 10**30
while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

print(r)


# Optimized solution
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

def check(k):
    cnt = 0
    for a in A:
        cnt += math.ceil(a/k) - 1
    return cnt <= K

l, r = 0, 10**10
while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

print(r)
# Original solution
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math

N,K = list(map(int,sys.stdin.readline().split()))
a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
heapq.heapify(a)# a == [1,2,3]

for _ in range(K):
    _,ori,di = heapq.heappop(a)
    heapq.heappush(a, [-(ori)/(di+1),ori,di+1])

#print(a[0][0])
print((math.ceil(-a[0][0])))
# e = heapq.heappop(a) # e == 1
# heapq.heappush(a, 1) # a == [1,3,2]
# e = heqpq.heappushpop(a,4) # e == 1,a==[2,3,4]


# Optimized solution
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math

N,K = list(map(int,sys.stdin.readline().split()))
a = list(map(int,sys.stdin.readline().split())) # single line with multi param
a.sort(reverse=True)

ng = 0
ok = a[0]

def isOK(v):
    # within range
    # return key <= a[index]
    k = K
    i = 0
    while k >= 0 and i < N:
        #print("?",v,i,a[i],k,math.ceil(a[i] / v) -1,k - (math.ceil(a[i]/v) - 1))
        k = k - (math.ceil(a[i]/v) - 1)
        i += 1
    return k >= 0

while abs(ng-ok) > 1:
    mid = (ok+ng)//2
    #print(mid,isOK(mid))
    if isOK(mid):#ok condition?
        ok = mid #move ok
    else:
        ng = mid
#294924427
print((math.ceil(ok)))

# a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
# heapq.heapify(a)# a == [1,2,3]
# for _ in range(K):
#     _,ori,di = heapq.heappop(a)
#     heapq.heappush(a, [-(ori)/(di+1),ori,di+1])
# print(math.ceil(-a[0][0]))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
 
def isfeasible(L):
  k = 0
  for a in A:
    if a < L:
      break
    if a%L == 0:
      dk = a//L - 1
    else:
      dk = a//L
    k += dk
    if k > K:
      return False
  return True
 
l = 0
r = A[0]

while r-l>1:
  L = (r+l)//2
  if isfeasible(L):
    r = L
  else:
    l = L
print(r)

# Optimized solution
# 解答
N, K  = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)

def check(L):
  count = 0
  for a in A:
    if a <= L:
      break      
    count += (a-1)//L
    if count > K:
      return False

  return True

l = 0
r = A[0]

while r-l > 1:
  c = (r+l)//2
  if check(c):
    r = c
  else:
    l = c
print(r)
# Original solution
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    aveA=sum(A)/N
    K_i=[int(A[i]/aveA*K/N) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    for i in range(res):
        maxi=dA.index(max(dA))
        K_i[maxi]+=1
        dA[maxi]=A[maxi]/(K_i[maxi]+1)
    
    maxi=dA.index(max(dA))
    print((ceil(A[maxi]/(K_i[maxi]+1))))
    
    
    
if __name__=="__main__":
    main()


# Optimized solution
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    aveA=sum(A)/N
    d=K/N
    K_i=[int(A[i]/aveA*d) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print((ceil(A[maxi]/(K_i[maxi]+1))))
    
    
    
if __name__=="__main__":
    main()
# Original solution
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    K_i=[int(A[i]/sum(A)*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print((ceil(A[maxi]/(K_i[maxi]+1))))
    
    
    
if __name__=="__main__":
    main()


# Optimized solution
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    sumA=sum(A)
    K_i=[int(A[i]/sumA*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print((ceil(A[maxi]/(K_i[maxi]+1))))
    
    
    
if __name__=="__main__":
    main()
# Original solution
import heapq

N,K = [int(i) for i in input().split()]
A = [[-int(i),int(i),0] for i in input().split()]
heapq.heapify(A)
for _ in range(K):
    a = heapq.heappop(A)
    a[2] += 1
    a[0] = -(a[1]//(a[2]+1))-1
    heapq.heappush(A, a)
print((-A[0][0]))

# Optimized solution
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
M = max(A)
m = 1
mid = (M+1)//2
while m<M:
  n = 0
  for a in A:
    n += -(-a//mid)-1
    if n > K:
      m = mid+1
      break
  else:
    M = mid
  mid = (M+m)//2
print(mid)
# Original solution
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
from math import ceil
def main(N, K, A):
    def cut_times(longest):
        return sum(a // longest for a in A if a > longest)
    under = 0
    r = 10**9
    for i in range(100):
        m = (under + r) / 2
        if cut_times(m) > K: under = m
        else: r = m
    print((ceil(r - 10**-10)))

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = list(map(int, input().split()))
    *A, = list(map(int, input().split()))
    main(N, K, A)


# Optimized solution
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, K, A):
    lo = 0
    hi = 10**9
    while hi - lo > 1:
        m = (lo + hi) // 2
        if sum((a + m - 1) // m - 1 for a in A) <= K: hi = m
        else: lo = m
    print(hi)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = list(map(int, input().split()))
    *A, = list(map(int, input().split()))
    main(N, K, A)
# Original solution
n,k=list(map(int,input().split()))
alst=list([int(x)*100 for x in input().split()])

ok=max(alst)
ng=0

while abs(ok-ng)>1:
    cen=(ok+ng)//2

    cnt=0

    for a in alst:
        cnt+=(a+cen-1)//cen-1

    if cnt<=k:
        ok=cen
    else:
        ng=cen+1

if ok%100==0:
    print((ok//100))
else:
    print((ok//100+1))

# Optimized solution
n,k=list(map(int,input().split()))
alst=list(map(int,input().split()))

ok=max(alst)
ng=0

while abs(ok-ng)>1:
    cen=(ok+ng)//2

    cnt=0

    for a in alst:
        cnt+=(a+cen-1)//cen-1

    if cnt<=k:
        ok=cen
    else:
        ng=cen

print(ok)
# Original solution
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 10 ** 16
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))


# Optimized solution
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 2 * 10 ** 14 + 1
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
# Original solution
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 2 * 10 ** 14 + 1
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))


# Optimized solution
def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 1_000_000_000
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
# Original solution
def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 1_000_000_000
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))


# Optimized solution
def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid
    return res - N <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(0, 1_000_000_000, K)))
# Original solution
import math
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
l,r=0,a[-1]
while math.ceil(r)>math.ceil(l):
    x=(l+r)/2
    cnt=0
    for i in a:
        if i%x==0:
            cnt+=i//x-1
        else:
            cnt+=i//x
    if cnt>k:
        l=x
    else:
        r=x
print((math.ceil(l)))

# Optimized solution
def resolve():
    import sys
    input = sys.stdin.readline
    import math
    n,k=list(map(int,input().split()))
    a=sorted(list(map(int,input().split())))
    l,r=0,a[-1]
    while math.ceil(r)>math.ceil(l):
        x=(l+r)/2
        cnt=0
        for i in a:
            if i%x==0:
                cnt+=i//x-1
            else:
                cnt+=i//x
        if cnt>k:
            l=x
        else:
            r=x
    print((math.ceil(l)))

if __name__ == '__main__':
    resolve()
# Original solution
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= list(map(int, input().strip().split()))
	# if k >= 10*8:
	# 	return 1
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	for i in range(k):
		x,cnt,orig = heappop(a)
		heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
	return -(heappop(a)[0])
 
 
print((solve()))

# Optimized solution
from heapq import heappush, heappop, heapify
import math
def check(a,mid,k):
	cnt = 0
	for x in a:
		cur_cnt = (x+mid-1)//mid - 1
		cnt+=cur_cnt
		if cnt > k:
			return False
	return True

def solve():
	n , k= list(map(int, input().strip().split()))
	a= [int(x) for x in input().strip().split()]
	l = 0
	r = 10**9+20
	while r-l > 1:
		mid = (r+l)//2
		if check(a,mid,k):
			r = mid
		else:
			l = mid
	return l+1
 
print((solve()))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

l = 0
r = max(A)
for _ in range(100):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)


# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

l = 0
r = max(A)
for _ in range(30):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)
# Original solution
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [int(ceil(a/pivot)) for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k
"""
if K >= 1000000:
    for i in range(N):
        h = hiritu[i]
        k = int(ceil(K*h/hirituSum))
        kaisu.append(k)
        K -= k
"""
leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print((ceil(l)))

# Optimized solution
from math import ceil
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

def is_ok(X):
    #最大値をX以下にできるか
    cnt = 0
    for a in A:
        cnt += ceil(a/X)-1
    return cnt <= K

def bisearch(high,low):
    while high - low > 1:
        mid = (high+low)//2
        if is_ok(mid):
            high = mid
        else:
            low = mid
    return high

print((bisearch(10**9+1,0)))
# Original solution
import math
n, k = list(map(int, input().split()))
aas = list(map(int, input().split()))
left = 1
right = 10**9
def judge(mid):
    cut = 0
    for i in aas:
        cut += math.ceil(i / mid) - 1
    if cut <= k:
        return True
    else:
        return False
while left < right:
    mid = (left + right) / 2
    if math.ceil(left) == math.ceil(right):
        break
    elif judge(mid):
        right = mid
    else:
        left = mid
print((math.ceil(left)))

# Optimized solution
import math
n, k = list(map(int, input().split()))
aas = list(map(int, input().split()))
diff = pow(10,-6)
left = 1
right = 10**9
def judge(mid):
    cut = 0
    for i in aas:
        cut += math.ceil(i / mid) - 1
    if cut <= k:
        return True
    else:
        return False
while left < right:
    mid = (left + right) / 2
    if (left <= right <= left + diff) or (right <= left <= right + diff):
        break
    elif judge(mid):
        right = mid
    else:
        left = mid
print((math.ceil(left)))
# Original solution
n, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))[::-1]

l = 0
r = a[0] + 1
ref = 0
ans = a[0]

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = min(ans, now)
        ref = 0
        r = now
print(ans)

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

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = now
        ref = 0
        r = now
print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = now
        ref = 0
        r = now
print(ans)

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

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
    if ref <= k:
        ans = now
        ref = 0
        r = now
    else:
        ref = 0
        l = now
print(ans)
# Original solution
while True:
    try:
        xA,yA,xB,yB,xC,yC,xD,yD = list(map(float, input().split()))
        if abs((yB-yA)*(yD-yC) + (xB-xA)*(xD-xC)) < 1.e-12:
                print("YES")
        else:
            print("NO")
    except:
        break

# Optimized solution
while True:
    try:
        xA,yA,xB,yB,xC,yC,xD,yD = list(map(float, input().split()))
        if abs((yB-yA)*(yD-yC) + (xB-xA)*(xD-xC)) < 1.e-10:
                print("YES")
        else:
            print("NO")
    except:
        break
# Original solution
from functools import reduce


def M(x, y):
    if x == 'T' and y == 'T':
        return 'T'
    elif x == 'T' and y == 'F':
        return 'F'
    elif x == 'F' and y == 'T':
        return 'T'
    else:
        return 'T'


_ = eval(input())
P = input().split()

print((reduce(M, P)))



# Optimized solution
from functools import reduce


def M(x, y):
    if x == 'T' and y == 'F':
        return 'F'
    else:
        return 'T'


_ = eval(input())
P = input().split()

print((reduce(M, P)))
# Original solution
# -*- coding: utf-8 -*-

import copy
import queue

N = int(eval(input()))
a_list = list(map(int, input().split()))

gain = sum([a for a in a_list if a > 0])

# Flow network
S = 0
T = N + 1
c = [{} for i in range(N + 2)]
for i, a in enumerate(a_list):
    index = i + 1
    if a <= 0:
        c[S][index] = -a
    else:
        c[index][T] = a
    for j in range(index, N + 1, index):
        if not j == index:
            c[index][j] = 10e15

# Residual network
r = copy.deepcopy(c)

# Edmonds-Karp algorithm
max_flow = 0
while True:
    # Find path to T
    q, s, p = queue.Queue(), {S}, None
    q.put((S,))
    findPath = False
    while not q.empty() and not findPath:
        cand_path = q.get(False)
        for to, path in list(r[cand_path[-1]].items()):
            if path == 0:
                continue
            elif to == T:
                p = cand_path + (to,)
                findPath = True
            elif not to in s:
                q.put(cand_path + (to,))
                s.add(to)

    if not findPath:
        break

    # Minimum flow
    min_flow = min([r[p[i]][p[i+1]] for i in range(len(p)-1)])
    max_flow += min_flow
    for i in range(len(p)-1):
        r[p[i]][p[i+1]] -= min_flow
        if p[i] in r[p[i+1]]:
            r[p[i+1]][p[i]] += min_flow
        else:
            r[p[i+1]][p[i]] = min_flow

print((gain - max_flow))


# Optimized solution
import copy
import collections

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

gain = sum([max(a, 0) for a in A])

# Flow network
S, T = 0, N + 1
c = [{} for i in range(N + 2)]
for i in range(N):
    ix = i + 1
    if A[i] <= 0:
        c[S][ix] = -A[i]
    else:
        c[ix][T] = A[i]

    for j in range(2 * ix, N + 1, ix):
        c[ix][j] = 10e15

# Residual network
r = copy.deepcopy(c)

# Edmonds-Karp algorithm
max_flow = 0
while True:
    # Find path to T
    q, s, p = collections.deque(), {S}, None
    q.append((S,))
    findPath = False
    while not len(q) == 0 and not findPath:
        cand_path = q.popleft()
        for to, path in list(r[cand_path[-1]].items()):
            if path == 0:
                continue
            elif to == T:
                p = cand_path + (to,)
                findPath = True
            elif not to in s:
                q.append(cand_path + (to,))
                s.add(to)

    if not findPath:
        break

    # Minimum flow
    min_flow = min([r[p[i]][p[i + 1]] for i in range(len(p) - 1)])
    max_flow += min_flow
    for i in range(len(p) - 1):
        r[p[i]][p[i + 1]] -= min_flow
        if p[i] in r[p[i + 1]]:
            r[p[i + 1]][p[i]] += min_flow
        else:
            r[p[i + 1]][p[i]] = min_flow

print((gain - max_flow))