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

N, X, M = map(int, input().split())
NN = N
li = []
while X not in li and N != 0:
    li = li + [X]
    X = X ** 2 % M
    N -= 1
    
if N == 0:
    print(sum(x for x in li))

elif N != 0 and X in li:
    l = len(li)
    s = li.index(X)
    T = l - s
    q = (NN - s) // T
    r = (NN - s) % T
    print(sum(li[i] for i in range(s)) + sum(li[i] for i in range(s, len(li))) * q
              + sum(li[i] for i in range(s, s + r)))

### FIXED CODE ###

N, X, M = map(int, input().split())
NN = N
li = []
isused = [False] * M
while isused[X] == False and N != 0:
    li.append(X)
    isused[X] = True
    X = (X ** 2) % M
    N -= 1
    
if N == 0:
    print(sum(li))

elif N != 0 and X in li:
    l = len(li)
    s = li.index(X)
    T = l - s
    q = (NN - s) // T
    r = (NN - s) % T
    print(sum(li) + sum(li[i] for i in range(s, len(li))) * (q-1) + sum(li[i] for i in range(s, s + r)))
### BUGGY CODE ###

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

for n in range(N):
    print(A.count(n+1))


### FIXED CODE ###

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

#for n in range(N):
#    print(A.count(n+1))

M = {}
for a in A:
    M[a] = M.get(a,0) + 1

for n in range(N):
    print(M.get(n+1,0))
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
def INT(m):
  if int(m)==m:
    return True
  else:
    return False
ans=0
a=[r,g,b]
a.sort()
r,g,b=a[0],a[1],a[2]
for i in range(n//b + 1):
  for j in range((n-i*b)//g + 1):
    if INT((n-i*b-j*g)/r):
      ans+=1
print(ans)

### FIXED CODE ###

r,g,b,n=map(int,input().split())
def INT(m):
  if int(m)==m:
    return True
  return False
aa=[r,g,b]
aa.sort()
a,b,c=aa[0],aa[1],aa[2]
ans=0
for i in range(n//c +1):
  for j in range((n-i*c)//b +1):
    if INT((n-i*c-j*b)/a):
      ans+=1
print(ans)
### BUGGY CODE ###

K, S = map(int, input().split())

count = 0

x = 0
while (x <= K):
    y = 0
    while (y <= K):
        z = 0
        while (z <= K):
            if x + y + z == S:
                count += 1
            z += 1
        y += 1
    x += 1

print(count)

### FIXED CODE ###

K, S = map(int, input().split())

count = 0

x = 0
while (x <= K):
    y = 0
    while (y <= K):
        if 0 <= S - (x + y) <= K:
            count += 1
        y += 1
    x += 1



print(count)
### BUGGY CODE ###

import numpy as np

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

a = []
b = []
m = []
for i in range(n):
    at, bt = map(int, input().split()) # a_tmp, b_tmp
    a.append(at)
    b.append(bt)

dp = np.zeros((n+1,h+1))
dp = [[0] * (h+1) for i in range(n+1)]
# print(dp2)

for i in range(n):
    for j in range(h):
        # print("Test")
        if j - a[i] < 0:
            o = b[i]
        else:
            o = dp[i+1][j+1-a[i]] + b[i]
        if i != 0:
            dp[i+1][j+1] = min(dp[i][j+1], o)
        else:
            dp[i+1][j+1] = o

print(int(dp[n][h]))

### FIXED CODE ###

#import numpy as np

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

a = []
b = []
m = []
for i in range(n):
    at, bt = map(int, input().split()) # a_tmp, b_tmp
    a.append(at)
    b.append(bt)

#dp = np.zeros((n+1,h+1))
dp = [[0]*(h+1) for _ in range(n+1)]
for i in range(n):
    for j in range(h):
        # print("Test")
        if j - a[i] < 0:
            o = b[i]
        else:
            o = dp[i+1][j+1-a[i]] + b[i]
        if i != 0:
            dp[i+1][j+1] = min(dp[i][j+1], o)
        else:
            dp[i+1][j+1] = o

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

N = int(input())
a = list(map(int,input().split()))
count = 0
k = 1
for i in range(N):
    if a[0] != k:
        a.pop(0)
        count += 1
    else:
        a.pop(0)
        k += 1
if k == 1:
    print(-1)
else:
    print(count)



### FIXED CODE ###

from collections import deque
N = int(input())
a = list(map(int,input().split()))
a = deque(a)
count = 0
k = 1
for i in range(N):
    if a[0] != k:
        a.popleft()
        count += 1
    else:
        a.popleft()
        k += 1
if k == 1:
    print(-1)
else:
    print(count)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
nedan_list = []
for i in range(n):
  price = a[i]
  nedan_list.append((i, price))
  while price > 1:
    price //= 2
    nedan_list.append((i, price))

nedan_list.sort(key=lambda x:x[1], reverse=True)
count = 0
saisyo_list = [True]*n
for e in nedan_list[m:]:
  if saisyo_list[e[0]]:
    saisyo_list[e[0]] = False
    count += e[1]
print(count)

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a) 

for i in range(m):
  max_ = -heapq.heappop(a)
  d = max_ // 2
  heapq.heappush(a, -d)

c = 0
for i in range(len(a)):
  c -= heapq.heappop(a)
print(c)
### BUGGY CODE ###

#----グローバル変数----
INF = 10**10 #無限大（最小化問題の場合）
dp=[]       #DPテーブル

h=[]   #足場の高さ
#----------------------

#----関数----

#DPテーブル更新関数　最小化用＆最大化用
def chmin(dp, idx, new_val):
    if dp[idx] > new_val:
        dp[idx] = new_val
        return True
    return False

def chmax(dp, idx, new_val):
    if dp[idx] < new_val:
        dp[idx] = new_val
        return True
    return False
#------------


#----実行開始----
# 入力
n,k = map(int, input().split())

s = input()
h = [int(x) for x in s.split()]

# DPテーブル初期化 (最小化問題なので INF に初期化)
for i in range(n):
    dp.append(INF)

# 初期条件
dp[0] = 0;

# ジャンプのループ
for i in range(1,n):
    farthest = max(0,i-k)
    for j in range(farthest,i):
        # jp check    
        jpcost = abs(h[j]-h[i])
        chmin(dp,i,dp[j]+jpcost)

# 出力
print(dp[n-1])

#---------------


### FIXED CODE ###

#----グローバル変数----
INF = 10**10 #無限大（最小化問題の場合）
dp=[]       #DPテーブル

h=[]   #足場の高さ
#----------------------

#----関数----

#DPテーブル更新関数　最小化用＆最大化用
def chmin(dp, idx, new_val):
    if dp[idx] > new_val:
        dp[idx] = new_val
        return True
    return False

def chmax(dp, idx, new_val):
    if dp[idx] < new_val:
        dp[idx] = new_val
        return True
    return False
#------------


#----実行開始----
# 入力
n,k = map(int, input().split())

s = input()
h = [int(x) for x in s.split()]

# DPテーブル初期化 (最小化問題なので INF に初期化)
for i in range(n):
    dp.append(INF)

# 初期条件
dp[0] = 0;

# ジャンプのループ
for i in range(1,n):
    farthest = max(0,i-k)
    for j in range(farthest,i):
        # jp check    
        jpcost = abs(h[j]-h[i])
        chmin(dp,i,dp[j]+jpcost)

# 出力
print(dp[n-1])

#---------------
### BUGGY CODE ###

s = input()[::-1]

cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in s:
    total += int(i) * x
    total %= 2019
    x *= 10 % 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)


### FIXED CODE ###

s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

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

n, k = map(int,input().split())
while n > k/2:
    n = abs(n - k)
print(n)

### FIXED CODE ###

n, k = map(int,input().split())
a = n // k
n = n - a*k
while n > k/2:
    n = abs(n - k)
print(n)
### BUGGY CODE ###

s = str(input())
t = str(input())

dp=[[0 for i in range(len(s)+1)] for j in range(len(t)+1)] 

for i in range(1,len(s)+1):
    for u in range(1,len(t)+1):
        if s[i-1]==t[u-1]:
            dp[u][i]=dp[u-1][i-1]+1
        else:
            dp[u][i]=max(dp[u-1][i],dp[u][i-1])
lenth=dp[-1][-1]
i=len(s)
j=len(t)
ans=""
while lenth>0:
    if s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        i-=1
        j-=1
        lenth-=1
    elif dp[j][i]==dp[j-1][i]:
        j-=1
    else:
        i-=1
    lenth=dp[j][i]
print(ans)

### FIXED CODE ###

s = str(input())
t = str(input())

dp=[[0 for i in range(len(s)+1)] for j in range(len(t)+1)] 

for i in range(1,len(s)+1):
    for u in range(1,len(t)+1):
        if s[i-1]==t[u-1]:
            dp[u][i]=dp[u-1][i-1]+1
        else:
            dp[u][i]=max(dp[u-1][i],dp[u][i-1])
lenth=dp[-1][-1]
i=len(s)
j=len(t)
ans=""
while lenth>0:
    if s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        i-=1
        j-=1
        lenth-=1
    elif dp[j][i]==dp[j-1][i]:
        j-=1
    else:
        i-=1
    lenth=dp[j][i]
print(ans)
### BUGGY CODE ###

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

for i in range(N):
    num = A[i]
    ans *= num

if ans > 10**18:
    ans = -1

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
check = 10 ** 18

for i in range(N):
    num = A[i]
    ans *= num
    if ans > check:
        ans = -1
        break
    elif ans == 0:
        break

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

S = input()
Q = int(input())
flip = 0
for i in range(Q):
    query = input()
    if query == str(1):
        flip += 1
    else:
        f = int(query[2])
        c = query[-1]
        if f == 1:
            if flip%2 == 1:
                S = S + c
            else:
                S = c + S
        else:
            if flip%2 == 1:
                S = c + S
            else:
                S = S + c
if flip%2 == 1:
    print(S[::-1])
else:
    print(S)

### FIXED CODE ###

from collections import deque
X = input()
S = deque()
for e in X:
    S.append(e)
Q = int(input())
flip = 0
for i in range(Q):
    query = input()
    if query == str(1):
        flip += 1
    else:
        f = int(query[2])
        c = query[-1]
        if f == 1:
            if flip%2 == 1:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if flip%2 == 1:
                S.appendleft(c)
            else:
                S.append(c)
S = "".join(S)
if flip%2 == 1:
    print(S[::-1])
else:
    print(S)
### BUGGY CODE ###

p=0
N,K=map(int,input().split())
a,b,c=map(int,input().split())
s=input()
L=list()
L_append = L.append
for i in range(N):
  if i<K:
    if s[i]=="r":
      p+=c
      L_append(i)
    elif s[i]=="s":
      p+=a
      L_append(i)
    else:
      p+=b
      L_append(i)
  else:
    if s[i]=="r" and s[i-K]!="r":
      p+=c
      L_append(i)
    elif s[i]=="s" and s[i-K]!="s":
      p+=a
      L_append(i)
    elif s[i]=="p" and s[i-K]!="p":
      p+=b
      L_append(i)
    if s[i]=="r" and s[i-K]=="r" and i-K not in L:
      p+=c
      L_append(i)
    if s[i]=="s" and s[i-K]=="s" and i-K not in L:
      p+=a
      L_append(i)
    if s[i]=="p" and s[i-K]=="p" and i-K not in L:
      p+=b
      L_append(i)
print(p)

### FIXED CODE ###

p=0
N,K=map(int,input().split())
a,b,c=map(int,input().split())
s=input()
L=list()
L_append = L.append
for i in range(N):
  if i<K:
    if s[i]=="r":
      p+=c
      L_append(i)
    elif s[i]=="s":
      p+=a
      L_append(i)
    else:
      p+=b
      L_append(i)
  else:
    if s[i]=="r" and s[i-K]!="r":
      p+=c
      L_append(i)
    elif s[i]=="s" and s[i-K]!="s":
      p+=a
      L_append(i)
    elif s[i]=="p" and s[i-K]!="p":
      p+=b
      L_append(i)
    if s[i]=="r" and s[i-K]=="r" and i-K not in L:
      p+=c
      L_append(i)
    elif s[i]=="s" and s[i-K]=="s" and i-K not in L:
      p+=a
      L_append(i)
    elif s[i]=="p" and s[i-K]=="p" and i-K not in L:
      p+=b
      L_append(i)
print(p)
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
s = [0] * 30
t = [1] * 30
for i in range(29):
    t[i + 1] = t[i] * 2
for i in range(N):
    aa = a[i]
    for j in range(30):
        if aa == 0:
            break
        s[j] += aa%2
        aa = aa//2
for i in range(30):
    s[i] = s[i]%2
for i in range(N):
    ans1 = [0] * 30
    ans = a[i]
    for j in range(30):
        ans1[j] = a[i]%2
        a[i] = a[i]//2
        if s[j] == 1:
            if ans1[j] == 1:
                ans -= t[j] 
            else:
                ans += t[j]
    print(ans,end = " ")
print()

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
s = [0] * 30
t = [1] * 30
for i in range(29):
    t[i + 1] = t[i] * 2
ss = a[0]
for j in range(N - 1):
    ss = ss ^ a[j + 1]
for j in range(N):
    print(a[j] ^ ss,end = " ")
print()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
bidx = 0
cidx = 0
abnums = [0] * (N+1)
bcnums = [0] * (N+1)
idx = 0
for i, a in enumerate(A):
    abnums[i+1] = abnums[i]
    if abnums[i+1] == N:
        continue
    for j, b in enumerate(B[idx:]):
        if a < b:
            abnums[i+1] += 1
        else:
            idx = j + idx
            break

idx = 0
for i, b in enumerate(B):
    bcnums[i+1] = bcnums[i]
    if bcnums[i+1] == N:
        continue
    for j, c in enumerate(C[idx:]):
        if b < c:
            bcnums[i+1] += 1
        else:
            idx = j + idx
            break

ans = 0
for n in abnums[1:]:
    ans += sum(bcnums[1:n+1])
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)
### BUGGY CODE ###

import copy
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))

c.sort()
c2 = copy.copy(c)
b_limit = 0
c_limit =0
count =0
c_count =0

for i in a:
    c_count =0
    c = copy.copy(c2)
    if b_limit == 1:
        break
    for j in  reversed(range(len(b))):
        if b[j] <= i:
            if b[j] == max(b):
                b_limit +=1
            break
        else:
            if len(c) ==0:
                count +=c_count
                continue
        for k in reversed(range(len(c))):
            if c[k] <= b[j]:
                count += c_count
                break
            c.pop(k)
            c_count +=1
            if k == 0:
                count +=c_count


print(count)



### FIXED CODE ###

import bisect

ans =0

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

for i in b:
    s = bisect.bisect_right(c,i)
    s_num = n-s

    t = bisect.bisect_left(a,i)
    t_num = t

    ans += s_num * t_num

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


n,y=map(int,input().split())
i,j,f=0,0,0
for i in range(y//10000+1):
    a=y-10000*i
    for j in range(a//5000+1):
        p=a-5000*j
        for f in range(p//1000+1):
            o=p-1000*f
            if p>(n-(i+j))*1000:
                break
            elif o==0 and i+j+f==n:
                print(i,j,f)
                exit()
print(-1,-1,-1)

### FIXED CODE ###

n,y=map(int,input().split())
i,j,f=0,0,0
for i in range(y//10000+1):
    a=y-10000*i
    for j in range(a//5000+1):
        p=a-5000*j
        if i+j+p//1000==n:
            print(i,j,p//1000)
            exit()
print(-1,-1,-1)
### BUGGY CODE ###

N, K = map(int, input().split())
D = K.bit_length()
to = [[0] * D for _ in range(N)]

for i, a in enumerate(map(int, input().split())):
    to[i][0] = a - 1

for j in range(D - 1):
    for i in range(N):
        h = to[i][j]
        to[i][j+1] = to[h][j]

v = 0
for i in reversed(range(D)):
    x = 1 << i
    if x <= K:
        v = to[v][i]
        K -= x

print(v + 1)

### FIXED CODE ###

N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

first = [0] * (N + 1)
second = [0] * (N + 1)
roop1 = []
roop2 = []

now = 1
while True:
    if not first[now]:
        first[now] = 1
        roop1.append(now)
        now = A[now]
    elif not second[now]:
        second[now] = 1
        roop2.append(now)
        now = A[now]
    else:
        break


if K < len(roop1):
    print(roop1[K])
else:
    K -= len(roop1)
    m = K % len(roop2)
    print(roop2[m])
### BUGGY CODE ###

n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
if a == 0:
    print(0)
    exit(0)
while count < 10**100:
    n -= a
    tmp += a
    if n <= 0:
        print(tmp + n)
        break
    n -= b
    if n <= 0:
        print(tmp)
        break
    

### FIXED CODE ###

n, a, b = list(map(int, input().split(' ')))
if a == 0:
    print(0)
elif n % (a+b) <= a:
    print(a*(n // (a+b))+ n % (a+b))
else:
    print( a*(n // (a+b))+a)
### BUGGY CODE ###

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

if n == 2:
    print(abs(a[1]) * 2)
    print(abs(a[0]) * 2)
else:
    for i in range(len(a)):
        b = a[:]
        b.remove(b[i])
        #print(b)
        
        cost = abs(b[0]) + abs(b[-1])
        for i in range(len(b)-1):
            cost += abs(b[i] - b[i+1])
        print(cost)

### FIXED CODE ###

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

a.insert(0,0)
a.append(0)

total = 0
for i in range(len(a)-1):
    total += abs(a[i] - a[i+1])

for j in range(1, len(a)-1):
    print(total - abs(a[j-1] - a[j]) - abs(a[j] - a[j+1]) + abs(a[j+1]- a[j-1]))
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = [input() for _ in range(N)]

col_S = [Counter(s) for s in S]

cnt = 0
for ind, col_s in enumerate(col_S):
    for ref_ind, ref_col_s in enumerate(col_S[ind+1:]):
        if col_s == ref_col_s: cnt += 1

print(cnt)

### FIXED CODE ###

N = int(input())
lS = [list(input()) for _ in range(N)]
S = [''.join(sorted(s)) for s in lS]
S = sorted(S)

cnt = 1
S.append('end')
last = S[0]
res = 0
for s in S[1:]:
    if last == s:
        cnt += 1
    else:
        res += cnt * (cnt-1) /2
        last = s
        cnt = 1

print(int(res))
### BUGGY CODE ###

n, k = map(int, input().split())
xy = []
for _ in range(n):
  xy.append(tuple(map(int, input().split())))

mins = None
for i, _xl in enumerate(xy):
  for _xr in xy[i:]:
    for j, _yu in enumerate(xy):
      for _yd in xy[j:]:
        c = 0
        for _xy in xy:
          if min(_xl[0], _xr[0]) <= _xy[0] <= max(_xl[0], _xr[0]) and min(_yd[1], _yu[1]) <= _xy[1] <= max(_yd[1], _yu[1]):
            c += 1
        if c >= k:
          if mins is None:
            mins = abs(_xl[0] - _xr[0]) * abs(_yu[1] - _yd[1])
          elif mins > abs(_xl[0] - _xr[0]) * abs(_yu[1] - _yd[1]):
            mins = abs(_xl[0] - _xr[0]) * abs(_yu[1] - _yd[1])
print(mins)

### FIXED CODE ###

from itertools import combinations

n, k = map(int, input().split())
xlist, ylist, xy = [], [], []
for _ in range(n):
  x, y = map(int, input().split())
  xlist.append(x)
  ylist.append(y)
  xy.append((x, y))

xlist.sort()
ylist.sort()
ans = (xlist[-1] - xlist[0]) * (ylist[-1] - ylist[0])
for x1, x2 in combinations(xlist, r=2):
  for y1, y2 in combinations(ylist, r=2):
    tmpk = 0
    for i in range(n):
      if x1 <= xy[i][0] <= x2 and y1 <= xy[i][1] <= y2:
        tmpk += 1

      if tmpk >= k:
        tmp_ans = (x2 - x1) * (y2 - y1)
        if ans > tmp_ans:
          ans = tmp_ans

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

from fractions import gcd
N, M = map(int, input().split())
if M%N==0:
  print(M//N)
else:
  c = M%N
  b = M//N
  ls = []
  ans = 0
  for i in range(1,b+1):
    x = M - i*N
    if gcd(i,x)>ans:
      ans = gcd(i,x)
  print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
ls = []
for i in range(1,M+1):
  if M%i==0:
    j = M//i
    if i<=M//N:
      ls += [i]
    if j<=M//N:
      ls += [j]
  if M**0.5<i:
    break
print(max(ls))
### BUGGY CODE ###

N=int(input())

A=[]
A=list(map(int,input().split()))
for i in range(1,N+1):
    print(A.count(i))


### FIXED CODE ###

N=int(input())
Acount=[0 for i in range(N)]
A=list(map(int,input().split()))
for i in range(N-1):
    Acount[A[i]-1]+=1
for i in range(N):
    print(Acount[i])
### BUGGY CODE ###

# (1,2,3,4,5..,N) + (1,2,3,4,...,N/2) * 2 + (1,2,...,N/3) * 3 + ...+(1,) * N
# 累積和を使うことでO(1)でそれぞれの計算をする．N回ループをするので，合計O(N)の計算量で終了する

N = int(input())

S=[0]*(N+1)
for i in range(1,N+1):
    S[i] = S[i-1] + i

ans = 0
for i in range(1,N+1):
    ind = int(N/i)
    ans += S[ind] * i

print(ans)



### FIXED CODE ###

# (1,2,3,4,5..,N) + (1,2,3,4,...,N/2) * 2 + (1,2,...,N/3) * 3 + ...+(1,) * N
# 累積和を使うことでO(1)でそれぞれの計算をする．N回ループをするので，合計O(N)の計算量で終了する

N = int(input())

S=[0]*(N+1)
for i in range(1,N+1):
    S[i] = S[i-1] + i

ans = 0
for i in range(1,N+1):
    ind = int(N/i)
    ans += S[ind] * i

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

import math

def comb(n, r):
    if n < 2:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

string = []
count = 0

for i in range(n):
    string.append("".join(sorted(input())))

base = len(string)
string_set = list(set(string))

if base == len(string_set):
    print(0)
else:
    total = 0
    for ref in string_set:
        total += (comb(string.count(ref), 2))
    print(total)


### FIXED CODE ###

n = int(input())
 
string = {}
count = 0

for i in range(n):
    base = sorted(input())

    if string.get("".join(base)) != None:
        count += int(string["".join(base)])
        string["".join(base)] += 1
    else:
        string["".join(base)] = 1

print(count)
### BUGGY CODE ###

import sys
n = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()
f = False
for l in range(n//2, 0, -1):
    for j in range(n):
        ptn = S[j:j+l]
        if j+l ==n:
            break
        #print(ptn)
        if ptn in S[j+l:]:
            print(l)
            f = True
            break
    if f == True:
        break
else:
    print(0)

### FIXED CODE ###

import sys
n = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


dp = [[0 for i in range(n)] for j in range(n)]
#初期条件
for j in range(1, n):
    if S[0] == S[j]:
        dp[0][j] = 1

#print(dp)

for i in range(1, n-1):
    for j in range(i+1, n):
        if S[i] ==S[j]:
            dp[i][j] = min(dp[i-1][j-1] +1, j-i)

maxp = 0
for i in range(n-1):
    for j in range(i+1, n):
        if maxp < dp[i][j]:
            maxp = dp[i][j]
#print(dp)
print(maxp)
### BUGGY CODE ###

n, m = map(int, input().split())
x = [[int(j) for j in input().split()] for i in range(n)]
a = []
b = []
for i in range(n):
  a.append(x[i][0])
  b.append(x[i][1])
mon = 0
cnt = 0
ind = 100000
while(cnt < m):
  min = 10000000000
  for i in range(n):
    if a[i] < min:
      min = a[i]
      ind = i
  while(b[ind] > 0 and cnt != m):
    cnt += 1
    mon += a[ind]
    b[ind] -= 1
  a[ind] = 100000000000
print(mon)

### FIXED CODE ###

import math
n, m = map(int, input().split())
a = []
for i in range(n):
    l = list(map(int, input().split()))
    a.append(l)
a.sort(key=lambda x: x[0])
sum = 0
cnt = 0
for i in range(n):
    if cnt + a[i][1] >= m:
        sum += (m-cnt)*a[i][0]
        cnt += m-cnt
        break
    else:
        sum += a[i][0]*a[i][1]
        cnt += a[i][1]
print(sum)
### BUGGY CODE ###

n,ng = map(int,input().split())
nglist = list(int(input()) for i in range(ng))

MOD   = 10**9+7 
dp    = [0]*(n+1)
dp[0] = 1

for i in range(1,n+1):

  if i in nglist:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])

### FIXED CODE ###

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

MOD    = 10**9+7 
nglist = [0]*(n+1)
dp     = [0]*(n+1)
dp[0]  = 1

for i in range(ng):
  x = int(input())
  nglist[x] = 1
 
for i in range(1,n+1):

  if nglist[i]==1:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

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

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

rec = [0] * n

def check(k):
    off = []
    on = []
    flag = 0
    for i in range(n):
        if (a[i]>>k)&1:
            flag += 1
            on.append(i)
        else:
            off.append(i)

    if flag%2 == 0:
        for i in on:
            rec[i] += pow(2, k)
    else:
        for i in off:
            rec[i] += pow(2, k)

for i in range(31):
    check(i)
print(*rec)



### FIXED CODE ###

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

rec = [0] * n

def check(k):
    off = []
    on = []
    flag = 0
    for i in range(n):
        if (a[i]>>k)&1:
            flag += 1
            on.append(i)
        else:
            off.append(i)

    if flag%2 == 0:
        for i in on:
            rec[i] += pow(2, k)
    else:
        for i in off:
            rec[i] += pow(2, k)

for i in range(31):
    check(i)
print(*rec)