Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#DPの練習

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

#壊れている階段とそうでない階段を判別するリスト
broken = [0] * (n+1)

#段ごとに何通りかを集計するためのリスト
dp = [0] * (n+1)
#0段目は必ず1通りしかない
dp[0] = 1


#壊れている階段をマークする
for i in range(m):
    broken[a[i]] = 1

#1段目から壊れている可能性があるので場合分け
if broken[1] == 1:
    dp[2] = 0
else:
    #1段目が無事な場合は1通り
    dp[2] = 1

#3段目以降
for i in range(2, n+1):
    if broken[i] == 1:
        #壊れていた場合次の段を確認する
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] = dp[i] % 1000000007

print(dp[n])



Fixed submission:
#coding:utf-8
#DPの練習

n, m = map(int, input().split())

#壊れている階段とそうでない階段を判別するリスト
broken = [0] * (n+1)

#段ごとに何通りかを集計するためのリスト
dp = [0] * (n+1)
#0段目は必ず1通りしかない
dp[0] = 1


#壊れている階段をマークする
for i in range(m):
    broken[int(input())] = 1

#1段目から壊れている可能性があるので場合分け
if broken[1] == 1:
    dp[1] = 0
else:
    #1段目が無事な場合は1通り
    dp[1] = 1

#2段目以降
for i in range(2, n+1):
    if broken[i] == 1:
        #壊れていた場合次の段を確認する
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] = dp[i] % 1000000007

print(dp[n])

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#DPの練習

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

#壊れている階段とそうでない階段を判別するリスト
broken = [0] * (n+1)

#段ごとに何通りかを集計するためのリスト
dp = [0] * (n+1)
#0段目は必ず1通りしかない
dp[0] = 1


#壊れている階段をマークする
for i in range(m):
    broken[a[i]] = 1

#1段目から壊れている可能性があるので場合分け
if broken[1] == 1:
    dp[2] = 0
else:
    #1段目が無事な場合は1通り
    dp[2] = 1

#3段目以降
for i in range(2, n+1):
    if broken[i] == 1:
        #壊れていた場合次の段を確認する
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] = dp[i] % 1000000007

print(dp[n])



Fixed submission:
#coding:utf-8
#DPの練習

n, m = map(int, input().split())

#壊れている階段とそうでない階段を判別するリスト
broken = [0] * (n+1)

#段ごとに何通りかを集計するためのリスト
dp = [0] * (n+1)
#0段目は必ず1通りしかない
dp[0] = 1


#壊れている階段をマークする
for i in range(m):
    broken[int(input())] = 1

#1段目から壊れている可能性があるので場合分け
if broken[1] == 1:
    dp[1] = 0
else:
    #1段目が無事な場合は1通り
    dp[1] = 1

#2段目以降
for i in range(2, n+1):
    if broken[i] == 1:
        #壊れていた場合次の段を確認する
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] = dp[i] % 1000000007

print(dp[n])
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
n = int(input())
h = list(map(int, input().split()))
counter = 1

#一番西がもっとも高い山ならその時点で終了
if max(h) == h[0]:
    print(counter)
else:
    for i in range(n):
        print(h[0:i+1])
        h_max = max(h[0:i+1])
        if (h[i] >= h_max) and (h[i] > h[0]):
            #print(h[i])
            counter += 1
    print(counter)


Fixed submission:
#coding:utf-8
a, b = map(int, input().split())

aa = 2*a - 1
ab = a + b
bb = 2*b - 1

print(max(aa, ab, bb))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
a, b, c = map(int, input.split())

if a = b and b = c and c = a:
    print('Yes')
else:
    print('No')

Fixed submission:
# coding: utf-8
a, b, c = map(int, input().split())

if a == b and b == c and c == a:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
import numpy as np
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

count = 0

for item in a:
    #A*Bについて、今回は行列の積を求めているのと同じ
    if np.dot(item, b) + c > 0:
        count += 1

print(count)

Fixed submission:
#coding:utf-8
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

count = 0

for i in range(0, n):
    #n行ごとに答えを計算する。最初はcで初期化
    ans = c
    for j in range(0, m):
        ans += a[i][j] * b[j]
        #m列目になったら判定実施
        if j == m-1 and ans > 0:
            count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = int(input())
a = input()
b = input()
c = input()
ans = 0

for i in range(n):
  ans += len(set(a[i], b[i], c[i])) - 1 
  
print(ans)


Fixed submission:
#coding:utf-8
n = int(input())
a = input()
b = input()
c = input()
ans = 0
 
for i in range(n):
  ans += len(set([a[i], b[i], c[i]])) - 1 
  
print(ans)

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = int(input())
a, b, c = map(str, input().split())
ans = 0

for i in range(n):
  ans += len(set(a[i], b[i], c[i])) - 1 
  
print(ans)

Fixed submission:
#coding:utf-8
n = int(input())
a = input()
b = input()
c = input()
ans = 0
 
for i in range(n):
  ans += len(set([a[i], b[i], c[i]])) - 1 
  
print(ans)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n1, n2, n3, n4 = map(str, input().split())
n = ''.join(n1, n2, n3, n4)

if '1'.count(n) == 1 and '9'.count(n) == 1 and '7'.count(n) == 1 and '4'.count(n) == 1:
  print('Yes')
else:
  print('No')

Fixed submission:
#coding:utf-8
n = input().split()

if '1' in n and '9' in n and '7' in n and '4' in n:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
s = input()
for i in range(n := len(s))
    if s[:i] + s[n-7+i:] == 'keyence':
        print('YES')
        exit()
print('NO')


Fixed submission:
# coding:utf-8
s = input()
n = len(s)
for i in range(n):
    if s[:i] + s[n-7+i:] == 'keyence':
        print('YES')
        exit()
print('NO')

Buggy python submission (verdict: Runtime Error):
# coding:utf-8
s = input()
for i in range(n := len(s))
	if s[:i] + s[n-7+i:] == 'keyence':
    	print('YES')
		exit()
print('NO')

Fixed submission:
# coding:utf-8
s = input()
n = len(s)
for i in range(n):
    if s[:i] + s[n-7+i:] == 'keyence':
        print('YES')
        exit()
print('NO')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

p1 = 0
p2 = 0
p3 = 0

for i in p:
  if i <= a:
    p1 += 1
  elif i >= (a+1) and i <= b:
    p2 += 1
  elif i >= (b+1)
    p3 += 1

print(min(min(p1, p2), p3))

Fixed submission:
#coding:utf-8
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

p1 = 0
p2 = 0
p3 = 0

for i in p:
  if i <= a:
    p1 += 1
  elif i >= (a+1) and i <= b:
    p2 += 1
  elif i >= (b+1):
    p3 += 1

print(min(min(p1, p2), p3))
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = h[0]

print(min(h[i + k - 1] - h[i] for i in range(n - k + 1))


Fixed submission:
# coding:utf-8
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = h[0]

print(min(h[i + k - 1] - h[i] for i in range(n - k + 1)))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
a, b, k = map(int, input().split())

for i in range(0, k):
    if i % 2 == 0:
        b += a / 2
        a /= 2
    else:
        a += b / 2
        b /= 2

print(a, b)


Fixed submission:
#coding:utf-8
s = input()

if len(s) == 2:
  print(s)
elif len(s) == 3:
  print(s[::-1])
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = int(input())

#全探索
for i in range(n//7):
    for j in range(n//4):
        if 7*i + 4*j == n:
            print('Yes')
            exit()

print('No')


Fixed submission:
#coding:utf-8
n, k = map(int, input().split())
#公平に配れるか1枚余るかどっちか

if n % k == 0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = input()
s = 0

for i in range(0, n):
    s += int(n[i])

if int(n) % s == 0:
    print('Yes')
else:
    print('No')


Fixed submission:
#coding:utf-8
n = input()
s = 0

for i in range(0, len(n)):
    s += int(n[i])

if int(n) % s == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

s = list(input())
ramen = 700

print(700 + 100 * ramen.count('o'))


Fixed submission:
#coding:utf-8

s = list(input())
ramen = 700

print(700 + 100 * s.count('o'))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for _ in range(n)]

choco = 0

for i in range(n):
    choco += (1 + (d - 1)//(a[i] - 1))

print(choco)

Fixed submission:
#coding:utf-8
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for _ in range(n)]

choco = 0

for i in range(0, n):
    tmp =  1 + (d - 1)//a[i]
    choco += tmp

print(choco+x)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# 500円玉の枚数
a = int(input())
# 100円玉の枚数
b = int(input())
# 50円玉の枚数
c = int(input())
# 合計金額
x = int(input())
 
def main():
    flag = "FALSE"
    count = 0
    for i in range(0, a+1):
        for j in range(0, b+1):
            for k in range(0, c+1):
                total = int(500*i+100*j+50*k)
                if total == x:
                    count = count + 1
                else:
                    pass
    print(count)
 
if __name__ == '__main__':
    main()
# coding: utf-8
# 500円玉の枚数
a = int(input())
# 100円玉の枚数
b = int(input())
# 50円玉の枚数
c = int(input())
# 合計金額
x = int(input())

def main():
    flag = "FALSE"
    count = 0
    for i in range(0, a+1):
        for j in range(0, b+1):
            for k in range(0, c+1):
                total = int(500*i+100*j+50*k)
                if total == x:
                    count = count + 1
                else:
                    pass
    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
# coding: utf-8
# 500円玉の枚数
a = int(input())
# 100円玉の枚数
b = int(input())
# 50円玉の枚数
c = int(input())
# 合計金額
x = int(input())
 
def main():
    flag = "FALSE"
    count = 0
    for i in range(0, a+1):
        for j in range(0, b+1):
            for k in range(0, c+1):
                total = int(500*i+100*j+50*k)
                if total == x:
                    count = count + 1
                else:
                    pass
    print(count)
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
coding:utf-8
import re
s = input()
#正規表現でひっかける
pattern = 'A?KIHA?BARA?$'
result = re.match(pattern , s)

if result:
    print('Yes')
else:
    print('No')

Fixed submission:
#coding:utf-8
import re
s = input()
#正規表現でひっかける
pattern = 'A?KIHA?BA?RA?$'
result = re.match(pattern , s)

if result:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

n = list(input())

if s[0] == s[1] and s[1] == s[2]:
  print('Yes')
elif s[1] == s[2] and s[2] == s[3]:
  print('Yes')
elif s[0] == s[1] and s[1] == s[2] and s[2] == s[3]:
  print('Yes')
else:
  print('No')

Fixed submission:
#coding:utf-8

n = list(input())

if n[0] == n[1] and n[1] == n[2]:
  print('Yes')
elif n[1] == n[2] and n[2] == n[3]:
  print('Yes')
elif n[0] == n[1] and n[1] == n[2] and n[2] == n[3]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

def lucas(num):
    if num == 0:
        return 2
    elif num == 1:
        return 1
    else:
        return lucas(num - 1) + lucas(num - 2)


def main():
    n = int(input())
    print(lucas(n))


if __name__ == "__main__":
    main()


Fixed submission:
# coding:utf-8
from functools import lru_cache


@lru_cache(maxsize=None)
def lucas(num):
    if num == 0:
        return 2
    elif num == 1:
        return 1
    else:
        return lucas(num - 1) + lucas(num - 2)


def main():
    n = int(input())
    print(lucas(n))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

a, b, c, d = map(int, input().split())
time = max(b,d) - min(a,c)
print(max(0, time))


Fixed submission:
#coding:utf-8

n = list(input())

if n[0] == n[2]:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
#coding:utf-8

a, b, c, d = map(int, input().split())

print(max(b,d) - min(a,c))


Fixed submission:
#coding:utf-8

n = list(input())

if n[0] == n[2]:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
#coding:utf-8

a, b, c, d = map(int, input().split())

print(min(a,c)- max(b,d))


Fixed submission:
#coding:utf-8

n = list(input())

if n[0] == n[2]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n = int(input())
two = [1, 2, 4, 8, 16, 32, 64]
ans = 0

for i in two:
    if  two <= n:
        ans = two

print(ans)

Fixed submission:
#coding:utf-8
n = int(input())
two = [1, 2, 4, 8, 16, 32, 64]
ans = 0

for i in range(7):
    if  two[i] <= n:
        ans = two[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

#数字をグループ分けしておく。リストの番号が0始まりなので、最初わざと0を入れる
group = [0,1,3,1,2,1,2,1,1,2,1,2,1]
x, y = map(int, input().slit())


if group[x] == group[y]:
  print('Yes')
else:
  print('No')



Fixed submission:
#coding:utf-8

#数字をグループ分けしておく。リストの番号が0始まりなので、最初わざと0を入れる
group = [0,1,3,1,2,1,2,1,1,2,1,2,1]
x, y = map(int, input().split())


if group[x] == group[y]:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
#coding:utf-8

#数字をグループ分けしておく。リストの番号が0始まりなので、最初わざと0を入れる
group = [0,1,3,1,2,1,2,1,1,2,1,2,1]
x, y = map(int, input().slit())

for i in group:
  if group[x] == group[y]:
    print('Yes')
  else:
    print('No')



Fixed submission:
#coding:utf-8

#数字をグループ分けしておく。リストの番号が0始まりなので、最初わざと0を入れる
group = [0,1,3,1,2,1,2,1,1,2,1,2,1]
x, y = map(int, input().split())


if group[x] == group[y]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

n = int(input())
power = 1

for i in range(0,n):
  power = ((i+1) * power) % (7 + 10＊＊９)

print(power)


Fixed submission:
#coding:utf-8

n = int(input())
p = 1

for i in range(0,n):
  p = ((i+1) * p) % (10**9 + 7)

print(p)

Buggy python submission (verdict: Runtime Error):
#coding:utf-8

n = int(input())
power = 1

for i in range(n):
  power = ((i+1) * power) % (7 + 10＊＊９)

print(power)

Fixed submission:
#coding:utf-8

n = int(input())
p = 1

for i in range(0,n):
  p = ((i+1) * p) % (10**9 + 7)

print(p)
Buggy python submission (verdict: Time Limit Exceeded):
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cost=0
satu=0
maxi=0
for i in range(N):
    if K-cost-A[i]>=0:
        cost+=A[i]
        cost2=cost
        satu=i+1
        satu2=satu
        for j in range(M):
            if K-cost2-B[j]>=0:
                satu2+=1
                cost2+=B[j]
            else:
                break
        maxi=max(maxi,satu,satu2)
    else:break
cost=0
satu=0
for i in range(M):
    if K-cost-B[i]>=0:
        cost+=B[i]
        cost2=cost
        satu=i+1
        satu2=satu
        for j in range(N):
            if K-cost2-A[j]>=0:
                satu2+=1
                cost2+=A[j]
            else:
                break
        maxi=max(maxi,satu,satu2)
    else:break
print(maxi)

Fixed submission:
import bisect
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
bka=[0]*N
bkb=[0]*M
bka[0]=A[0]
bkb[0]=B[0]

for i in range(1,N):
    bka[i]+=bka[i-1]+A[i]
for j in range(1,M):
    bkb[j]+=bkb[j-1]+B[j]
ans=0
c=bisect.bisect_left(bkb,K)
if c != M:
    if bkb[c] == K:
        c +=+ 1
ans = max(ans, c)
for i in range(N):
    count=i+1
    k=K-bka[i]
    if k<0:continue
    c = bisect.bisect_left(bkb,k)
    b=c
    if c!=M:
        if bkb[c]==k:
            c+=count+1
        else:c+=count
    else:c+=count
    ans=max(ans,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
maxx=0
K-=A
maxx=max(maxx,A)
if K<=0:
    print(maxx)
    exit()
K-=B
aa=B*0
maxx=max(maxx,maxx+aa)
if K<=0:
    print(maxx)
    exit()
K-=C
aa=C*-1
maxx=max(max,maxx+aa)
if K<=0:
    print(maxx)
    exit()

Fixed submission:
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
if A>=K:
    print(K)
    exit()
if A+B>=K:
    print(A)
    exit()
K=K-(A+B)
print(A+(K*-1))
exit()
Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
B=0
while(True):
    A=X+B**5
    A=int(A)
    if A**5-B**5==X :
        print(A,B)
        exit()
    B-=1

Fixed submission:
X=int(input())
B=0
for i in range(-118,120):
    for j in range(-119,119):
        if X==i**5-j**5:
            print(i,j)
            exit()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=list(map(int,(stdin.readline().strip().split()))).sort()
moji=A[0]
count=1
i=0
length=len(A)-1
j=0
sougou=0
while(i!=length):

    if moji==A[i+1]:
        count+=1
        i+=1
        j+=1
    else:
        sougou += 1
        print(count)
        count=1
        j=1
        i+=1
        moji=A[i]
if j>=1:
    sougou += 1
    print(count)
for _ in range(N-sougou):print(0)

Fixed submission:
from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=list(map(int,(stdin.readline().strip().split())))
num_list=[0]*N
moji=A[0]
i=0
length=len(A)-1
for i in A:
    num_list[i-1]+=1
for num in num_list:
    print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=np.array(list(map(int,(stdin.readline().strip().split()))))
count=np.count_nonzero(A==1)
print(np.count_nonzero(A==1))
flag=True
for i in range(2,N+1):
    count+=np.count_nonzero(A==i)
    if flag:print((np.count_nonzero(A==i)))
    else:print(0)
    if count == N - 1: flag = False


Fixed submission:
from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=list(map(int,(stdin.readline().strip().split())))
num_list=[0]*N
moji=A[0]
i=0
length=len(A)-1
for i in A:
    num_list[i-1]+=1
for num in num_list:
    print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=np.array(list(map(int,(stdin.readline().strip().split()))))
print(np.count_nonzero(A==1))
for i in range(2,N+1):
    print((np.count_nonzero(A==i)))


Fixed submission:
from sys import stdin
import numpy as np
N=list(map(int,(stdin.readline().strip().split())))[0]
A=list(map(int,(stdin.readline().strip().split())))
num_list=[0]*N
moji=A[0]
i=0
length=len(A)-1
for i in A:
    num_list[i-1]+=1
for num in num_list:
    print(num)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import itertools
#from math import gcd
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        return z

# K = list(map(int, (stdin.readline().strip().split())))[0]
# i=[x for x in range(1,K+1)]
# j=[x for x in range(1,K+1)]
# k=[x for x in range(1,K+1)]
# num_list=set(map(tuple,(sorted(x) for x in (itertools.product(i,j,k)))))
#
# ans=0
# for i,j,k in num_list:
#     if i==j:
#         if j==k:
#             ans+=K
#         else:
#             ans+=gcd(i,gcd(j,k))*3
#     elif j==k:ans+=gcd(i,gcd(j,k))*3
#     else:ans+=gcd(i,gcd(j,k))*6
K = int(input())

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

Fixed submission:
from sys import stdin
import itertools
from math import gcd
# def gcd(a,b):
#     x=max(a,b)
#     y=min(a,b)
#     if x%y==0:return y
#     else:
#         while(x%y!=0):
#             z=x%y
#             x=y
#             y=z
#         return z

# K = list(map(int, (stdin.readline().strip().split())))[0]
# i=[x for x in range(1,K+1)]
# j=[x for x in range(1,K+1)]
# k=[x for x in range(1,K+1)]
# num_list=set(map(tuple,(sorted(x) for x in (itertools.product(i,j,k)))))
#
# ans=0
# for i,j,k in num_list:
#     if i==j:
#         if j==k:
#             ans+=K
#         else:
#             ans+=gcd(i,gcd(j,k))*3
#     elif j==k:ans+=gcd(i,gcd(j,k))*3
#     else:ans+=gcd(i,gcd(j,k))*6
K = int(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        return z

K = list(map(int, (stdin.readline().strip().split())))[0]
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(i,gcd(j,k))
print(ans)

Fixed submission:
from sys import stdin
import itertools
from math import gcd
# def gcd(a,b):
#     x=max(a,b)
#     y=min(a,b)
#     if x%y==0:return y
#     else:
#         while(x%y!=0):
#             z=x%y
#             x=y
#             y=z
#         return z

# K = list(map(int, (stdin.readline().strip().split())))[0]
# i=[x for x in range(1,K+1)]
# j=[x for x in range(1,K+1)]
# k=[x for x in range(1,K+1)]
# num_list=set(map(tuple,(sorted(x) for x in (itertools.product(i,j,k)))))
#
# ans=0
# for i,j,k in num_list:
#     if i==j:
#         if j==k:
#             ans+=K
#         else:
#             ans+=gcd(i,gcd(j,k))*3
#     elif j==k:ans+=gcd(i,gcd(j,k))*3
#     else:ans+=gcd(i,gcd(j,k))*6
K = int(input())

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        k = gcd(i, j)
        for l in range(1, K + 1):
            a = gcd(k, l)
            ans += a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            if j-i !=k-j:
                if S[i-1] != S[j-1] and S[j-1] !=S[k-1] and S[i-1] != S[k-1]:
                    ans+=1
print(ans)

Fixed submission:
from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans = S.count("R")*S.count("G")*S.count("B")
for i in range(N):
    for j in range(i+1,N):
        k=2*j-i
        if k>=N:break
        if S[i]!=S[j] and S[j]!=S[k] and S[i] !=S[k]:
                ans-=1
print(ans)