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

def gcd(a, b):
	while a > 0 and b > 0:
		a, b = b, a % b
	return a + b

def st(a, b):
	if b == 0:
		return 1
	if b % 2 == 0:
		q = st(a, b // 2)
		return q * q
	return a * st(a, b - 1)

n = int(input())
a = []
for i in range(n + 1):
	x = int(input())
	a.append(x)
ans = 0
for x in range(1, 32):
	tmp = 0
	r = st(x, n)
	for i in range(0, n + 1):
		tmp += a[i] * r
		r //= x
	ans = gcd(ans, abs(tmp))
v = []
j = 2
while j * j <= ans:
	if ans % j == 0:
		ans //= j
		v.append(j)
	else:
		j += 1
if ans != 1:
	v.append(ans)
v.sort()
for i in range(len(v)):
	if i == 0 or v[i] != v[i - 1]:
		print(v[i])


### FIXED CODE ###

def gcd(a, b):
	while a > 0 and b > 0:
		a, b = b, a % b
	return a + b

def st(a, b):
	if b == 0:
		return 1
	if b % 2 == 0:
		q = st(a, b // 2)
		return q * q
	return a * st(a, b - 1)

n = int(input())
a = []
for i in range(n + 1):
	x = int(input())
	a.append(x)
ans = 0
for x in range(1, 18):
	tmp = 0
	r = st(x, n)
	for i in range(0, n + 1):
		tmp += a[i] * r
		r //= x
	ans = gcd(ans, abs(tmp))
v = []
j = 2
while j * j <= ans:
	if ans % j == 0:
		ans //= j
		v.append(j)
	else:
		j += 1
if ans != 1:
	v.append(ans)
v.sort()
for i in range(len(v)):
	if i == 0 or v[i] != v[i - 1]:
		print(v[i])
### BUGGY CODE ###

# coding: utf-8
N = int(input())
A = [int(input()) for i in range(N)]
for i in range(N):
    B = A[:i] + A[i+1:]
    print(max(B))

### FIXED CODE ###

# coding: utf-8
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A)
for i in range(N):
    if A[i] != B[-1]:
        print(B[-1])
    else:
        print(B[-2])
### BUGGY CODE ###

# O(EV)
def bellman_ford(s):
    d = [0]*n # 各頂点への最小コスト
    d[s] = 0 # 自身への距離は0
    x=s
    for tt in range(k):
        update = False # 更新が行われたか
        aa,bb,cc=g[x][0],g[x][1],g[x][2]
        if d[bb] < d[aa] + cc:
                d[bb] = d[aa] + cc
                update = True
            
        if not update:
            break

        x=bb
    return d

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

g=[]
p=list(map(int,input().split()))
c=list(map(int,input().split()))

if max(c)<0:
    print(max(c))
    exit()

for i in range(n):
    g.append((i,p[i]-1,c[p[i]-1]))

ans=0

for i in range(n):
  ans=max(ans,max(bellman_ford(i)))

print(ans)

### FIXED CODE ###

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

ans=float('inf')*-1

for i in range(n):
    visited=[i]
    pin=0
    now=i
    for j in range(k):
        now=p[now]-1
        pin+=c[now]
        ans=max(ans,pin)
        visited+=[now]

        if visited[0]==visited[-1]:
            if pin>0:
                pin*=(k//(len(visited)-1)-1)
                ans=max(ans,pin)

                for s in range(k%(len(visited)-1)+len(visited)-1):
                    now=p[now]-1
                    pin+=c[now]
                    ans=max(ans,pin)

                break

            else:
                break

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

n, q = map(int, input().split())
s = str(input())
lr = []
for i in range(q):
    lr.append(list(input().split()))

for i in range(q):
    cnt = 0
    start = int(lr[i][0])-1
    end = int(lr[i][1])-1

    for j in range(start, end):
        if s[j] == 'A':
            if s[j+1] == 'C':
                cnt += 1

    print(cnt)


### FIXED CODE ###

n, q = map(int, input().split())
s = str(input())
lr = []
for i in range(q):
    lr.append(list(input().split()))

n = len(s)
ary = [0 for i in range(len(s)+1)]

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        ary[i+1] = ary[i] + 1
    else:
        ary[i+1] = ary[i]

for i in range(q):
    ans = ary[int(lr[i][1])] - ary[int(lr[i][0])]
    print(ans)
### BUGGY CODE ###

mod = 998244353
N,K = map(int,input().split())
move = []
for _ in range(K):
    x,y = map(int,input().split())
    for i in range(x,y+1):
        move.append(i)
move.sort()
move = set(move)
memo = [0]*(N+1)
memo[1] = 1
for i in range(2,N+1):
    for j in move:
        if 0<i-j:
            memo[i] += memo[i-j]
        else:
            break
    memo[i] = memo[i]%mod
print(memo[-1]%mod)

### FIXED CODE ###

mod = 998244353
N,K = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(K)]

dp = [0]*(N+1)
dp_sum = [0]*(N+1)
dp[1] = dp_sum[1] = 1
for i in range(2,N+1):
    for l,r in move:
        if 0<i-l:
            dp[i] += dp_sum[i-l]
            if 0<i-r-1:
                dp[i] -= dp_sum[i-r-1]
        dp[i] %= mod
    dp_sum[i] = dp_sum[i-1] + dp[i]
            
print(dp[-1]%mod)
### BUGGY CODE ###

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

MAX_A = 10 ** 6
X = [0] * (MAX_A + 1)
for a in A:
    for i in range(a, MAX_A + 1, a):
        X[i] += 1

ans = len([a for a in A if X[a] == 1])
print(ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

A = set(A)
MAX_A = 10 ** 6
X = [0] * (MAX_A + 1)
for a in A:
    for i in range(a, MAX_A + 1, a):
        X[i] += 1

ans = len([a for a in A if (X[a] == 1) and (C[a] == 1)])
print(ans)
### BUGGY CODE ###

def checkStn(stnData,numStn):
    ftn = False
    for i in range(numStn - 1):
        if stnData[i] == "W" and stnData[i+1] == "R":
            ftn = True
            break
    return ftn

def exchangeStn(stnData,numStn):
    cnt = 0
    for i in range(numStn):
        for j in range(numStn - 1 ,-1, -1):
            if i < j:
                if stnData[i] == "W" and stnData[j] == "R":
                    stnData[i] = "R"
                    stnData[j] = "W"
                    cnt += 1
                    break
    return cnt


numStn = int(input())
stnData = list(input())

ftn = checkStn(stnData,numStn)
cnt = 0

while ftn == True:
    ftn = checkStn(stnData,numStn)
    cnt += exchangeStn(stnData,numStn)

print(cnt)

### FIXED CODE ###

numStn = int(input())
stnData = list(input())

ttlW = stnData.count("W")
ttlR = stnData.count("R")

cnt = ttlR - stnData[:ttlR].count("R")

print(cnt)
### BUGGY CODE ###

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

wv = [None] + [list(map(int, input().split())) for i in range(N)]

dp = [{0: 0}] + [{} for i in range(N)]

for i in range(1, N+1):
  w, v = wv[i]
  for mw, mv in dp[i-1].items():
    dp[i][mw] = max(dp[i].get(mw, 0), dp[i-1].get(mw, 0))
    if mw + w < W+1:
      dp[i][mw+w] = max(dp[i].get(mw+w, 0), dp[i-1][mw]+v, dp[i-1].get(mw+w, 0))

print(max(dp[N].values()))


### FIXED CODE ###

import sys
input = sys.stdin.readline

def dp_fn():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))
  
  DP = {0:0}
  
  for w, v in WV:
    keys = sorted(DP.keys(), reverse=True)
    for i in keys:
      j = DP[i]
      if j+w <= W:
        if i+v in DP:
          DP[i+v] = min(DP[i+v], j+w)
        else:
          DP[i+v] = j+w
  return max(DP.keys())
  
print(dp_fn())
### BUGGY CODE ###

# ABC 153 D
H = int(input())
def del_jug(L):
    return set(L) !=set([1])

cnt=0
L = [H]
while  del_jug(L):
    
    H = int(L[-1]/2)
    L.append(H)
    L.append(H)
    L =sorted(L)
    
    L.pop(-1)
    
    cnt+=1
    
print(cnt+len(L))

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(1000000)

H = int(input())

def f(n):
    if n ==1:
        return 1
    else:
        return  2*f(n//2) +1
    
print(f(H))
### BUGGY CODE ###

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

result = 1
for i in a:
    result *= i

if result > pow(10, 18):
    print(-1)
    exit(0)
print(result)

### FIXED CODE ###

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

for i in a:
    if i == 0:
        print(0)
        exit(0)

result = 1
for i in a:
    result *= i
    if result > pow(10, 18):
        print(-1)
        exit(0)

print(result)
### BUGGY CODE ###

import bisect
import heapq
n, m = map(int, input().split())
#a = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
#a = list(map(lambda x: x * -1, a))
b, c = [], []

for i in range(m):
    v1, v2 = map(int, input().split())
    b.append(v1)
    c.append(v2)

#print(a)

for i in range(m):
    idx = bisect.bisect_left(a, c[i])
    #print('idx: ' + str(idx))
    cnt = min(idx, b[i])
    a = [c[i]] * cnt + a[cnt:]
    a.sort()

#print(a)
print(sum(a))




### FIXED CODE ###

import bisect
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
#b, c = [], []
bc = []
heapq.heapify(a)

for i in range(m):
    bc.append(list(map(int, input().split())))
    # v1, v2 = map(int, input().split())
    # b.append(v1)
    # c.append(v2)
bc.sort(key = lambda x: x[1], reverse=True)

for i in range(m):
    cnt = 0
    while True:
        if cnt == bc[i][0]:
            break
        minV = heapq.heappop(a)
        #print('# minV: ' + str(minV))
        if minV >= bc[i][1]:
            heapq.heappush(a, minV)
            break
        else:
            heapq.heappush(a, bc[i][1])
        cnt += 1

#print(a)
print(sum(a))
### BUGGY CODE ###

from collections import defaultdict

root = 10000
MOD = 2 ** 61 - 1
def rolling_hash(s):
    hs = [0] * (len(s) + 1)
    for i in range(len(s)):
        hs[i + 1] = hs[i] * root + ord(s[i]) % MOD
    return hs

#"""
N = int(input())
S_list = [input() for _ in range(N)]
"""
def to_alpha(n):
    ret = ''
    while n > 0:
        n -= 1
        ret += chr(n % 26 + ord('a'))
        n //= 26
    return ret

N = 10 ** 5
S_list = [to_alpha(i) for i in range(2, 2 * N + 2, 2)]
#"""


S_list.sort(key=len)

ans = 0
wanted = {chr(i): set() for i in range(ord('a'), ord('z') + 1)}
for S in S_list:
    alpha_set = set()
    hash_of_S = rolling_hash(S)
    for i in range(len(S)):
        alpha_set.add(S[i])
        suffix_hash = (hash_of_S[len(S)] - hash_of_S[i+1] * pow(root, (len(S) - i - 1), MOD)) % MOD
        for alpha in alpha_set:
            if suffix_hash in wanted[alpha]:
                ans += 1

    suffix_of_S = (hash_of_S[len(S)] - hash_of_S[1] * pow(root, (len(S) - 1), MOD)) % MOD
    wanted[S[0]].add(suffix_of_S)

print(ans)


### FIXED CODE ###

from collections import defaultdict

root = 10000
MOD = 2 ** 61 - 1


#"""
N = int(input())
S_list = [input() for _ in range(N)]
"""
def to_alpha(n):
    ret = ''
    while n > 0:
        n -= 1
        ret += chr(n % 26 + ord('a'))
        n //= 26
    return ret

N = 2 * 10 ** 5
S_list = [to_alpha(i) for i in range(2, 2 * N + 2, 2)]
#"""


S_list.sort(key=len)

ans = 0
wanted = defaultdict(set)
for S in S_list:
    suffix_hashes = [0]
    for c in S[-1:0:-1]:
        suffix_hashes.append((suffix_hashes[-1] * root + ord(c)) % MOD)
    suffix_hashes.reverse()
    l = len(S)
    alpha_set = set()
    for i, c in enumerate(S):
        alpha_set.add(c)
        # print(alpha_set, suffix_hashes[i])
        if suffix_hashes[i] in wanted:
            for alpha in wanted[suffix_hashes[i]]:
                if alpha in alpha_set:
                    ans += 1
    wanted[suffix_hashes[0]].add(S[0])
        
# print(wanted)
print(ans)
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    for m in range(0, M):
        tmp = [int(x) for x in input().split()]
        A.extend([tmp[1]] * min(tmp[0],N))
 
    A.sort()
    A.reverse()
    A = A[:N]
    print(sum(A))
 
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy

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

a = numpy.array([int(e) for e in input().split(" ")],dtype=numpy.int64)
changes=[]
for i in range(m):
    changes.append([int(e) for e in input().split(" ")])


a.sort()
#昇順ソート

changes.sort(key=lambda x:(x[1],x[0]),reverse = True)

change_num = 0
for change in changes:
    for i in range(change_num, min(change[0] + change_num,n)):
        if a[i] < change[1]:
            change_num += 1
            a[i] = change[1]
        else:
            break

print(a.sum())
### BUGGY CODE ###

def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if root[x] > root[y]:
        x, y = y, x

    root[x] += root[y]
    root[y] = x

def size(x):
    return -root[find(x)]

def same(x,y):
    return find(x) == find(y)

def member(x):
    rt = find(x)
    return [i for i in range(n) if find(i) == rt]

def roots():
    return [i for i, x in enumerate(root) if x < 0]

def member_count(x):
    return len(roots())

def all_group_members():
    return {r: member(r) for r in roots()}

n , m = map(int,input().split())
root = [-1 for i in range(n)]

for _ in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    unite(a,b)

print(len(all_group_members())-1)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int,input().split())
uf = UnionFind(n)

for _ in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    uf.union(a , b)
    
print(uf.group_count()-1)
### BUGGY CODE ###

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

def mex(L):
  L.sort()
  ans = 0
  for i in L:
    if i <= ans:
      ans += 1
    else:
      break
  return ans

DP = [0] * (K + 1)
M = 100000

for i in range(a[0], K + 1):
  L = []
  for j in range(N):
    if i - a[j] < 0:
      break
    L.append(DP[i - a[j]])
  DP[i] = mex(L)

if DP[-1] == 0:
  print("Second")
else:
  print("First")


### FIXED CODE ###

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

def mex(L):
  L.sort()
  ans = 0
  for i in L:
    if i <= ans:
      ans += 1
    else:
      break
  return ans

DP = [0] * (K + 1)
M = 100000

for i in range(a[0], K + 1):
  L = []
  for j in range(N):
    if i - a[j] < 0:
      break
    L.append(DP[i - a[j]])
  DP[i] = mex(L)

if DP[-1] == 0:
  print("Second")
else:
  print("First")
### BUGGY CODE ###

n, m = map(int, input().split())
roots = []
next_room = []
out = [0]*n
out[0] = 'Yes'
for _ in range(m):
    root = list(map(int, input().split()))
    if 1 in root:
        if root[0]==1:
            out[root[1]-1]=1
        else:
            out[root[0]-1]=1
    else:
        roots.append(root)
while True:
    out_tmp = out.copy()
    for root in roots:
        if out[root[0]-1] != 0 and out[root[1]-1] == 0:
            out_tmp[root[1]-1] = root[0]
        elif out[root[1]-1] != 0 and out[root[0]-1] == 0:
            out_tmp[root[0]-1] = root[1]
    out = out_tmp
    if out.count(0)==0:
        break
for o in out:
    print(o)

### FIXED CODE ###

n, m = [int(x) for x in input().split()] # nは頂点の数、mは辺の数
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a-1].append(b)
    g[b-1].append(a)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u-1] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v-1]:
            if d[i-1] is None:
                d[i-1] = d[v-1] + 1
                queue.append(i)
    return d

d = bfs(1)
for i in range(n):
    if d[i] == 0:
        print('Yes')
    else:
        for j in g[i]:
            if d[i]-1==d[j-1]:
                print(j)
                break
### BUGGY CODE ###

from fractions import gcd

def solve(p, q, a, n, l=1):

    #if n==1:
    #    #print(p, q, a, n, l, 1 if p==1 and q<=a and q>=l else 0)
    #    return 1 if p==1 and q<=a and q>=l else 0
    ans = 1 if p==1 and q<=a and q>=l else 0
    #denom = l if p==0 else max(l, int(q/p))
    for denom in range(max(l, int(q/p)), a+1):  #n/denom >= p/q:
        if n*q < denom*p: break
        p_, q_ = p*denom-q, q*denom
        if p_ <= 0:
            denom += 1
            continue
        gcd_ = gcd(p_, q_)
        p_ //= gcd_
        q_ //= gcd_
        if n==2 and p_==1 and q_*denom<=a and q_>=denom:
            ans += 1
        else:
            ans += solve(p_, q_, a//denom, n-1, denom)

        denom += 1
    #print(p, q, a, n, l, ans)
    return ans

while True:
    p, q, a, n = map(int, input().split())
    if p==q==a==n==0:
        break
    gcd_ = gcd(p, q)
    p //= gcd_
    q //= gcd_
    if n==1:
        print(1 if p==1 and q<=a else 0)
    else:
        print(solve(p, q, a, n))




### FIXED CODE ###

from fractions import gcd

def solve(p, q, a, n, l=1):
    ans = 1 if p==1 and q<=a and q>=l else 0
    denom = max(l, q//p)
    p_denom = denom*p
    while n*q >= p_denom and denom <= a:  #n/denom >= p/q:
        p_, q_ = p_denom-q, q*denom
        if p_ <= 0:
            denom += 1
            p_denom += p
            continue
        gcd_ = gcd(p_, q_)
        p_ //= gcd_
        q_ //= gcd_
        if n==2 and p_==1 and q_*denom<=a and q_>=denom:
            ans += 1
        else:
            ans += solve(p_, q_, a//denom, n-1, denom)
        denom += 1
        p_denom += p
    #print(p, q, a, n, l, ans)
    return ans

while True:
    p, q, a, n = map(int, input().split())
    if p==q==a==n==0:
        break
    gcd_ = gcd(p, q)
    p //= gcd_
    q //= gcd_
    if n==1:
        print(1 if p==1 and q<=a else 0)
    else:
        print(solve(p, q, a, n))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
buff_readline = sys.stdin.buffer.readline


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


from collections import deque

def slv(N, P):
    P = [p-1 for p in P]
    M = N+2
    cost = [0] * M**2
    occupy = [True] * M**2
    for i in range(N):
        for j in range(N):
            cost[i*M+j + M + 1] = min(i, j, N-i-1, N-j-1)

    ans = 0
    for p in P:
        x = p // N
        y = p % N
        p = x * M + y + M + 1
        ans += cost[p]
        occupy[p] = False
        s = [p]
        while s:
            pi = s.pop()
            for d in [-1, 1, -M, M]:
                ni = pi + d
                nc = cost[pi] + (1 if occupy[pi] else 0)
                if nc < cost[ni]:
                    s.append(ni)
                    cost[ni] = nc
    return ans


def main():
    N = read_int()
    P = read_int_n()
    print(slv(N, P))

    # import random
    # N = 500
    # P = list(range(1, N**2+1))
    # random.shuffle(P)
    # print(slv(N, P))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
buff_readline = sys.stdin.buffer.readline


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def slv(N, P):
    M = N+2
    cost = [0] * M**2
    occupy = [1] * M**2
    for i in range(N):
        im = i*M + M + 1
        for j in range(N):
            cost[im+j] = min(i, j, N-i-1, N-j-1)

    ds = [-1, 1, -M, M]
    ans = 0
    for p in P:
        p -= 1
        x = p // N
        y = p % N
        p = x * M + y + M + 1
        ans += cost[p]
        occupy[p] = 0
        s = []
        s.append(p)
        while s:
            pi = s.pop()
            for d in ds:
                ni = pi + d
                nc = cost[pi] + occupy[pi]
                if nc < cost[ni]:
                    cost[ni] = nc
                    s.append(ni)
    return ans


def main():
    N = read_int()
    P = read_int_n()
    print(slv(N, P))


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

from queue import Queue
from collections import defaultdict

def solve(n, q, AB, PX):
    count = defaultdict(int)
    for p, x in PX:
        count[p] += x

    tree = defaultdict(lambda: [])
    for a, b in AB:
        tree[a].append(b)
        tree[b].append(a)

    ret = [0] * n
    q = Queue()
    q.put((0, 1, count[1]))
    while not q.empty():
        f, c, x = q.get()
        count[c] += count[f]
        ret[c - 1] = count[c]
        for n in tree[c]:
            if n != f:
                q.put((c, n, count[c]))

    return ret

_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)]
print(*solve(_n, _q, _AB, _PX))


### FIXED CODE ###

from collections import defaultdict, deque

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

tree = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

count = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    count[p - 1] += x

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)
### BUGGY CODE ###

n = int(input())
def f(i):
    if i==0:
        return 2
    elif i==1:
        return 1
    else:
        return f(i-1)+f(i-2)
print(f(n))

### FIXED CODE ###

n = int(input())
memo = [0]*87
def f(i):
    if memo[i]:
        return memo[i]
    if i==0:
        return 2
    elif i==1:
        return 1
    else:
        memo[i] = f(i-1)+f(i-2)
        return memo[i]
print(f(n))
### BUGGY CODE ###

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

    def calc(x: int, n: int):
        y = int(n/x)
        return int(y * (y + 1) * x / 2)

    result = 0
    for i in range(1, N+1):
        result += calc(i, N)
    print(result)

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

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

    ans = 0
    for i in range(1, N+1):
        n = N // i
        ans += i * (n + 1) * n // 2
    print(ans)

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

### ABC133-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
l=0
r=A[-1]
m=(l+r)//2
sA=sum(A)
x0=0
while l<r:
    x0=m
    xm=m
    sx=2*xm
    for i in range(n-1):
        xm=A[i]-xm
        sx+=2*xm
    if sA==sx:
        break
    elif sx<sA:
        l=m
        m=(l+r)//2
    else:
        r=m
        m=(l+r)//2
print(2*x0,end=" ")
xm=x0
for i in range(n-1):
    xm=A[i]-xm
    print(2*xm,end=" ")
print()

### FIXED CODE ###

### ABC133-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
l=0
r=A[-1]
m=(l+r)//2
sA=sum(A)
x0=0
while l<=r:
    x0=m
    xm=m
    sx=2*xm
    for i in range(n-1):
        xm=A[i]-xm
        sx+=2*xm
    if sA==sx:
        break
    elif sx<sA:
        l=m+1
        m=(l+r)//2
    else:
        r=m-1
        m=(l+r)//2
print(2*x0,end=" ")
xm=x0
for i in range(n-1):
    xm=A[i]-xm
    print(2*xm,end=" ")
print()
### BUGGY CODE ###

N,M = (int(x) for x in input().split())

max_i = 0
for i in range(1, M//N+1):
    if M%i == 0 and M//i >= N:
        max_i = i
print(max_i)


### FIXED CODE ###

N,M = (int(x) for x in input().split())

max_i = 0
for i in range(1, int(M**0.5)+1):
    if M%i == 0:
        if M//i >= N:
            max_i = max(max_i, i)
        if i >= N:
            max_i = max(max_i, M//i)
print(max_i)
### BUGGY CODE ###

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

ans = 0

for n in range(1000):
    pin = str(n).zfill(3)
    head = 0
    for c in S:
        if c == pin[head]:
            head += 1
        if head == 3:
            ans += 1
            break

print(ans)


### FIXED CODE ###

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

ans = 0

for n in range(1000):
    pin = str(n).zfill(3)
    head = 0
    for c in S:
        if c == pin[head]:
            head += 1
        if head == 3:
            ans += 1
            break

print(ans)