Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
x = int(input())
k = 10000
a = np.arange(-k, k)[:, np.newaxis]
b = np.arange(-k, k)
 
res = a**5 - b**5  == x
res.nonzero()
ans = (np.argwhere(res) - k )[0]
print(ans[0],ans[1])

Fixed submission:
D = {}
k = 130
x = int(input())
for i in range(-k, k+1):
    D[i] = i**5
for i in range(-k, k+1):
    for j in range(-k, k+1):
        if D[i]-D[j] == x:
            print(i,j)
            exit()
Buggy python submission (verdict: Runtime Error):
def cal(i):
    return floor(a*i/b)-a*floor(i/b)
from  math import floor
a, b, n = map(int, input().split())
if b-1<n:
    ans = cal(b-1)
print(max(cal(ans), cal(0),cal(n)))

Fixed submission:
a, b, n = map(int, input().split())
def cal(x):
    return (a*x)//b - a*(x//b)
print(cal(min(b-1,n)))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
print(min(n%k,k-n%k) if n >= k else min(n,n%k,n-k%n))

Fixed submission:
n,k=map(int,input().split())
if n >= k:
    print(min(n%k,k-n%k))
elif n == 0:
    print(n)
else:
    print(min(n,k-n))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s=input()
    q=int(input())
    for _ in range(q):
        t=input()
        if t=='1':
            s=s[::-1]
        else:
            t = t.split()
            if int(t[1])==1:
                s = t[2] + s
            else:
                s  += t[2]
    print(s)
main()

Fixed submission:
def main():
    s=input()
    q=int(input())
    rot = 0
    A = ''
    B = ''
    for _ in range(q):
        t=input()
        if t=='1':
            rot += 1
        else:
            t = t.split()
            if (int(t[1])+rot)%2==1:
                A += t[2] 
            else:
                B  += t[2]
    if not rot%2:
        print(''.join(A[::-1]+s+B))
    else:
        print(''.join(B[::-1]+s[::-1]+A))        
main()
Buggy python submission (verdict: Runtime Error):
A = []
B = [0]*9

# Aには [1, 2, 3, 4, 5, 6, 7, 8, 9] の形で格納.
for _ in range(3):
    A += [int(i) for i in input().split()]

# 印をつけた数字をBに残しておく.
n=int(input())
for _ in range(n):
    b = int(input())
    for i, a in enumerate(A):
        if b == a:
            B[i] = 1

#ビンゴの可能性がある組を作っておく.
C = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
flag = 0

# Bで1と記録が残っていれば真
for a,b,c in C:
    if B[a-1] and B[b-1] and B[c-1]:
        flag = 1
print('Yes' if Chk else 'No')

Fixed submission:
import itertools
def main():
    A=[list(map(int,input().split())) for _ in range(3)]
    n=int(input())
    B=list(int(input()) for _ in range(n))
    B=sorted(B)
    C=itertools.combinations(B,3)
    if n<3:
        print('No')
        return
    
    ans=[]
    ans.append(sorted(A[0]))
    ans.append(sorted(A[1]))
    ans.append(sorted(A[2]))
    ans.append(sorted([a[0] for a in A]))
    ans.append(sorted([a[1] for a in A]))
    ans.append(sorted([a[2] for a in A]))
    ans.append(sorted([A[0][0],A[1][1],A[2][2]]))
    ans.append(sorted([A[0][2],A[1][1],A[2][0]]))
    for c in C:
        if list(c) in ans:
            print('Yes')
            return
    print('No')
    
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split())
    P=list(map(int,input().split()))
    ave=[(p+1)/2 for p in P]
    L=[sum(ave[i:i+k]) for i in range(n-k+1)]
    print(max(L))
main()

Fixed submission:
def main():
    n,k=map(int,input().split())
    P=list(map(int,input().split()))
    ave=[(p+1)/2 for p in P]
    s=sum(ave[:k])
    ans=s
    for left in range(n-k):
        s -= ave[left]
        s += ave[left+k]
        if s>ans:
            ans = s
    print(ans)
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    if 1 not in a:
        print(-1)
    else:
        ans = a.index(1)
        k = ans
        for i in range(2,n):
            a = a[k+1:]
            if i not in a:
                ans += len(a)
                print(ans)
                exit()
            else:
                k = a.index(i)
                ans += k
        print(ans)
if __name__=="__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    i = 1
    ans = 0
    for a in A:
        if a == i:
            i += 1
        else:
            ans += 1
    # ans==nのときは Aに1がないので -1を出力.
    print(ans if ans!=n else -1)
main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=tuple(list(map(int,input().split())))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s += (a[i]^a[j])%(10**9+7)
print(s%(10**9+7))

Fixed submission:
import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0
#print(A & 1)

# A_iは60ビットまで与えられる.
for i in range(60):
    #A&1は配列Aを1ビット目を表示する: [1,2,3]→[1,0,1]
    c = np.count_nonzero(A & 1) #配列Aの1ビット目が非ゼロのものをカウント
    #cは桁数nを超えないのでn-c>=0
    # c*(n-c)は(0の個数)*(1の個数)を表す.
    ans += 2**i*c*(n-c) #bit毎に計算したのち2**iをかけて10進数に戻す.
    # Aを1ビット右シフト
    A >>= 1 #一つ上の桁数でも同様. 大きな位では0なので値として出てこない.
print(ans%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=tuple(list(map(int,input().split())))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s += a[i]^a[j]
print(s%(10**9+7))

Fixed submission:
import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0
#print(A & 1)

# A_iは60ビットまで与えられる.
for i in range(60):
    #A&1は配列Aを1ビット目を表示する: [1,2,3]→[1,0,1]
    c = np.count_nonzero(A & 1) #配列Aの1ビット目が非ゼロのものをカウント
    #cは桁数nを超えないのでn-c>=0
    # c*(n-c)は(0の個数)*(1の個数)を表す.
    ans += 2**i*c*(n-c) #bit毎に計算したのち2**iをかけて10進数に戻す.
    # Aを1ビット右シフト
    A >>= 1 #一つ上の桁数でも同様. 大きな位では0なので値として出てこない.
print(ans%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=tuple(list(map(int,input().split())))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s += (a[i]^a[j])%(10**9+7)
print(s%(10**9+7))

Fixed submission:
import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0
#print(A & 1)

# A_iは60ビットまで与えられる.
for i in range(60):
    #A&1は配列Aを1ビット目を表示する: [1,2,3]→[1,0,1]
    c = np.count_nonzero(A & 1) #配列Aの1ビット目が非ゼロのものをカウント
    #cは桁数nを超えないのでn-c>=0
    # c*(n-c)は(0の個数)*(1の個数)を表す.
    ans += 2**i*c*(n-c) #bit毎に計算したのち2**iをかけて10進数に戻す.
    # Aを1ビット右シフト
    A >>= 1 #一つ上の桁数でも同様. 大きな位では0なので値として出てこない.
print(ans%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
def check(pin):
    flag = 0
    for s in S:
        if flag == 0:
            if pin[0] in s:
                flag = 1
        elif flag == 1:
            if pin[1] in s:
                flag = 2
        else:
            if pin[2] in s:
                return True
    return False
            
n = int(input())
S = input()
ans = 0
# Sではなく,PINの候補を全探索
for i in range(10):
    for j in range(10):
        for k in range(10):
            PIN = str(i)+str(j)+str(k)
            if check(PIN):
                ans += 1
print(ans)

Fixed submission:
N=int(input())
s=input()
PIN=[]
firs=[]
sec=[]
thir=[]
for i in range(N-2):
    if s[i] not in firs:
        firs.append(s[i])
        for j in range(i+1,N-1):
            if s[j] not in sec:
                sec.append(s[j])
                for k in range(j+1,N):
                    if s[k] not in thir:
                        thir.append(s[k])
                        PIN.append(s[i]+s[j]+s[k])
                thir=[]
        sec=[]       
print(len(PIN))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
PIN = set()
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            PIN.add(S[i] + S[j] + S[k])
print(len(PIN))

Fixed submission:
N=int(input())
s=input()
PIN=[]
firs=[]
sec=[]
thir=[]
for i in range(N-2):
    if s[i] not in firs:
        firs.append(s[i])
        for j in range(i+1,N-1):
            if s[j] not in sec:
                sec.append(s[j])
                for k in range(j+1,N):
                    if s[k] not in thir:
                        thir.append(s[k])
                        PIN.append(s[i]+s[j]+s[k])
                thir=[]
        sec=[]       
print(len(PIN))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=input()
PIN=[]
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            PIN.append(s[i]+s[j]+s[k])
print(len(set(PIN)))

Fixed submission:
N=int(input())
s=input()
PIN=[]
firs=[]
sec=[]
thir=[]
for i in range(N-2):
    if s[i] not in firs:
        firs.append(s[i])
        for j in range(i+1,N-1):
            if s[j] not in sec:
                sec.append(s[j])
                for k in range(j+1,N):
                    if s[k] not in thir:
                        thir.append(s[k])
                        PIN.append(s[i]+s[j]+s[k])
                thir=[]
        sec=[]       
print(len(PIN))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n=int(input())
L=map(int,input().split())
ans=0
for a, b, c in combinations(L,3):
    if abs(b-c) < a < b+c:
        ans += 1
print(ans)

Fixed submission:
import bisect
n = int(input())
L = sorted(map(int,input().split()))
ans = 0
# a<b<cとしてa,bを決めると c < b+aだけ確かめれば良い!
for i in range(n-1):
    for j in range(i+1,n):
        # bisectで初めてa+b以上になる元のindexを見つける
        # j番以降の元であればc>bを満たす.
        ans += bisect.bisect_left(L, L[i]+L[j]) - j - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import factorial
def comb(n,k):
    return factorial(n)//factorial(k)//factorial(n-k)
def main():
    n,k=map(int,input().split())
    mod=10**9+7
    for i in range(1,k+1):
        print(comb(n-k+1,i)*comb(k-1,i-1)%mod)
main()

Fixed submission:
def ExtGCD(a, b):
    if b == 0:
        return a, 1, 0
    else:
        d, x, y = ExtGCD(b, a % b)
        x -= (a // b) * y
        return d, y, x
def ModInv(a, mod):
    return ExtGCD(a, mod)[1] % mod
def ModComb(n, k, mod):
    if n < k or n < 0 or k < 0:
        return 0
    elif n == 0 or k == 0:
        return 1
    q, a = 1, 1
    for i in range(n-k+1, n+1):
        q = (q * i) % mod
    for i in range(2, k+1):
        a = (a * i) % mod
    return int(q * ModInv(a, mod) % mod)
def main():
    n,k=map(int,input().split())
    mod=10**9+7
    for i in range(1,k+1):
        print(ModComb(n-k+1,i,mod)*ModComb(k-1,i-1,mod)%mod)
        # 最後のに%modつけるの忘れてた。。。。。。
main()
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]

#TLEの対策.配列ではなく変数を使う.
p,q=0,1

for i in range(1,n+1):
    #最新のp,q以前の値は捨てて良い.つまり配列を使用する必要なし.
    p,q=q,(p+q)%(10**9+7)*(not i in a) #n*Trueは1, n*Falseは0を表す.
print(q)

Fixed submission:
n,m=map(int,input().split())
#TLEの対策1. a in listと比べて a in setはめちゃんこ速い!!
a=set([int(input()) for _ in range(m)])

#TLEの対策2.配列ではなく変数を使う(対策1と比べると対して効果なし).
p,q=0,1

for i in range(1,n+1):
    #最新のp,q以前の値は捨てて良い.つまり配列を使用する必要なし.
    p,q=q,(p+q)%(10**9+7)*(not i in a) #n*Trueは1, n*Falseは0を表す.
print(q)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(int(input()) for _ in range(m))
dp=[0]*(n+1)
dp[0]=1
if a[0]==1:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
        dp[i] %= 1000000007
print(dp[n]%1000000007)

Fixed submission:
n,m=map(int,input().split())
#TLEの対策1. a in listと比べて a in setはめちゃんこ速い!!
a=set([int(input()) for _ in range(m)])

#TLEの対策2.配列ではなく変数を使う(対策1と比べると対して効果なし).
p,q=0,1

for i in range(1,n+1):
    #最新のp,q以前の値は捨てて良い.つまり配列を使用する必要なし.
    p,q=q,(p+q)%(10**9+7)*(not i in a) #n*Trueは1, n*Falseは0を表す.
print(q)
Buggy python submission (verdict: Runtime Error):
s=int(input())
x=a%100
y=a//100
print(("AMBIGUOUS" if 0<x<13 else "MMYY") if 0<y<13 else "YYMM" if 0<x<13 else "NA")

Fixed submission:
s=input()
c=0
if 0<int(s[0])*10+int(s[1])<13:c+=1
if 0<int(s[2])*10+int(s[3])<13:c+=2
print("AMBIGUOUS" if c==3 else "YYMM" if c==2 else "MMYY" if c==1 else "NA")
Buggy python submission (verdict: Runtime Error):
s=input()
L=[]
c=0
for i in range(len(s)):
    if s[i] in "ACGT":
        c+=1
    else:
        L.append(c)
        c=0
print(max(L))

Fixed submission:
s=input()
L=[]
c=0
for i in range(len(s)):
    if s[i] in "ACGT":
        c+=1
        L.append(c)
    else:
        L.append(c)
        c=0
print(max(L))
Buggy python submission (verdict: Time Limit Exceeded):
def main(): #グローバル名前空間で大きな処理を書かない
    n,k=map(int,input().split())
    H=["dammy"]+list(map(int,input().split()))
    dp=[0]*(n+1)
    for i in range(2,min(k+2,n+1)):
        dp[i]=min(dp[j]+abs(H[i]-H[j]) for j in range(1,i))
    for i in range(k+2,n+1):
        dp[i] = min(dp[i-j]+abs(H[i]-H[i-j]) for j in range(1,k+1)) #TLEになる.
    print(dp[n])
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [0] * n
    for i, Hi in enumerate(H):
        if i == 0:
            continue
        s = max(0, i-k) # iがk以下かどうかで処理が変わる.
        dp[i] = min([dl + abs(hl - Hi) for dl, hl in zip(dp[s:i], H[s:i])])
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=["dammy"]+list(map(int,input().split()))
dp=[0]*(n+1)
for i in range(2,min(k+2,n+1)):
    dp[i]=min(dp[j]+abs(H[i]-H[j]) for j in range(1,i))
for i in range(k+2,n+1):
    dp[i] = min(dp[i-j]+abs(H[i]-H[i-j]) for j in range(1,k+1))
print(dp[n])

Fixed submission:
def main():
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [0] * n
    for i, Hi in enumerate(H):
        if i == 0:
            continue
        s = max(0, i-k) # iがk以下かどうかで処理が変わる.
        dp[i] = min([dl + abs(hl - Hi) for dl, hl in zip(dp[s:i], H[s:i])])
    print(dp[-1])
main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,c,d=map(int,input().split())
n=np.array([c-a,d-b])
p=np.array([-n[1],n[0]])
print(*([c,d]+p),*([a,b]+p))

Fixed submission:
import numpy as np
a,b,c,d=map(int,input().split())
n=np.array([c-a,d-b])
p=np.array([-n[1],n[0]])
print(*([c,d]+p), end=" ") #print(*([c,d]+p),*([a,b]+p))がPython3.4.3には対応してない？
print(*([a,b]+p))
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
#枠を大きめに確保してout of rangeを避ける!
grid = ["."*(w+2)]
for _ in range(h):
    grid.append("." + input() + ".")
grid += ["."*(w+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j]=="#":
            if not (grid[i][j-i]=="#" or grid[i][j+1]=="#"or \
                grid[i-1][j]=="#" or grid[i+1][j]=="#"):
                    print("No")
                    exit()
print("Yes")

Fixed submission:
h,w=map(int,input().split())
s=list(input() for _ in range(h))
flag=1
for i in range(h):
    for j in range(w):
        check=0
        if s[i][j]=="#":
            if i!=0 and s[i-1][j]=="#":check +=1
            if i!=h-1 and s[i+1][j]=="#":check += 1
            if j!=0 and s[i][j-1]=="#":check += 1
            if j!=w-1 and s[i][j+1]=="#":check += 1
            if check==0:flag=0
print("Yes" if flag else "No")
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    n=int(sys.stdin.readline())
    m=(n-1)//2+2
    x=tuple(map(int,input().split()))
    x = (0,) + x + (0,)
    for i in range(n):
        print(sorted(x[:i+1]+x[i+2:])[m])
if __name__ == '__main__':
    main()

Fixed submission:
# ABC094C - Many Medians (ARC095C)
def main():
    n = int(input())
    x = list(map(int, input().split()))
    # 偶数個の数から一つ数を取り除いたものの中央値はl,hのいずれか.
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    ans = [h if e <= l else l for e in x] # l以下の値を取り除いたならば中央値はh
    print("\n".join(map(str, ans)))
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    m=(n-1)//2+2
    x=tuple(map(int,input().split()))
    x = (0,) + x + (0,)
    for i in range(n):
        print(sorted(x[:i+1]+x[i+2:])[m])
main()

Fixed submission:
# ABC094C - Many Medians (ARC095C)
def main():
    n = int(input())
    x = list(map(int, input().split()))
    # 偶数個の数から一つ数を取り除いたものの中央値はl,hのいずれか.
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    ans = [h if e <= l else l for e in x] # l以下の値を取り除いたならば中央値はh
    print("\n".join(map(str, ans)))
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=list(map(int,input().split()))
for i in range(n):
    k=x.pop(0)
    y=x[:] #deepcopyと同じ.
    print(sorted(y)[(n-1)//2])
    x.append(k)

Fixed submission:
# ABC094C - Many Medians (ARC095C)
def main():
    n = int(input())
    x = list(map(int, input().split()))
    # 偶数個の数から一つ数を取り除いたものの中央値はl,hのいずれか.
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    ans = [h if e <= l else l for e in x] # l以下の値を取り除いたならば中央値はh
    print("\n".join(map(str, ans)))
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split())
    A=tuple(map(int,input().split()))
    L=set(A)
    m=len(L)-k
    if m<=0:
        print(0)
    else:
        D=[A.count(l) for l in L]
        D.sort()
        print(sum(D[:m]))
main()

Fixed submission:
from collections import Counter
def main():
    n,k=map(int,input().split())
    A=Counter(list(map(int,input().split())))
    # Aの重複元の個数を降順に並べてk番以降の和を数える.
    print(sum(sorted(A.values())[::-1][k:]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    L=set(A)
    m=len(L)-k
    if m<=0:
        print(0)
    else:
        D=[0]*len(L)
        for i, l in enumerate(L):
            D[i]=A.count(l)
        print(sum(sorted(D)[:m]))
main()

Fixed submission:
from collections import Counter
def main():
    n,k=map(int,input().split())
    A=Counter(list(map(int,input().split())))
    # Aの重複元の個数を降順に並べてk番以降の和を数える.
    print(sum(sorted(A.values())[::-1][k:]))
main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    ind = 0
    length = len(D)
    for t in T:
        if ind == length:
            print('NO')
            return
        else:
            index = bisect_left(D[ind:], t)
            if D[ind:][index] != t:
                print('NO')
                return
            else:
                ind += index + 1
    print('YES')
main()

Fixed submission:
from collections import Counter
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    CD = Counter(D)
    CT = Counter(T).items()
    for i, c in CT:
        if CD[i] < c:
            print('NO')
            return
    print('YES')
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    ind = 0
    for t in T:
        if ind == len(D):
            print('NO')
            return
        for i, d in enumerate(D[ind:]):
            if t == d:
                ind += i + 1
                break
        else:
            print('NO')
            return
    print('YES')
main()

Fixed submission:
from collections import Counter
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    CD = Counter(D)
    CT = Counter(T).items()
    for i, c in CT:
        if CD[i] < c:
            print('NO')
            return
    print('YES')
main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
D = sorted(list(map(int, input().split())))
m = int(input())
T = sorted(map(int, input().split()))
for t in T:
    if t in D:
        D = D[D.index(t)+1:]
    else:
        print('NO')
        exit()
print('YES')

Fixed submission:
from collections import Counter
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    CD = Counter(D)
    CT = Counter(T).items()
    for i, c in CT:
        if CD[i] < c:
            print('NO')
            return
    print('YES')
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    T=sorted(set(list(int(input()) for _ in  range(n))))[::-1]
    k=T[0]
    while 1:
        for t in T:
            if k%t>0:
                k += T[0]
                break
        else: #for文がbreakしなければここを読む.
            print(k)
            break
main()

Fixed submission:
from fractions import gcd
#from math import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
def main():
    n=int(input())
    T=set(list(int(input()) for _ in  range(n)))
    ans=1
    for t in T:
        ans = lcm(t,ans)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    T=sorted(set(list(int(input()) for _ in  range(n))))
    k=T[-1]
    while 1:
        for t in T:
            if k%t>0:
                k += T[-1]
                break
        else: #for文がbreakしなければここを読む.
            print(k)
            break
main()

Fixed submission:
from fractions import gcd
#from math import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
def main():
    n=int(input())
    T=set(list(int(input()) for _ in  range(n)))
    ans=1
    for t in T:
        ans = lcm(t,ans)
    print(ans)
main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
m=int(input())
print((n-1)*(m-1))

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,m=map(int,input().split())
    L=[list(map(int,input().split())) for _ in range(m)]
    S=[]
    for l in L:
        if l[0]==1: S.append(l[1])
    for l in L:
        if l[0] in S and l[1]==n:
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")
main()

Fixed submission:
def main():
    n,m=map(int,input().split())
    L=[list(map(int,input().split())) for _ in range(m)]
    S=[]
    G=[]
    for l in L:
        if l[0]==1: S.append(l[1])
        if l[1]==n: G.append(l[0])
    print("POSSIBLE"if len(set(S)&set(G))>0 else "IMPOSSIBLE")
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    x=int(input())
    ans=abs(x)
    L=[0]
    for i in range(1,10**9):
        P=L[:]
        for l in L:
            P.append(l+i)
            P.append(l-i)
        if x in P:
            print(i)
            break
        L=P[:]
main()

Fixed submission:
def main():
    x=int(input())
    for i in range(1,10**9):
        if x>i*(i+1)//2: continue
        print(i)
        break
main()