CodeEff/ECCO huggingface dataset:
# Original solution
from collections import defaultdict
def solve():
	Base = 2000
	MAX = Base*2
	p = 10**9+7
	F = [1]; Finv = [0]*(MAX*2+1)
	for i in range(MAX*2): F.append(F[i]*(i+1)%p)
	Finv[MAX] = pow(F[MAX],p-2,p)
	for i in range(MAX,0,-1): Finv[i-1] = Finv[i]*i%p
	N = int(input())
	A_MAX = B_MAX = 0
	dp = [[0]*(MAX+2) for i in range(MAX+2)]
	goals = defaultdict(int)
	for i in range(N):
		A,B = list(map(int,input().split()))
		if A > A_MAX: A_MAX = A
		if B > B_MAX: B_MAX = B
		goals[(A,B)] += 1
		dp[Base-B][Base-A] += 1
	for j in range(Base-B_MAX,Base+B_MAX+1):
		for i in range(Base-A_MAX,Base+A_MAX+1):
			dp[j+1][i] = (dp[j+1][i] + dp[j][i]) % p
			dp[j][i+1] = (dp[j][i+1] + dp[j][i]) % p
	ans = 0
	for (A,B),v in goals.items():
		ans = (ans+(dp[Base+B][Base+A]-F[A*2+B*2]*Finv[A*2]*Finv[B*2]%p)*v) % p
	print((ans + p)*pow(2,p-2,p) % p)
solve()

# Optimized solution
from collections import defaultdict
def solve():
	Base = 2000
	MAX = Base*2
	p = 10**9+7
	F = [1]; Finv = [0]*(MAX*2+1)
	for i in range(MAX*2): F.append(F[i]*(i+1)%p)
	Finv[MAX] = pow(F[MAX],p-2,p)
	for i in range(MAX,0,-1): Finv[i-1] = Finv[i]*i%p
	N = int(input())
	dup = A_MAX = B_MAX = 0
	dp = [[0]*(MAX+2) for i in range(MAX+2)]
	goals = defaultdict(int)
	for i in range(N):
		A,B = list(map(int,input().split()))
		dup = (dup + F[A*2+B*2]*Finv[A*2]*Finv[B*2])%p
		if A > A_MAX: A_MAX = A
		if B > B_MAX: B_MAX = B
		goals[(Base+A,Base+B)] += 1
		dp[Base-B][Base-A] += 1
	for j in range(Base-B_MAX,Base+B_MAX+1):
		for i in range(Base-A_MAX,Base+A_MAX+1):
			dp[j+1][i] = (dp[j+1][i] + dp[j][i]) % p
			dp[j][i+1] = (dp[j][i+1] + dp[j][i]) % p
	ans = 0
	for (i,j),v in goals.items():
		ans = (ans + dp[j][i]*v) % p
	print(((ans - dup)*pow(2,p-2,p)+p) % p)
solve()
# Original solution
a, b, c = list(map(int, input().split()))
if a+b+c <= 21:
    print("win")
else:
    print("bust")

# Optimized solution
print(("win" if sum([int(x) for x in input().split()]) <= 21 else "bust"))
# Original solution
a, b, c = list(map(int, input().split()))
if a+b+c >= 22:
  print("bust")
else:
  print("win")

# Optimized solution
B1, A2, A3 = list(map(int, input().split()))
C = B1 + A2 + A3
if C <= 21:
  print('win')
if C >= 22:
  print('bust')
# Original solution
print((['win','bust'][sum(list(map(int,input().split())))>=22]))

# Optimized solution
print(('bwuisnt'[sum(map(int, input().split())) < 22::2]))
# Original solution
a = [int(i) for i in input().split()]
print(('bust' if sum(a) >= 22 else 'win'))

# Optimized solution
a = list(map(int, input().split()))
print(('bust' if sum(a) >= 22 else 'win'))
# Original solution
a,b,c=[int(x) for x in input().split()]
if a+b+c>=22:
    print('bust')
else:
    print('win')




# Optimized solution
a=list(map(int,input().split()))
if(sum(a)>=22):
    print("bust")
else:
    print("win")
# Original solution
a = list(map(int, input().split()))

if sum(a) >= 22:
    print('bust')
else:
    print('win')


# Optimized solution
a1, a2, a3 = list(map(int, input().split()))

if a1 + a2 + a3 >= 22:
    print('bust')
else:
    print('win')
# Original solution
a1, a2, a3 = list(map(int, input().split()))

if a1 + a2 + a3 >= 22:
    print('bust')
else:
    print('win')


# Optimized solution
a = list(map(int, input().split()))

if a[0] + a[1] + a[2] >= 22:
    print('bust')
else:
    print('win')
# Original solution
A,B,C=list(map(int,input().split()))
if A+B+C>21:
    print("bust")
else:
    print("win")

# Optimized solution
A,B,C=list(map(int,input().split()))
if A+B+C>=22:
    print('bust')
else:
    print('win')
# Original solution
A,B,C=list(map(int,input().split()))

if A+B+C>=22:
	print("bust")
elif A+B+C<=21:
	print("win")

# Optimized solution
A,B,C=list(map(int,input().split()))

if A+B+C<=21:
  print("win")
elif A+B+C>=22:
  print("bust")
# Original solution
a,b,c=list(map(int,input().split()))
print(('bust' if a+b+c>=22 else 'win'))

# Optimized solution
A = list(map(int, input().split()))
print(("bust" if sum(A) >= 22 else "win"))
# Original solution
A = sum(map(int, input().split()))
print(("bust" if A >= 22 else "win"))

# Optimized solution
A = list(map(int, input().split()))
print(("bust" if sum(A) >= 22 else "win"))
# Original solution
a, b, c = list(map(int, input().split()))
if a + b + c >= 22:
    print('bust')
else:
    print('win')

# Optimized solution
a = list(map(int, input().split()))
if sum(a) >= 22:
    print('bust')
else:
    print('win')
# Original solution
a = sum(list(map(int, input().split())))
if a >+ 21:
    print('bust')
else:
    print('win')

# Optimized solution
a1, a2, a3 = list(map(int, input().split()))
a = a1 + a2 + a3
if a >+ 21:
    print('bust')
else:
    print('win')
# Original solution
a, b, c = list(map(int, input().split()))
if a+b+c >= 22:
    print("bust")
elif a+b+c <= 21:
    print("win")

# Optimized solution
a = list(map(int, input().split()))

if sum(a) >= 22:
    print('bust')
else:
    print('win')
# Original solution
A1, A2, A3 = list(map(int, input().split()))

if (A1 + A2 + A3) >= 22:
    print('bust')
else:
    print('win')


# Optimized solution
if sum(map(int, input().split())) >= 22:
    ans = 'bust'
else:
    ans = 'win'
print(ans)
# Original solution
print(('bwuisnt'[sum(map(int,input().split()))<22::2]))

# Optimized solution
print(('bwuisnt'[eval(input().replace(*' +'))<22::2]))
# Original solution
a = list(map(int, input().split()))
if sum(a) >= 22:
    print('bust')
else:
    print('win')


# Optimized solution
a1, a2, a3 = list(map(int, input().split()))
if a1+a2+a3 >= 22:
    print('bust')
else:
    print('win')
# Original solution
A = list(map(int,input().split()))
if sum(A) >= 22:
    print('bust')
else:
    print('win')

# Optimized solution
s = input().split()

sum_s = int(s[0]) + int(s[1]) + int(s[2])
if sum_s >= 22:
    print('bust')
else:
    print('win')
# Original solution
a1,a2,a3 = list(map(int,input().split()))

sum_a=a1+a2+a3

if sum_a<=21:
  print('win')
else :
  print('bust')

# Optimized solution
a1,a2,a3 = list(map(int,input().split()))

if a1+a2+a3<=21:
  print('win')
else :
  print('bust')
# Original solution
a = eval(input().replace(" ","+"))
print(((a>21)*"bust" or "win"))

# Optimized solution
print(((eval(input().replace(" ","+"))>21)*"bust" or "win"))
# Original solution
print(("bust" if sum(list(map(int, input().split()))) >= 22 else "win"))

# Optimized solution
print(("win" if sum(list(map(int, input().split()))) < 22 else "bust"))
# Original solution
a = list(map(int, input().split()))
if sum(a) >= 22:
    print('bust')
else:
    print('win')

# Optimized solution
def main():
    A = list(map(int, input().split()))
    print(('win' if sum(A) <= 21 else 'bust'))

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))

dp = [[-float("INF")]*(n+1) for i in range(n+1)]
low = [-float("INF")]*(n+1)
col = [-float("INF")]*(n+1)
m = 0
a,b = A[:2]
dp[a][b] = 0
dp[b][a] = 0
low[a] = 0
col[a] = 0
low[b]
col[b] = 0
base = 0

for _ in range(1,n):
    a,b,c = A[3*_-1:3*_+2]
    q = []
    if a==b==c:
        base += 1
        continue
    for j in range(3):
        q.append((a,b,max(m,dp[c][c]+1)))
        for i in range(1,n+1):
            q.append((a,i,low[i]))
        if a==b:
            for i in range(1,n+1):
                q.append((c,i,dp[a][i]+1))
        a,b,c = b,c,a
    for a,b,v in q:
        dp[a][b] = max(dp[a][b],v)
        dp[b][a] = max(dp[b][a],v)
        low[a] = max(low[a],v)  
        low[b] = max(low[b],v)  
        col[a] = max(col[a],v)  
        col[b] = max(col[b],v) 
        m = max(m,v)     
print((max(m,dp[A[-1]][A[-1]]+1)+base))


# Optimized solution
import sys
input = sys.stdin.readline
def main():
    n = int(eval(input()))
    A = list(map(int,input().split()))

    dp = [[-float("INF")]*(n+1) for i in range(n+1)]
    low = [-float("INF")]*(n+1)
    col = [-float("INF")]*(n+1)
    m = 0
    a,b = A[:2]
    dp[a][b] = 0
    dp[b][a] = 0
    low[a] = 0
    col[a] = 0
    low[b]
    col[b] = 0
    base = 0

    for _ in range(1,n):
        a,b,c = A[3*_-1:3*_+2]
        q = []
        if a==b==c:
            base += 1
            continue
        for j in range(3):
            q.append((a,b,max(m,dp[c][c]+1)))
            for i in range(1,n+1):
                q.append((a,i,low[i]))
            if a==b:
                for i in range(1,n+1):
                    q.append((c,i,dp[a][i]+1))
            a,b,c = b,c,a
        for a,b,v in q:
            dp[a][b] = max(dp[a][b],v)
            dp[b][a] = max(dp[b][a],v)
            low[a] = max(low[a],v)  
            low[b] = max(low[b],v)  
            col[a] = max(col[a],v)  
            col[b] = max(col[b],v) 
            m = max(m,v)     
    print((max(m,dp[A[-1]][A[-1]]+1)+base))
if __name__ == "__main__":
    main()
# Original solution
from collections import deque


def upd(dp, a, b, v):
    dp[a][b] = max(dp[a][b], v)
    dp[b][a] = max(dp[b][a], v)
    dp[-1][a] = max(dp[-1][a], v)
    dp[-1][b] = max(dp[-1][b], v)
    dp[a][-1] = max(dp[a][-1], v)
    dp[b][-1] = max(dp[b][-1], v)
    dp[-1][-1] = max(dp[-1][-1], v)


def main():
    N = int(eval(input()))
    A = list([int(x) - 1 for x in input().split()])

    INF = 1 << 32
    dp = [[-INF] * (N + 1) for _ in range(N + 1)]
    upd(dp, A[0], A[1], 0)
    base = 0

    for i in range(2, 3 * N - 1, 3):
        x, y, z = A[i], A[i + 1], A[i + 2]
        if x == y == z:  # x, y, z 3文字すべて等しいとき
            base += 1
        else:
            q = deque()
            for _ in range(3):
                # a, b, x, y, z のうち, b, y, z を消すとき
                for k in range(N):
                    v = dp[k][N]
                    if y == z:
                        v = max(v, dp[k][y] + 1)
                    q.append((k, x, v))
                # a, b, x, y, z のうち, a, b, z を消すとき
                v = max(dp[z][z] + 1, dp[N][N])
                q.append((x, y, v))
                # x, y, z をローテート
                x, y, z = z, x, y
            while q:
                a, b, v = q.popleft()
                upd(dp, a, b, v)

    l = A[-1]
    ans = max(dp[N][N], dp[l][l] + 1)
    print((ans + base))


if __name__ == '__main__':
    main()


# Optimized solution
from collections import deque


def upd(a, b, v):
    global N
    dp[a][b] = max(dp[a][b], v)
    dp[b][a] = max(dp[b][a], v)
    dp[N][a] = max(dp[N][a], v)
    dp[N][b] = max(dp[N][b], v)
    dp[a][N] = max(dp[a][N], v)
    dp[b][N] = max(dp[b][N], v)
    dp[N][N] = max(dp[N][N], v)


N = int(eval(input()))
A = list([int(x) - 1 for x in input().split()])

INF = 1 << 32
dp = [[-INF] * (N + 1) for _ in range(N + 1)]
upd(A[0], A[1], 0)
base = 0

for i in range(2, 3 * N - 1, 3):
    x, y, z = A[i], A[i + 1], A[i + 2]
    if x == y == z:  # x, y, z 3文字すべて等しいとき
        base += 1
    else:
        q = deque()
        for _ in range(3):
            # a, b, x, y, z のうち, b, y, z を消すとき
            for k in range(N):
                v = dp[k][N]
                if y == z:
                    v = max(v, dp[k][y] + 1)
                q.append((k, x, v))
            # a, b, x, y, z のうち, a, b, z を消すとき
            v = max(dp[z][z] + 1, dp[N][N])
            q.append((x, y, v))
            # x, y, z をローテート
            x, y, z = z, x, y
        while q:
            a, b, v = q.popleft()
            upd(a, b, v)

l = A[-1]
ans = max(dp[N][N], dp[l][l] + 1)
print((ans + base))
# Original solution
N = int(eval(input()))
A = [int(a) for a in input().split()] + [0] * 2
X = [[-10**10] * (N+1) for _ in range(N+1)]
X[A[0]][A[1]] = 0
ans = 0
ma = 0
MA = [-10**10] * (N+1)
MA[A[0]] = MA[A[1]] = 0
for i in range(N):
    B = A[i*3+2:i*3+5]
    cnt = len(set(B))
    if cnt == 1:
        ans += 1
    elif cnt == 2:
        a1 = B[0]^B[1]^B[2]
        a2 = (sum(B) - a1) // 2
        X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, MA[j]) for j in range(N+1)], max(X[a1][a2], X[a2][a2] + 1, ma), max(ma, X[a2][a2], X[a1][a1] + 1)
        X[a2] = [max(X[a2][j], MA[j]) for j in range(N+1)]
        MA = [max(m, x1, x2) for m, x1, x2 in zip(MA, X[a1], X[a2])]
        MA[a1] = max(MA[a1], max(X[a1]), X[a2][a1])
        MA[a2] = max(MA[a2], X[a1][a2], X[a2][a2])
        ma = max(ma, MA[a1], MA[a2])
    else:
        a, b, c = B
        # X[a][b], X[a][c], X[b][c] = max(X[a][b], ma, X[c][c] + 1), max(X[a][c], ma, X[b][b] + 1), max(X[b][c], ma, X[a][a] + 1)
        X[a][b], X[a][c], X[b][c] = max(ma, X[c][c] + 1), max(ma, X[b][b] + 1), max(ma, X[a][a] + 1)
        X[a] = [max(x, m) for x, m in zip(X[a], MA)]
        X[b] = [max(x, m) for x, m in zip(X[b], MA)]
        X[c] = [max(x, m) for x, m in zip(X[c], MA)]
        MA[a] = max(MA[a], max(X[a]))
        MA[b] = max(MA[b], X[a][b], max(X[b]))
        MA[c] = max(MA[c], X[a][c], X[b][c], max(X[c]))
        MA = [max(m, xa, xb, xc) for m, xa, xb, xc in zip(MA, X[a], X[b], X[c])]
        ma = max(ma, MA[a], MA[b], MA[c])

print((ans + max(ma, max(max(x) for x in X))))

# Optimized solution
N = int(eval(input()))
A = [int(a) for a in input().split()] + [0] * 2
X = [[-10**10] * (N+1) for _ in range(N+1)]
X[A[0]][A[1]] = 0
ans = 0
ma = 0
MA = [-5] * (N+1)
MA[A[0]] = MA[A[1]] = 0
for i in range(N):
    B = A[i*3+2:i*3+5]
    cnt = len(set(B))
    if cnt == 1:
        ans += 1
    elif cnt == 2:
        a1 = B[0]^B[1]^B[2]
        a2 = (sum(B) - a1) // 2
        X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, MA[j]) for j in range(N+1)], max(ma, X[a2][a2] + 1), max(ma, X[a1][a1] + 1)
        X[a2] = [max(x, m) for x, m in zip(X[a2], MA)]
        MA = [max(m, x1, x2) for m, x1, x2 in zip(MA, X[a1], X[a2])]
        MA[a1] = max(MA[a1], max(X[a1]))
        MA[a2] = max(MA[a2], X[a1][a2], X[a2][a2])
        ma = max(ma, MA[a1], MA[a2])
    else:
        a, b, c = B
        X[a][b], X[a][c], X[b][c] = max(ma, X[c][c] + 1), max(ma, X[b][b] + 1), max(ma, X[a][a] + 1)
        X[a] = [max(x, m) for x, m in zip(X[a], MA)]
        X[b] = [max(x, m) for x, m in zip(X[b], MA)]
        X[c] = [max(x, m) for x, m in zip(X[c], MA)]
        MA[a] = max(MA[a], max(X[a]))
        MA[b] = max(MA[b], X[a][b], max(X[b]))
        MA[c] = max(MA[c], X[a][c], X[b][c], max(X[c]))
        MA = [max(m, xa, xb, xc) for m, xa, xb, xc in zip(MA, X[a], X[b], X[c])]
        ma = max(ma, MA[a], MA[b], MA[c])

print((ans + max(ma, max(max(x) for x in X))))
# Original solution
K = int(eval(input()))

# from fractions import gcd
from math import gcd

def f(x, y, z):
    r = gcd(gcd(x, y), z)
    return r



ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += f(i, j, k)

print(ans)

# Optimized solution
K = int(eval(input()))

# from fractions import gcd
from math import gcd

# def f(x, y, z):
#     r = gcd(gcd(x, y), z)
#     return r

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            # ans += f(i, j, k)
            ans += gcd(gcd(i, j), k)

print(ans)
# Original solution
from math import gcd
from functools import reduce
# import itertools
from collections import defaultdict

a=int(eval(input()))

def ggcd(*numbers):
    return reduce(gcd, numbers)

sum=0

for x in range(1,a+1):
    for y in range(1,a+1):
        if x == 1 and y==1 : sum+=(1*a);continue
        for z in range(1,a+1):
            if x==y==z:
                sum+=x
            else:
                if(x == y or y==z):
                    sum += gcd(x, z)
                elif(x==z):
                    sum += gcd(x, y)
                else:
                    sum += ggcd(x, y,z)
                    

print(sum)


# Optimized solution
from math import gcd
from functools import reduce
# import itertools
from collections import defaultdict

a=int(eval(input()))

sum=0


for x in range(1,a+1):
    for y in range(1,a+1):
        for z in range(1,a+1):
            sum+=gcd(gcd(x,y),z)


print(sum)
# Original solution
import math
k = int(eval(input()))
ans = 0

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

print(ans)

# Optimized solution
import math
k = int(eval(input()))
ans = 0
ab = {}

for a in range(1,k+1):
  for b in range(1,k+1):
    tmp = math.gcd(a, b)
    if tmp not in ab:
      ab[tmp] = 1
    else:
      ab[tmp] += 1

for c in range(1,k+1):
  for d in list(ab.keys()):
    ans += math.gcd(c, d) * ab[d]

print(ans)
# Original solution
import math
 
K = int(eval(input()))
 
ans = 0
 
for a in range(1, K+1):
	for b in range(1, K+1):
		for c in range(1, K+1):
			ans += math.gcd(math.gcd(a,b), c)
 
print(ans)

# Optimized solution
import math
 
K = int(eval(input()))
 
ans = 0
 
for a in range(1, K+1):
	for b in range(1, K+1):
		tmp = math.gcd(a,b)
		for c in range(1, K+1):
			ans += math.gcd(tmp,c)
 
print(ans)
# Original solution
import math
k = int(eval(input()))
ans = 0
list_gcd = [[0]*202 for _ in range(202)]

for i in range(1, 201):
    for j in range(i, 201):
        num = math.gcd(i, j)
        list_gcd[i][j] = num
        list_gcd[j][i] = num

ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            num = list_gcd[i][j]
            ans += list_gcd[num][l]

print(ans)

# Optimized solution
import math
k = int(eval(input()))
ans = 0
for i in range(1, k+1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            num = math.gcd(i, j)
            ans += math.gcd(num,l)

print(ans)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K=int(eval(input()))
tgt=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            tgt+=gcd(i, j, k)
print(tgt)

# Optimized solution
from math import gcd
K=int(eval(input()))
K1=K+1
tgt=0
for i in range(1,K1):
    for j in range(1,K1):
        for k in range(1,K1):
            tgt+=gcd(gcd(i, j), k)
print(tgt)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
n = int(eval(input()))
for i in range(n):
  for j in range(n):
    for k in range(n):
      ans += gcd(i+1, j+1, k+1)
print(ans)

# Optimized solution
from math import gcd
k = int(eval(input()))+1
ans = 0
for i in range(1,k):
    for j in range(1,k):
        for l in range(1,k):
            ans+=gcd(gcd(i,j),l)
print(ans)
# Original solution
import math
from functools import reduce
import itertools 

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(eval(input()))

_sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            _sum +=gcd(a, b, c)

print(_sum)

# Optimized solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(eval(input()))

_sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            _sum +=gcd(a, b, c)

print(_sum)
# Original solution
import math
K = int(eval(input()))

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += math.gcd(math.gcd(a,b),c)
print(ans)
exit()


# Optimized solution
from math import gcd
K = int(eval(input()))

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a,b),c)
print(ans)
exit()
# Original solution
import math

def gcd(a,b):
    if a ==b:
        return a
    elif a !=b:
        return math.gcd(a,b)
    
    
        
cnt=0
K = int(eval(input()))
for i in range(1,K+1):
    for m in range(1,K+1):
        c = gcd(i,m)
        for u in range(1,K+1):
            cnt+= gcd(c,u)
print(cnt)

# Optimized solution
import math
K = int(eval(input()))

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)
# Original solution
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


K = int(eval(input()))
sum = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(i, j, k)
print(sum)

# Optimized solution
import math


K = int(eval(input()))
sum = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        i_j = math.gcd(i, j)
        for k in range(1, K+1):
            sum += math.gcd(i_j, k)
print(sum)
# Original solution
def gcd(m,n):
    while (m % n != 0):
        temp = n
        n = m % n
        m = temp
    return(n)


k = int(eval(input()))
s = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            s += gcd(a,gcd(b,c))
print(s)

# Optimized solution
def gcd(m,n):
    while (m % n != 0):
        temp = n
        n = m % n
        m = temp
    return(n)


k = int(eval(input()))
s = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        t = gcd(a,b)
        for c in range(1,k+1):
            s += gcd(t,c)
print(s)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K=int(eval(input()))

i=1
r=0

while(i<K+1):
  j=1
  while(j<K+1):
    k=1
    while(k<K+1):
      if(i==1 or j==1 or k==1):
        r+=1
      elif(i==j and j==k):
        r+=i
      elif(i==j):
        r+=math.gcd(j,k)
      elif(j==k):
        r+=math.gcd(i,j)
      elif(i==k):
        r+=math.gcd(i,j)
      else:
        r+=gcd(i, j, k)
      k+=1
    j+=1
  i+=1

print(r)

# Optimized solution
import math

K=int(eval(input()))
r=0

for i in range(1,K+1):
  for j in range(1,K+1):
    a=math.gcd(i,j)
    for k in range(1,K+1):
      b=math.gcd(a,k)
      r+=b
print(r)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(eval(input()))
sum = K ** 2
for a in range(2,K+1) :
    for b in range(1,K+1) :
        for c in range(1,K+1) :
            sum += gcd(a, b, c)

print(sum)

# Optimized solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(eval(input()))
sum = K ** 2
for a in range(2,K+1) :
    for b in range(1,K+1) :
        if gcd(a,b) == 1 :
            sum += K
        else :
            for c in range(1,K+1) :            
                sum += gcd(a, b, c)
            
print(sum)
# Original solution
from math import gcd
K = int(eval(input()))

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(gcd(i, j), k)

print(ans)


# Optimized solution
from math import gcd
K = int(eval(input()))

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = gcd(i, j)
        if tmp == 1:
            ans += K
        else:
            for k in range(1, K + 1):
                ans += gcd(tmp, k)

print(ans)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(eval(input()))

a = 1
b = 1
c = 1
d = 0

for i in range(K):
    
    for j in range(K):
        
        for k in range(K):
            d = gcd(gcd(a, b), c) + d
            c = c + 1
            
        
        c = 1
        b = b + 1
    
    b = 1
    a = a + 1
    
print(d)

# Optimized solution
from math import gcd

K = int(eval(input())) + 1
d = 0

for i in range(1, K):
    for j in range(1, K):
        for k in range(1, K):
            d = gcd(gcd(i, j), k) + d
print(d)
# Original solution
import math
import functools

k = int(eval(input()))
k = k+1
ans = 0
for i in range(1,k):
	for j in range(1,k):
		for kk in range(1,k):
			ans += functools.reduce(math.gcd, [i,j,kk])
print(ans)

# Optimized solution
import math

def solve(n):
    n = n+1
    ans = 0
    for i in range(1,n):
        for j in range(1,n):
            tmp = math.gcd(i, j)
            for k in range(1,n):
                ans += math.gcd(tmp, k)
    return ans

def main():
    k = int(eval(input()))
    print((solve(k)))

if __name__ == '__main__':
    main()