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

#!/usr/bin/env python3
import sys
from itertools import combinations


def solve(N, A):
    L = list(combinations(range(N), 2))
    ct = 0
    for l in L:
        if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
            ct += 1
    print(ct)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
            for line in sys.stdin:
                for word in line.split():
                    yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    A = [int(next(tokens)) for _ in range(N)]
    solve(N, A)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import product
from collections import Counter
# from itertools import combinations


def solve(N, A):
    B = [i - A[i] for i in range(N)]
    C = [i + A[i] for i in range(N)]
    Bc = Counter(B)
    Cc = Counter(C)
    ct = 0
    for k, i in Bc.items():
        if k in Cc:
            ct += i * Cc[k]
    print(ct)
    # bg = []
    # sm = []
    # # cl = set()
    # for i in range(N):
    #     if A[i] <= i - 1:
    #         bg.append(i)
    #         # cl.add(i)
    #     if A[i] >= 1 - i:
    #         sm.append(i)
    #         # cl.add(i)
    # # L = list(combinations(cl, 2))
    # L = list(product(bg, sm))
    # ct = 0
    # for l in L:
    #     if l[0] > l[1]:
    #         if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
    #             ct += 1
    # print(ct)
    # # L = list(combinations(range(N), 2))
    # # ct = 0
    # # for l in L:
    # #     if abs(l[0] - l[1]) == A[l[0]] + A[l[1]]:
    # #         ct += 1
    # # print(ct)
    # return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
            for line in sys.stdin:
                for word in line.split():
                    yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    A = [int(next(tokens)) for _ in range(N)]
    solve(N, A)

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

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

count = 0

for i in range(1,n+1):
    tmp = li.count(i)
    count += (tmp * (tmp-1))//2

for k in range(n):
    tmp = li.count(li[k])
    answer = count - (tmp * (tmp-1))//2 + ((tmp-1) * (tmp-2))//2
    print(answer)

### FIXED CODE ###

import collections

n=int(input())
li = list(map(int,input().split()))
cli = collections.Counter(li)
cli_values = tuple(cli.values())

count = 0

for cli_value in cli_values:
    if cli_value > 1:
        count += (cli_value * (cli_value-1))//2

for k in range(n):
    tmp = cli[li[k]]
    answer = count - (tmp * (tmp-1))//2 + ((tmp-1) * (tmp-2))//2
    print(answer)
### BUGGY CODE ###

def main():
     AlfaToNum={'a':2,'b':3,'c':5,'d':7,'e':11,'f':13,'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
     n=int(input())
     s=[]
     ans=0
     for i in range(n):
          si=input()
          cnt=1
          for j in si:
               cnt*=AlfaToNum[j]
          s.append(cnt)
     #print(s)
     for i in range(n):
          for j in range(i+1,n):
               if s[i]==s[j]:
                    ans+=1
     print(ans)
if __name__ == '__main__':
     main()

### FIXED CODE ###

def main():
     AlfaToNum={'a':2,'b':3,'c':5,'d':7,'e':11,'f':13,'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
     n=int(input())
     s=[]
     ans=0
     for i in range(n):
          si=input()
          cnt=1
          for j in si:
               cnt*=AlfaToNum[j]
          s.append(cnt)
     #print(s)
     s.sort()
     cnt=1
     for i in range(n-1):
          if s[i]==s[i+1]:
               cnt+=1
          else:
               ans+=cnt*(cnt-1)//2
               cnt=1
     ans+=cnt*(cnt-1)//2
     print(ans)
if __name__ == '__main__':
     main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*pqc = map(int, read().split())

g = [[] for _ in range(n)]
M = iter(pqc)

#s = [set() for _ in range(n)]
s = set()
for p,q,c in zip(M,M,M):
    p -= 1
    q -= 1
    g[p].append((q,c))
    g[q].append((p,c))
    if p==0 or q==0: s.add(c)
    #s[p].add(c)
    #s[q].add(c)
    


from collections import deque
def bfs01(g,s):
    n = len(g)
    #checked = [0]*n
    #checked[0] = 1
    ans = INF = 1<<30
    mask = (1<<20)-1
    q = deque((ci,1) for ci in s)
    res = {ci:1 for ci in s}
    #print(res)
    while q:
        vl,dv = q.popleft()
        if res[vl] < dv: continue
        v,l = vl>>20, vl&mask
        for to,line in g[v]:
            tl = (to<<20)+line
            ndv = dv+(0 if l==line else 1)
            if tl not in res or res[tl] > ndv:
                res[tl] = ndv
                if l==line: q.appendleft((tl,ndv))
                else: q.append((tl,ndv))
                
                if to == n-1: ans = min(ans,ndv)
                
                #print(tl,ndv,(v,l,dv),l==line)
                
        #print(q)
    if ans==INF: ans=-1
    return ans



print(bfs01(g,s))


#print(res)




### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*pqc = map(int, read().split())

g = {}
M = iter(pqc)

for p,q,c in zip(M,M,M):
    pc = ((p-1)<<20)+c
    qc = ((q-1)<<20)+c
    pp = (p-1)<<20
    qq = (q-1)<<20
    
    if pc not in g: g[pc] = []
    if qc not in g: g[qc] = []
    if pp not in g: g[pp] = []
    if qq not in g: g[qq] = []
    
    g[pc].append(qc)
    g[pc].append(pp)

    g[qc].append(pc)
    g[qc].append(qq)

    g[pp].append(pc)
    g[qq].append(qc)

if 0 not in g: g[0] = []

from collections import deque
q = deque([(0,0)])
res = {0:0}

mask = (1<<20)-1
while q:
    vl,dv = q.popleft()
    if res[vl] < dv: continue
    if (vl>>20) == n-1:
        res[(n-1)<<20] = dv+1
        break
    for tl in g[vl]:
        ndv = dv + (vl&mask==0 or tl&mask==0)
        if tl not in res or res[tl] > ndv:
            res[tl] = ndv
            if vl&mask==0 or tl&mask==0:
                q.append((tl,ndv))
            else:
                q.appendleft((tl,ndv))

if (n-1)<<20 in res:
    print(res[(n-1)<<20]//2)
else:
    print(-1)
### BUGGY CODE ###

N, X, M = map(int,input().split())
import sys
ans = 0
ls = [X%M] + [-1]*(M+1)
for i in range(N):
    a = ls[i]
    ls[i+1] = pow(a,2,M)
    if i+1 < N and ls[i+1] in ls[:i]:
        b = ls[i+1]
        L = ls.index(b)
        R = i
        len_roop = R - L + 1
        p = (N - L) // len_roop
        q = (N - L) % len_roop
        break
else:
    for i in range(N):
        ans += ls[i]
    print(ans)   
    sys.exit()
    
sum_roop = 0        
for i in range(L, R+1):
    sum_roop += ls[i]
    
sum_edge = 0
for i in range(L, L+q):
    sum_edge += ls[i] 
    
for i in range(L):
    ans += ls[i]
else:
    ans += sum_roop * p + sum_edge        
    
print(ans) 

### FIXED CODE ###

N, X, M = map(int,input().split())
ans = 0
ls = [X%M] + [-1]*(M+1)
ls_app = [0]*(M+1)

for i in range(N):
    a = ls[i]
    ls_app[a] = i
    ls[i+1] = pow(a,2,M)
    if i+1 < N and ls_app[ls[i+1]] != 0:
        b = ls[i+1]
        L = ls.index(b)
        R = i
        len_roop = R - L + 1
        p = (N - L) // len_roop
        q = (N - L) % len_roop
        break
else:
    for i in range(N):
        ans += ls[i]
    print(ans)   
    exit()
    
sum_roop = 0        
for i in range(L, R+1):
    sum_roop += ls[i]
    
sum_edge = 0
for i in range(L, L+q):
    sum_edge += ls[i] 
    
for i in range(L):
    ans += ls[i]
else:
    ans += sum_roop * p + sum_edge        
    
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


mod=998244353
pp=pow(2,mod-2,mod)

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

dp=[[0 for j in range(s+1)] for i in range(n+1)]
dp[0][0]=pow(2,n,mod)

for i in range(n):
    for j in range(s+1):
        if dp[i][j]>=1:
            if j+l[i]<=s:
                dp[i+1][j+l[i]]+=dp[i][j]*pp# +pow(2,n-1,mod)
                #dp[i+1][j+l[i]]%=mod
            dp[i+1][j]+=dp[i][j]
print(dp[-1][-1]%mod)


### FIXED CODE ###

#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


mod=998244353
pp=pow(2,mod-2,mod)

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

dp=[[0 for j in range(s+1)] for i in range(n+1)]
dp[0][0]=pow(2,n,mod)

for i in range(n):
    for j in range(s+1):
        if dp[i][j]>=1:
            if j+l[i]<=s:
                dp[i+1][j+l[i]]+=dp[i][j]*pp# +pow(2,n-1,mod)
                dp[i+1][j+l[i]]%=mod
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j]%=mod
print(dp[-1][-1]%mod)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
total = 0

for i in range(n-1):
    a_i = A[i]
    a_other = sum(A[i+1:])
    # print(a_i)
    # print(a_other)
    total += a_i * a_other

print(total%(10**9 + 7))

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
total = 0
sum_A = sum(A)

for i in range(n-1):
    sum_A -= A[i]
    total += A[i] * sum_A

print(total%(10**9 + 7))
### BUGGY CODE ###

import numpy as np

L, N = map(int, input().split())
X = np.array([int(input()) for _ in range(N)])
Y1 = np.concatenate(([X[0]], X[1:] - X[:-1], [L - X[-1]]))
Y2 = Y1[::-1]
Z = np.concatenate((np.arange(N, -1, -2), np.arange(N - 1, -1, -2)[::-1]))


def myfunc(n, Y):
    return np.sum(Y[n:n + (N - n + 1)//2]) - np.sum(Y[:n]) - np.sum(Y[-((N - n + 1)//2):])


len1 = np.dot(Z, Y1)
len2 = np.dot(Z, Y2)
ans = max(len1, len2)
for n in range(1, (N + 1) // 2):
    len1 += myfunc(n, Y1)
    len2 += myfunc(n, Y2)
    ans = max(ans, len1, len2)

print(ans)

### FIXED CODE ###

import numpy as np
import sys

L, N = map(int, input().split())
X = np.array([int(sys.stdin.readline()) for _ in range(N)])
X2 = L - X[::-1]
Y1 = np.concatenate(([X[0]], X[1:] - X[:-1], [L - X[-1]]))
Y2 = Y1[::-1]
Z = np.concatenate((np.arange(N, -1, -2), np.arange(N - 1, -1, -2)[::-1]))


def myfunc(n, x):
    return x[n + (N - n + 1)//2 - 1] - 2 * x[n - 1] - (L - x[N - (N - n + 1)//2])


len1 = np.dot(Z, Y1)
len2 = np.dot(Z, Y2)
x1 = X.tolist()
x2 = X2.tolist()
ans = max(len1, len2)
for n in range(1, (N + 1) // 2):
    len1 += myfunc(n, x1)
    len2 += myfunc(n, x2)
    ans = max(ans, len1, len2)

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

class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        # ここの再帰をDFSで実装して高速化できるか試す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def size(self,x):
        # 集合のサイズを調べる
        return self.par.count(self.find(x))

    def union(self, vx, vy):
        # 根を探す
        x = self.find(vx)
        y = self.find(vy)
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.find(vx)
        else:
            self.par[y] = x
            self.find(vy)
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
uf=UnionFind(n)
out=[[] for i in range(n+1)]

for i in range(m):
    a,b=map(int,input().split())
    uf.union(a,b)
    out[a].append(b)
    out[b].append(a)

for i in range(k):
    c,d=map(int,input().split())
    if uf.check(c,d):
        out[c].append(d)
        out[d].append(c)
'''
print(out)
print(uf.par)
'''
for i in range(1,n+1):
    ans=uf.size(i)-1-len(out[i])
    print(ans,end=' ')


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [-1] * n
        # rank
        self.size = [1] * n

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        self.par[y]=x
        self.size[x]+=self.size[y]

import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
uf=UnionFind(n)
out=[[] for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)
    out[a-1].append(b-1)
    out[b-1].append(a-1)

for i in range(k):
    c,d=map(int,input().split())
    if uf.check(c-1,d-1):
        out[c-1].append(d-1)
        out[d-1].append(c-1)

for i in range(n):
    ans=uf.size[uf.find(i)]-1-len(out[i])
    print(ans,end=' ')
### BUGGY CODE ###

import math
import itertools
n = range(1,int(input())+1)
pp = list(itertools.product(n, repeat=3))
sum = 0
for p in pp:
  sum+=math.gcd(math.gcd(p[0],p[1]),p[2])
print(sum)

### FIXED CODE ###

import math
import itertools
n = range(1,int(input())+1)
ppp = list(itertools.combinations(n, 3))
pp = list(itertools.combinations(n, 2))
asum,bsum,csum = 0,0,0
for p in ppp:
  asum+=math.gcd(math.gcd(p[0],p[1]),p[2])

for p in pp:
  bsum+=math.gcd(p[0],p[1])

for p in n:
  csum+=p

print(asum*6+bsum*6+csum)
### BUGGY CODE ###

N, K=map(int,input().split(' '))
H=list(map(int,input().split(' ')))
dp=[]

for i in range(N):
	if i==0:
		dp.append(0)
	elif i==1:
		dp.append(abs(H[1]-H[0]))
	else:
		dp.append(min([ dp[i-j]+abs(H[i]-H[i-j]) for j in range(1,K+1) if i-j>=0]))
		
print(dp[N-1])

### FIXED CODE ###

N, K=map(int,input().split(' '))
H=list(map(int,input().split(' ')))
dp=[]

for i in range(N):
	if i==0:
		dp.append(0)
	elif i==1:
		dp.append(abs(H[1]-H[0]))
	else:
		d = min([ dp[i-j]+abs(H[i]-H[i-j]) for j in range(1,K+1) if i-j>=0])
		dp.append(d)
		
print(dp[N-1])
### BUGGY CODE ###

S = input()
T = input()
for i in range(len(S)):
  if S[i] != T[i]:
    tmp1 = S[i]
    tmp2 = T[i]
    S = S.replace(tmp1, "0")
    S = S.replace(tmp2, "1")
    S = S.replace("0", tmp2)
    S = S.replace("1", tmp1)
print("Yes" if S == T else "No")    


### FIXED CODE ###

from collections import Counter
print("Yes" if sorted(Counter(input()).values()) == sorted(Counter(input()).values()) else "No")
### BUGGY CODE ###

g = {}
a = int(input())
vertices = [i for i in range(1, a + 1)]
for i in range(a - 1):
    c = [int(s) for s in input().split()]
    if c[0] not in g: g[c[0]] = [(c[1], c[2])]
    else: g[c[0]].append((c[1], c[2]))

    if c[1] not in g: g[c[1]] = [(c[0], c[2])]
    else: g[c[1]].append((c[0], c[2]))

Q = [vertices[0]]
d = {i: False for i in vertices}
d[vertices[0]] = True
c = {}
c[vertices[0]] = 0
delta = [vertices[0]] 
while(True):
    for i in g[Q[0]]:
        if d[i[0]] == False:
            delta.append(i[0]) 
            d[i[0]] = True
            if i[1] % 2 == 0: c[i[0]] = c[Q[0]]
            else: c[i[0]] = (c[Q[0]] + 1) % 2
            Q.append(i[0])
    Q = Q[1:]
    if Q == []:
        if set(delta) == set(vertices): break
        else: Q.append(list(set(delta).intersection(set(vertices)))[0])

for i in vertices: print(c[i])

### FIXED CODE ###

g = {}
a = int(input())
for i in range(a - 1):
    c = [int(s) for s in input().split()]
    if c[0] not in g: g[c[0]] = [(c[1], c[2])]
    else: g[c[0]].append((c[1], c[2]))

    if c[1] not in g: g[c[1]] = [(c[0], c[2])]
    else: g[c[1]].append((c[0], c[2]))

c = {}
d = {i: False for i in range(1, a + 1)}
c[1], d[1] = 0, True
Q = [1]
while(Q != []):
    r = Q.pop(0)
    for i in g[r]:
        if d[i[0]] == False:
            d[i[0]] = True
            Q.append(i[0])
            if i[1] % 2 == 0: c[i[0]] = c[r]
            else: c[i[0]] = (c[r] + 1) % 2
for i in range(1, a + 1): print(c[i])
### BUGGY CODE ###

def check(string):
    for j in range(n - 2):
        if s[j] != temp[0]:continue 
        for k in range(j + 1, n - 1):
            if s[k] != temp[1]:continue 
            for l in range(k + 1, n):
                if s[l] == temp[2]:return 1
            
            return 0
    return 0
n = int(input())
s = input()
res = 0

for i in range(1000):
    temp = '00' + str(i)
    temp = temp[-3:]
    res += check(temp)
print(res)
    

### FIXED CODE ###

n=int(input())
s=input()
#000~999からいくつ作れるか試す
num='0123456789'
ans=0
#候補の暗証番号を生成する
for first_num in num:
    for second_num in num:
        for third_num in num:
            temp_lock=first_num+second_num+third_num
            temp_cnt=0
            for i in s:
                if temp_cnt==0 and i==temp_lock[0]:
                    temp_cnt=1
                elif temp_cnt==1 and i==temp_lock[1]:
                    temp_cnt=2
                elif temp_cnt==2 and i==temp_lock[2]:
                    ans+=1
                    break
print(ans)
### BUGGY CODE ###

n=int(input())


from math import floor
total=0
for m in range(1,n):
    if floor(n/m)==n%m:
        total+=m

print(total)


### FIXED CODE ###

n=int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

arr = make_divisors(n)
total=0
for m in arr:
    r = n//m

    if r<m-1:
        total +=m-1


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

n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=0
if(mn!=1):
    print("-1")
    exit()
r=len(h)
i=-1
while(True):
    i=i+1
    if i==r:
        break
    for j in range(r-1):
        if(h[i]==i+1):
            break
        else:
            cnt=cnt+1
            del h[i]
            r=r-1
print(cnt)


### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=0
if(mn!=1):
    print("-1")
    exit()
i=1
for k in h:
    if(k==i):
        i=i+1
    else:
        cnt=cnt+1
print(cnt)
### BUGGY CODE ###

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

DIV=10**9+7

def gcd(a,b):
  if a<b:
    a,b=b,a
  while a%b!=0:
    a,b=b,a%b
  return b

def lcd(a,b):
  return a*b//(gcd(a,b))

L=1
for i in range(N):
  L=lcd(L,A[i])

ans=0
import numpy as np
A=np.array(A,dtype=int)
ans=np.sum(L//A)
ans%=DIV

print(ans)


### FIXED CODE ###

import math
from fractions import gcd
from functools import reduce

DIV=10**9+7

def lcm(a,b):
  return a*b//(gcd(a,b))

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

ans=sum(list(map(lambda x:g//x,A)))
print(ans%DIV)
### BUGGY CODE ###

N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*(N-1)
for i in range(N-1):
    if S[i]=='A' and S[i+1] == 'C':
        a[i] = 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(sum(a[l-1:r-1]))

### FIXED CODE ###

N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split(" ")))
order = ""
for i in range(n):
    order += str(a.index(i+1)+1) + " " 
order.rstrip()
print(order)  

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split(" ")))
b = [0]*n
order = ""
for i in range(n):
	b[a[i]-1]= i+1
for i in b:
  order += str(i) + " "
order.rstrip
print(order)
### BUGGY CODE ###

def gcd_cnt(t):
    for i in range(t, n+1,t):
        kosuu_ls[i]+=i
    #print("defない", kosuu_ls)

n = int(input())
sub = 0
#約数でそのままアクセス可能
kosuu_ls = [0]*(n+1)
for t in range(1,n+1):
    gcd_cnt(t)
#最後に全部たす
for i in range(1,n+1):
    sub+=(kosuu_ls[i])
print(sub)
#print(kosuu_ls)


### FIXED CODE ###

def gcd_cnt(n):
    sub = 0
    for i in range(1, n+1):
        kosuu = n//i
        sub+=kosuu*(2*i + (kosuu-1)*i)//2
    return sub

n = int(input())
sub = gcd_cnt(n)
print(sub)
### BUGGY CODE ###

import re
h,w = map(int, input().split())
m=[]
d = [[0]*w for _ in range(h)]
u = [[0]*w for _ in range(h)]
for _ in range(h):
  t=[]
  for i in re.split("(#)", input()):
    if not i == "#":
      t.extend([len(i)]*len(i))
    else:
      t.append(0)
  m.append(t)

for i in range(w):
  for j in range(h):
    if m[j][i] == 0:
      d[j][i] = 0
    else:
      if j != 0:
        d[j][i] = d[j-1][i] + 1
      else:
        d[j][i] = 1

    if m[h-1-j][i] == 0:
      u[h-1-j][i] = 0
    else:
      if h-1-j == h-1:
        u[h-1-j][i] = 1
      else:
        u[h-1-j][i] = u[h-j][i] + 1
ans=0
for i in range(w):
  for j in range(h):
    ans = max(ans, u[j][i]+d[j][i]+m[j][i])
print(ans - 2)

### FIXED CODE ###

import re
h,w = map(int, input().split())
m=[]
d = [[0]*w for _ in range(h)]
u = [[0]*w for _ in range(h)]
for _ in range(h):
  t=[]
  for i in re.split("(#)", input()):
    if not i == "#":
      t.extend([len(i)]*len(i))
    else:
      t.append(0)
  m.append(t)

for i in range(w):
  for j in range(h):
    if m[j][i] == 0:
      d[j][i] = 0
    else:
      if j != 0:
        d[j][i] = d[j-1][i] + 1
      else:
        d[j][i] = 1

    if m[h-1-j][i] == 0:
      u[h-1-j][i] = 0
    else:
      if h-1-j == h-1:
        u[h-1-j][i] = 1
      else:
        u[h-1-j][i] = u[h-j][i] + 1
ans=0
for i in range(w):
  for j in range(h):
    ans = max(ans, u[j][i]+d[j][i]+m[j][i])
print(ans - 2)
### BUGGY CODE ###

import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	if K <= 10 ** 5:
		loc = 0
		for i in range(K):
			loc = A[loc] - 1
		print(loc + 1)
		return

	loc = 0
	for i in range(10 ** 5):
			loc = A[loc] - 1

	start = loc
	loop = [loc]
	loc = A[loc] - 1
	while loc != start:
		loop.append(loc)
		loc = A[loc] - 1

	M = len(loop)
	ans = loop[(K - 10 ** 5) % M]
	print(ans + 1)
	
	




if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	if K <= 2 * (10 ** 5):
		loc = 0
		for i in range(K):
			loc = A[loc] - 1
		print(loc + 1)
		return

	loc = 0
	for i in range(2 * (10 ** 5)):
			loc = A[loc] - 1

	start = loc
	loop = [loc]
	loc = A[loc] - 1
	while loc != start:
		loop.append(loc)
		loc = A[loc] - 1

	M = len(loop)
	ans = loop[(K - 2 * (10 ** 5)) % M]
	print(ans + 1)
	
	




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

n,m=map(int,input().split())
a=m//n
ans=1
for i in range(1,a+1):
    if m%i==0:
        ans=max(ans,i)
print(ans)


### FIXED CODE ###

import sys
n,m=map(int,input().split())
a=m//n
ans=1
if m%n==0:
  print(int(m//n))
  sys.exit()
for i in range(1,a+1):
    if m%i==0:
        ans=max(ans,i)
print(ans)
### BUGGY CODE ###

N = int(input())
TA = [tuple(map(int, input().split())) for i in range(N)]

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N):
    j = 1
    while tak > TA[i][0]*j or aok > TA[i][1]*j:
        j += 1
    tak = TA[i][0] * j
    aok = TA[i][1] * j

print(tak+aok)

### FIXED CODE ###

N = int(input())
TA = [tuple(map(int, input().split())) for i in range(N)]

def floordiv(a,b):
    return (a+b-1)//b

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N): 
    mul = max(floordiv(tak,TA[i][0]), floordiv(aok,TA[i][1]))
    tak = TA[i][0] * mul
    aok = TA[i][1] * mul

print(tak+aok)