Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import takewhile, islice


S = input()
total = 0
for idx in range(len(S) + 1):
    left = sum(1 for _ in takewhile(lambda x: x == "<", reversed(S[:idx])))
    right = sum(1 for _ in takewhile(lambda x: x == ">", islice(S, idx, None)))
    total += max((left, right))
print(total)


Fixed submission:
S = input()
A = [0 for _ in range(len(S) + 1)]

for idx in range(len(S)):
    if S[idx] == "<":
        A[idx + 1] = max(A[idx + 1], A[idx] + 1)

for idx in reversed(range(len(S))):
    if S[idx] == ">":
        A[idx] = max(A[idx], A[idx + 1] + 1)

print(sum(A))

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

S = input()
total = 0
for idx in range(len(S) + 1):
    left = sum(1 for _ in takewhile(lambda x: x == "<", reversed(S[:idx])))
    right = sum(1 for _ in takewhile(lambda x: x == ">", S[idx:]))
    total += max((left, right))
print(total)


Fixed submission:
S = input()
A = [0 for _ in range(len(S) + 1)]

for idx in range(len(S)):
    if S[idx] == "<":
        A[idx + 1] = max(A[idx + 1], A[idx] + 1)

for idx in reversed(range(len(S))):
    if S[idx] == ">":
        A[idx] = max(A[idx], A[idx + 1] + 1)

print(sum(A))

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

S = input()
total = 0
for idx in range(len(S) + 1):
    left = sum(1 for _ in takewhile(lambda x: x == "<", reversed(S[:idx])))
    right = sum(1 for _ in takewhile(lambda x: x == ">", S[idx:]))
    total += max((left, right))
print(total)


Fixed submission:
S = input()
A = [0 for _ in range(len(S) + 1)]

for idx in range(len(S)):
    if S[idx] == "<":
        A[idx + 1] = max(A[idx + 1], A[idx] + 1)

for idx in reversed(range(len(S))):
    if S[idx] == ">":
        A[idx] = max(A[idx], A[idx + 1] + 1)

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(" ")))

d = {}
for a in A:
    d[A.index(a) + 1] = a

ans = [str(k) for k, _ in sorted(d.items(), key=lambda x: x[1])]
print(" ".join(ans))


Fixed submission:
N = int(input())
A = list(map(int, input().split(" ")))

d = dict(zip(range(N), A))

ans = [str(k + 1) for k, _ in sorted(d.items(), key=lambda x: x[1])]
print(" ".join(ans))
Buggy python submission (verdict: Runtime Error):
from math import gcd


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


A, B = tuple(map(int, input().split(" ")))

print(len(set(prime_factorize(gcd(A, B)))) + 1)


Fixed submission:
from fractions import gcd


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


A, B = tuple(map(int, input().split(" ")))

print(len(set(prime_factorize(gcd(A, B)))) + 1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if c - (a - b) >= 0:
    print(c - (a - b))
else:
    print(0)

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

if c - (a - b) >= 0:
    print(c - (a - b))
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import re

N, Q = map(int, input().split())
S = input()
targets = [tuple(map(int, input().split())) for _ in range(Q)]

for target in targets:
    l, r = target
    s = S[l - 1:r]
    print(len(re.findall("AC", s)))


Fixed submission:
N, Q = map(int, input().split())
S = input()
queries = [tuple(map(int, input().split())) for _ in range(Q)]
counters = [0 for _ in range(N + 1)]
for idx, s in enumerate(S):
    counters[idx + 1] = counters[idx] + (1 if S[idx:idx + 2] == "AC" else 0)
for q in queries:
    l, r = q
    print(counters[r - 1] - counters[l - 1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
favorites = {*tuple(range(1, M + 1))}
for _ in range(N):
    K, *fav = map(int, input().split())
    favorites = favorites & set(fav)
print(len(favorites))


Fixed submission:
N, M = map(int, input().split())
favorites = set(i for i in range(1, M + 1))
for _ in range(N):
    K, *fav = map(int, input().split())
    favorites = favorites & set(fav)
print(len(favorites))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
c = 0
while True:
    c += S.count("BW")
    replaced = S.replace("BW", "WB")
    if replaced == S:
        break
    else:
        S = replaced
print(c)

Fixed submission:
S = input()
c = 0
current_B_counter = 0
for s in S:
    if s == "B":
        current_B_counter += 1
    if s == "W":
        c += current_B_counter

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

print(min(map(lambda x: x[-1] - x[0], [H[i:i + K] for i in range(len(H)) if len(H[i:i + K]) == K])))


Fixed submission:
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()

print(min((H[i + K - 1] - H[i] for i in range(N - K + 1))))

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

print(min(map(lambda x: x[-1] - x[0], [H[i:i + K] for i in range(len(H)) if len(H[i:i + K]) == K])))


Fixed submission:
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()

print(min((H[i + K - 1] - H[i] for i in range(N - K + 1))))
Buggy python submission (verdict: Runtime Error):
from itertools import product

A, B, C, D = input()
for op1, op2, op3 in product("+-", repeat=3):
    expr = f"{A}{op1}{B}{op2}{C}{op3}{D}"
    if eval(expr) == 7:
        print(f"{A}{op1}{B}{op2}{C}{op3}{D}=7")
        break


Fixed submission:
from itertools import product

A, B, C, D = input()
for op1, op2, op3 in product("+-", repeat=3):
    expr = "{}{}{}{}{}{}{}".format(A, op1, B, op2, C, op3, D)
    if eval(expr) == 7:
        print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
        break
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))


Fixed submission:
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from functools import reduce
from operator import or_


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())
lcm = Counter()
for _ in range(N):
    factors = Counter(prime_factorize(int(input())))
    for key, value in factors.items():
        if lcm[key] < value:
            lcm[key] = value
ans = 1
for key, value in lcm.items():
    ans *= key ** value
print(ans)


Fixed submission:
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from functools import reduce
from operator import or_


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())
T = [Counter(prime_factorize(int(input()))) for _ in range(N)]

factors = reduce(or_, (c.keys() for c in T))
ans = 1
for factor in factors:
    ans *= factor ** max(c[factor] for c in T)
print(ans)


Fixed submission:
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))
Buggy python submission (verdict: Runtime Error):
a, b, c = input().split(" ")

print("YES" if b - a == c -b else "NO")


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

print("YES" if b - a == c - b else "NO")
Buggy python submission (verdict: Runtime Error):
from typing import Tuple, List


def manhattan_distance(p: Tuple[int, int], q: Tuple[int, int]) -> int:
    return abs(p[0] - q[0]) + abs(p[1] - q[1])


N, M = map(int, input().split())
students: List[Tuple[int, int]] = [tuple(map(int, input().split())) for _ in range(N)]
checkpoints: List[Tuple[int, int]] = [tuple(map(int, input().split())) for _ in range(M)]

for student in students:
    p = min([(manhattan_distance(student, checkpoint), idx) for idx, checkpoint in enumerate(checkpoints, start=1)])
    print(p[1])


Fixed submission:
def manhattan_distance(p, q) -> int:
    return abs(p[0] - q[0]) + abs(p[1] - q[1])


N, M = map(int, input().split())
students = [tuple(map(int, input().split())) for _ in range(N)]
checkpoints = [tuple(map(int, input().split())) for _ in range(M)]

for student in students:
    p = min([(manhattan_distance(student, checkpoint), idx) for idx, checkpoint in enumerate(checkpoints, start=1)])
    print(p[1])
Buggy python submission (verdict: Runtime Error):
from collections import deque

A = deque(input())
B = deque(input())
C = deque(input())

current = A.popleft()

while True:
    if current == "a":
        current = A.popleft()
    elif current == "b":
        current = B.popleft()
    elif current == "c":
        current = C.popleft()
    if current == "a" and len(A) == 0:
        print("A")
        break
    elif current == "b" and len(B) == 0:
        print("B")
        break
    elif current == "c" and len(C) == 0:
        print("C")
        break

Fixed submission:
from collections import deque

A = deque(input())
B = deque(input())
C = deque(input())

current = "a"

while True:
    if current == "a":
        current = A.popleft()
    elif current == "b":
        current = B.popleft()
    elif current == "c":
        current = C.popleft()
    if current == "a" and len(A) == 0:
        print("A")
        break
    elif current == "b" and len(B) == 0:
        print("B")
        break
    elif current == "c" and len(C) == 0:
        print("C")
        break
Buggy python submission (verdict: Runtime Error):
x = intput()
if 'A' <= x <= 'Z':
  print("A")
else:
  print("a")

Fixed submission:
x = input()
if 'A' <= x <= 'Z':
  print("A")
else:
  print("a")
Buggy python submission (verdict: Runtime Error):
n=int(input())
c=list(map(int,input().split()))
q=int(input())
su=0
w={}
for i in range(len(c)):
	su=su+c[i]
	if(c[i] not in w):
		w[c[i]]=1
	else:
		w[c[i]]=w[c[i]]+1
for j in range(q):
	r,s=map(int,input().split())
	count=w[r]
	if(s in w):
		w[s]=w[s]+count
	else:
		w[s]=count
	su=su-count*r+count*s
	print(su)



Fixed submission:
n=int(input())
c=list(map(int,input().split()))
q=int(input())
su=0
d=[]
for i in range(1000003):
	d.append(0)
for i in range(len(c)):
	d[c[i]]=d[c[i]]+1
	su=su+c[i]
for j in range(q):
	r,s=map(int,input().split())
	su=su-d[r]*r+d[r]*s
	d[s]=d[s]+d[r]
	d[r]=0
	print(su)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c=list(map(int,input().split()))
q=int(input())
s=0
for j in range(q):
	r,s=map(int,input().split())
	d=[]
	for i in range(len(c)):
		if(c[i]==r):
			d.append(i)
	for i in d:
		c[i]=s
	print(sum(c))

Fixed submission:
n=int(input())
c=list(map(int,input().split()))
q=int(input())
su=0
d=[]
for i in range(1000003):
	d.append(0)
for i in range(len(c)):
	d[c[i]]=d[c[i]]+1
	su=su+c[i]
for j in range(q):
	r,s=map(int,input().split())
	su=su-d[r]*r+d[r]*s
	d[s]=d[s]+d[r]
	d[r]=0
	print(su)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=list(map(int,input().split()))
print(b)
c=1
for i in range(a):
  c=c*b[i]
if(c>1000000000000000000):
  print(-1)
else:
  print(c)

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

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=list(map(int,input().split()))
c=1
for i in range(a):
  c=c*b[i]
if(c>1000000000000000000):
  print(-1)
else:
  print(c)

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

Buggy python submission (verdict: Runtime Error):
list_a=list(map(int, input().split()))
result=1
for a in range(list_a):
  result = result*a
  
if result > 10**18:
  print('-1')
else:
  print(result)

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
N = int(input())
list_n = list(map(int, input().split()))
flag = 0
for i in range(N):
  if list_n[i] % 2 == 0:
    if (list_n[i] % 3 != 0) and (list_n[i] % 5 != 0):
      print('DENIED')
      flag = 1
      break
    else:
      continue
if flag == 0:
  print('APPROVED')

Fixed submission:
a,b,c = map(int, input().split())
if a == b:
  if a != c:
    print('Yes')
  else:
    print('No')
else:
  if (a == c) or (b == c):
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

keta_now = 0
res_num = []

MAP = {
    1:"a",
    2:"b",
    3:"c",
    4:"d",
    5:"e",
    6:"f",
    7:"g",
    8:"h",
    9:"i",
    10:"j",
    11:"k",
    12:"l",
    13:"m",
    14:"n",
    15:"o",
    16:"p",
    17:"q",
    18:"r",
    19:"s",
    20:"t",
    21:"u",
    22:"v",
    23:"w",
    24:"x",
    25:"y",
    26:"z",
}

while True:
    keta_now += 1
    if n < sum([26**k for k in range(keta_now+1)]):
        
        for i in range(keta_now, 0, -1):
            for al in range(26, 0, -1):
                if i == 1:
                    res_num.append(n)
                    break
                if n >= (26**(i-1) * al):
                    res_num.append(al)
                    n -= (26**(i-1) * al)
                    break
            
        break           
print("".join([MAP[n] for n in res_num]))


Fixed submission:
"""
問題の解釈
長さがlであるような文字列の中で辞書順でk番目のものを求めよ

26進表記における位の値の求め方
1. 変数xをk-1で初期化し、xが0となるまで以下の操作を繰り返す
2. xを26で割った商がq、余りがrであるとする。この操作がi回目に実行された時のrがk-1の下からi番目の桁である。xをqで置き換える
"""
ALPHABET = "abcdefghijklmnopqrstuvwxyz"

n = int(input())

# 長さの判定
# 26 **11 > 10*15より
ll = 0
for l in range(1, 12):
    ll += 26**l
    if ll >= n:
        break

ans = []
for li in range(1, l+1):
    r = n % 26
    q = n // 26
    if r == 0:
        q -= 1
    ans.append(r)
    n = q

answer = ""
for s in ans[::-1]:
    answer += ALPHABET[s-1] 
print(answer)

Buggy python submission (verdict: Runtime Error):
n = int(input())

import math
# 桁判定
keta_now = 0
res_num = []

MAP = {
    1:"a",
    2:"b",
    3:"c",
    4:"d",
    5:"e",
    6:"f",
    7:"g",
    8:"h",
    9:"i",
    10:"j",
    11:"k",
    12:"l",
    13:"m",
    14:"n",
    15:"o",
    16:"p",
    17:"q",
    18:"r",
    19:"s",
    20:"t",
    21:"u",
    22:"v",
    23:"w",
    24:"x",
    25:"y",
    26:"z",
}

while True:
    keta_now += 1
    # if n < (26**keta_now + 26**(keta_now-1)):
    if n < sum([26**k for k in range(keta_now+1)]):
        # 26より大きく702以下
        
        # 最大桁iのうち、i**1からi**26(a to z)でnより小さく最大のものを26_iとする
        # n - 26_i
        # (i-1)**1から(i-1)**26でn -26_iより小さく最大のもの
        # 繰り返してiが0の時に終了
        for i in range(keta_now, 0, -1):
            for al in range(26, 0, -1):
                if i == 1:
                    res_num.append(n)
                    break
                if n >= (26**(i-1) * al):
                    res_num.append(al)
                    n -= (26**(i-1) * al)
                    break
            
        break           
print("".join([MAP[n] for n in res_num]))
    

Fixed submission:
"""
問題の解釈
長さがlであるような文字列の中で辞書順でk番目のものを求めよ

26進表記における位の値の求め方
1. 変数xをk-1で初期化し、xが0となるまで以下の操作を繰り返す
2. xを26で割った商がq、余りがrであるとする。この操作がi回目に実行された時のrがk-1の下からi番目の桁である。xをqで置き換える
"""
ALPHABET = "abcdefghijklmnopqrstuvwxyz"

n = int(input())

# 長さの判定
# 26 **11 > 10*15より
ll = 0
for l in range(1, 12):
    ll += 26**l
    if ll >= n:
        break

ans = []
for li in range(1, l+1):
    r = n % 26
    q = n // 26
    if r == 0:
        q -= 1
    ans.append(r)
    n = q

answer = ""
for s in ans[::-1]:
    answer += ALPHABET[s-1] 
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

a0 = a[0]
a_else = a[1:]

for ai  in a_else:
    a0 *= ai


if a0 > 10**18:
    print('-1')
else:
    print(a0)
    

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

a0 = a[0]
a_else = a[1:]
th = 10**18
for ai in sorted(a_else):
    a0 *= ai
    if a0 > th:
        print('-1')
        exit()

print(a0)
Buggy python submission (verdict: Runtime Error):
x = int(input())
ans = 0
for i in range(x+1):
    if (i%3 != 0) and (i%5 != 0):
      a += i

print(a)

Fixed submission:
x = int(input())
ans = 0
for i in range(x+1):
    if (i%3 != 0) and (i%5 != 0):
      ans += i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lrs = [ list(map(int, input().split())) for _ in range(m)]

cards = set([i for i in range(lrs[0][0], lrs[0][1]+1)])
for lr in lrs[1:]:
    tmp = set([i for i in range(lr[0], lr[1]+1)])
    cards.intersection_update(tmp)
    

print(len(cards))
        
    

Fixed submission:
n, m = map(int, input().split())
lrs = [ list(map(int, input().split())) for _ in range(m)]

cards = [lrs[0][0], lrs[0][1]] # [min, max]

for lr in lrs[1:]:
    if (lr[1] < cards[0]) or (lr[0] > cards[1]):
        print(0)
        exit()

    cards[0] = max(cards[0], lr[0])
    cards[1] = min(cards[1], lr[1])
    

print(cards[1] - cards[0] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ans = a[0]
for a_ in a[1:]:
    ans *= a_
print(-1 if ans > 10 ** 18 else ans)


Fixed submission:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

if 0 in a:
    print(0)
    exit()

ans = a[0]
for a_ in a[1:]:
    if ans * a_ <= 10 ** 18:
        ans *= a_
    else:
        print(-1)
        break
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
n, m, q  = map(int, input().split())
abcd  = [tuple(map(int, input().split())) for i in range(q)]

ans = 0

def check(A):
    global ans
    max_ = 0

    # 点数計算
    for (a, b, c, d) in abcd:
        if A[b-1] - A[a-1] == c:
            max_ += d

    # 最大値更新
    ans = max(ans, max_)

def suretu(A=[], st=1):
    # 再帰的に数字を1つずつ足してって数列生成
    for i in range(st, 11):
        if len(A) == m: # 数列完成
            check(A)
            return
        else:
            suretu(A + [i], i)

    return ans

print(suretu())


Fixed submission:
#!/usr/bin/env python3
n, m, q  = map(int, input().split())
abcd  = [tuple(map(int, input().split())) for i in range(q)]

ans = 0

def check(A):
    global ans
    max_ = 0

    # 点数計算
    for (a, b, c, d) in abcd:
        if A[b-1] - A[a-1] == c:
            max_ += d

    # 最大値更新
    ans = max(ans, max_)

def suretu(A=[], st=1):
    # 再帰的に数字を1つずつ足してって数列生成
    for i in range(st, m+1):
        if len(A) == n: # 数列完成
            check(A)
            return
        else:
            suretu(A + [i], i)

    return ans

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

x = min(b. n)
print(int(a * x / b))


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

x = min(b - 1, n)
ans = int(a * x / b)

#if a == 1 or b == 1 or b == n:
#    print(0)
#else:
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

sum_ = 0
for i in range(1, n+1):
  if i%15 !=0:
    sum += i
    
print(sum_)

Fixed submission:
n = int(input())

sum_ = 0
for i in range(1, n+1):
  if i%15 !=0 and i%3 !=0 and i%5 !=0:
    sum_ += i
    
print(sum_)

Buggy python submission (verdict: Runtime Error):
n = int(input())

sum_ = 0
for i in range(1, n+1):
  if n%15 !=0:
    sum += i
    
print(sum_)

Fixed submission:
n = int(input())

sum_ = 0
for i in range(1, n+1):
  if i%15 !=0 and i%3 !=0 and i%5 !=0:
    sum_ += i
    
print(sum_)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

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

n = int(input())

sum_ = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      sum_ += gcd(a, b, c)
    
print(sum_)

Fixed submission:
import math
from functools import reduce

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

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

n = int(input())

sum_ = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      sum_ += gcd(a, b, c)
    
print(sum_)

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

n = int(input())

sum_ = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      sum_ += math.gcd(a, b, c)
    
print(sum_)

Fixed submission:
import math
from functools import reduce

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

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

n = int(input())

sum_ = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      sum_ += gcd(a, b, c)
    
print(sum_)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

# 条件1だけを満たす組み合わせの数
ans = S.count('R') * S.count('G') * S.count('B')

# 条件2を満たさないものを、条件1でカウントしたものから減算
for l in range(N): # left
  for r in range(l+1, N): # right
    c = (r - l) // 2 + l # center
    if c - l == r - c: # 条件2を満たさない
      if len(set([S[l], S[c], S[r]])) == 3: # 条件1を満たす
        ans -= 1

print(ans)

Fixed submission:
N = int(input())
S = input()

# 条件1だけを満たす組み合わせの数
ans = S.count('R') * S.count('G') * S.count('B')

# 条件2を満たさないものを、条件1でカウントしたものから減算
for l in range(N): # left
  for r in range(l+1, N): # right
    c = (r - l) // 2 + l # center
    if c - l == r - c: # 条件2を満たさない
      if len(set([S[l], S[c], S[r]])) == 3: # 条件1を満たす
        ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(K):
  x = queue.pop(0)
  
  if x % 10 != 0:
    queue.append(10 * x + (x % 10) - 1)
    
  queue.append((10 * x) + x % 10)
    
  if x % 10 != 9:
    queue.append(10 * x + (x % 10) + 1)
    
print(x)

Fixed submission:
from collections import deque
K = int(input())
queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(K):
  x = queue.popleft()
  
  if x % 10 != 0:
    queue.append(10 * x + (x % 10) - 1)
    
  queue.append((10 * x) + x % 10)
    
  if x % 10 != 9:
    queue.append(10 * x + (x % 10) + 1)
    
print(x)