Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02616 (python)

Fixed submission:
from collections import deque #両端から取り出すのが速い
N,K = map(int,input().split())
A = list(map(int,input().split()))
pos = []
neg = []
for a in A:
    if a >= 0:
        pos.append(a)
    else:
        neg.append(-a)
pos = deque(sorted(pos))
neg = deque(sorted(neg))
mod = 10**9+7
ans = 1
sign = 1
if K%2 == 1: #Kが奇数の時pos（ある場合）から必ず１つ取る
    if len(pos) > 0:
        ans = ans*pos.pop() % mod
    else:
        ans = ans*neg.popleft() % mod
        sign *= -1
    K -= 1
while K > 0: #偶数の場合と奇数の残りの処理
    if len(pos) == 1 and len(neg) == 1:
        ans = ans*-neg.pop()*pos.pop() % mod
    elif sign == 1:#通常バージョン
        if len(pos) < 2 or (len(neg) >= 2 and pos[-2]*pos[-1] < neg[-2]*neg[-1]):
            ans = ans*neg.pop()*neg.pop() % mod
        else:
            ans = ans*pos.pop()*pos.pop() % mod
    else:#奇数の前処理で負になっている場合(最終結果も負になるので小さくしたい)
        if len(pos) < 2 or (len(neg) >= 2 and pos[-2]*pos[-1] < neg[-2]*neg[-1]):
            ans = ans*neg.popleft()*neg.popleft() % mod
        else:
            ans = ans*pos.popleft()*pos.popleft() % mod
    K -= 2
ans = ans*sign % mod
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
ans = 1
ansb = 1
if K % 2 == 0:
    for i in range(K//2):
        if A[0]*A[1] >= A[-1]*A[-2]:
            ans *= A[0]*A[1]
            A.pop(0)
            A.pop(1)
        elif A[0]*A[1] < A[-1]*A[-2]:
            ans *= A[-1]*A[-2]
            A.pop(-1)
            A.pop(-2)
elif K == 1:
    ans = A[-1]
elif K % 2 == 1 and K != 1:
    B = list.copy(A)
    for i in range(K//2):
        if A[0]*A[1] >= A[-1]*A[-2]:
            ans *= A[0]*A[1]
            A.pop(0)
            A.pop(0)
        elif A[0]*A[1] < A[-1]*A[-2]:
            ans *= A[-1]*A[-2]
            A.pop(-1)
            A.pop(-1)
    ans *= A[-1]
    for i in range(K//2):
        if B[0]*B[1] <= B[-1]*B[-2]:
            ansb *= B[0]*B[1]
            B.pop(0)
            B.pop(0)
        elif B[0]*B[1] > B[-1]*B[-2]:
            ansb *= B[-1]*B[-2]
            B.pop(-1)
            B.pop(-1)
    ansb *= B[-1]
    ans = max(ans,ansb)
print(ans%(7+10**9))
Problem p02621 (python)

Fixed submission:
a = int(input())
print(a + a**2 + a**3)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 5*10**5 #Nの最大値
g1 = [1, 1] #元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())
ans = 0
for i in range(N+1):
    ans += cmb(N,i,mod)*((-1)**i)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())
ans = 0
for i in range(N+1):
    ans += cmb(N,i,mod)*((-1)**i)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2)
    ans %= mod
print(ans)
Problem p02628 (python)

Fixed submission:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
p = list(map(int, input().split())
p.sort()
s= sum(p[:k])
print(s)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
i=0
p = list(map(int, input().split())
p.sort()
s= sum(p[:k])
print(s)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
i=0
p = []
while i < n:
    p.append(int(input()))
    i += 1
#print(p)
#s=0
#l=0
#while l < k:
#    s += min(p)
#    p = p.remove(min(p))
#    l += 1
#print(s)　こっちはうまくいかない
p.sort()
s= sum(p[:k])
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
i=0
p = []
while i < n:
    p.append(int(input()))
    i += 1

p.sort()
s= sum(p[:k])
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
i=0
p = []
while i < n:
    p.append(int(input()))
    i += 1
#print(p)
#s=0
#l=0
#while l < k:
#    s += min(p)
#    p = p.remove(min(p))
#    l += 1
#print(s)
p.sort()
s= sum(p[:k])
print(s)
Problem p02630 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
L = [0]*100001
s = sum(A)
for a in A:
    L[a] += 1 #数字のカウント
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    s += L[B]*(C-B) #合計値の変化
    L[C] += L[B] 
    L[B] = 0 #Bの値の数だけCに移す
    print(s)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
L = [0]*100000
s = sum(A)
for a in A:
    L[a] += 1 #数字のカウント
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    s += L[B]*(C-B) #合計値の変化
    L[C] += L[B] 
    L[B] = 0 #Bの値の数だけCに移す
    print(s)
Problem p02678 (python)

Fixed submission:
n,m = map(int,input().split())

import heapq

def dijkstra(s):
    d = 1
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * n # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for u in e[v]:
            tmp = 1 + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                heapq.heappush(hq, (tmp, u))
    return cost

e = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    e[a].append(b)
    e[b].append(a) # 有向グラフでは削除

d = dijkstra(0)
# print(d)
# print(e)
ans = [0]*(n)
for i in range(1,n):
    for j in e[i]:
        # print(i,j)
        if d[j] == d[i] - 1:
            ans[i] = j + 1
            continue

print("Yes")
print(*ans[1:], sep="\n")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())

import heapq

def dijkstra(s):
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * n # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, u in e[v]:
            tmp = d + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                heapq.heappush(hq, (tmp, u))
    return cost

e = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    e[a].append((1, b))
    e[b].append((1, a)) # 有向グラフでは削除

d = dijkstra(0)
# print(d)
ans = [1]*(n)
for i in range(1,n):
    for j in e[i][1]:
        print(i,j)
        if d[j] == d[i] - 1:
            ans[i] = j + 1

print(*ans[1:], sep="\n")

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

N,M = map(int,input().split())
l = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    l[A-1][B-1] = 1
    l[B-1][A-1] = 1
a = np.array(l)
n, labels = connected_components(a)
if n == 1:
    print('Yes')
    s = [0]
    t = [i for i in range(1,N)]
    ans = [0]*N
    x = 1
    #print(l)
    while True:
        S = s.copy()
        for i in S:
            for j in t:
                if l[i][j] == 1 :
                    s.append(j)
                    t.remove(j)
                    ans[j] = i+1
                    #print(i,j)
        if t == []:
            break
    for i in range(1,N):
        print(ans[i])
else:
    print('No')
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if t[:-1] == s:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if not(a[posi] in way):
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len(way):
    print(way[k] + 1)
else:
    print(way[(k-rest) % cycle + rest] + 1)
Problem p02684 (python)

Fixed submission:
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if binary_search(hq, a[posi]) != -1:
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len(way):
    print(way[k] + 1)
else:
    print(way[(k-rest) % cycle + rest] + 1)

Buggy submission (verdict: Runtime Error):
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if binary_search(hq, a[posi]) != -1:
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len[way]:
    print(way[k])
else:
    print(way[(k-rest) % cycle + rest] + 1)
Problem p02614 (python)

Fixed submission:
from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    h,w,K=map(int,input().split())
    g=[[_ for _ in input()] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if g[i][j]=='.':
                g[i][j]=0
            else:
                g[i][j]=1
    n=h+w
    cnt=0
    for i in range(2 ** n):
        gg=deepcopy(g)
        for j in range(n):
            if ((i >> j) & 1):
                if j-h<0:
                    for k in range(w):
                        gg[j][k]=2
                else:
                    for l in range(h):
                        gg[l][j-h]=2
        
        ans=0
        for i in range(h):
            for j in range(w):
                if gg[i][j]==1:
                    ans+=1

        if ans==K:
            cnt+=1
    print(cnt)


    
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    h,w,K=map(int,input().split())
    g=[[_ for _ in input()] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if g[i][j]=='.':
                g[i][j]=0
            else:
                g[i][j]=1
    n=h+w
    cnt=0
    for i in range(2 ** n):
        gg=deepcopy(g)
        for j in range(n):
            if ((i >> j) & 1):
                if j-h<0:
                    for k in range(w):
                        gg[j][k]=2
                else:
                    for l in range(h):
                        gg[l][j-h]=2
        
        ans=0
        for i in range(h):
            for j in range(w):
                if gg[i][j]==1:
                    ans+=1

        if ans==K:
            cnt+=1
    print(cnt)


    
resolve()
Problem p02641 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))


            cur = 0
            if x not in p:
                return x
            
            while True:
                if x-cur not in p:
                    return x-cur
                if x+cur not in p:
                    return x+cur

                cur+=1
    print(main())


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if cur<x:
                    if l[cur] not in p:
                        return l[cur]
                if cur<len(r):
                    if r[cur] not in p:
                        return r[cur]
                cur+=1
    print(main())


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if l[cur] not in p:
                    return l[cur]
                if r[cur] not in p:
                    return r[cur]
                cur+=1
    print(main())


resolve()
Problem p02642 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    l=[0]*(10**6+5)

    for i in A:
        if l[i]!=0:
            l[i]+=1
            continue
        for j in range(i,10**6+5,i):
            l[j]+=1
    
    cnt=0
    for i in A:
        if l[i]==1:
            cnt+=1
    print(cnt)




    
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    l=[0]*(10**6+1)

    for i in A:
        if l[i+1]!=0:
            l[i+1]+=1
            continue
        for j in range(1,10**6//i):
            l[j*i+1]+=1
    
    cnt=0
    for i in A:
        if l[i+1]<=1:
            cnt+=1
    print(cnt)




    
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    l=[0]*(10**6+1)

    for i in A:
        for j in range(1,10**6//i):
            l[j*i+1]+=1
    
    cnt=0
    for i in A:
        if l[i+1]<=1:
            cnt+=1
    print(cnt)




    
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    l=[0]*(10**6+1)

    for i in A:
        for j in range(1,10**6//i):
            l[j*i+1]+=1
    
    cnt=0
    for i in A:
        if l[i+1]<=1:
            cnt+=1
    print(cnt)




    
resolve()
Problem p02665 (python)

Fixed submission:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    l = [0]*(n+1)
    l[n] = (A[n], A[n])
    for i in reversed(range(1, n+1)):
        l[i-1] = (max(math.ceil(l[i][0]/2)+A[i-1], 1), l[i][1]+A[i-1])

    if 1 not in range(l[0][0], l[0][1]+1):
        print(-1)
    else:
        ans = [0]*(n+1)
        ans[0] = 1
        cnt = 1
        for i in range(n):
            ans[i+1] = min((ans[i]-A[i])*2, l[i+1][1])
        print(sum(ans))


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    l = [0]*(n+1)
    l[n] = (A[n], A[n])
    for i in reversed(range(1, n+1)):
        l[i-1] = (max(math.ceil(l[i][0]/2)+A[i-1], 1), l[i][1]+A[i-1])

    if 1 not in range(l[0][0], l[0][1]+1):
        print(-1)
    else:
        ans = [0]*(n+1)
        ans[0] = 1
        cnt = 1
        for i in range(n):
            ans[i+1] = min((ans[i]-A[i])*2, l[i+1][1])
        print(sum(ans))


resolve()
Problem p02691 (python)

Fixed submission:
#!/usr/bin/python3
# import bisect
from collections import Counter, deque, OrderedDict,defaultdict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

    N = int(input())
    A = list(map(int, input().split()))
    d=defaultdict(int)
    cnt=0
    for k,v in enumerate(A):
        d[k+v]+=1
        cnt+=d[k-v]

    print(cnt)


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

    N = int(input())
    num = [i for i in range(1, N+1)]
    A = list(map(int, input().split()))
    d=defaultdict(int)
    cnt=0
    for k,v in enumerate(A):
        d[k+v]+=1
        cnt+=d[k-v]

    print(cnt)


resolve()
Problem p02713 (python)

Fixed submission:
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(combinations_with_replacement(KK,3))
    for i in I:
        ls=len(set(i))
        if ls==1:
            ans+=reduce(gcd,i)
        elif ls == 2:
            ans+=reduce(gcd,i)*3
        else:
            ans+=reduce(gcd,i)*6





    print(ans)


resolve()

Buggy submission (verdict: Runtime Error):
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,S)
    print(ans)


resolve()

Buggy submission (verdict: Runtime Error):
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,S)
    print(ans)


resolve()