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

def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

def resolve():
  N = int(input())
  count = 1

  for c in range(1, N-1):
    factorized = factorization(N-c)
    num_of_pattern = 1
    even_flag = True
    
    for segment in factorized:
      num_of_pattern *= segment[1] + 1

      if segment[1] % 2 == 1:
        even_flag = False

    count += num_of_pattern

  print(count)

if __name__ == "__main__":
  resolve()

### FIXED CODE ###

def resolve():
  N = int(input())
  count = 0

  for A in range(1, N):
    count += ((N-1)//A)
  print(count)

if __name__ == "__main__":
  resolve()
### BUGGY CODE ###

#!/usr/bin/env python3

import itertools

mod = 10**9+7

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

ans = 0
for x, y in itertools.combinations(a, 2):
    # print(x ^ y)
    ans += (x ^ y)

print(ans % mod)


### FIXED CODE ###

#!/usr/bin/env python3

# mod = 10**9+7

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

# max_digit = 61

# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]

# for i in range(len(a)):
#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1

# # for i in range(max_digit):
# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1
# for i in range(61):
#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
# print(ans % mod)


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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m for x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*non_bit*m)%mod
    m <<= 1
print(ans)
### BUGGY CODE ###

n,W=map(int, input().split())
a=[]
max_v=0
for _ in range(n):
    w,v=map(int, input().split())
    a.append((w,v))
    max_v+=v

dp=[[float('inf') for j in range(max_v+1)] for i in range(n+1)] # dp[n][v] = min weight using up to n-th items and value = v

for i in range(1,n+1):
    w,v=a.pop()
    for j in range(max_v+1):
        if j-v>=0:
            dp[i][j]=min(
                dp[i-1][j-v]+w # use j-th item (w,v)
                ,dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
    dp[i][v]=min(w,dp[i-1][v])
    
ans=0
for j in range(max_v+1):
    if dp[n][j]<=W:
        ans=j
print(ans)

### FIXED CODE ###

n,W=map(int, input().split())
a=[]
max_v=0
for _ in range(n):
    w,v=map(int, input().split())
    a.append((w,v))
    max_v+=v

dp=[[float('inf') for j in range(max_v+1)] for i in range(n+1)] # dp[n][v] = min weight using up to n-th items and value = v

for i in range(1,n+1):
    w,v=a.pop()
    for j in range(max_v+1):
        if j-v>=0:
            dp[i][j]=min(
                dp[i-1][j-v]+w # use j-th item (w,v)
                ,dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
    dp[i][v]=min(w,dp[i-1][v])
    
ans=0
for j in range(max_v+1):
    if dp[n][j]<=W:
        ans=j
print(ans)
### BUGGY CODE ###

s = input()
ans = 0
while True:
    pos_0 = s.find('01')
    pos_1 = s.find('10')
    if pos_0==-1 and pos_1==-1:
        break
    pos = max(pos_0,pos_1)
    s = s.replace(s[pos:pos+2],'',1)
    ans+=2
print(ans)

### FIXED CODE ###

s = input()
print(min(s.count('0')*2,s.count('1')*2))
### BUGGY CODE ###

def main():
    import collections
    N, P = map(int, input().split())
    S = input()[::-1]
    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if int(s) % P == 0:
                ans += N - i
    else:
        mod = [0] * P
        mod[0] = 1
        current = 0
        X = 0
        for s in S:
            current = (current + int(s) * 10 ** X) % P
            ans += mod[current]
            mod[current] += 1
            X += 1
    
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import collections
    N, P = map(int, input().split())
    S = input()[::-1]
    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if int(s) % P == 0:
                ans += N - i
    else:
        mod = [0] * P
        mod[0] = 1
        current = 0
        X = 1
        for s in S:
            current = (current + int(s) * X) % P
            ans += mod[current]
            mod[current] += 1
            X = X * 10 % P
    
    print(ans)

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

import numpy as np
import sys

readline = sys.stdin.readline

N = int(input())
A = np.array(readline().split(), np.int64)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

for q in range(Q):
    A = [BC[q][1] if x==BC[q][0] else x for x in A]
    print(sum(A))

### FIXED CODE ###

import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
num_array = np.zeros(10**5, np.int64)
for n in A:
    num_array[n-1] += 1

# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''

    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]
    '''

    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = num_array[BC[q][0] - 1]
    # リスト内の要素数の更新
    num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]
    num_array[BC[q][0] - 1] = 0

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)
### BUGGY CODE ###

s = input()
q = int(input())
count = 1
while count < q+1:
    line = input()
    if "2" in line:
        t, f, c = line.split()
        if f == "1":
            s = c + s
        else:
            s = s + c
    else:
        s = s[::-1]
    count += 1
print(s)

### FIXED CODE ###

s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))
### BUGGY CODE ###

import sys

s = input()
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev == True:
                s = s + c
            else:
                s = c + s
        elif f == '2':
            if rev == True:
                s = c + s
            else:
                s = s + c
if rev == True:
    s = s[::-1]
print(s)

### FIXED CODE ###

import sys
from collections import deque

# sys.stdin = open('test_cases/abc158d/in/01.txt', 'r')
# sys.stdin = open('input.txt', 'r')

s = deque([s for s in input()])
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        elif f == '2':
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
if rev == True:
    s.reverse()
print(''.join(s))
### BUGGY CODE ###

N,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
mod = 10**9+7

E = [[] for _ in [0]*N]
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

ans = K
q = [0]
V = [-1]*N
V[0] = [0,0]
while q:
    qq = []
    for i in q:
        tmp = sorted(set(V[i]))
        cSet = list(range(tmp[0])) + list(range(tmp[0]+1,tmp[-1])) + list(range(tmp[-1]+1,K))
        l = len(cSet)
        for j in E[i]:
            if V[j]!=-1:continue
            ans = ans * l % mod
            if ans == 0:break
            qq.append(j)
            V[j] = [cSet.pop(),V[i][0]]
            l -= 1
    q = qq
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
mod = 10**9+7

E = [[] for _ in [0]*N]
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

ans = K
q = [0]
V = [False for _ in [0]*N]
V[0] = True
while q:
    qq = []
    for i in q:
        #tmp = sorted(set(V[i]))
        #cSet = list(range(tmp[0])) + list(range(tmp[0]+1,tmp[-1])) + list(range(tmp[-1]+1,K))
        l = K-2+(i==0)
        for j in E[i]:
            if V[j]:continue
            ans = ans * l % mod
            if ans == 0:break
            qq.append(j)
            V[j] = True
            l -= 1
    q = qq
print(ans)
### BUGGY CODE ###

from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    y, x, s = q.popleft()
    for dy, dx in walk:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < W and 0 <= ny < H and maze[ny][nx] == '.' and path[ny][nx] > s:
            path[ny][nx] = s
            q.appendleft((ny, nx, s))
    for dy, dx in warp:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < W and 0 <= ny < H and maze[ny][nx] == '.' and path[ny][nx] > s + 1:
            path[ny][nx] = s + 1
            q.appendleft((ny, nx, s + 1))

ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)


### FIXED CODE ###

from collections import deque


def solve(H, W, Ch, Cw, Dh, Dw, maze):
    # 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む
    walled_maze = ['##{}##'.format(row) for row in maze]
    walled_maze.insert(0, '##{}##'.format('#' * W))
    walled_maze.insert(0, '##{}##'.format('#' * W))
    walled_maze.append('##{}##'.format('#' * W))
    walled_maze.append('##{}##'.format('#' * W))

    INF = 10 ** 12
    path = [[INF] * (W + 4) for _ in range(H + 4)]
    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    yet = deque()
    yet.append((Ch + 2, Cw + 2, 0))    # 囲った壁の分だけプラス
    path[Ch + 2][Cw + 2] = 0
    done = deque()

    while yet:
        y, x, s = yet.popleft()
        done.append((y, x, s))
        for dy, dx in walk:
            ny = y + dy
            nx = x + dx
            if walled_maze[ny][nx] == '.' and path[ny][nx] > s:
                path[ny][nx] = s
                yet.append((ny, nx, s))
        if len(yet) == 0:
            while done:
                y, x, s = done.popleft()
                for dy, dx in warp:
                    ny = y + dy
                    nx = x + dx
                    if walled_maze[ny][nx] == '.' and path[ny][nx] > s + 1:
                        path[ny][nx] = s + 1
                        yet.append((ny, nx, s + 1))
    ans = path[Dh + 2][Dw + 2] if path[Dh + 2][Dw + 2] < INF else -1
    print(ans)


if __name__ == '__main__':
    H, W = map(int, input().split())
    Ch, Cw = map(lambda x: int(x) - 1, input().split())
    Dh, Dw = map(lambda x: int(x) - 1, input().split())
    maze = [input() for _ in range(H)]
    solve(H, W, Ch, Cw, Dh, Dw, maze)
### BUGGY CODE ###

N, W = map(int, input().split())
Wl = []; Vl = []
for i in range(N):
    w, v = map(int, input().split())
    Wl.append(w); Vl.append(v)
# dp[i番目までの品物を使用][wを超えない]
dp = [[0]*(W+10) for _ in range(N+10)]

for i in range(N):
    w, v = Wl[i], Vl[i]
    for j in range(W+1):
        if j+w < W+1: dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j]+v)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(max(dp[N]))

### FIXED CODE ###

N, W = map(int, input().split())
Wl = []; Vl = []
for i in range(N):
    w, v = map(int, input().split())
    Wl.append(w); Vl.append(v)
# dp[i番目までの品物を使用][wを超えない]
dp = [[0]*(W+10) for _ in range(N+10)]

for i in range(N):
    w, v = Wl[i], Vl[i]
    for j in range(W+1):
        if j+w < W+1: dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j]+v)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(max(dp[N]))
### BUGGY CODE ###

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

cnt_reverse = 0
for i in range(q):
  query = input()
  
  if query[0] == '1':
    cnt_reverse += 1
  elif (query[2] == '1' and cnt_reverse % 2==0) or (query[2] == '2' and cnt_reverse % 2==1):
    s = query[4] + s
  else:
    s  = s + query[4]
if cnt_reverse%2==1:
  s = s[::-1]
print(s)

### FIXED CODE ###

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

cnt_reverse = False
left = ''
for i in range(q):
  query = input()
  
  if query[0] == '1':
    cnt_reverse = not cnt_reverse
  elif (query[2] == '1' and not cnt_reverse) or (query[2] == '2' and cnt_reverse):
    left = left + query[4]

  else:
    s  = s + query[4]
s = left[::-1] + s
if cnt_reverse:
  s = s[::-1]
print(s)
### BUGGY CODE ###

import fractions
K = int(input())
sum = 0
for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        tmp = fractions.gcd(a,b)
        for c in range(1,K+1,1):
            sum+=fractions.gcd(c,tmp)
print(sum)

### FIXED CODE ###

import math
K = int(input())
sum = 0
for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        tmp = math.gcd(a,b)
        for c in range(1,K+1,1):
            sum+=math.gcd(c,tmp)
print(sum)
### BUGGY CODE ###

N,K=input().split()
n,k=int(N),int(K)
p=list(input().split())

for i in range (len(p)):
    p[i]=int(p[i])
    
def f(m,p):
    q=0
    for i in range (m):
        q=q+p[i]
    return q

r=[]
for i in range (n-k+1):
    a=f(i+k,p)-f(i,p)
    r.append(a)

maxs=max(r)

print((maxs+k)/2)


### FIXED CODE ###

n, k = list (map (int, input ().split ()))
p = [0] + list (map (int, input ().split ()))
s = [0 for i in range (n + 1)]
mx = 0
tag = 0
f = [0.0 for i in range (n + 1)]
for i in range (1, n + 1) :
    s[i] = s[i - 1] + (p[i] + 1) * p[i] / 2 / p[i]
    if (i >= k and s[i] - s[i - k] > mx) :
        mx = s[i] - s[i - k]
print (mx)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    from itertools import product
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    for bit in range(1 << N):
        cur_x = [0]
        cur_y = [0]
        for i in range(N):
            if bit & (1 << i):
                cur_x.append(T[i][0])
                cur_y.append(T[i][1])
        for i, (x, y, p) in enumerate(T):
            X_dist[bit][i] = p*min(abs(cx - x) for cx in cur_x)
            Y_dist[bit][i] = p*min(abs(cy - y) for cy in cur_y)

    pow_2 = [pow(2, i) for i in range(N)]

    answer = [100_000_000_000] * (N+1)
    for bit in product(range(3), repeat=N):
        x_bit = 0
        y_bit = 0
        x_set = set()
        y_set = set()
        for i in range(N):
            if bit[i] == 2:
                # x = a
                x_bit += pow_2[i]
                x_set.add(T[i][0])
            elif bit[i] == 1:
                # y = a
                y_bit += pow_2[i]
                y_set.add(T[i][1])
        cnt = len(x_set) + len(y_set)
        # 距離の評価
        cur_d = 0
        for i in range(N):
            cur_d += min(X_dist[x_bit][i], Y_dist[y_bit][i])
        answer[cnt] = min(answer[cnt], cur_d)

    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# writer解(c++)を写経した．answerのfor文のところ何やってるかさっぱりわかりませんが…
# https://atcoder.jp/contests/m-solutions2020/submissions/15122924
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    X = []
    Y = []
    P = []
    for _ in range(N):
        a, b, c = (int(i) for i in input().split())
        X.append(a)
        Y.append(b)
        P.append(c)
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    # bit 001001 とかの1が立っている集落に道を作る
    for bit in range(1 << N):
        for i in range(N):
            X_dist[bit][i] = P[i]*abs(X[i])
            Y_dist[bit][i] = P[i]*abs(Y[i])
            for k in range(N):
                if bit & (1 << k):
                    X_dist[bit][i] = \
                        min(X_dist[bit][i], P[i]*abs(X[i] - X[k]))
                    Y_dist[bit][i] = \
                        min(Y_dist[bit][i], P[i]*abs(Y[i] - Y[k]))

    # これはなに？
    answer = [INF] * (N+1)
    for i in range(1 << N):
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                cnt += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1

    for ans in answer:
        print(ans)


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

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

lst = [0]*(N-K+1)

lst[0] = 1
for i in range(K):
    lst[0] = lst[0] * A[i]

for i in range(1,N-K+1):
    lst[i] = lst[i-1] / A[i-1]
    lst[i] = lst[i] * A[K-1+i]
    if lst[i] > lst[i-1]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

for i in range(1,N-K+1):
    if (A[K-1+i] / A[i-1]) > 1:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=math.gcd(math.gcd(i,j),k)
print(ans)

### FIXED CODE ###

import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        for k in range(j,n+1):
            if(i==j and j==k and i==k):ans+=math.gcd(math.gcd(i,j),k)
            elif(i!=j and j!=k and i!=k):ans+=math.gcd(math.gcd(i,j),k)*6
            else:ans+=math.gcd(math.gcd(i,j),k)*3
print(ans)
### BUGGY CODE ###

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

to = [[] for _ in range(N)]
dist = [[0 for _ in range(3)] for _ in range(100005)]
for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  to[a].append(b)

sv, tv = map(int, input().split())
sv -= 1
tv -= 1

for i in range(N):
  for j in range(3):
    dist[i][j] = float("inf")
q = [[sv, 0]]
dist[sv][0] = 0
while len(q) != 0:
  v = q[0][0]
  l = q[0][1]
  q.pop(0)
  for u in to[v]:
    nl = (l + 1) % 3
    if dist[u][nl] != float("inf"):
      continue
    dist[u][nl] = dist[v][l] + 1
    q.append([u, nl])
ans = dist[tv][0]
if ans == float("inf"):
  ans = -1
else:
  ans //= 3
print(ans)

### FIXED CODE ###

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

to = [[] for _ in range(N)]
dist = [[0 for _ in range(3)] for _ in range(100005)]
for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  to[a].append(b)

sv, tv = map(int, input().split())
sv -= 1
tv -= 1

for i in range(N):
  for j in range(3):
    dist[i][j] = float("inf")
q = [[sv, 0]]
dist[sv][0] = 0
while len(q) != 0:
  v = q[0][0]
  l = q[0][1]
  q.pop(0)
  for u in to[v]:
    nl = (l + 1) % 3
    if dist[u][nl] != float("inf"):
      continue
    dist[u][nl] = dist[v][l] + 1
    q.append([u, nl])
ans = dist[tv][0]
if ans == float("inf"):
  ans = -1
else:
  ans //= 3
print(ans)
### BUGGY CODE ###

N,X=map(int,input().split())
G=list(map(int,input().split()))

S=[0]
for g in G:
    S.append(S[-1]+g)

ANS=1<<60

def length(x):
    if x==1:
        return 5
    else:
        return 2*x+1

for rep in range(1,N+1):
    score=X*N+X*rep
    count=1
    
    for i in range(N,0,-rep):
        score+=(S[i]-S[max(0,i-rep)])*length(count)
        count+=1
        
    ANS=min(ANS,score)
    
print(ANS)

### FIXED CODE ###

N,X=map(int,input().split())
G=list(map(int,input().split()))

S=[0]
for g in G:
    S.append(S[-1]+g)

ANS=1<<60

def length(x):
    if x==1:
        return 5
    else:
        return 2*x+1

for rep in range(1,N+1):
    score=X*N+X*rep
    count=1
    
    for i in range(N,0,-rep):
        score+=(S[i]-S[max(0,i-rep)])*length(count)
        count+=1
        
    ANS=min(ANS,score)
    
print(ANS)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,W=map(int,input().split())
    w=[0]*(n+1)
    v=[0]*(n+1)
    for i in range(1,n+1):
        w[i],v[i]=map(int,input().split())
    dp=[[-1]*(W+1) for _ in range(n+1)]

    def solve(i,x): # i番目の時点で残り容量x
        if(x<0): return -INF
        if(i>n): return 0
        if(dp[i][x]!=-1): return dp[i][x]
        dp[i][x]=max(solve(i+1,x),solve(i+1,x-w[i])+v[i])
        return dp[i][x]

    print(solve(1,W))
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,w=map(int,input().split())
    W=[0]*n; V=[0]*n
    for i in range(n):
        a,b=map(int,input().split())
        W[i]=a; V[i]=b
    # dp[i][k] iまでの品物で、重さがk以下
    dp=[[0]*(w+1) for _ in range(n+1)]
    for i in range(1,n+1):
        for k in range(w+1):
            if k-W[i-1]>=0:
                dp[i][k]=max(dp[i-1][k-W[i-1]]+V[i-1],dp[i-1][k])
            else:
                dp[i][k]=dp[i-1][k]
    print(dp[n][w])
resolve()
### BUGGY CODE ###

import numpy as np
n = int(input())
A = list(map(int,input().split()))
q = int(input())
B = []
C = []
for _ in range(q):
    b,c = map(int,input().split())
    A = [c if a == b else a for a in A]
    print(sum(A))

### FIXED CODE ###

import numpy as np
n = int(input())
A = list(map(int,input().split()))
q = int(input())
ar = np.zeros(10**5+1)
for i in A:
    ar[i] += 1
ans = np.sum(A) 
for _ in range(q):
    b,c = map(int,input().split())
    ans = ans+ar[b]*(c-b)
    ar[c] += ar[b]
    ar[b] = 0
    print(int(ans))