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

from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]

ans = min([abs(sum(A)-2*a) for a in list(accumulate(A))[:len(A)-1]])
print(ans)

### FIXED CODE ###

from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
tmp = list(accumulate(A))[:len(A)-1]
total  = sum(A)

    
ans = min([abs(total-2*a) for a in tmp])
print(ans)
### BUGGY CODE ###

from heapq import heappush, heappop
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append((b, c))
    G[b].append((a, c))

INF = float("inf")
d = [[INF] * N for i in range(N)]
for i in range(N):
    d[i][i] = 0
for i in range(N):
    que = [(0, i)]
    while que:
        cost, v = heappop(que)
        if d[i][v] < cost:
            continue
        for w, c in G[v]:
            if d[i][v] + c < d[i][w]:
                d[i][w] = d[i][v] + c
                heappush(que, (d[i][w], w))

Q, K = map(int, input().split())
K -= 1
for i in range(Q):
    x, y = map(int, input().split())
    print(d[x - 1][K] + d[y - 1][K])


### FIXED CODE ###

from heapq import heappush, heappop
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append((b, c))
    G[b].append((a, c))

Q, K = map(int, input().split())
K -= 1

INF = float("inf")
d = [INF] * N
d[K] = 0
que = [(0, K)]
while que:
    cost, v = heappop(que)
    if d[v] < cost:
        continue
    for w, c in G[v]:
        if d[v] + c < d[w]:
            d[w] = d[v] + c
            heappush(que, (d[w], w))

for i in range(Q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])
### BUGGY CODE ###

from collections import deque


def max_heapify(A, i):
    H = len(A) - 1
    l, r = i * 2 + 1, i * 2 + 2
    if l <= H and A[l] > A[i]:
            largest = l
    else:
        largest = i
    if r <= H and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)


def build_max_heap(A):
    for i in range(len(A) // 2, -1, -1):
        max_heapify(A, i)


def extract(S):
    build_max_heap(S)
    return S.popleft()

S = deque()
while True:
    cmd = input().split()
    if cmd[0] == "insert":
        S.append(int(cmd[1]))
    elif cmd[0] == "extract":
        print(extract(S))
    else:
        break

### FIXED CODE ###

import heapq


hq = []
while True:
    cmd = input().split()
    if cmd[0] == "insert":
        heapq.heappush(hq, -int(cmd[1]))
    elif cmd[0] == "extract":
        print(-heapq.heappop(hq))
    else:
        break
### BUGGY CODE ###

K = int(input())
A = list(map(lambda x:int(x), input().split(" ")))
A.reverse()

n = [2]

for a in A:
    tmp = []
    for t in filter(lambda x:x%a==0, n):
        for i in range(t,t+a):
            tmp.append(i)
    n = list(set(tmp))

if len(n)>0:
    print(min(n),max(n))
else:
    print("-1")


### FIXED CODE ###

K = int(input())
A = list(map(lambda x:int(x), input().split(" ")))
A.reverse()

n = [2,2]

for a in A:

    n1 = (n[0]//a+(1 if n[0]%a>0 else 0))*a
    n2 = (n[1]//a)*a
    # print([n,n1,n2,a])
    if n1>n2:
        print("-1")
        exit()
    n[0] = n1
    n[1] = n2+a-1

if len(n)>0:
    print(min(n),max(n))
else:
    print("-1")
### BUGGY CODE ###

H,N = map(int,input().split())

AB = []

for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

dp = [0]*(H+1)
dp[0] = 0

for i in range(1,H+1):
    dp[i] = min(dp[max(0,i-a)]+b for a,b in AB)
    
print(dp[H])

### FIXED CODE ###

H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))
### BUGGY CODE ###

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

    mod_value = 10**9 + 7
    sum_ = 0
    for i in range(len(A)-1):
        sum_ = (sum_ + A[i]*sum(A[i+1:])) % mod_value
    print(sum_)
main()

### FIXED CODE ###

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

    mod_value = 10**9 + 7
    sum_ = 0
    b_sum = 0
    for i in range(len(A)-1):
        b_sum = b_sum + A[len(A)-i-1]
        sum_ = sum_ + (A[len(A)- i - 2]*b_sum) % mod_value
    print(sum_%mod_value)
main()
### BUGGY CODE ###

n = int(raw_input())
a = map(int,raw_input().split())

lp = [0]
lx = [0]

nowlp = 0
nowlx = 0

for x in range( len(a) ):
  nowlp += a[x]
  nowlx ^= a[x]

  lp.append(nowlp)
  lx.append(nowlx)
#print lp
#print lx

ans = 0

for l in range(1,len(a)+1 ):
  for r in range(l,len(a)+1 ):
    if lp[r] - lp[l-1] == lx[r] ^ lx[l-1]:
      #print l,r,lp[r],lp[l], lx[r] ,lx[l]
      ans += 1
    if len(bin(lp[r] - lp[l-1])) - len(bin(lp[r] ^ lp[l-1])) > 2:
      break

print ans


### FIXED CODE ###

n = int(raw_input())
a = map(int,raw_input().split())

lp = [0]
nowlp = 0

for x in range( len(a) ):
  nowlp += a[x]
  lp.append(nowlp)

ans = 0
prev = [ [0,0] ]

for l in range(0,n-1):
  r = prev[l][1] + 1
  ans += prev[l][1]-l
  now = lp[r] - lp[l]

  while r <= n-1 and now^a[r] == now+a[r]:
    ans += 1
    now += a[r]
    r += 1
  prev.append( [l,r-1] )

ans += n
print ans
### BUGGY CODE ###

mod=10**9+7
s=input()
n=len(s)
DP=[[0]*13 for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  r=pow(10,n-1-i,13)
  if s[i]=="?":
    for j in range(10):
      rr=(r*j)%13
      for k in range(13):
        if k>=rr:
          DP[i+1][k]+=DP[i][k-rr]
        else:
          DP[i+1][k]+=DP[i][k-rr+13]
        DP[i+1][k]%=mod
  else:
    rr=(r*int(s[i]))%13
    for k in range(13):
      if k>=rr:
        DP[i+1][k]+=DP[i][k-rr]
      else:
        DP[i+1][k]+=DP[i][k-rr+13]
      DP[i+1][k]%=mod
print(DP[n][5]%mod)


### FIXED CODE ###

mod=10**9+7
s=input()
n=len(s)
R=[[[0]*13 for _ in range(10)] for __ in range(13)]
for i in range(13):
  for j in range(10):
    for k in range(13):
      R[i][j][k]=(k-i*j)%13

P=[0]*(n+1)
P[0]=1
for i in range(n):
  P[i+1]=(P[i]*10)%13

DP=[[0]*13 for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  r=P[n-1-i]
  if s[i]=="?":
    for k in range(13):
      DP[i+1][k]=sum(DP[i][R[r][j][k]] for j in range(10))
      DP[i+1][k]%=mod
  else:
    for k in range(13):
      DP[i+1][k]=DP[i][R[r][int(s[i])][k]]
      DP[i+1][k]%=mod
print(DP[n][5]%mod)
### BUGGY CODE ###

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

count = 0
min = 0
for i in range(num):
  min = a[i]
  for j in range(i):
    if min > a[j]:
      min = a[j]
  if min == a[i]:
    count += 1
print(count)

### FIXED CODE ###

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

min = a[0]
count = 1
for i in range(num - 1):
  if min > a[i+1]:
    min = a[i+1]
    count += 1
print(count)
### BUGGY CODE ###

N,K,Q=map(int,input().split())
List=[int(input()) for i in range(Q)]
for j in range(1,N+1):
  
  if (K-Q+List.count(j)) <1:
    print('No')
  else:
    print('Yes')

### FIXED CODE ###

N,K,Q=map(int,input().split())
scores=[0 for i in range(N)]

for j in range(Q):
  A=int(input())
  scores[A-1]+=1
  
for score in scores:
  if K-Q+score>0:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

import numpy as np

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


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

npA = np.array([])
for x in a:
    npA=np.append(npA, x)

# for x in range(N):
#     print(a[x])
for x in range(M):
    a[np.argmax(a)] //= 2

total = 0
for x in range(N):
    total+=a[x]

print(total)




### FIXED CODE ###

import math
import heapq
N,M = list(map(int, input().split()))
a=list(map(int, input().split()))

npA = []
for x in a:
    heapq.heappush(npA, -x)

# for x in range(N):
#     print(a[x])
npA.sort()


for x in range(M):
    # temp=heapq.heappop(npA)
    # print("{}//2={}".format(temp,math.ceil(temp/2)))
    heapq.heappush(npA, math.ceil(heapq.heappop(npA)/2))#get the max value!!
    

total = 0
for x in range(N):
    # temp = heapq.heappop(npA)
    # print(temp)
    total+=heapq.heappop(npA)

print(-total)
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(10**9):
    a.sort(reverse=True)
    cnt = 0
    for j in range(N):
        if a[j]%2 == 0 and cnt == 0:
            a[j] //= 2
            cnt = 1
        else:
            a[j] *= 3
    if cnt == 0:
        print(ans)
        exit()
    else:
        ans +=1

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    while a[i] % 2 == 0:
        a[i] //= 2
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
removed = []
for i in range(N):
    A.append(int(input()))
for j in range(len(A)):
    remove = A.pop(j)
    print(max(A))
    A.insert(j,remove)

### FIXED CODE ###

N = int(input())
numbers = []
for i in range(N):
    numbers.append(int(input()))
ordered = sorted(numbers, reverse = True)

for j in range(len(numbers)):
    if numbers[j] == ordered[0]:
        print(ordered[1])
    else:
        print(ordered[0])
### BUGGY CODE ###

s = list(input())
q = int(input())

rev = 0

for i in range(q):
    t = list(input().split())
    if t == ['1']:
        rev += 1
        continue
    if t[1] == '1':
        if rev % 2 == 0:
            s.insert(0, t[2])
        else:
            s.append(t[2])
    else:
        if rev % 2 == 0:
            s.append(t[2])
        else:
            s.insert(0, t[2])
if rev % 2 != 0:
    s.reverse()

print(''.join(s))


### FIXED CODE ###

from collections import deque
s = list(input())
q = int(input())

s = deque(s)
rev = 0

for i in range(q):
    t = list(input().split())
    if len(t) == 1:
        rev += 1
        continue
    if t[1] == '1':
        if rev % 2 == 0:
            s.appendleft(t[2])
        else:
            s.append(t[2])
    else:
        if rev % 2 == 0:
            s.append(t[2])
        else:
            s.appendleft(t[2])
if rev % 2 != 0:
    s.reverse()

print(''.join(s))
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
for _ in range(n):
    if set(a) == set([-1,0]) or set(a) == set([0]):
        break
    i = a.index(max(a))
    if i == 0:
        print(-1)
        exit()
    if a[i-1] + 1 == a[i]:
        a[i] = -1
        ans += 1
    elif a[i-1] == -1:
        a[i-1] = a[i] - 1
        a[i] = -1
        ans += 1
    else:
        print(-1)
        exit()
print(ans)

### FIXED CODE ###

n = int(input())
prev = ans = -1
a = [int(input()) for _ in range(n)]
for i in a:
    if i - prev > 1:
        print(-1)
        exit()
    elif i - prev == 1:
        ans += 1
    else:
        ans += i
    prev = i
print(ans)
### BUGGY CODE ###

i = list(map(int, input().split()))
K = i[0]
N = i[1]

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

m = K

for i in range(N):
  for j in range(N):
    t = max(abs(s[i] - s[j]), K - abs(s[i] - s[j]))
    if t <= m:
      m = t
      
print(m)

### FIXED CODE ###

i = list(map(int, input().split()))
K = i[0]
N = i[1]

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

m = K

for i in range(N - 1):
  t = max(abs(s[i] - s[i + 1]), K - abs(s[i] - s[i + 1]))
  if t <= m:
     m = t

if max(abs(s[0] - s[N - 1]), K - abs(s[0] - s[N - 1])) <= m:
  m = max(abs(s[0] - s[N - 1]), K - abs(s[0] - s[N - 1]))

print(m)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
AF = [A[i] * F[i] for i in range(N)]
for _ in range(K):
    j = AF.index(max(AF))
    A[j] -= 1
    AF[j] = A[j] * F[j]
print(max(AF))

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):  # a, x, kは全て整数ということに注意(//またはint())
    k = 0  # 修行回数初期化
    for a, f in zip(A, F):  # O(N)
        e = x // f
        if a <= e:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - e
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1):  # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)
### BUGGY CODE ###

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

n, k = map(int, rl().split())

li = list(map(int, rl().split()))

dp = np.full(n, float('inf'))

dp[0] = 0
dp[1] = abs(li[0] - li[1])

if k < n:    
    for i in range(2, k):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
    for i in range(k, n):
        for j in range(i-k, i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
else:
    for i in range(n):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
        
print(int(dp[-1]))




### FIXED CODE ###

import sys

rl = sys.stdin.readline

n, k = map(int, rl().split())

li = list(map(int, rl().split()))

dp = [1<<60]*n

dp[0] = 0
dp[1] = abs(li[0] - li[1])

if k < n:    
    for i in range(2, k):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
    for i in range(k, n):
        for j in range(i-k, i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
else:
    for i in range(n):
        for j in range(i):
            a = dp[j] + abs(li[j] - li[i])
            if dp[i] > a:
                dp[i] = a
        
print(int(dp[-1]))
### BUGGY CODE ###

mod = 1000000007
n, m = map(int, input().split())
dat_m = []
dp = []
for i in range(n + 1):
    dp.append([0] * (n + 1))
for i in range(m):
    dat_m.append(int(input()))
dp[0][0] = 1
#print(dp[0][0])
for i in range(1, n + 1):
    #dp[i][:i-1] = dp[i-1][:i - 1]
    dp[i][i-1] = dp[i - 1][i - 1]
    dp[i][i] = dp[i - 1][i - 1]

    if i > 1:
        dp[i][i] += dp[i - 1][i - 2]
        dp[i][i-2] = dp[i - 1][i - 2]

    if i in dat_m:
        dp[i][i] = 0

    dp[i][i] = dp[i][i] % mod

import pprint
print(dp[n][n])
#pprint.pprint(dp)

### FIXED CODE ###

mod = 1000000007
n, m = map(int, input().split())
dat_m = []
dp = [0] * (n + 1)
for i in range(m):
    t = int(input())
    dp[t] = -1

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

print(dp[n])
### BUGGY CODE ###

import sys
 
sys.setrecursionlimit(200000000)
 
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
l = [[] for i in range(n+1)]
for pi in ab:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])

l_2 = [0 for i in range(n+1)]
for p, x in px:
    l_2[p] += x

def dfs(graph, start, oya):
    if start != 1:
        graph[start].remove(oya)
    if len(graph[start]) == 0:
        return
    else:
        for i in graph[start]:
            dfs(graph, i, start)
 
dfs(l, 1, 1)
 
def dfs_2(graph, start, ans, x, l_2):
    ans[start] += x
    if len(graph[start]) == 0:
        return
    else:
        for i in graph[start]:
            dfs_2(graph, i, ans, x+l_2[i], l_2)
 
ans = [0 for i in range(n+1)]
dfs_2(l, 1, ans, l_2[1], l_2)
        
for i in range(1, n+1):
    print(ans[i], end=' ')
print()

### FIXED CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
l = [[] for i in range(n+1)]
for a, b in ab:  
    l[a].append(b)

value = [0 for i in range(n+1)]
for p, x in px:
    value[p] += x

stack = [1]
while stack:
    label = stack.pop()
    for i in l[label]:
        value[i] += value[label]
    stack += l[label]
        
print(*value[1:])
### BUGGY CODE ###

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

temp_prev = 0
temp_curr = 0
x = 0.0
while x <= n:
    temp_prev = temp_curr
    temp_curr = int(a * x / b) - a * int(x / b)
    x += 1.0

    if temp_curr < temp_prev:
        break

print(max(temp_curr, temp_prev))

### FIXED CODE ###

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

temp_prev = 0
temp_curr = 0
x = min(n, b-1)

while x <= n:
    temp_prev = temp_curr
    temp_curr = int(a * x / b) - a * int(x / b)
    x += 1.0

    if temp_curr <= temp_prev:
        break

print(max(temp_curr, temp_prev))
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
for i in range(N):
    for j in reversed(range(i + 1, (N // 2) + 1)):
        k = S[i:j+1]
        if k in S[:i]:
            if len(k) > ans:
                ans = len(k)
        if k in S[j+1:]:
            if len(k) > ans:
                ans = len(k)
print(ans)


### FIXED CODE ###

N=int(input())
S=input()

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)
### BUGGY CODE ###

import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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


treeList = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  treeList[a].append(b) # a<bとは限らないため、双方向にする
  treeList[b].append(a)


data3 = getSomeInputListInt(q)

ans = np.zeros(n)

for i in range(len(data3)):
    ans[data3[i][0]-1] += data3[i][1]


def treeTrace(crnt, prnt):
    for i in range(len(treeList[crnt])):
        if prnt == treeList[crnt][i]:
            continue
        ans[treeList[crnt][i]] += ans[crnt]

        treeTrace(treeList[crnt][i], crnt)

treeTrace(0, -1)

for s in ans:
    print(int(s), end =" ")


### FIXED CODE ###

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import collections

def main():
    _,M= map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    A = collections.deque(A)
    
    B = []
    for _ in range(M):
        b,c = map(int,input().split())
        B.append((b,c))
    B.sort(key=lambda x: x[1])

    Q = collections.deque()
    for b,c in B:
        for _ in range(b):
            Q.append(c)

    x = 0
    while Q:
        c = Q.pop()
        if len(A) > 0 and c > A[0]:
            A.popleft()
            x += c

    print(x + sum(A))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
import bisect

def main():
    _,M= map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    
    B = []
    for _ in range(M):
        b,c = map(int,input().split())
        B.append((b,c))
    B.sort(key=lambda x: x[1])

    x = 0
    m = 0
    while B:
        b,c = B.pop()
        n = bisect.bisect(A,c,lo=m,hi=min(m+b,len(A)))
        x += (n-m)*c
        m = n

    print(x + sum(A[n:]))

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

n = int(input())
a = list(map(int, input().split()))
b = max(a)
che,re = [0 for i in range(b)],[]
for i in a:
    che[i-1] = 1
for i in a:
    if i in re:
        che[i-1] = 0
    else:
        re.append(i)
        c = b // i
        for j in range(2,c+1):
            che[i*j-1] = 0
print(che.count(1))


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = max(a)
che = [1 for i in range(b)]
for i in a:
    if che[i-1] == 1:
        c = b // i
        for j in range(2,c+1):
            che[i*j-1] = 0
        che[i-1] = 2
    elif che[i-1] == 2:
        che[i-1] = 0
ans = 0
for i in a:
    if che[i-1] == 2:
        ans += 1
print(ans)
### BUGGY CODE ###

K,S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S:
                count += 1
print(count)

### FIXED CODE ###

K,S = map(int,input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K:
            count += 1
print(count)
### BUGGY CODE ###

s = input()[::-1]

dp = [[0 for _ in range(13)] for _ in range(len(s))]

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

for i in range(1, len(s)):
    if s[i] == "?":
        mod = pow(10, i, 13)
        mod_list = [(mod*i)%13for i in range(10)]
        for j in mod_list:
            for k in range(13):
                dp[i][(k+j)%13] += dp[i-1][k]
    else:
        mod = (pow(10, i, 13)*int(s[i]))%13
        for k in range(13):
            dp[i][(k+mod)%13] += dp[i-1][k]

print(dp[-1][5]%(10**9+7))


### FIXED CODE ###

s=input()
l=len(s)

mod=10**9+7

dp=[[0 for j in range(13)] for i in range(l)]

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

for i in range(1, l):
 if s[i]=='?':
   for j in range(10):
     for k in range(13):
       dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
 else:
   for k in range(13):
     dp[i][(k*10+int(s[i]))%13]+=dp[i-1][k]%mod
print(dp[-1][5]%mod)
### BUGGY CODE ###

s = input()
n = int(input())
qs = [input().split(' ') for i in range(n)]

div = True
for q in qs:
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        s = q[2] + s
    else:
        s = s + q[2]


if div:
    print(s)
else:
    s = ''.join(list(reversed(s)))
    print(s)


### FIXED CODE ###

from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))
### BUGGY CODE ###

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

a,b=map(int,input().split())
c=gcd(a,b)
ans = 1
div = 2
first_flag=1
while c>1:
    while c%div == 0:
        c /= div
        if first_flag == 1:
            ans += 1
            first_flag = 0 
    div = div+1
    first_flag = 1
print(ans)

### FIXED CODE ###

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

a,b=map(int,input().split())
c=gcd(a,b)
ans = 1
div = 2
first_flag=1
while c>1:
    if  div**2 > c:
        ans +=1
        break
    while c%div == 0:
        c /= div
        if first_flag == 1:
            ans += 1
            first_flag = 0 
    div += 1
    first_flag = 1
print(ans)