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

def main():
    n=int(input())
    ans=0
    bit=[0]*60
    seki=10**9+7
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(60):
            if a[i]%2==1:
                bit[j]+=1
            a[i]=a[i]>>1
    for i in range(60):
        ans+=(bit[i]*(n-bit[i]))*(2**i)
    print(ans%seki)
main()


### FIXED CODE ###

def main():
    n=int(input())
    ans=0
    bit=[0]*60
    seki=10**9+7
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(60):
            if a[i]%2==1:
                bit[j]+=1
            a[i]=a[i]>>1
    for i in range(60):
        ans+=(bit[i]*(n-bit[i]))*(2**i)
    print(ans%seki)
main()
### BUGGY CODE ###

import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

X,Y,Z,K = LI()
A = LI()
B = LI()
C = LI()


A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = A[0] + B[0] + C[0]
l = 0
while h > l+1:
    m = (h+l) // 2

    num = 0
    for a in A:
        for i in B:
            j = len(C) - 1
            while i + C[j] < m - a:
                j -= 1
                if j < 0: break
            else:
                num += j + 1
                continue
            break
    if num > K:
        l = m
    else:
        h = m

ans = []
for a in A:
    for i in B:
        j = len(C) - 1
        while i + C[j] < l - a:
            j -= 1
            if j < 0: break
        else:
            for k in range(j+1):
                ans.append(a+i+C[k])
ans.sort(reverse=True)
print (*ans[:K],sep='\n')



### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

X,Y,Z,K = LI()
A = LI()
B = LI()
C = LI()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = A[0] + B[0] + C[0]
l = 0
while h > l+1:
    m = (h+l) // 2

    num = 0
    for a in A:
        j = len(C) - 1
        for i in B:
            while i + C[j] < m - a:
                j -= 1
                if j < 0: break
            else:
                num += j + 1
                continue
            break
    if num > K:
        l = m
    else:
        h = m

ans = []
cnt = 0
for a in A:
    j = len(C) - 1
    last_cnt = cnt
    for i in B:

        while i + C[j] <= l - a:
            j -= 1
            if j < 0: break
        else:
            for k in range(j+1):
                ans.append(a+i+C[k])
                cnt += 1
            continue
        break
ans.sort(reverse=True)
for _ in range(K-len(ans)):
    ans.append(l)
print (*ans[:K],sep='\n')
### BUGGY CODE ###

import numpy as np

H,W = map(int,input().split())
grid = np.zeros((H+2,W+2), dtype=bool)
grid[1:-1, 1:-1] = tuple(tuple(map(lambda c: c != '#', input())) for _ in range(H))

scores = np.zeros((H+2, W+2), dtype=int)

for i in range(1, H+1):
    s = 0
    for j in range(1,W+1):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0

for i in range(1, H+1):
    s = 0
    for j in reversed(range(1,W+1)):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0

for j in range(1, W+1):
    s = 0
    for i in range(1,H+1):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0

for j in range(1, W+1):
    s = 0
    for i in reversed(range(1,H+1)):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0


print(scores.max()+1)

### FIXED CODE ###

from itertools import chain

H,W = map(int,input().split())
grid = tuple(tuple(map(lambda c: c != '#', input())) for _ in range(H))

scores = [[0]*W for _ in range(H)]

for i in range(H):
    s = 0
    for j in range(W):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0

for i in range(H):
    s = 0
    for j in reversed(range(W)):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0

for j in range(W):
    s = 0
    for i in range(H):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0

for j in range(W):
    s = 0
    for i in reversed(range(H)):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0


print(1 + max(chain.from_iterable(scores)))
### BUGGY CODE ###

#python3
#python3
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
MOD = int(1e9+7)
ans=0
for k in range(60):
  x=0
  t=1<<k
  for i in range(n):
    if a[i]&t:
      x+=1
  c=x*(n-x)*2**k
  ans+=c
print(ans%MOD)



### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mxbit = 0
for i in range(N):
  mxbit = max(mxbit, a[i].bit_length())
cs = [0] * mxbit
for i in range(N):
  for j in range(mxbit):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    x = (a[i] & t) > 0
    cs[j] += x
res = 0
#print(cs[-1])
#print(cs)
for i in range(N):
  t = 0
  for j in range(mxbit):
    x = 1 << j
    if a[i] & x != 0:
      x %= mod
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += x * (N - (cs[j]))
    else:
      x %= mod
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += x * cs[j]
    #print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod * pow(2, mod - 2, mod) % mod)
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.readline # for speed up

n,k=map(int,input().split())
k=min(k,n)
h=list(map(int,input().split()))

c=[0]*n
for ii in np.arange(1,k):
  for jj in range(ii):
    cjj=c[jj]+abs(h[ii]-h[jj])
    #print(ii,jj,cjj)
    if jj==0:
      c[ii]=cjj
    elif c[ii]>cjj:
      c[ii]=cjj
"""
c[1]=c[0]+abs(h[1]-h[0])
c[2]=min(c[0]+abs(h[2]-h[0]),c[1]+abs(h[2]-h[1]))
c[3]=min(c[0]+abs(h[3]-h[0]),c[1]+abs(h[3]-h[1]),c[2]+abs(h[3]-h[2]))
"""

#print(c)

for ii in np.arange(k,n):
  for jj in np.arange(ii-k,ii):
    cjj=c[jj]+abs(h[ii]-h[jj])
    #print(ii,jj,cjj)
    if jj==ii-k:
      c[ii]=cjj
    elif c[ii]>cjj:
      c[ii]=cjj
#print(c)

print(c[n-1])

### FIXED CODE ###

import numpy as np
import sys
input=sys.stdin.readline # for speed up

n,k=map(int,input().split())
k=min(k,n)
h=list(map(int,input().split()))

c=[0]*n
kn=np.arange(1,k)
h0=h[0]
c0=c[0]
for (ii,hii) in zip(kn,h[1:k]):
  #hii=h[ii]
  cii=c0+abs(hii-h0)
  for (cjj,hjj) in zip(c[1:ii],h[1:ii]):
    if cii>cjj:
      #cii=min(cii,cjj+abs(hii-hjj))
      if hii==hjj:
        #cii=min(cii,cjj)
        cii=cjj
      elif hii>hjj:
        if cii>cjj+hii-hjj:
          cii=cjj+hii-hjj
      elif cii>cjj-hii+hjj:
        cii=cjj-hii+hjj
  c[ii]=cii
"""
c[1]=c[0]+abs(h[1]-h[0])
c[2]=min(c[0]+abs(h[2]-h[0]),c[1]+abs(h[2]-h[1]))
c[3]=min(c[0]+abs(h[3]-h[0]),c[1]+abs(h[3]-h[1]),c[2]+abs(h[3]-h[2]))
"""
#print(c)
kn=np.arange(k,n)
for (ii,hii,hiik) in zip(kn,h[k:n],h[0:n-k]):
  #hii=h[ii]
  cii=c[ii-k]+abs(hii-hiik)
  for (cjj,hjj) in zip(c[ii-k+1:ii],h[ii-k+1:ii]):
    if cii>cjj:
      #cii=min(cii,cjj+abs(hii-hjj))
      if hii==hjj:
        #cii=min(cii,cjj)
        cii=cjj
      elif hii>hjj:
        if cii>cjj+hii-hjj:
          cii=cjj+hii-hjj
      elif cii>cjj-hii+hjj:
        cii=cjj-hii+hjj
  c[ii]=cii
  #print(c)
print(c[n-1])
### BUGGY CODE ###

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

mod = 10 ** 9 + 7
sum = 0

for i in range(n):
    for j in range(i + 1, n):
        sum += a[i] * a[j] % mod

sum %= mod
print(sum)

### FIXED CODE ###

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

mod = 10 ** 9 + 7
s = sum(a)
sum = 0

for i in range(n):
    s -= a[i]
    sum += s * a[i] % mod

sum %= mod
print(sum)
### BUGGY CODE ###

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

dp = [[0] * N for _ in range(N)]

dp[-1] = [1 if s == S[-1] else 0 for s in S]
for i in range(N-2, -1, -1):
    dp[i][-1] = 1 if S[i] == S[-1] else 0
    for j in range(N-2, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if dp[i][j] > 0:
            ans = max(ans, min(dp[i][j], j-i))

print(ans)


### FIXED CODE ###

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

dp = [[0] * N for _ in range(N)]

dp[-1] = [1 if s == S[-1] else 0 for s in S]
for i in range(N-2, -1, -1):
    dp[i][-1] = 1 if S[i] == S[-1] else 0
    for j in range(N-2, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if dp[i][j] > 0:
            ans = max(ans, min(dp[i][j], j-i))

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

H, W = map(int, input().split())
s = [[c for c in input()] for i in range(H)]
s_vrt = [[s[i][j] for i in range(H)] for j in range(W)]
# 0: lr, 1: up
memo = [[[-1, -1] for j in range(W)] for i in range(H)]

def count_light_place(i, j):
    line_lr = s[i]
    line_up = s_vrt[j]
    m = memo[i][j]
    c_lr = m[0]
    if c_lr == -1:
        c_lr = count_light_line(j, line_lr)
        memo[i][j][0] = c_lr

    c_up = m[1]
    if c_up == -1:
        c_up = count_light_line(i, line_up)
        memo[i][j][1] = c_up

    return c_lr + c_up - 1

def count_light_line(k, line):
    count = 0
    for dn in reversed(range(k)):
        if line[dn] == '#':
            break
        count += 1
 
    for up in range(k, len(line)):
        if line[up] == '#':
            break
        count += 1
    return count 


count_max = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            continue
        count = count_light_place(i, j)
        if count_max < count:
            count_max = count

print(count_max)

### FIXED CODE ###

import numpy as np


H, W = map(int, input().split())
s = np.array([[c for c in input()] for i in range(H)]) == '.'
s_t = s.transpose()

dp_l = np.zeros((W, H), dtype=int)
dp_r = np.zeros((W, H), dtype=int)
dp_u = np.zeros((H, W), dtype=int)
dp_d = np.zeros((H, W), dtype=int)

dp_l[0] = s_t[0]
dp_r[W-1] = s_t[W-1]
dp_u[0] = s[0]
dp_d[H-1] = s[H-1]

for i in range(1, W):
    dp_l[i] = s_t[i] * (dp_l[i-1] + 1)

for i in reversed(range(W-1)):
    dp_r[i] = s_t[i] * (dp_r[i+1] + 1)

for i in range(1, H):
    dp_u[i] = s[i] * (dp_u[i-1] + 1)

for i in reversed(range(H-1)):
    dp_d[i] = s[i] * (dp_d[i+1] + 1)

cnts = dp_l + dp_r + dp_d.transpose() + dp_u.transpose()
print(max(np.amax(cnts, 0)) - 3)
### BUGGY CODE ###

st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; t = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    t += len(st[i])

T = max([x, y, t])
xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; t = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    t += len(st[i])
if abs(x) + abs(y) > t:
    print("No")
else:
    T = max([abs(x), abs(y), t])
    xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
    yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
    xx[0][T]=True
    yy[0][T]=True
    xx[1][T+XL[0]]=True
    for i in range(2, len(XL)+1):
        for j in range(2*T+1):
            if j-XL[i-1] < 0:
                xx[i][j]=xx[i-1][j+XL[i-1]]
            elif j+XL[i-1] > 2*T:
                xx[i][j]=xx[i-1][j-XL[i-1]]
            else:
                xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]
    
    for i in range(1,len(YL)+1):
        for j in range(2*T+1):
            if j-YL[i-1] < 0:
                yy[i][j]=yy[i-1][j+YL[i-1]]
            elif j+YL[i-1] > 2*T:
                yy[i][j]=yy[i-1][j-YL[i-1]]
            else:
                yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

    if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

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

for i in range(q):
    query = list(input().split())
    if len(query) == 1:
        s = s[::-1]
    elif query[1] == '1':
        s = query[2] + s
    elif query[1] == '2':
        s = s + query[2]
        
print(s)
        

### FIXED CODE ###

from sys import stdin
input = stdin.readline

s = input().rstrip()
q = int(input())

isRev = False

head = ''

for i in range(q):
    query = list(input().split())
    if len(query) == 1:
        isRev = not isRev
    else:
        if isRev and query[1] == '1':
            s = s + query[2]
        elif query[1] == '1':
            head = head + query[2]
        elif isRev and query[1] == '2':
            head = head + query[2]
        elif query[1] == '2':
            s = s + query[2]
            
if isRev:
    s = s[::-1] + head
else:
    s = head[::-1] + s
        
print(s)
### BUGGY CODE ###

import time
n = int(input())
sTime = time.time()

def sum_digit(n):
    s = 0
    while n>0:
        s += n%10
        n //= 10
    return s


mi = n
t = 0
for i in range(1, 10**n):
    mi = min(mi, sum_digit(n*i))
    t = time.time() - sTime
    if t > 2.9:
        break
        
print(mi)

### FIXED CODE ###

n = int(input())

while n % 2 == 0:
    n //= 2
while n % 5 == 0:
    n //= 5
if n == 1:
    print(1)
else:
    X = [n for i in range(n)]
    
    j = 1
    s = 1
    post = []
    m = 0
    while True:
        s *= 10
        s %= n
        post.append(s)
        X[s] = min(j, X[s])
        m += 1
        if s == 1:
            break
    ans = 0
    while True:
        if ans > 0:
            break
        pre = post
        post = []
        j += 1
        for p in pre:
            pp = (p + 1) % n
            if pp == 0:
                X[0] = j
                ans = j
                break
            if X[pp] == n:
                for i in range(m):
                    post.append(pp)
                    X[pp] = j
                    pp *= 10
                    pp %= n
    print(ans)
### BUGGY CODE ###

import math
A,B,N=map(int,input().split())
result=0
if B<=N:
	x=B-1
	while x<=N:
	  tmp=math.floor(A*x/B)-A*math.floor(x/B)
	  if tmp>result:
	    result=tmp
	  x+=B
if B>N:
  x=0
  while x<=N:
    tmp=math.floor(A*x/B)-A*math.floor(x/B)
    if tmp>result:
      result=tmp
    x+=1
if B==1:
  print(0)
else:
  print(result)


### FIXED CODE ###

import math
A,B,N=map(int,input().split())
result=0
if B<=N:
	x=(N//B)*B-1
	result=math.floor(A*x/B)-A*math.floor(x/B)
if B>N:
	result=math.floor(A*N/B)-A*math.floor(N/B)
if B==1:
  print(0)
else:
  print(result)
### BUGGY CODE ###

import collections
s = list(input())
p = []
n = len(s)
kar = 0
for i in range(n):
    kar = (kar + int(s[n-1-i])*(10**i))%2019
    p.append(kar)
c = collections.Counter(p)
ans = 0
for x , y in c.items():
    ans += y*(y-1)//2
    if x == 0:
        ans += y
print(ans)

### FIXED CODE ###

s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

for i in range(2019):
    ans += p[i]*(p[i]-1)//2
    if i == 0:
        ans += p[i]
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = input()
input_line = input()
Ai = input_line.split(" ")
Comment = "YES"
N = int(N)
for i in range(N):
  for j in range(i+1,N):
    if(Ai[i] == Ai[j]):
      Comment = "NO"
      break
      
print(Comment)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

N = input()
input_line = input()
Ai = input_line.split(" ")
NumAi = np.array(Ai)
Comment = "NO"
N = int(N)
if(len(NumAi) == len(np.unique(NumAi))):
  Comment = "YES"

#if(NumAi != set)
      
print(Comment)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
A = [list(reversed(list(map(lambda x:int(x)-1,input().split())))) for i in range(N)]

k = 0
end = 0
while 1:
    used = set()
    for i,q in enumerate(A):
        if not q: continue
        if i in used: continue
        j = q[-1]
        if j in used: continue
        if A[j][-1] == i:
            A[j].pop()
            A[i].pop()
            used.add(i)
            used.add(j)
            if not A[i]: end += 1
            if not A[j]: end += 1
    if not used:
        print(-1)
        exit()
    if end == N:
        print(k+1)
        exit()
    k += 1

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
A = [list(reversed(list(map(lambda x:int(x)-1,input().split())))) for i in range(N)]
B = {i:row for i,row in enumerate(A)}

end = 0
for k in range(8000):
    used = set()
    dels = []
    for i,q in B.items():
        if not q: continue
        if i in used: continue
        j = q[-1]
        if j in used: continue
        if A[j][-1] == i:
            A[j].pop()
            A[i].pop()
            used.add(i)
            used.add(j)
            if not A[i]:
                end += 1
                dels.append(i)
            if not A[j]:
                end += 1
                dels.append(j)
    if not used:
        print(-1)
        exit()
    if end == N:
        print(k+1)
        exit()
    for i in dels:
        del B[i]

print(N*(N-1)//2)
### BUGGY CODE ###

def main():
    import collections
    import copy
    N,K = map(int, input().split())
    V = collections.deque(map(int, input().split()))

    answer = [[0]*(K+1) for _ in range(K+1)]


    for i in range(1,K+1):
        for j in range(1,min(i+1,N+1)):
            opt = 0
            for k in range(j+1):
                tmp = copy.deepcopy(V)
                tmp2 = collections.deque()
                for _ in range(k):
                    tmp2.append(tmp.popleft())
                for _ in range(j-k):
                    tmp2.append(tmp.pop())
                tmp2 = list(tmp2)
                tmp2.sort()
                for l in range(min(i-j,j)):
                    if tmp2[l] < 0:
                        tmp2[l] = 0
                S = sum(tmp2)
                if S > opt:
                    opt = S
            answer[i][j] = opt
    print(max(max(answer)))

main()

### FIXED CODE ###

def main():
    import collections
    import copy
    N,K = map(int, input().split())
    V = collections.deque(map(int, input().split()))

    answer = [[0]*(K+1) for _ in range(K+1)]


    for i in range(1,K+1):
        for j in range(max(1,i//2),min(i+1,N+1)):
            opt = 0
            for k in range(j+1):
                tmp = copy.deepcopy(V)
                tmp2 = collections.deque()
                for _ in range(k):
                    tmp2.append(tmp.popleft())
                for _ in range(j-k):
                    tmp2.append(tmp.pop())
                tmp2 = list(tmp2)
                tmp2.sort()
                for l in range(min(i-j,j)):
                    if tmp2[l] < 0:
                        tmp2[l] = 0
                S = sum(tmp2)
                if S > opt:
                    opt = S
            answer[i][j] = opt
    Ans = 0
    for i in range(K+1):
        for j in range(K+1):
            if answer[i][j] > Ans:
                Ans = answer[i][j]
    print(Ans)

main()
### BUGGY CODE ###

from functools import reduce
import copy
def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y) #再帰定義
  
def gcd_list(numbers):
    return reduce(gcd, numbers)
  
n=int(input())
a_o=list(map(int,input().split()))
g=[1]*n
for i in range(n):
  a=copy.copy(a_o)
  a.pop(i)
  g[i]=gcd_list(a)
print(max(g))

### FIXED CODE ###

def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y) #再帰定義
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
r=[0]*n
for i in range(1,n):
  if i==1:
    l[1]=a[0]
    r[-2]=a[-1]
  else:
    l[i]=gcd(l[i-1],a[i-1])
    r[-i-1]=gcd(r[-i],a[-i])
g=[0]*n
for i in range(n):
  if l[i]==0 or r[i]==0:
    g[i]=l[i]+r[i]
  else:
    g[i]=gcd(l[i],r[i])
print(max(g))
### BUGGY CODE ###

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            gcd = []
            #print(i,j,k)
            for l in range(1,min(i,j,k)+1):
                #print(i,j,k,l)
                if  i%l==0 and j%l==0 and k%l==0:
                    gcd.append(l)
                    #print(i,j,k,l)
                #print(gcd)
            ans += max(gcd)
print(ans)


### FIXED CODE ###

K = int(input())
ans = 0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

for i in range(1,K+1):
    for j in range(1,K+1):
        gcd_ij = gcd(i,j)
        for k in range(1,K+1):
            ans += gcd(gcd_ij, k)
print(ans)
### BUGGY CODE ###

from queue import Queue
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = [(0,1),(1,0),(0,-1),(-1,0)]
q = Queue()
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      q.put((i,j))
      a[i][j] = 0
while not q.empty():
  y,x = q.get()
  for dx,dy in d:
    if 0 <= x+dx < w and 0 <= y+dy < h and a[y+dy][x+dx] == ".":
      a[y+dy][x+dx] = a[y][x] + 1
      q.put((y+dy,x+dx))
m = 0
for i in range(h):
  m = max(m,max(a[i]))
print(m)

### FIXED CODE ###

from collections import deque
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque()
cnt = h*w
t = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      q.append((i,j))
      a[i][j] = 0
      cnt -= 1
while cnt:
  y,x = q.popleft()
  for dx,dy in d:
    if 0 <= x+dx < w and 0 <= y+dy < h and a[y+dy][x+dx] == ".":
      a[y+dy][x+dx] = a[y][x] + 1
      cnt -= 1
      q.append((y+dy,x+dx)) 
for i in range(h):
  m = max(a[i])
  t = max(t,m)
print(t)
### BUGGY CODE ###

import sys

N = int(input())
H = list(map(int, input().split()))
ans = ("Yes")

for i in range(N-1):
  for j in range(N-i-1):
    if H[i]-H[i+j+1] >= 2:
      ans = ("No")
      print(ans)
      sys.exit()
      
print(ans)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = ("Yes")

for i in range(N-1):
    if H[N-1-i] - H[N-2-i] == -1:
        H[N-2-i] -= 1
    elif H[N-1-i] - H[N-2-i] <= -2:
        ans = ("No")

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

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
sum=0
i1=1
i2=1
i3=1
gc=0
K=int(input())
for i in range(K):
  if i2==(K+1):
        i2=1
  for j in range(K):
    if i1==(K+1):
        i1=1
    for z in range(K):
      
      #print(i)
      sum+=gcd(i1,i2,i3)
      i1+=1
      
    i2+=1
    
  i3+=1
      
#sum+=gcd(K,K,K)
print(sum)
#print(gcd(5,10,20))

### FIXED CODE ###

import math  
from itertools import product  

x = int(input())  

s = 0  
for a, b, c in product(range(1, x+1), repeat=3):  
  s += math.gcd(math.gcd(a, b), c)  
print(s)