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

def gcd(a, b):
    bigger = max(a, b)
    smaller = min(a, b)
    while smaller != 0:
        bigger, smaller = smaller, bigger % smaller
    return bigger


def gcd_seq(seq):
    ans = seq[0]
    for n in seq:
        ans = gcd(ans, n)
    return ans


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


### FIXED CODE ###

def gcd(a, b):
    bigger = max(a, b)
    smaller = min(a, b)
    while smaller != 0:
        bigger, smaller = smaller, bigger % smaller
    return bigger


N = int(input())
A = list(map(int, input().split()))
gcd_l = [A[0]] + [0] * (N - 1)
for i in range(1, N):
    gcd_l[i] = gcd(gcd_l[i - 1], A[i])
del gcd_l[-1]

gcd_r = [0] * (N - 1) + [A[-1]]
for i in range(N - 1, 0, -1):
    gcd_r[i - 1] = gcd(gcd_r[i], A[i - 1])
del gcd_r[0]

gcds = [gcd_l.pop(), gcd_r.pop(0)]
for l, r in zip(gcd_l, gcd_r):
    gcds.append(gcd(l, r))
print(max(gcds))
### BUGGY CODE ###

import math

A,B=map(int,input().split())
min=min(A,B)
rng=math.ceil(min/2)
divisor=[1]
for i in range(2,min+1):
    if A%i==0 and B%i==0:
        for x in divisor:
            if i%x==0 and x!=1:
                break
        else:
            divisor+=[i]

print(len(divisor))


### FIXED CODE ###

import math

divisor=[1]
stack=[]
#eiclidean algorithm
A,B=map(int,input().split())
p=max(A,B)
q=min(A,B)
int2=0
gcd=0
while True:
    int2=p%q
    if int2==0:
        gcd=q
        break
    else:
        p=q
        q=int2

if gcd!=1:
    stack.append(gcd)
    
for i in range(2,math.ceil(math.sqrt(gcd))+1):
    if gcd%i==0:
        p=gcd//i
        stack.append(p)
        for x in divisor:
            if i%x==0 and x!=1:
                break
        else:
            divisor+=[i]

while len(stack)!=0:
    p=stack.pop()
    for x in divisor:
        if p%x==0 and x!=1:
            break
    else:
        divisor+=[p]


print(len(divisor))
### BUGGY CODE ###

import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

for i in lis_pat:
    lis_num.append(lis_all.count(i))

ans = 0
for i in lis_num:
    if i != 1:
        ans += comb(i,2)
   
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)
### BUGGY CODE ###

N,M=map(int,input().split())

if M==6700417 or M==524287 or M==131071 :
    print(1)
else:
    for i in range(M//N,0,-1):
        if M%i==0:
            print(i)
            break



### FIXED CODE ###

N,M=map(int,input().split())

base=M//N
li=[]


for i in range(1,int(pow(M,1/2))+1):
    if i<=base and M%i==0:
        li.append(i)
    if M%i==0 and M//i<=base:
        li.append(M//i)

print(max(li))
### BUGGY CODE ###

N, Q = [int(i) for i in input().split()]
S = input()
l, r = [[None] * Q for _ in range(2)]
for i in range(Q):
  l[i], r[i] = [int(i) for i in input().split()]

for i in range(Q):
  s = S[l[i]-1:r[i]]
  f = False
  count = 0
  for n in s:
    if n == 'A':
      if not f:
        f = True
    elif n == 'C':
      if f:
        count += 1
        f = False
    else:
      f = False
  print(count)


### FIXED CODE ###

import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])
### BUGGY CODE ###

H,W=map(int, input().split())
A=[]
for i in range(H):
  A.append(list(input()))
ds=[]
for i in range(H):
  for j in range(W):
    if A[i][j] == '#':
      ds.append((i, j))

x=-1
q=[(p, 0) for p in ds]
while(q):
  (p, n)=q[0]
  #print(q)
  del q[0]
  x=max(x, n)
#  print(p, n)
  (i,j)=p
  A[i][j] = '#'
  if i > 0 and A[i-1][j] == '.': q.append(((i-1, j), n+1))
  if i < H-1 and A[i+1][j] == '.': q.append(((i+1, j), n+1))
  if j > 0 and A[i][j-1] == '.': q.append(((i, j-1), n+1))
  if j < W-1 and A[i][j+1] == '.': q.append(((i, j+1), n+1))

  
#print(H,W)
#print(A)
#print(ds)
print(x)

### FIXED CODE ###

def f(h, w):
    dt = [[-1, 0], [0, -1], [0, 1], [1, 0]]
    t = [[True] * (w + 2)]
    for _ in range(h):
        t += [[True] + [(c == "#") for c in input()] + [True]]
    t += [[True] * (w + 2)]
    kuro = []
    for i, ti in enumerate(t[1:-1]):
        for j, tij in enumerate(ti[1:-1]):
            if tij:
                kuro+=[(i + 1, j + 1)]
    cnt = -1
    while kuro:
        cnt += 1
        nxt = []
        for i, j in kuro:
            ti=t[i]
            if not ti[j+1]:
                ti[j + 1]=True
                nxt += [(i, j+1)]
            if not ti[j-1]:
                ti[j - 1]=True
                nxt += [(i, j-1)]
            if not t[i - 1][j]:
                t[i - 1][j]=True
                nxt += [(i - 1, j)]
            if not t[i + 1][j]:
                t[i + 1][j]=True
                nxt += [(i + 1, j)]
        kuro = nxt
    print(cnt)
 
 
h, w = map(int, input().split())
f(h, w)
### BUGGY CODE ###

h,n = map(int,input().split())
li2=[input() for i in range(n)]
ab = []
w = 10 ** 10
for i in range(n):
    ab.append( [int(x.strip()) for x in li2[i].split()])
    w_sub = (int(h / ab[i][0]) + 1) * ab[i][1]
    if w_sub < w:
        w = w_sub

dp = [[0] * (w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j < ab[i][1]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i+1][j-ab[i][1]]+ab[i][0])

ans = 0
for i in range(w+1):
    if dp[n][i] >= h:
        print(i)
        exit()

### FIXED CODE ###

a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

for i in range(1, len(dp)):
    dp[i] = min(dp[i - a] + b for a, b in x)

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

def c_alternating_path(H, W, Grid):
    from collections import deque
    ans = 0
    already_checked = [[False] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if already_checked[h][w]:
                continue
            if Grid[h][w] == '#':
                reached_black = 0
                tmp = 0
                is_visit = [[False] * W for _ in range(H)]
                q = deque([(h, w)])
                while q:
                    row, col = q.pop()
                    if is_visit[row][col]:
                        continue
                    if (not already_checked[row][col]) and Grid[row][col] == '#':
                        already_checked[row][col] = True
                        reached_black += 1
                    is_visit[row][col] = True
                    if Grid[row][col] == '.':
                        tmp += 1
                    for dr, dc in zip((1, 0, -1, 0), (0, 1, 0, -1)):
                        nr, nc = row + dr, col + dc
                        if (0 <= nr < H and 0 <= nc < W
                                and Grid[row][col] != Grid[nr][nc]
                                and not is_visit[nr][nc]):
                            q.appendleft((nr, nc))
                ans += tmp * reached_black
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(c_alternating_path(H, W, Grid))

### FIXED CODE ###

def c_alternating_path(H, W, Grid):
    from itertools import product
    from collections import deque

    ans = 0
    is_visited = [[False] * W for _ in range(H)]
    for h, w in product(range(H), range(W)):
        if Grid[h][w] == '#' and not is_visited[h][w]:
            count_white, count_black = 0, 0
            q = deque([(h, w)])
            while q:
                row, col = q.popleft()
                if is_visited[row][col]:
                    continue

                is_visited[row][col] = True
                if Grid[row][col] == '#':
                    count_black += 1
                else:
                    count_white += 1

                for dr, dc in [(0, -1), (1, 0), (0, 1), (-1, 0)]:
                    nr, nc = row + dr, col + dc
                    if (0 <= nr < H and 0 <= nc < W
                        and Grid[row][col] != Grid[nr][nc]
                            and not is_visited[nr][nc]):
                        q.append((nr, nc))
            ans += count_black * count_white
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(c_alternating_path(H, W, Grid))
### BUGGY CODE ###

import itertools
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(1, min(k+1, 100)):
    tmp = [0]*(n+1)
    for i in range(n):
        tmp[max(0, i - a[i])] += 1
        tmp[min(i + a[i] + 1, n)] -= 1
    tmp = list(itertools.accumulate(tmp))
    a = tmp[:n]
print(*a)

### FIXED CODE ###

import numpy as np
from numba import jit
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
@jit
def imos(a):
    tmp = np.zeros(n+1, dtype=np.int64)
    for i in range(n):
        tmp[max(0, i - a[i])] += 1
        tmp[min(i + a[i] + 1, n)] -= 1
    tmp = np.cumsum(tmp)
    return tmp[:n]

for j in range(1, min(k+1, 50)):
    a = imos(a)
print(*a)
### BUGGY CODE ###

from collections import deque

n = int(input())
AA = [deque(list(map(int, input().split()))) for _ in range(n)]
max_n = n * (n - 1) // 2
cnt = 0
ans = -1
shuryo = False
for d in range(1, n * n):
    used = [False] * (n)
    update = False
    for i in range(n):
        if used[i] is True:
            continue
        if not AA[i]:
            continue
        aite = AA[i][0] - 1
        if used[aite] is True:
            continue
        if not AA[aite]:
            continue
        if AA[aite][0] - 1 == i:
            AA[i].popleft()
            AA[aite].popleft()
            used[aite] = True
            used[i] = True
            cnt += 1
            update = True

        if cnt == max_n:
            shuryo = True
            break
    if update is False:
        break

    if shuryo:
        break
if shuryo:
    ans = d
print(ans)


### FIXED CODE ###

from collections import deque

n = int(input())
AA = [deque(list(map(int, input().split()))) for _ in range(n)]

graph = [[] for _ in range(n * n)]


def calc(i, j):
    if j > i:
        i, j = j, i
    return i * n + j


to = [0] * (n * n)
for i in range(n):
    for j in range(n - 2):
        u = calc(i, AA[i][j] - 1)
        v = calc(i, AA[i][j + 1] - 1)
        graph[u].append(v)
        to[v] += 1
start = []
for i in range(n * n):
    if to[i] == 0:
        start.append(i)


def topological_sort(edge_num, graph, start, to):
    topo = []
    cnt = 0
    stack = deque(start)
    while stack:
        v = stack.popleft()
        topo.append(v)
        cnt += 1
        for u in graph[v]:
            to[u] -= 1
            if to[u] == 0:
                stack.append(u)
    return topo, cnt


topo, cnt = topological_sort(n * n, graph, start, to)
if cnt != n * n:
    print(-1)
    exit()
day = [1] * (n * n)
for i in topo:
    for j in graph[i]:
        day[j] = day[i] + 1
print(max(day))
### BUGGY CODE ###

import math
a,b,n=map(int,input().split())
ans=0
for x in range(n+1):
    tui=math.floor(a*x/b)-a*math.floor(x/b)
    ans=max(ans,tui)
print(ans)

### FIXED CODE ###

import math
a,b,n=map(int,input().split())
c=min(b-1,n)
print(math.floor(a*c/b)-a*math.floor(c/b))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
ans = []
n = len(A)
for i in range(1,len(A)-1):
    sum = 0
    for j in range(len(A)):
        if i != j:
            if i == j-1:
                sum += abs(A[j]-A[j-2])
            else:
                sum += abs(A[j]-A[j-1])
    ans.append(sum)
for i in ans:
    print(i)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
ans = []
n = len(A)
S = 0
for i in range(1,n):
    S += abs(A[i]-A[i-1])

for i in range(1,n-1):
    sum = S + abs(A[i+1]-A[i-1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])
    ans.append(sum)

for i in ans:
    print(i)
### BUGGY CODE ###

import sys

input = sys.stdin.readline
N = int(input().strip())
N = str(N)[::-1]
before = 0
ans = 0
ansB = 0
for i, c in enumerate(N):
    n = int(c)+before
    ansB += int(c)
    if 0 <= n < 5:
        before = 0
        ans += n
    elif n == 5:
        if i+1 == len(N):
            before = 0
            ans += n
            continue
        if int(N[i+1]) < 5:
            before = 0
            ans += n
        else:
            ans += 10-n
            before = 1
    else:
        ans += 10-n
        before = 1
print(ans + before)



### FIXED CODE ###

import sys

input = sys.stdin.readline
N = list(map(int, input().strip()))[::-1]
ans = 0
before = 0
L = len(N)
for i, c in enumerate(N):
    n = c + before
    if 0 <= n < 5:
        before = 0
        ans += n
    elif n == 5:
        if i+1 == L:
            before = 0
            ans += n
            continue
        if N[i+1] < 5:
            before = 0
            ans += n
        else:
            ans += 10-n
            before = 1
    else:
        ans += 10-n
        before = 1
print(ans + before)
### BUGGY CODE ###

n = int(raw_input())
nums = [int(raw_input()) for i in range(n)]

maxv = nums[1] - nums[0]
for j in range(1, n):
    for i in range(j):
        maxv = max(maxv, nums[j]-nums[i])

print maxv


### FIXED CODE ###

# coding: utf-8
# 答えを見た。。。

n = int(raw_input())
R = [int(raw_input()) for i in range(n)]

maxv = -2000000000
minv = R[0]

for r in R[1:]:
    maxv = max(maxv, r - minv)
    minv = min(minv, r)

print maxv
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
s = [1,a[0]] #shone buttons
while True: #unitl 2 appears in s or a loop generates 
    if s[-1] == 2: #if 2 appears
        break
    if len(set(s)) != len(s): #if a loop generates: mathematical induction
        break 
    s += [a[s[-1]-1]]
# print(s)
if s[-1] == 2:
    print(len(s)-1)
else:
    print(-1)



### FIXED CODE ###

n = int(input())
a = [int(input())-1 for i in range(n)]
#ボタンを押す=listから値を取得して-1にする
#取得した値=光っているボタンの番号
#光っているボタンの番号が1ならbreak
#取得した値が-1なら2を通らずループしてしまっている
sb = 0
ans = 0
while True:
    if sb == 1:
        flag = True
        break
    elif sb == -1:
        flag = False
        break
    tmp = a[sb]
    a[sb] = -1
    sb = tmp
    ans += 1
if flag:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

n=int(input())
S=list(input())
ans=0
for i in range(n-2):
  for j in range(i,n-1):
    if S[i]==S[j]:
      continue
    for k in range(j,n):
      if S[j]==S[k] or S[i]==S[k]:
        continue
      if j-i != k-j:
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
s=list(input())

nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    k=2*j-i
    if k>=n or k<=j:
      continue
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      cnt+=1
print(ans-cnt)
### BUGGY CODE ###

import heapq
import itertools
N,M,R=map(int, raw_input().split())
r=map(int, raw_input().split())

cost=[ [ float("inf") for i in range(N+1)] for i in range(N+1) ]
nl=[ [] for i in range(N+1) ]

for i in range(M):
	A,B,C=map(int, raw_input().split())
	cost[A][B]=C
	cost[B][A]=C
	nl[A].append(B)
	nl[B].append(A)


for i in range(N+1): cost[i][i]=0


def Dij(start):

	#Initialize
	d=[float("inf") for i in range(N+1)]
	d[start]=0
	q=[]
	heapq.heappush(q,(0,start))
	
	while len(q)!=0:
		tmp=heapq.heappop(q)
		u=tmp[1]

		for v in nl[u]:
			alt=d[u]+cost[u][v]
			if d[v]>alt:
				d[v]=alt
				heapq.heappush(q,(alt,v))
	return d


l=list(itertools.permutations(r))


ans=float("inf")

for i in l:
	dist=0
	for j in range(R):
		if j==0:
			prev=i[j]
			continue
		cur=i[j]
		d=Dij(prev)
		dist+=d[cur]
		prev=cur
	ans=min(ans,dist)

print ans




### FIXED CODE ###

import heapq
import itertools
N,M,R=map(int, raw_input().split())
r=map(int, raw_input().split())

cost=[ [ float("inf") for i in range(N+1)] for i in range(N+1) ]
nl=[ [] for i in range(N+1) ]

for i in range(M):
	A,B,C=map(int, raw_input().split())
	cost[A][B]=C
	cost[B][A]=C
	nl[A].append(B)
	nl[B].append(A)


for i in range(N+1): cost[i][i]=0


def Dij(start):

	#Initialize
	d=[float("inf") for i in range(N+1)]
	d[start]=0
	q=[]
	heapq.heappush(q,(0,start))
	
	while len(q)!=0:
		tmp=heapq.heappop(q)
		u=tmp[1]

		for v in nl[u]:
			alt=d[u]+cost[u][v]
			if d[v]>alt:
				d[v]=alt
				heapq.heappush(q,(alt,v))
	return d


l=list(itertools.permutations(r))

C={}
for i in r:
	C[i]=Dij(i)


ans=float("inf")


for i in l:
	dist=0
	for j in range(R):
		if j==0:
			prev=i[j]
			continue
		cur=i[j]
		dist+=C[prev][cur]
		prev=cur
	ans=min(ans,dist)

print ans
### BUGGY CODE ###

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

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K = int(readline())
    if K%2==0:
        print(-1)
    else:
        seven = 7
        ans = 1
        pre = INF
        while True:
            seven = seven%K
            if seven==0:
                print(ans)
                break
            else:
                if pre==seven:
                    print(-1)
                    break
                pre = seven
                seven = seven*10+7
                ans += 1


if __name__ == '__main__':
    main()


### FIXED CODE ###

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

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K = int(readline())
    if K%2==0:
        print(-1)
    else:
        seven = 7
        amari = set([7])
        ans = 1
        while True:
            seven = seven%K
            if seven==0:
                print(ans)
                break
            else:
                seven = seven*10+7
                if seven in amari:
                    print(-1)
                    break
                ans += 1
                amari.add(seven)


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



R,G,B,N=[int(c) for c in input().split()]

C=sorted([R,G,B])



if(C==[1,1,1]):
	print((N+2)*(N+1)//2)







count=0
for i in range(N//C[2]+1):
	for j in range(N//C[1]+1):
		if(N-C[2]*i-C[1]*j>=0 and (N-C[2]*i-C[1]*j)%C[0]==0):
			count+=1
print(count)



### FIXED CODE ###



R,G,B,N=[int(c) for c in input().split()]

C=sorted([R,G,B])



if(C==[1,1,1]):
	print((N+2)*(N+1)//2)
	exit()






count=0
for i in range(N//C[2]+1):
	for j in range(N//C[1]+1):
		if(N-C[2]*i-C[1]*j>=0 and (N-C[2]*i-C[1]*j)%C[0]==0):
			count+=1
print(count)
### BUGGY CODE ###

X,Y,Z,K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
taste_list = []

for i in range(X):
  for j in range(Y):
    for k in range(Z):
      taste_list.append(A_list[i]+B_list[j]+C_list[k])
taste_list.sort(reverse=True)
for i in range(K):
  print(taste_list[i])

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
AB = AB[:K]

ABC = []
for ab in AB:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import heapq

def solve(H: int, W: int, black):
    Q = []
    marked = [[0] * W for h in range(H)]
    for h, w in black:
        heapq.heappush(Q, (0, h, w))
        marked[h][w] = 1
    dmax = 0
    while len(Q) > 0:
        d, h, w = heapq.heappop(Q)
        dmax = max(d, dmax)
        for hh, ww in [(h-1, w), (h+1, w), (h, w-1), (h, w+1)]:
            if 0 <= hh <= H-1 and 0 <= ww <= W-1 and marked[hh][ww] == 0:
                heapq.heappush(Q, (d+1, hh, ww))
                marked[hh][ww] = 1
    print(dmax)
    return


# Generated by 1.1.4 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()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    black = []
    for h in range(H):
        line = next(tokens)
        for w, c in enumerate(line):
            if c == '#':
                black.append((h, w))
    solve(H, W, black)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

inf = float('inf')

def solve(H: int, W: int, A: "List[str]"):
    dist = [[inf] * W for h in range(H)]
    for h in range(1, H):
        for w in range(1, W):
            if A[h][w] == '#':
                dist[h][w] = 0
            else:
                dist[h][w] = min(dist[h-1][w], dist[h][w-1]) + 1
    
    dmax = 0
    for h in range(H-1, -1, -1):
        for w in range(W-1, -1, -1):
            if A[h][w] == '#':
                dist[h][w] = 0
            elif h+1 <= H-1 and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], min(dist[h+1][w], dist[h][w+1]) + 1)
            elif w+1 == W and h+1 <= H-1:
                dist[h][w] = min(dist[h][w], dist[h+1][w] + 1)
            elif h+1 == H and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], dist[h][w+1] + 1)
            dmax = max(dist[h][w], dmax)
    print(dmax) 
    return


# Generated by 1.1.4 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()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, A)

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

import math

k = int(input())
A = 0

def gcd(a,b,c):
    d = math.gcd(a,b)
    e = math.gcd(d,c)
    return e

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            y = gcd(a,b,c)
            A += y

print(A)





### FIXED CODE ###

import math

k = int(input())
A = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        p = math.gcd(a,b)
        for c in range(1,k+1):
            y = math.gcd(p,c)
            A += y

print(A)