Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(1,k+1):
            if i+j<n:
                dp[i+j] = min(dp[i]+abs(h[i]-h[i+j]),dp[i+j])
            else:
                break
                
    print(dp[n-1])

main()

Fixed submission:
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,n):
        dp[i] = min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,min(i,k)+1))
    print(dp[n-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(1,k+1):
            if i+j<n:
                dp[i+j] = min(dp[i]+abs(h[i]-h[i+j]),dp[i+j])
                
    print(dp[n-1])

main()

Fixed submission:
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,n):
        dp[i] = min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,min(i,k)+1))
    print(dp[n-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
H = [int(i) for i in input().split()]

dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j >= N:
            break
        dp[i+j] = min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
    

print(dp[-1])

Fixed submission:
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,n):
        dp[i] = min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,min(i,k)+1))
    print(dp[n-1])

main()
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])
    prefecture[p].sort()
for i in range(1,N+1):#iは県の番号   
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        ans.append([prefecture[i][j-1][1],i,j])
ans.sort()
for i in range(len(ans)):
    print('{:06}{:06}'.format(ans[i][1],ans[i][2]))
        

Fixed submission:
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])

for i in range(1,N+1):#iは県の番号
    prefecture[i].sort()
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        ans.append([prefecture[i][j-1][1],i,j])
ans.sort()
for i in range(len(ans)):
    print('{:06}{:06}'.format(ans[i][1],ans[i][2]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])
    prefecture[p].sort()
for i in range(1,N+1):#iは県の番号
    tmp_p = str(i)
    while(len(tmp_p)!=6):
         tmp_p = '0'+tmp_p
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        tmp_x = str(j)
        while (len(tmp_x)!=6):
            tmp_x = '0'+tmp_x
        ans.append([prefecture[i][j-1][1],tmp_p+tmp_x])
ans.sort()
for i in range(len(ans)):
    print(ans[i][1])
        

Fixed submission:
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])

for i in range(1,N+1):#iは県の番号
    prefecture[i].sort()
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        ans.append([prefecture[i][j-1][1],i,j])
ans.sort()
for i in range(len(ans)):
    print('{:06}{:06}'.format(ans[i][1],ans[i][2]))
Buggy python submission (verdict: Runtime Error):
import sys
N,T =map(int,input().split())
c=[]
t=[]
t_count=0
for i in range(N):
    c_n,t_n=map(int,input().split())
    if t_n<=T:
        c.append(c_n)
        t.append(t_n)
        if i>len(t):
            break
        if t[i]>=T:
            t_count += 1
    

if t_count==N:
    print("TLE")
    sys.exit()

print(min(c))

Fixed submission:
import sys
N,T =map(int,input().split())
c=[]
t=[]
t_count=0
for i in range(N):
    c_n,t_n=map(int,input().split())
    if t_n>T:
        t_count+=1
    if t_n<=T:
        c.append(c_n)
        t.append(t_n)
        #if i>len(t):
            #break
        
    

if t_count==N:
    print("TLE")
    sys.exit()

print(min(c))
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = []
Y = []
Height =[] 
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    Height.append(h)

List = []
for Cx in range(101):
    for Cy in range(101):
        tmp_h = Height[-1]+abs((Cx-X[-1]))+abs((Cy-Y[-1]))
        if tmp_h >= 1:
            List.append([Cx,Cy,tmp_h])
    
#1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
#制約が小さいからできる全探索

for i in range(1,N-1):
    for j in List[:]:
        if Height[i] == max(j[2]-abs(X[i]-j[0])-abs(Y[i]-j[1]),0):
            continue
        else:
            List.remove(j)

print(List[0][0],List[0][1],List[0][2])

Fixed submission:
N = int(input())
X = []
Y = []
Height =[] 
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    Height.append(h)
List = []
flag = 0
for i in range(N):
    if flag ==1:
        break
    if Height[i]==0:
        continue
    else:
        for Cx in range(101):
            for Cy in range(101):
                tmp_h = Height[i]+abs((X[i]-Cx))+abs((Y[i]-Cy))
                if tmp_h >= 1 :
                    List.append([Cx,Cy,tmp_h])
        flag = 1
     
    #1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
    #制約が小さいからできる全探索

for i in range(1,N):
    for j in List[:]:
        if Height[i] == max(j[2]-abs((X[i]-j[0]))-abs((Y[i]-j[1])),0):
            continue
        else:
            List.remove(j)

print(List[-1][0],List[-1][1],List[-1][2])

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = []
Y = []
Height =[] 
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    Height.append(h)
List = []
for Cx in range(101):
    for Cy in range(101):
        tmp_h = Height[0]+abs((X[0]-Cx))+abs((Y[0]-Cy))
        if tmp_h >= 1:
            List.append([Cx,Cy,tmp_h])

#1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
#制約が小さいからできる全探索

for i in range(1,N):
    for j in List[:]:
        if Height[i] == max(j[2]-abs((X[i]-j[0]))-abs((Y[i]-j[1])),0):
            continue
        else:
            List.remove(j)
print(List[0][0],List[0][1],List[0][2])

Fixed submission:
N = int(input())
X = []
Y = []
Height =[] 
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    Height.append(h)
List = []
flag = 0
for i in range(N):
    if flag ==1:
        break
    if Height[i]==0:
        continue
    else:
        for Cx in range(101):
            for Cy in range(101):
                tmp_h = Height[i]+abs((X[i]-Cx))+abs((Y[i]-Cy))
                if tmp_h >= 1 :
                    List.append([Cx,Cy,tmp_h])
        flag = 1
     
    #1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
    #制約が小さいからできる全探索

for i in range(1,N):
    for j in List[:]:
        if Height[i] == max(j[2]-abs((X[i]-j[0]))-abs((Y[i]-j[1])),0):
            continue
        else:
            List.remove(j)

print(List[-1][0],List[-1][1],List[-1][2])
Buggy python submission (verdict: Runtime Error):
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if len(string)>k:
            brak
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Fixed submission:
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if len(string)>k:
            break
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if string not in Dict.keys() and len(string)<=k:
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Fixed submission:
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if len(string)>k:
            break
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Fixed submission:
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if len(string)>k:
            break
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,K = map(int,input().split())
List =[]
for i in range(a,b+1):
    List.append(i)
ans = []

for i in List[:K]:
    ans.append(i)
for i in List[-K:]:
    ans.append(i)

ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)

Fixed submission:
a,b,k = map(int,input().split())
List =[]

ans = []

for i in range(a,min(a+k,b+1)):
    ans.append(i)
for i in range(b,max(b-k,a),-1):
    ans.append(i)

ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
a,b,K = map(int,input().split())
List =[]
for i in range(a,b+1):
    List.append(i)
for i in range(K):
    print(List[i])
for i in range(b-a+1-K,len(List)):
    print(List[i])

Fixed submission:
a,b,k = map(int,input().split())
List =[]

ans = []

for i in range(a,min(a+k,b+1)):
    ans.append(i)
for i in range(b,max(b-k,a),-1):
    ans.append(i)

ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
import collections
H,W = map(int,input().split())
Map = []
black_cnt = 0
for i in range(H):
    tmp = list(input())
    black_cnt += tmp.count('#')
    Map.append(tmp)

Counter = [[float('inf') for j in range(W)]for i in range(H)]
Visited = [[False for j in range(W)]for i in range(H)]
q = collections.deque()
q.append((0,0,0))
while q:
    y,x,cnt = q.popleft()
    if 0>y or H<=y or 0>x or W<=x:
        continue
    if Map[y][x] == '#':
        continue
    if cnt > Counter[y][x]:
        continue
    if Visited[y][x]:
        continue
    Visited[y][x]=True
    Map[y][x] = cnt
    cnt += 1
    q.append((y+1,x,cnt))
    q.append((y-1,x,cnt))
    q.append((y,x+1,cnt))
    q.append((y,x-1,cnt))
print(H*W-Map[H-1][W-1]-black_cnt-1)

Fixed submission:
import collections
H,W = map(int,input().split())
Map = []
black_cnt = 0
for i in range(H):
    tmp = list(input())
    black_cnt += tmp.count('#')
    Map.append(tmp)

Counter = [[float('inf') for j in range(W)]for i in range(H)]
Visited = [[False for j in range(W)]for i in range(H)]
q = collections.deque()
q.append((0,0,0))
while q:
    y,x,cnt = q.popleft()
    if 0>y or H<=y or 0>x or W<=x:
        continue
    if Map[y][x] == '#':
        continue
    if cnt > Counter[y][x]:
        continue
    if Visited[y][x]:
        continue
    Visited[y][x]=True
    Map[y][x] = cnt
    cnt += 1
    q.append((y+1,x,cnt))
    q.append((y-1,x,cnt))
    q.append((y,x+1,cnt))
    q.append((y,x-1,cnt))
if Visited[H-1][W-1] == False:
    print('-1')
else:
    print(H*W-Map[H-1][W-1]-black_cnt-1)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
T = [int(input()) for i in range(n)]

T_list = np.array(T)
print(np.lcm.reduce(T_list))

Fixed submission:
import numpy as np
n = int(input())
T = [int(input()) for i in range(n)]

print(np.lcm.reduce(T))
Buggy python submission (verdict: Runtime Error):
import math
import collections
N = int(input())
A = [int(i) for i in input().split()]

def trial_division(n):
    Num = n
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return [Num]
    else:
        factor.append(n)
        return factor


List = [[] for i in range(N)]
for i in range(N):
    tmp = trial_division(A[i])
    tmp = collections.Counter(tmp)
    List[i] = tmp[2]

cnt0,cnt1,cnt2 = 0,0,0
for i in range(len(List)):
    if List[i]==1 and List[i+1]!=1:
        cnt0 += 1

    if List[i]==0:
        cnt0+=1
        
    elif List[i]==1:
        cnt1+=1
        
    else:
        cnt2 += 1
        


if cnt2+1>=cnt0:
    print('Yes')
else:
    print('No')



Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

cnt4,cnt2,cnt = 0,0,0

for i in A:
    if i%4==0:
        cnt4 += 1
    elif i%2==0:
        cnt2 += 1
    else:
        cnt += 1
cnt += cnt2%2

if cnt4+1>=cnt:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
import math
import collections
N = int(input())
A = [int(i) for i in input().split()]

def trial_division(n):
    Num = n
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return [Num]
    else:
        factor.append(n)
        return factor


List = [[] for i in range(N)]
for i in range(N):
    tmp = trial_division(A[i])
    tmp = collections.Counter(tmp)
    List[i] = tmp[2]

cnt0,cnt1,cnt2 = 0,0,0
for i in range(len(List)):
    if List[i]==1 and List[i+1]!=1:
        cnt0 += 1

    if List[i]==0:
        cnt0+=1
        
    elif List[i]==1:
        cnt1+=1
        
    else:
        cnt2 += 1
        


if cnt2+1>=cnt0:
    print('YES')
else:
    print('NO')



Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

cnt4,cnt2,cnt = 0,0,0

for i in A:
    if i%4==0:
        cnt4 += 1
    elif i%2==0:
        cnt2 += 1
    else:
        cnt += 1
cnt += cnt2%2

if cnt4+1>=cnt:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [str(i) for i in input().split()]
dp = [[0,0] for i in range(N+1)]

dp[0][0],dp[0][1] = A[0],A[0]
for i in range(1,N):
    dp[i][0] = dp[i-1][1]+A[i]
    dp[i][1] = A[i]+dp[i-1][0]
ans = list(dp[N-1][1])
print(*ans)

Fixed submission:
import collections
N = int(input())
A = [i for i in input().split()]

ans = collections.deque()
for i in range(N):
    if (i+1)%2==N%2:
        ans.appendleft(A[i])
    else:
        ans.append(A[i])
print(*ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [str(i) for i in input().split()]
dp = [[0,0] for i in range(N+1)]

dp[0][0],dp[0][1] = A[0],A[0]
for i in range(1,N):
    dp[i][0] = dp[i-1][1]+A[i]
    dp[i][1] = A[i]+dp[i-1][0]
ans = list(dp[N-1][1])
print(*ans)

Fixed submission:
import collections
N = int(input())
A = [i for i in input().split()]

ans = collections.deque()
for i in range(N):
    if (i+1)%2==N%2:
        ans.appendleft(A[i])
    else:
        ans.append(A[i])
print(*ans)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = []
B = []
F = []

for i in range(1,int(math.sqrt(N)),1):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))


Fixed submission:
import math

N = int(input())
A = []
B = []
F = []

for i in range(1,int(math.sqrt(N))+1,1):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))

Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = []
B = []
F = []
for i in range(1,int(N/2),1):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))


Fixed submission:
import math

N = int(input())
A = []
B = []
F = []

for i in range(1,int(math.sqrt(N))+1,1):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))

Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = []
B = []
F = []
for i in range(1,N/2):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))


Fixed submission:
import math

N = int(input())
A = []
B = []
F = []

for i in range(1,int(math.sqrt(N))+1,1):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))

Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = []
B = []
F = []
for i in range(1,N):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))


Fixed submission:
import math

N = int(input())
A = []
B = []
F = []

for i in range(1,int(math.sqrt(N))+1,1):
    if (N%i)== 0:
        A.append(N/i)
        B.append(i)
for i in range(len(A)):
    count_A = int(math.log10(A[i])+1)
    count_B = int(math.log10(B[i])+1)
    if count_A >= count_B:
        F.append(count_A)
    else:
        F.append(count_B)
print(min(F))
Buggy python submission (verdict: Runtime Error):
S = list(input())
tmp = ''
L = len(S)
S.append('0')
S.append('0')
ans = 0
for i in range(L):
    tmp += str(S[i])
    if tmp=='dream':
        if tmp+str(S[i+1])+str(S[i+2])+str(S[i+3])=='dreamera':
            ans += len(tmp)
            tmp = ''
        elif tmp+str(S[i+1])+str(S[i+2])=='dreamer':
            ans += len(tmp)+2
            tmp = ''
            i+=2
        else:
            ans += len(tmp)
            tmp = ''
    if tmp == 'erase':
        if tmp+str(S[i+1])=='eraser':
            ans += len(tmp)+1
            tmp  = ''
            i+=1
        else:
            ans += len(tmp)
            tmp = ''
if ans == L:
    print('YES')
else:
    print('NO')

Fixed submission:
S = list(input())
tmp = ''
L = len(S)
S = S[-1:-L-1:-1]
Kouho = ['maerd','remaerd','esare','resare']
ans = 0
for i in range(L):
    
    tmp += str(S[i])
    if tmp in Kouho:
        ans += len(tmp)
        tmp = ''
if ans == L:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
    k=int(input())
    a,b=map(int,input().split())
    print("OK" if a//k < b//k or a%k==0 or b%k==0 else "NG")

Fixed submission:
k=int(input())
a,b=map(int,input().split())
print("OK" if a//k < b//k or a%k==0 or b%k==0 else "NG")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    print(a.count(i+1))


Fixed submission:
import collections
n = int(input())
a = collections.Counter(list(map(int, input().split())))

for i in range(n):
    print(a[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    if y == 0:
        return x
    else:
        return (gcd(y, x % y))


ans = 0
k = int(input())

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):
            ans += gcd(t, c)
print(ans)


Fixed submission:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return (gcd(y, x % y))


ans = 0
k = int(input())

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)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    if y == 0:
        return x
    else:
        return (gcd(y, x % y))


ans = 0
k = int(input())

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)


Fixed submission:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return (gcd(y, x % y))


ans = 0
k = int(input())

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)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(str(input()))
q = int(input())
hanten = 0

for i in range(q):
    x = input().split()
    if len(x) == 1:
        t = x[0]
        if t == "1" and hanten == 0:
            hanten = 1
        elif t == "1" and hanten == 1:
            hanten = 0

    else:
        f = int(x[1])
        c = str(x[2])
        if f == 1 and hanten == 0:
            s.insert(0, c)

        elif f == 1 and hanten == 1:
            s.append(c)

        elif f == 2 and hanten == 0:
            s.append(c)

        elif f == 2 and hanten == 1:
            s.insert(0, c)

else:
    d = len(s)
    if hanten == 1:
        for i in range(d):
            print(s[d-1-i], end="")
    else:
        for i in range(d):
            print(s[i], end="")


Fixed submission:
from collections import deque

s = deque(str(input()))
q = int(input())
hanten = 0

for i in range(q):
    x = input().split()
    if len(x) == 1:
        t = x[0]
        if t == "1" and hanten == 0:
            hanten = 1
        elif t == "1" and hanten == 1:
            hanten = 0

    else:
        f = int(x[1])
        c = str(x[2])
        if f == 1 and hanten == 0:
            s.appendleft(c)

        elif f == 1 and hanten == 1:
            s.append(c)

        elif f == 2 and hanten == 0:
            s.append(c)

        elif f == 2 and hanten == 1:
            s.appendleft(c)

else:
    if hanten == 1:
        s.reverse()

print("".join(s))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = 0

for i in range(n):
    if k ** (i - 1) <= n < k ** i:
        ans = i
        break
if ans == 0:
    ans += 1
print(ans)


Fixed submission:
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = float("inf")

for i in range(x[0], x[-1]+1):
    t = 0
    for q in range(n):
        t += (i - x[q]) ** 2
    else:
        if ans > t:
            ans = t

print(ans)