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

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

acc = [0]
for i in range(0, N):
    acc.append(acc[i] + A[i])

ans = []
for k in range(1, N + 1):
    cost = k * X + N * X
    for i in range(0, (N + k - 1) // k):
        l = k * i
        r = min([l + k, N])
        t = i + 1
        if t == 1:
            cost += (acc[r] - acc[l]) * 5
        else:
            cost += (acc[r] - acc[l]) * (2 * t + 1)
    ans.append(cost)

print(min(ans))

### FIXED CODE ###

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

acc = [0]
for i in range(0, N):
    acc.append(acc[i] + A[i])

ans = []
for k in range(1, N + 1):
    cost = k * X + N * X
    for i in range(0, (N + k - 1) // k):
        l = k * i
        r = min([l + k, N])
        t = i + 1
        if t == 1:
            cost += (acc[r] - acc[l]) * 5
        else:
            cost += (acc[r] - acc[l]) * (2 * t + 1)
    ans.append(cost)

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

N, K = map(int, input().split(" "))
h_arr = list(map(int, input().split(" ")))
dp = [0]*N
 
for i in range(1, N):
	dp[i] = min(abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i))
print(dp[N-1])

### FIXED CODE ###

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])
### BUGGY CODE ###

N = int(input())
S = input()
pins = []
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      pin = S[i]+S[j]+S[k]
      if pins.count(pin) == 0:
        pins.append(pin)
print(len(pins))

### FIXED CODE ###

N = int(input())
S = input()
count = 0
for i in range(0,1000):
  if i >= 100:
    t = str(i)
  elif i >= 10:
    t = "0"+str(i)
  else:
    t = "00"+str(i)
  ti = 0
  for j in range(N):
    if S[j] == t[ti]:
      ti += 1
      if ti == 3:
        count += 1
        break
print(count)
### BUGGY CODE ###

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

nopass = 0
for i in range(1, N+1):
	for j in gate:
		if j[0] > i or j[1] < i:
			nopass += 1
			break
print(N - nopass)

### FIXED CODE ###

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

max_L = max([ i[0] for i in gate])
min_R = min([ i[1] for i in gate])
ans = 0
if max_L > min_R:
	ans = 0
else:
	ans = min_R - max_L + 1
print(ans)
### BUGGY CODE ###

from collections import defaultdict

def knapsack():
    n, max_w = map(int, input().split())
    dp = defaultdict(int)
    dp[0] = 0
    for _ in range(n):
        w, v = map(int, input().split())
        for item in list(dp.keys()):
            dp[item+w] = max(dp[item] + v, dp[item+w])
    max_v = 0
    for w, v in dp.items():
        if w <= max_w:
            max_v = max(v, max_v)
    print(max_v)
    

knapsack()

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, W = [int(i) for i in input().split()]

def ans(N, W):
    d = [float("inf")] * (N * 1000 + 1)
    d[0] = 0
    V = 0

    for i in range(N):
        wi, vi = [int(i) for i in input().split()]
        V = V + vi

        for v in range(V, vi-1, -1):
            w_ = d[v - vi] + wi
            if w_ < d[v]:
                d[v] = w_

    for v in range(V, -1, -1):
        if d[v] <= W:
            return v

print(ans(N, W))
### BUGGY CODE ###

n,m = map(int, input().split())
h = list(map(int, input().split()))
cnt = n
ng = []
for i in range(m):
  a,b = map(int, input().split())   
  if h[a-1] >= h[b-1] and b not in ng:
    cnt -= 1
    ng.append(b)
  if h[a-1] <= h[b-1] and a not in ng:
    cnt -= 1
    ng.append(a)
print(n -len(ng))

### FIXED CODE ###

n,m = map(int, input().split())
h = list(map(int, input().split()))
cnt = n
ng = {}
for i in range(m):
  a,b = map(int, input().split())   
  if h[a-1] >= h[b-1]:
    ng[b] = 1
  if h[a-1] <= h[b-1]:
    ng[a] = 1
print(n -len(ng))
### BUGGY CODE ###

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

l, r = list(map(int,input().split(" ")))
s = set(range(l, r+1))

for _ in range(1,m):
    l, r = list(map(int,input().split(" ")))
    s_temp = set(range(l, r+1))
    s = s & s_temp
    
print(len(s))

### FIXED CODE ###

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

l_max, r_min = list(map(int,input().split(" ")))

for _ in range(1,m):
    l, r = list(map(int,input().split(" ")))
    
    if l >= l_max:
        l_max = l
        
    if r <= r_min:
        r_min = r


        
print(len(range(l_max, r_min+1)))
### BUGGY CODE ###

N=int(input())
D=list(map(int,input().split(' ')))
M=int(input())
T=list(map(int,input().split(' ')))
ans='YES'
for t in set(T):
  if T.count(t)>D.count(t):
    ans='NO'
    break
print(ans)

### FIXED CODE ###

import collections
N=int(input())
D=list(map(int,input().split(' ')))
M=int(input())
T=list(map(int,input().split(' ')))
cd = collections.Counter(D)
ct = collections.Counter(T)
ans = 'YES'
for t in list(ct.keys()):
	if ct[t]>cd[t]:
		ans = 'NO'
		break
print(ans)
### BUGGY CODE ###

mod=10**9+7
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod
inv=[0]*(N+1)
for i in range(N+1):
  inv[i]=power(i,mod-2)
dp=[[0]*(X+1) for i in range(N+1)]
for x in range(X+1):
  dp[N][x]=x
for i in range(N)[::-1]:
  for x in range(X+1):
    dp[i][x]=dp[i+1][x%S[i]]*inv[N-i]+(N-i-1)*dp[i+1][x]*inv[N-i]
    dp[i][x]%=mod
print((dp[0][X]*Factorial[N])%mod)

### FIXED CODE ###

mod=10**9+7
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return ((power(x,y//2)**2)*x)%mod
inv=[0]*(N+1)
for i in range(N+1):
  inv[i]=power(i,mod-2)
dp=[[0]*(X+1) for i in range(N+1)]
for x in range(X+1):
  dp[N][x]=x
for i in range(N)[::-1]:
  for x in range(X+1):
    dp[i][x]=dp[i+1][x%S[i]]+(N-i-1)*dp[i+1][x]
    dp[i][x]%=mod
print((dp[0][X])%mod)
### BUGGY CODE ###

import bisect
n = int(input())
L = [int(input())]
ans = 0
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.append(t)
        L.sort()
    else:
        L[k-1] = t
print(len(L))


### FIXED CODE ###

from collections import deque
import bisect
n = int(input())
L = deque([int(input())])
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.appendleft(t)
    else:
        L[k-1] = t
print(len(L))
### BUGGY CODE ###

class PQueue:
    def __init__(self):
        self.keys = []
        
    def maxHeapify(self, i):
        l = i * 2 + 1
        r = i * 2 + 2
        if l < len(self.keys) and self.keys[l] > self.keys[i]:
            largest = l
        else:
            largest = i
        if r < len(self.keys) and self.keys[r] > self.keys[largest]:
            largest = r
        if largest != i:
            self.keys[i], self.keys[largest] = self.keys[largest], self.keys[i]
            self.maxHeapify(largest)

    def insert(self, key):
        i = len(self.keys)
        self.keys.append(key)
        parent = (i - 1) // 2
        while i > 0 and self.keys[parent] < self.keys[i]:
            self.keys[i], self.keys[parent] = self.keys[parent], self.keys[i]
            i = parent
            parent = (parent - 1) // 2

    def heapExtraMax(self):
        max_key = self.keys[0]
        if len(self.keys) > 1:
            self.keys[0] = self.keys.pop()
        else:
            del self.keys[0]
        self.maxHeapify(0)
        return max_key


S = PQueue()

import sys

for x in sys.stdin.readlines():
    if x[0] == 'i':
        k = int(x[7:])
        S.insert(k)
    elif x[:2] == 'ex':
        m_k = S.heapExtraMax()
        print(m_k)
    else:
        pass

### FIXED CODE ###

def setHeapDown_max(heap, pos):
    targetkey = heap[pos]
    while pos > 0:
        parentpos = (pos - 1) >> 1
        parent = heap[parentpos]
        if parent < targetkey:
            heap[pos] = parent
            pos = parentpos
            continue
        break
    heap[pos] = targetkey

def setHeapUp_max(heap, pos):
    endpos = len(heap)
    targetkey = heap[pos]
    childpos = 2*pos + 1
    while childpos < endpos:
        rightpos = childpos + 1
        if rightpos < endpos and not heap[rightpos] < heap[childpos]:
            childpos = rightpos
        heap[pos] = heap[childpos]
        pos = childpos
        childpos = 2*pos + 1
    heap[pos] = targetkey
    setHeapDown_max(heap, pos)

def heapPush_max(heap, key):
    heap.append(key)
    setHeapDown_max(heap, len(heap) - 1)

def heapPop_max(heap):
    lastkey = heap.pop()
    if heap:
        returnkey = heap[0]
        heap[0] = lastkey
        setHeapUp_max(heap, 0)
        return returnkey
    return lastkey


import sys

S = []

ans = []

for x in sys.stdin.readlines():
    if x[0] == 'i':
        k = int(x[7:])
        heapPush_max(S, k)
    elif x[1] == 'x':
        ans.append(heapPop_max(S))
    else:
        pass

print(*ans, sep = '\n')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int,input().split()))
import bisect
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        count += bisect.bisect_left(l[j+1:],l[i]+l[j])
print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int,input().split()))
import bisect
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        count += bisect.bisect_left(l,l[i]+l[j]) - j - 1
print(count)
### BUGGY CODE ###

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

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans=0
for i in range(N+1):
    if A[i]>K:
        break
    else:
        ans=max(ans,i)
        for j in range(M+1):
            if A[i]+B[j]>K:
                break
            else:
                ans=max(ans,i+j)
print(ans)   

### FIXED CODE ###


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

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i-1
        break
else:
    ans1=N
ans2=0
ans3=0
# print(ans1)
for i in range(ans1+1):
#     print(i)
    while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
        ans2+=1
#         print(ans1,ans2,i)
    ans3=max(ans3,ans1+ans2-1)
print(ans3)
### BUGGY CODE ###

#for _ in range(int(input())):
n,k=map(int,input().split())
x=[int(x) for x in input().split()]
ans=[1]*n
ans[0]=x[0]
for i in range(1,k):
  ans[i]=ans[i-1]*x[i]
c=0
for i in range(k,n):
  ans[i]=(ans[i-1]//x[c])*x[i]
  if ans[i]>ans[i-1]:
    print('Yes')
  else:print('No')
  c+=1


### FIXED CODE ###


n,k=map(int,input().split())
x=[int(x) for x in input().split()]
ans=[1]*n
ans[0]=x[0]
c=0
for i in range(k,n):

  if x[c]<x[i]:
    print('Yes')
  else:print('No')
  c+=1
### BUGGY CODE ###

n = int(input())
x = [int(i) for i in input().split()]
x2,answer = set(x),0
for j in x2:
	if x.count(j) < j : answer += x.count(j)
	elif x.count(j) > j: answer += x.count(j)-j
print(answer)

### FIXED CODE ###

import collections
n = int(input())
a = [int(i) for i in input().split()]
c = collections.Counter(a)
answer = 0
for i in c.most_common():
	if i[0]>i[1]:
		answer += i[1]
	elif i[0]<i[1]:
		answer += i[1]-i[0]
print(answer)
### BUGGY CODE ###

# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

z = [list(map(int, input().split())) for _ in range(M)]

num1 = [a[i] + b[j] for i in range(A) for j in range(B)]
# print("num1:", num1)        

for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    num1.append(num)
# print(num1)
print(min(num1))

### FIXED CODE ###

# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
z = [list(map(int, input().split())) for _ in range(M)]

num1 = a1[0] + b1[0]
# print("num1:", num1)
for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)
### BUGGY CODE ###

import heapq
N=int(input())
xy=[list(map(int,input().split()))+[i] for i in range(N)]
xy.sort()
path = []
for k in range(N-1):
    x,y,i = xy[k]
    x2,y2,j = xy[k+1]
    heapq.heappush(path,(abs(x-x2),i,j))
xy.sort(key=lambda x:x[1])
for k in range(N-1):
    x,y,i = xy[k]
    x2,y2,j = xy[k+1]
    heapq.heappush(path,(abs(y-y2),i,j))
union = [[i] for i in range(N)]
cnt = 0
ans = 0
while cnt < N-1:
    c,i,j = heapq.heappop(path)
    if union[i] is union[j]:continue
    while union[j]:
        k = heapq.heappop(union[j])
        if k != j : union[k] = union[i]
        heapq.heappush(union[i],k)
    union[j] = union[i]
    ans += c
    cnt += 1
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
N=int(input())
xy=[list(map(int,input().split()))+[i] for i in range(N)]
xy.sort()
path = []

def get_par(n):
    if par[n] is None:return n
    par[n] = get_par(par[n])
    return par[n]

def same(i,j):
    return get_par(i) == get_par(j)

def unite(i,j):
    j = get_par(j)
    par[j] = get_par(i)
    return

for k in range(N-1):
    x,y,i = xy[k]
    x2,y2,j = xy[k+1]
    path.append((abs(x-x2),i,j))
xy.sort(key=lambda x:x[1])
for k in range(N-1):
    x,y,i = xy[k]
    x2,y2,j = xy[k+1]
    path.append((abs(y-y2),i,j))
path.sort(key = lambda x:x[0],reverse=True)
par = [None]*N
cnt = 0
ans = 0
while cnt < N-1:
    c,i,j = path.pop()
    if same(i,j):continue
    unite(i,j)
    ans += c
    cnt += 1
print(ans)
### BUGGY CODE ###

import sys
from bisect import bisect_left

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()

    for _ in range(M):
        B, C = map(int, input().split())
        insert = bisect_left(A, C)
        n = min(B, insert)
        A = A[n:insert] + [C] * n + A[insert:]

    return sum(A)



if __name__ == '__main__':
    print(main())



### FIXED CODE ###

import sys
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    heap = []
    ans = 0
    for a in map(int, input().split()):
        heappush(heap, a)
        ans += a

    BC = []
    for _ in range(M):
        B, C = map(int, input().split())
        BC.append((B, C))

    BC = sorted(BC, key=lambda x: -x[1])
    for B, C in BC:
        for _ in range(B):
            a = heappop(heap)
            if a < C:
                heappush(heap, C)
                ans += C - a
            else:
                heappush(heap, a)
                break

    return ans


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

# N,Kの把握
l1 = list(map(int, input().split()))
N = l1[0]
K = l1[1]
 

#空リストを作成。a,bを把握し、リストにaを追加、b回。これをN回くりかえし
l3 = []
for i in range(N):
	l2 = list(map(int, input().split()))
	a = l2[0]
	b = l2[1]
	if len(l3) > K and max(l3) < a:
		pass #リストの要素数がKを上回っている場合、要素の最大値よりも大きい数は追加しない。
	else:
		adl=[a] * b
		l3 = l3 + adl
 
# リストをソートし、K番目を出力
l3.sort()
print(str(l3[K-1]))

### FIXED CODE ###

# N,Kの把握
l1 = list(map(int, input().split()))
N = l1[0]
K = l1[1]

#リストをすぐに作成するのが悪手。数値と回数をセット作成
dic = {}
for i in range(N):
	l2 = list(map(int, input().split()))
	a = l2[0]
	b = l2[1]
	if a in dic:
		dic[a] += b #既に存在する数値であればそのまま回数を＋
	else:
		dic.update({a: b}) #新規の数値であれば追加

dic = sorted(dic.items(), key=lambda x:x[0])

x = 0
for key, value in dic: #回数値を足していき、総回数＞＝Kとなったときの数値を出力する。
	x += value
	if x >= K:
		print(str(key))
		break
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,Q = map(int,readline().split())
ki = [list(map(int,readline().split())) for i in range(N-1)]
co = [list(map(int,readline().split())) for i in range(Q)]
 
ki.sort()
#print(ki)

kid = deque(ki)
#print(kid)
 
ver = [[0,False] for i in range(N)]
 
for i in range(Q):
    ver[co[i][0]-1][0] += co[i][1]

ver[0][1] = True
#print(ver)


while len(kid) != 0:
    k = kid.popleft()
    if ver[k[0]-1][1] == True:
        ver[k[1]-1][0] += ver[k[0]-1][0]
        ver[k[1]-1][1] = True
    elif ver[k[1]-1][1] == True:
        ver[k[0]-1][0] += ver[k[1]-1][0]
        ver[k[0]-1][1] = True
    else:
        kid.append(k)

'''
for i in range(N-1):
    if ver[ki[i][1]-1] != ver2[ki[i][1]-1]:
        ver[ki[i][0]-1] += ver[ki[i][1]-1]
    else:
        ver[ki[i][1]-1] += ver[ki[i][0]-1]
'''
for i in range(N):
    print(ver[i][0],end=' ')


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,Q = map(int,readline().split())
ki = []
for i in range(N-1):
    ki.append(list(map(int,readline().split())))
co = []
for i in range(Q):
    co.append(list(map(int,readline().split())))
 
ki.sort(key=lambda x: x[1])

kid = deque(ki)
ver = []
check = []
for i in range(N):
    ver.append(0)
    check.append(False)
 
for c in co:
    ver[c[0]-1] += c[1]

check[0] = True

kid2 = deque()

while len(kid) != 0:
    k = kid.popleft()
    if check[k[0]-1] == True:
        ver[k[1]-1] += ver[k[0]-1]
        check[k[1]-1] = True
    elif check[k[1]-1] == True:
        ver[k[0]-1] += ver[k[1]-1]
        check[k[0]-1] = True
    else:
        kid2.append(k)

while len(kid2) != 0:
    k = kid2.pop()
    if check[k[0]-1] == True:
        ver[k[1]-1] += ver[k[0]-1]
        check[k[1]-1] = True
    elif check[k[1]-1] == True:
        ver[k[0]-1] += ver[k[1]-1]
        check[k[0]-1] = True
    else:
        kid2.appendleft(k)


print(' '.join(map(str,ver)))
### BUGGY CODE ###

def main():
    import sys
    sys.setrecursionlimit(100000)
    n, m, *ab, = map(int, open(0).read().split())

    p = [-1] * (n + 1)

    def f(x):
        if p[x] < 0:
            return x
        else:
            return f(p[x])

    ans = -1
    for i, j in zip(ab[::2], ab[1::2]):
        if i > j:
            i, j = j, i

        pi, pj = f(i), f(j)
        if pi == pj:
            continue
        p[pi] += p[pj]
        ans = min(ans, p[pi])
        p[j] = pi
        p[pj] = pi

    print(-ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, m, *ab, = map(int, open(0).read().split())
    p = [-1] * (n + 1)

    def find(x):
        while p[x] > 0:
            x = p[x]
        return x

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi == pj:
            return
        if p[pi] < p[pj]:
            pi, pj = pj, pi
            i, j = j, i
        p[pi] += p[pj]
        p[pj] = pi
        reconnect(j, pi)

    def reconnect(i, j):
        while p[i] > 0:
            k = p[i]
            p[i] = j
            i = k

    for i, j in zip(ab[::2], ab[1::2]):
        union(i, j)

    print(-min(p))


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

A, B, K = map(int, input().split())
l = [i for i in range(A, B+1)]
del l[K:-K]
print(*l, sep='\n')
    

### FIXED CODE ###

a, b, k = map(int, input().split())
r = range(a, b+1)
print(*sorted(set(r[:k]) | set(r[-k:])), sep='\n')
### BUGGY CODE ###

N = int(input())
L = []
for l in range(N):
	L.append(int(input()))

maxL = max(L)
subL = L
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:
	for i in range(N):
		if L[i] == maxL:
			num[i] = i
			L[i] = 0
	
	if max(L) != 0:
		secL = max(L)
	else:
		secL = max(subL)
	
	for i in range(N):
		if i in num:
			print(secL)
		else:
			print(maxL)



### FIXED CODE ###

N = int(input())
L = []
for l in range(N):
	L.append(int(input()))

maxL = max(L)
subL = L
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:	
	for i in range(N):
		if L[i] == maxL:
			L[i] = 0
			print(max(L))
		else:
			print(maxL)
### BUGGY CODE ###

def main():
    num = int(input())
    ans = 0

    for div in range(1, num + 1):
        for i in range(div, num + 1):
            if i % div == 0:
                ans += i

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    num = int(input())
    ans = 0

    for divisor in range(1, num + 1):
        quotient = num // divisor
        ans += (quotient + 1) * quotient * divisor // 2

    print(ans)


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

n = int(input())
wordlist = [input() for i in range(n)]
wordtuple = tuple(set(wordlist))
checklist = []
ans = []
a = len(wordtuple)
for j in range(a) :
    checklist.append(wordlist.count(wordtuple[j]))
anslist = [i for i, v in enumerate(checklist) if v == max(checklist)]
for k in anslist :
    ans.append(wordtuple[k])
ans.sort()
for l in range(len(ans)) :
    print(ans[l])

### FIXED CODE ###

n = int(input())
d = {}
for i in range(n) :
    s = input()
    if s not in d :
        d[s] = 1
    else :
        d[s] += 1
m = max(d.values())
ans = []
for i in d :
    if d[i] == m :
        ans.append(i)
ans.sort()
for i in ans:
    print(i)
### BUGGY CODE ###

from sys import stdin
readline = stdin.readline

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

prev = 0
point = 1
ans = []
for i in range(N):
    if i < K:
        point *= A[i]
    else:
        prev = point
        point *= A[i]
        point /= A[i-K]
        if prev < point:
            ans.append("Yes")
        else:
            ans.append("No")
print(*ans, sep='\n') 


### FIXED CODE ###

from sys import stdin
readline = stdin.readline

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

prev = 0
point = 1
ans = []
for i in range(N):
    if i >= K:
        if A[i-K] < A[i]:
            ans.append("Yes")
        else:
            ans.append("No")
print(*ans, sep='\n')
### BUGGY CODE ###


S = list(input())
Q = int(input())
l = []
for i in range(Q):
  l.append(list(input().split()))
    
flag = 1 #1ならふつう, -1なら逆


for i in range(Q):
    if l[i][0] == "1":
        flag *= -1
    elif flag == 1:
        if l[i][1] == "1":
            S = list(l[i][2]) + S
            
        else:
            S = S + list(l[i][2])
            
    else:
        if l[i][1] == "2":
            S = list(l[i][2]) + S
            
        else:
            S = S + list(l[i][2])
            
if flag == 1:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))

### FIXED CODE ###

from collections import deque

S = deque(list(input()))
Q = int(input())
l = []
for i in range(Q):
  l.append(list(input().split()))
    
flag = 1 #1ならふつう, -1なら逆


for i in range(Q):
    if l[i][0] == "1":
        flag *= -1
    elif flag == 1:
        if l[i][1] == "1":
            S.appendleft(l[i][2])
            
        else:
            S.append(l[i][2])
            
    else:
        if l[i][1] == "2":
            S.appendleft(l[i][2])
            
        else:
            S.append(l[i][2])


if flag == 1:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))