Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

n,a,b = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
INF = 500
dp = [[[INF for i in range(411)] for j in range(411)] for k in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    for j in range(a*n+1):
        for k in range(b*n+1):
            if j - l[i][0]>=0 and k - l[i][1]>=0:
                dp[i+1][j][k] = min(dp[i][j][k],dp[i][j - l[i][0]][k - l[i][1]]+l[i][2])
            else:
                dp[i+1][j][k] = dp[i][j][k]
i =1
ans = INF
while i*max(a,b)<=400:
    ans = min(ans, dp[n][i*a][i*b])
    i+=1
if ans==INF:
    print(-1)
else:
    print(ans)

Fixed submission:

n,a,b = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
INF = 500
dp = [[[INF for i in range(411)] for j in range(411)] for k in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    for j in range(a*n+1):
        for k in range(b*n+1):
            if j - l[i][0]>=0 and k - l[i][1]>=0:
                dp[i+1][j][k] = min(dp[i][j][k],dp[i][j - l[i][0]][k - l[i][1]]+l[i][2])
            else:
                dp[i+1][j][k] = dp[i][j][k]
i =1
ans = INF
while i*max(a,b)<=400:
    ans = min(ans, dp[n][i*a][i*b])
    i+=1
if ans==INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
x , n = map(int , input().split())
b = list(map(int,input().split()))
for i in b:
    a[i] = 1
t = 1
ans = 0
while 1:
    if x-t not in b:
        ans = x - t
        break
    if x+t not in b:
        ans = x + t
        break
    t += 1
print(ans)

Fixed submission:
x , n = map(int , input().split())
b = []
if n!=0:
    b = list(map(int,input().split()))
t = 0
ans = 0
while 1:
    if x-t not in b:
        ans = x - t
        break
    if x+t not in b:
        ans = x + t
        break
    t += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
x , n = map(int , input().split())
a = [0] * 101
b = list(map(int,input().split()))
for i in b:
    a[i] = 1
t = 1
ans = 0
while 1:
    if a[x-t] == 0:
        ans = x - t
        break
    if a[x+t] == 0:
        ans = x + t
        break
    t += 1
print(ans)

Fixed submission:
x , n = map(int , input().split())
b = []
if n!=0:
    b = list(map(int,input().split()))
t = 0
ans = 0
while 1:
    if x-t not in b:
        ans = x - t
        break
    if x+t not in b:
        ans = x + t
        break
    t += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
S = int(input())
p = S // 3
A = 0

for b in range(p):

    r = S-3*(b+1)

    if b == 0:
        A+=1
    else:

        x = 1
        y = 1
        z = 1
        for k in range(r+b):
            x *= k+1
        for k in range(r):
            y *= k+1
        for k in range(b):
            z *= k+1

        A += int(x/(y*z))


print(int(A%(10**9+7)))





Fixed submission:
import numpy as np
from functools import reduce


mod = 10**9+7
def cmb(R,B):
    numerator = reduce(lambda x,y: x * y % mod, [R+B-k for k in range(B)])
    denominator = reduce(lambda x, y: x * y % mod, [B-k for k in range(B)])
    return numerator * pow(denominator, mod - 2, mod) % mod


S = int(input())
p = S // 3
A = 0

for b in range(p):

    r = S-3*(b+1)

    if b == 0:
        A+=1
    else:
        A+=cmb(r,b)

print(A%mod)
Buggy python submission (verdict: Runtime Error):
a = input()

if a.isupper() == True:
  print('A')

elif a.supper() == False:
  print('a')

Fixed submission:
a = input ()

if a.isupper():
    print('A')
else:
    print('a')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

DP = [0]
for i in range(N - 1):
    act = float("inf")
    for k in range(K):
        if i - k < 0: continue
        act = min(DP[-1 - k] + abs(h[i - k] - h[i + 1]), act)
    DP += [act]

print(DP[-1])

Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

N,K=map(int,input().split())
height_list=list(map(int,input().split()))
score_list=[ 0, abs(height_list[0]-height_list[1]) ]



for i in range(2,N):
    tmp_list = []
    for k in range(K):
        tmp_list.append(abs(height_list[i]-height_list[i-k-1])+score_list[i-k-1])
    score_list.append(min(tmp_list))

print(score_list[N-1])



Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
height_list=list(map(int,input().split()))
score_list=[ 0, abs(height_list[0]-height_list[1]) ]



for i in range(2,N):
    tmp_list = []
    for k in range(K):
        tmp_list.append(abs(height_list[i]-height_list[i-k-1])+score_list[i-k-1])
    score_list.append(min(tmp_list))

print(score_list[N-1])



Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
import math
n,x,m=map(int, input().split())
a = x
ans = a
l=[a]
flg=[0]*m

for i in range(1,m):
    tmp=(a*a)%m
    a=tmp 
    ans+=tmp
    if flg[a]==1:
        lp = l.index(a)
        break
    else:
        l.append(a)
        flg[a]=1

if lp != 0:
    l2 = l[lp:]
    tmp = sum(l2)
    b=math.floor((n-len(l))/len(l2))
    c=(n-len(l))%len(l2)
    if c==0:
        ans+=b*tmp
    else:
        ans+=b*tmp+sum(l2[:c])-l2[0]

print(ans)

Fixed submission:
n,x,m=map(int, input().split())
a=x
ans=a
flg=[0]*m
flg[a]=1
l=[a]
lp=-1

for i in range(1,m+1):   
    if n <= i:
        break
    tmp=(a*a)%m
    a=tmp
    if flg[a]==1:
        lp = l.index(a)
        break
    else:    
        ans+=tmp
        l.append(a)
        flg[a]=1

if lp != -1:
    l2 = l[lp:]
    tmp = sum(l2)
    b=(n-len(l))//len(l2)
    c=n-len(l)-b*len(l2)
    ans=ans+(b*tmp)+sum(l2[:c])

print(ans)

Buggy python submission (verdict: Runtime Error):
n,x,m=map(int, input().split())
a = x
ans = a
l=[a]

for i in range(1,n):
    tmp=(a*a)%m
    a=tmp  
    ans+=tmp
    if a in l:
        lp = l.index(a)
        break
    else:
        l.append(a)

l2 = l[lp:]
tmp = sum(l2)

b=int((n-len(l))/len(l2))
c=(n-len(l))%len(l2)

ans+=b*tmp+sum(l2[:c])
print(ans)

Fixed submission:
n,x,m=map(int, input().split())
a=x
ans=a
flg=[0]*m
flg[a]=1
l=[a]
lp=-1

for i in range(1,m+1):   
    if n <= i:
        break
    tmp=(a*a)%m
    a=tmp
    if flg[a]==1:
        lp = l.index(a)
        break
    else:    
        ans+=tmp
        l.append(a)
        flg[a]=1

if lp != -1:
    l2 = l[lp:]
    tmp = sum(l2)
    b=(n-len(l))//len(l2)
    c=n-len(l)-b*len(l2)
    ans=ans+(b*tmp)+sum(l2[:c])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
ans=0

for i in range(n):
    for j in range(n):
        if i > j:
            ans += a[i]*a[j]
        if ans > (10 ** 9 + 7):
            ans = ans % (10 ** 9 + 7)

print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
ans=0

s=sum(a)

for i in range(1,len(a)+1):
    ans += a[i-1] * (s-a[i-1])
    s = s-a[i-1]
    ans = ans % (10 ** 9 + 7)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n=int(input())
a=list(map(int, input().split()))
ans=0

for v in itertools.combinations(a, 2):
    ans += v[0]*v[1]

ans = ans % (10 ** 9 + 7)
print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
ans=0

s=sum(a)

for i in range(1,len(a)+1):
    ans += a[i-1] * (s-a[i-1])
    s = s-a[i-1]
    ans = ans % (10 ** 9 + 7)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n=int(input())
a=list(map(int, input().split()))
ans=0

for v in itertools.combinations(a, 2):
    ans += v[0]*v[1]
    if ans > (10 ** 9 + 7):
        ans = ans % (10 ** 9 + 7)

print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
ans=0

s=sum(a)

for i in range(1,len(a)+1):
    ans += a[i-1] * (s-a[i-1])
    s = s-a[i-1]
    ans = ans % (10 ** 9 + 7)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n=int(input())
a=list(map(int, input().split()))
ans=0

for v in itertools.combinations(a, 2):
    ans += v[0]*v[1]
    ans = ans % (10 ** 9 + 7)

print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
ans=0

s=sum(a)

for i in range(1,len(a)+1):
    ans += a[i-1] * (s-a[i-1])
    s = s-a[i-1]
    ans = ans % (10 ** 9 + 7)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x,k,d=map(int, input().split()) 
tmp = k

ans = abs(x)%d
k = k - int(abs(x)/d)

if k < 0:
    ans = x
    k = tmp

for i in range(k):
    if abs(ans) <= d and (k-i)%2 == 0:
        print(abs(ans))
        exit()
    elif ans >= 0:
        ans = ans - d
    elif ans < 0:
        ans = ans + d

print(abs(ans))


Fixed submission:
x,k,d=map(int, input().split()) 
tmp = k

ans = abs(x)%d
k = k - int(abs(x)/d)

if k < 0:
    ans = abs(x)
    ans = ans - (tmp * d)
    print(ans)
    exit()

for i in range(k):
    if abs(ans) <= d and (k-i)%2 == 0:
        print(abs(ans))
        exit()
    elif ans >= 0:
        ans = ans - d
    elif ans < 0:
        ans = ans + d

print(abs(ans))

Buggy python submission (verdict: Time Limit Exceeded):
x,k,d=map(int, input().split()) 
ans = x

for i in range(k):
    if abs(ans) <= d and (k-i)%2 == 0:
        print(abs(ans))
        exit()
    elif ans >= 0:
        ans = ans - d
    elif ans < 0:
        ans = ans + d

print(abs(ans))


Fixed submission:
x,k,d=map(int, input().split()) 
tmp = k

ans = abs(x)%d
k = k - int(abs(x)/d)

if k < 0:
    ans = abs(x)
    ans = ans - (tmp * d)
    print(ans)
    exit()

for i in range(k):
    if abs(ans) <= d and (k-i)%2 == 0:
        print(abs(ans))
        exit()
    elif ans >= 0:
        ans = ans - d
    elif ans < 0:
        ans = ans + d

print(abs(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
a=list(map(int, input().split())) 
cnt = 0
tmp = 1

for i in range(n):
    if cnt < k:
        tmp = tmp * a[i]
        cnt += 1
    else:
        tmp2 = tmp / a[i-k] * a[i]
        if tmp < tmp2:
           print('Yes')
        else:
            print('No')
        tmp = tmp2
    #print(tmp)

Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split())) 

for i in range(n):
    if i >= k:
        if a[i-k] < a[i]:
            #print(a[i])
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ans = 0
ai = 0
tmp = 0

for i in range(n):
    if tmp + a[i] <= k:
        tmp = tmp + a[i]
        ans += 1
        ai = i

for i in range(m):
    if tmp + b[i] <= k:
        tmp = tmp + b[i]
        ans += 1
    elif tmp - a[ai] + b[i] <= k:
        tmp = tmp - a[ai] + b[i]
        ai -= 1

print(ans)

Fixed submission:
import sys
from itertools import accumulate

n,m,k=map(int, input().split())
a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
ans = 0
j = m

#print(a,b)

for i,item in enumerate(a):
        if k<item:
            break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def num_divisors_table(n):
    table = [0] * (n + 1)   
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
        table[i] *= i   
    return table

ans = num_divisors_table(N)
#print(ans)
print(sum(ans))

Fixed submission:
n = int(input())

def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
    
print(div(n))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))

a.sort()
dp = [True] * (max(a) + 1)
ans = 0

for i,num in enumerate(a):
    if dp[num-1]:
        j= 2 * num
        while j <= max(a):
            dp[j-1] = False
            j += num
        if not i+1==len(a):
            if a[i]==a[i+1]:
                dp[num-1] = False

for k in a:
    if dp[k-1]:
        ans += 1

#print(dp)
print(ans)

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

a.sort()
dp = [True] * a[-1]
ans = 0

for i,num in enumerate(a):
    if dp[num-1]:
        j= 2 * num
        while j <= a[-1]:
            dp[j-1] = False
            j += num
        if not i+1==len(a):
            if a[i]==a[i+1]:
                dp[num-1] = False

for k in a:
    if dp[k-1]:
        ans += 1

#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))

l = sorted(a)
dp = [True] * (max(l) + 1)
ans = 0

for i,num in enumerate(l):
    if dp[num-1]:
        j= 2 * num
        while j <= max(l):
            dp[j-1] = False
            j += num
        if not i+1==len(l):
            if l[i]==l[i+1]:
                dp[num-1] = False

for k in l:
    if dp[k-1]:
        ans += 1

#print(dp)
print(ans)

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

a.sort()
dp = [True] * a[-1]
ans = 0

for i,num in enumerate(a):
    if dp[num-1]:
        j= 2 * num
        while j <= a[-1]:
            dp[j-1] = False
            j += num
        if not i+1==len(a):
            if a[i]==a[i+1]:
                dp[num-1] = False

for k in a:
    if dp[k-1]:
        ans += 1

#print(dp)
print(ans)

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

l = sorted(a)
tmp = l
ans = []
ans.append(tmp[0])

#print(l)

for i in range(n):
    tmp = [s for s in tmp if s % ans[0] != 0]
    #print(tmp)
    if tmp != []:
        if tmp[0] not in ans:
            ans.insert(0,tmp[0])

if len(ans) == 1 and l[0] == l[1]:
    print(0)
else:
    print(len(ans))

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

a.sort()
dp = [True] * a[-1]
ans = 0

for i,num in enumerate(a):
    if dp[num-1]:
        j= 2 * num
        while j <= a[-1]:
            dp[j-1] = False
            j += num
        if not i+1==len(a):
            if a[i]==a[i+1]:
                dp[num-1] = False

for k in a:
    if dp[k-1]:
        ans += 1

#print(dp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input()) 
c=list(map(int, input().split()))

ans = 1
for i in range(n):
    ans *= c[i]
    
if ans > 1000000000000000000:
        print('-1')
else:
    print(ans)
 

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

ans = 1
if 0 in c:
    print('0')
    exit()

for i in range(n):
    ans *= c[i]
    if ans > 1000000000000000000:
        print('-1')
        exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
x=int(input())

b = -1
for i in range(100000):
    tmp = i*i*i*i*i + 1
    if x == tmp:
        a = i
        break

print(a,b)

Fixed submission:
x=int(input())
a = 0
b = 0

for i in range(1000):
    for j in range(1,1000):
        tmp = (i*i*i*i*i) + (j*j*j*j*j)
        if x == tmp:
            a = i
            b = -j
            break

for i in range(1000):
    for j in range(1,1000):
        tmp = (i*i*i*i*i) - (j*j*j*j*j)
        if x == tmp:
            a = i
            b = j
            break

print(a,b)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i+a[i]))
    tmp = i - a[i]
    ans += ru.count(tmp)

print(ans)

Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i+a[i]))
    #print(ru)
    for j in range(len(ru)-1):
        if ru[j] == i - a[i]:
            ans += 1

print(ans)

Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(1,n):
    ru.append(a[0] + a[i])
#print(ru)

tmp =  [j for j in range(len(ru))  if j+1 == ru[j]]
ans = ans + len(tmp)

for i in range(1,n-1):
    ru.pop(0)
    ru = [x- a[i-1] +a[i] for x in ru]
    #print(ru)
    tmp =  [j for j in range(len(ru)) if j+1 == ru[j]]
    ans = ans + len(tmp)


print(ans)

Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split())) 
ans = 0
cnt = 1

for i in range(n-1):
    tmp = a[i] + a[i+1]
    for j in range(i+2,n):
        tmp = tmp - a[j-1] + a[j]
        #print(cnt,tmp)
        cnt += 1
        if cnt == tmp:
            ans += 1
    cnt = 1

print(ans)

Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n=int(input())
a=list(map(int, input().split())) 
ans = 0
n = range(n)

for c in itertools.combinations(n, 2):
    #print(c)
    if c[1]-c[0] == a[c[0]]+a[c[1]]:
        ans += 1

print(ans)

Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b,n=map(int, input().split()) 
max = -10000
tmp = 0

for i in range(1, n+1):
    tmp = math.floor(a * i / b) - math.floor(i / b)
    if max < tmp:
        max = tmp

print(max)

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

max = int(b/k)

for i in range(1,max+1):
    tmp = k * i
    if a <= tmp and b >= tmp:
        print('OK')
        exit()

print('NG')
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n=int(input()) 
a=list(map(int, input().split())) 

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

Fixed submission:
import collections

n=int(input()) 
a=list(map(int, input().split())) 

l = [0] * n

for i in range(n-1):
    l[a[i]-1] = l[a[i]-1] + 1

for i in range(n):
    print(l[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

k=int(input())
sum = 0

for a in range(k+1):
    for b in range(k+1):
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = sum + gcd(a,b,c)

print(sum)

Fixed submission:
import math
from functools import reduce

k=int(input())
sum = 0

for a in range(k+1):
    for b in range(k+1):
        tmp = math.gcd(a,b)
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = sum + math.gcd(tmp,c)

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

k=int(input())
sum = 0

for a in range(k+1):
    for b in range(k+1):
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = sum + gcd(a,b,c)

print(sum)

Fixed submission:
import math
from functools import reduce

k=int(input())
sum = 0

for a in range(k+1):
    for b in range(k+1):
        tmp = math.gcd(a,b)
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = sum + math.gcd(tmp,c)

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(1,int(n/2)+1):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)

Fixed submission:
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(1,int((n-i)/2)+1):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(0,int(n-i)):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)

Fixed submission:
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(1,int((n-i)/2)+1):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(0,n):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)

Fixed submission:
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(1,int((n-i)/2)+1):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input()) 
c = 0
tmp = 0

for i in range(3234566668):
    if i != 0:
        s = str(i)
        if len(s) != 1:
            for j in range(len(s)-1):
                if int(s[j]) > int(s[j+1]):
                    a = int(s[j]) - int(s[j+1])
                else:
                    a = int(s[j+1]) - int(s[j])
                if a > 1:
                    tmp = 0
                    break
                tmp = 1
        else:
            tmp = 1

        if tmp == 1:
            c = c + 1
        if c == n:
            print(i)
            exit()

Fixed submission:
from collections import deque
k=int(input())

q = deque([1,2,3,4,5,6,7,8,9])
ans = 0
flg = 0
cnt = 0

while(flg != 1):
    ans = q.popleft()
    cnt += 1

    tmp = ans % 10
    if tmp != 0:
        q.append(ans * 10 + tmp - 1)
    
    q.append(ans * 10 + tmp)
    
    if tmp != 9:
        q.append(ans * 10 + tmp + 1)

    if cnt == k:
        print(ans)
        flg = 1