Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
for i in range(n//4,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        y=s*i*j
        if t>0 and s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()


Fixed submission:
s=int(input())
for i in range(s//4,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        y=s*i*j
        if t>0 and s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        if t<=0:
            continue
        if s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()

Fixed submission:
s=int(input())
for i in range(s//4,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        y=s*i*j
        if t>0 and s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        if t>0:
            if s*i*j%t==0:
                print(s*i*j//t,i,j)
                break
    else:
        continue
    break

Fixed submission:
s=int(input())
for i in range(s//4,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        y=s*i*j
        if t>0 and s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as de
p=de(int)
h,w=map(int,input().split())
for i in range(h):
    a=list(input())
    for j in range(w):
        p[ord(a[i])-ord("a")]+=1
c=0
d=0
for i in p.values():
    c+=i%2
    d+=i//2
if w%2==1:
    if h-c>=0 and (h-c)%2==0:
        print("Yes")
    else:
        print("No")
else:
    if c!=0:
        print("No")
    else:
        print("Yes")

Fixed submission:
h,w=map(int,input().split())
d=[0]*26
for i in range(h):
    b=list(input())
    for j in range(w):
        d[ord(b[j])-ord("a")]+=1
s=0
t=0
r=0
for i in range(26):
    if d[i]%4==0:
        s+=d[i]//4
    elif d[i]%2==0:
        s+=d[i]//4
        t+=(d[i]%4)//2
    else:
        s+=d[i]//4
        t+=(d[i]%4)//2
        r+=1
if h%2==0 and w%2==0:
    if t==0 and r==0:
        print("Yes")
    else:
        print("No")
elif h%2==1 and w%2==1:
    if r==1 and(w+h-2-2*t)>=0 and (w+h-2-2*t)%4==0:
        print("Yes")
    else:
        print("No")
else:
    q=(w if h%2==1 else h)
    if q-2*t>=0  and (q-2*t)%4==0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[]
p=[]
for i in range(n):
    a=input()
    if not a in s:
        s.append(a)
        p.append(1)
    else:
        p[s.index(a)]=(p[s.index(a)]+1)%2
print(sum(p))

Fixed submission:
from collections import Counter
n=int(input())
s=[int(input())for i in range(n)]
d=Counter(s)
c=0
for a,b in d.items():
    if b%2==1:
        c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n):
    if i!=n-1
        if p[i]==i+1:
            d=p[i+1]
            p[i+1]=p[i]
            p[i]=d
            c+=1
    else:
        if p[i]==i+1:
            c+=1
print(c)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n):
    if i!=n-1:
        if p[i]==i+1:
            d=p[i+1]
            p[i+1]=p[i]
            p[i]=d
            c+=1
    else:
        if p[i]==i+1:
            c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
from fraction import gcd
a=int(input())
s=int(input())
k=s
for i in range(a-1):
    d=int(input())
    k=(k*d)//gcd(k,d)
print(k)

Fixed submission:
from fractions import gcd
a=int(input())
s=int(input())
k=s
for i in range(a-1):
    d=int(input())
    k=(k*d)//gcd(k,d)
print(k)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[[]for i in range(n+1)]
g=[0]*(n+1)
h=[True]*(n+1)
for i in range(n-1):
    a,b,c=map(int,input().split())
    s[a].append([b,c])
    s[b].append([a,c])
def dfs(x):
    h[x]=False
    for i in s[x]:
        if h[i[0]]:
            g[i[0]]=g[x]+i[1]
            dfs(i[0])
q,k=map(int,input().split())
dfs(k)
for i in range(q):
    x,y=map(int,input().split())
    print(g[x]+g[y])

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
n=int(input())
s=[[]for i in range(n+1)]
g=[0]*(n+1)
h=[True]*(n+1)
for i in range(n-1):
    a,b,c=map(int,input().split())
    s[a].append([b,c])
    s[b].append([a,c])
def dfs(x):
    h[x]=False
    for i in s[x]:
        if h[i[0]]:
            g[i[0]]=g[x]+i[1]
            dfs(i[0])
q,k=map(int,input().split())
dfs(k)
for i in range(q):
    x,y=map(int,input().split())
    print(g[x]+g[y])
Buggy python submission (verdict: Runtime Error):
from itertools import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=max(a)
p=a[0]
for i in range(1,n):
    p=gcd(a[0],a[i])
print("POSSIBLE" if k%p==0 and k<=c else "IMPOSSIBLE")

Fixed submission:
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=max(a)
p=a[0]
for i in range(1,n):
    p=gcd(a[0],a[i])
print("POSSIBLE" if k%p==0 and k<=c else "IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[[]for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
def f(a,b):
    c,flag,ans=[[a,[0,a]]],False,[]
    while c or flag=False:
        p,q=c.pop()
        for i in s[p]:
            if i==b:
                ans=q[1:]+[b]
                break
            else:
                if q[-2]!=i:
                    c.append([i,q+[i]])
    else:
        return ans
def f(x,l):
    c=0
    p,d=[x],[0]*(n+1)
    while p:
        a=p.pop()
        if a not in x or a==x:
            c+=1
            d[a]=1
            for i in s[a]:
                if d[i]==0:
                    p.append(i)
    else:
        return c
t=f(a,b)
t=[f(i,ans)for i in t]
print("Fennec"if sum(t[:-len(t)//2])>sum(t[-len(t)//2:]) else"Snuke")

Fixed submission:
from heapq import *
n=int(input())
s=[[]for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
def f(a):
    p=[float("INF")for i in range(n+1)]
    p[a],q=0,[[0,a]]
    while q:
        i,j=heappop(q)
        for w in s[j]:
            if p[w]>i+1:
                p[w]=i+1
                heappush(q,[i+1,w])
    else:
        return p[1:]
s1,t1=f(1),f(n)
a,b=0,0
for i in range(n):
    if s1[i]<=t1[i]:
        a+=1
    else:
        b+=1
print("Fennec" if a>b else "Snuke")
Buggy python submission (verdict: Runtime Error):
from statistics import mode
n=int(input())
a=list(map(int,input().split()))
t=mode(a)
b=[i for i in range(n)if a[i]==t]
c=n+1
d=1
m=10**9+7
for i in range(1,n+2):
    if i==1:
        print(n)
    else:
        c=(c*(n-i+2))//i
        d=(d*(n-b[1]+b[0]+2-i))//(i-1)
        print((c-d)%m)

Fixed submission:
m=10**9+7
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
for i in range(n+1):
    if b[a[i]]==0:
        b[a[i]]=i+1
    else:
        s=b[a[i]]+n-i-1
        break
p,q=1,1
for i in range(1,n+2):
    p=((p*(n+2-i))*pow(i,m-2,m))%m
    q=(1 if i==1 and s>=i-1 else(0 if s<i-1 else ((q*(s-i+2))*pow(i-1,m-2,m)))%m)
    print((p-q)%m)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[0]+[int(input())for i in range(n)]
p=[1]
k=0
while n:
    if s[p[k]]==2:
        print(k+1)
        break
    elif k==len(set(p)):
        print(-1)
        break
    else:
        p.append(s[p[k]])
        k+=1

Fixed submission:
n=int(input())
s=[0]+[int(input())for i in range(n)]
t=s[1]
k=1
while n:
    if t==2:
        print(k)
        break
    elif t==0:
        print(-1)
        break
    else:
        a=s[t]
        s[t]=0
        t=a
        k+=1

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[0]+[int(input())for i in range(n)]
t=s[1]
p=[1]
k=1
while n:
    if t==2:
        print(k)
        break
    elif p.count(t)>0:
        print(-1)
        break
    else:
        p.append(t)
        t=s[t]
        k+=1

Fixed submission:
n=int(input())
s=[0]+[int(input())for i in range(n)]
t=s[1]
k=1
while n:
    if t==2:
        print(k)
        break
    elif t==0:
        print(-1)
        break
    else:
        a=s[t]
        s[t]=0
        t=a
        k+=1
Buggy python submission (verdict: Runtime Error):
s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
if len(list(set(d)))==1:
    print(0)
else:
    for i in range(26):
        t=p[i]
        d=s[:]
        c=0
        while len(d)>0:
            c+=1
            for j in range(len(d)-1):
                if d[j]==t or d[j+1]==t:
                    d[j]=t
            else:
                d.pop(-1)
                if len(list(set(d)))==1 and d[0]==t:
                    break
        q=min(q,c)
    print(q)

Fixed submission:
s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
if len(list(set(s)))==1:
    print(0)
else:
    for i in range(26):
        t=p[i]
        d=s[:]
        c=0
        while len(d)>0:
            c+=1
            for j in range(len(d)-1):
                if d[j]==t or d[j+1]==t:
                    d[j]=t
            else:
                d.pop(-1)
                if len(list(set(d)))==1 and d[0]==t:
                    break
        q=min(q,c)
    print(q)
Buggy python submission (verdict: Runtime Error):
print("no"if len(set(input()))!=len(input()) else"yes")

Fixed submission:
a=input()
print("no"if len(set(a))!=len(a)else"yes")
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right as br
n,k=map(int,input().split())
b=[0]*(n+1)
def f(x):
    c=0
    while x>0:
        c+=b[x]
        x-=x&-x
    return c
def g(x,a):
    while x<n+1:
        b[x]+=a
        x+=x&-x
for i in range(n):
    g(i+1,int(input())-k)
c=[0]
d=0
for i in range(1,n+1):
    t=f(i)
    k=br(c,t)
    c.insert(k,f(i))
    d+=i-k
print((n*(n+1))//2-d)

Fixed submission:
n=int(input())
a=[int(input())for i in range(n)]
a.sort()
c=0
p=sum(a)
if p%10!=0:
    print(p)
else:
    for i in range(n):
        if a[i]%10!=0:
            break
        else:
            c+=1
    print(0 if c==n else p-a[i])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split());a,b=[list(map(int,input().split()))for i in range(n)],[float("INF")]*(n+1);b[1]=0
for i in range(1,n+1):
    for s,t,u in a:
        if b[t]>b[s]-u:
            b[t]=b[s]-u
            if i==n and t==n:print("inf");exit()
print(-b[-1])

Fixed submission:
n,m=map(int,input().split());a,b=[list(map(int,input().split()))for i in range(m)],[float("INF")]*(n+1);b[1]=0
for i in range(1,n+1):
    for s,t,u in a:
        if b[t]>b[s]-u:
            b[t]=b[s]-u
            if i==n and t==n:print("inf");exit()
print(-b[-1])
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a%4!=0 and b%4!=0 and c%4!=0 or(a==b and b==c):
    print(-1)
else:
    s=a+b+c
    d=0
    j=0
    while a%2!=1 and b%2!=1 and c%2!=1:
        d+=1
        h=s
        j=a
        a=(s-a)//2
        b=j//2+c//2
        c=h-a-b
print(d)

Fixed submission:
a,b,c=map(int,input().split())
if a==b and b==c and a%2!=1:
    print(-1)
else:
    s=a+b+c
    d=0
    j=0
    while a%2!=1 and b%2!=1 and c%2!=1:
        d+=1
        h=s
        j=a
        a=(s-a)//2
        b=j//2+c//2
        c=h-a-b
    print(d)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as d
s=d(int)
s[0]=0
n,w=map(int,input().split())
for i in range(n):
    q,v=map(int,input().split())
    c=s.copy()
    for p,r in c.items():
        if p+q<=w:
            s[p+q]=max(c[p+q],c[p]+v)
print(max(s.values()))

Fixed submission:
from collections import defaultdict as d
s=d(int)
s[0]=0
n,w=map(int,input().split())
for i in range(n):
    q,v=map(int,input().split())
    c=s.copy()
    for p,r in c.items():
        if p+q<=w:
            s[p+q]=max(s[p+q],r+v)
print(max(s.values()))
Buggy python submission (verdict: Runtime Error):
n=input()
a=input()
c=str()
for i in range(0,len(a))
	c+=n[i]+a[i]
print(c if len(n)==len(a) else c+n[len(n)-1])

Fixed submission:
n=input()
a=input()
c=str()
for i in range(0,len(a)):
    c+=n[i]+a[i]
print(c if len(n)==len(a) else c+n[len(n)-1])
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
k,h=b,b
k+=a[0]-a[0]%2
k+=a[3]-a[3]%2
k+=a[4]-a[4]%2
if min(a[0],a[3],a[4])>0:
    h+=3
    a[0],a[3],a[4]=a[0]-1,a[3]-1,a[4]-1
    h+=a[0]-a[0]%2
    h+=a[3]-a[3]%2
    h+=a[4]-a[4]%2
print(max(k,h))

Fixed submission:
a=list(map(int,input().split()))
k,h=a[1],a[1]
k+=a[0]-a[0]%2
k+=a[3]-a[3]%2
k+=a[4]-a[4]%2
if min(a[0],a[3],a[4])>0:
    h+=3
    a[0],a[3],a[4]=a[0]-1,a[3]-1,a[4]-1
    h+=a[0]-a[0]%2
    h+=a[3]-a[3]%2
    h+=a[4]-a[4]%2
print(max(k,h))
Buggy python submission (verdict: Runtime Error):
def root(x,d):
    if d[x]!=x:
        d[x]=root(x,d)
    return d[x]
def unite(x,y,h):
    x=root(x,h)
    y=root(y,h)
    if x!=y:
        h[x]=min(x,y)
        h[y]=h[x]
from collections import defaultdict
n,k,l=map(int,input().split())
a=[i for i in range(n+1)]
b=[i for i in range(n+1)]
for i in range(k):
    s,t=map(int,input().split())
    unite(s,t,a)
for i in range(l):
    s,t=map(int,input().split())
    unite(s,t,b)
d=defaultdict(int)
l=""
for i in range(1,n+1):
    d[(root(a[i],a),root(b[i],b))]+=1
for i in range(1,n+1):
    l+=str(d[(root(a[i],a),root(b[i],b))])+" "
print(l[:-1])

Fixed submission:
def root(x,d):
    if d[x]!=x:
        d[x]=root(d[x],d)
    return d[x]
def unite(x,y,h):
    x=root(x,h)
    y=root(y,h)
    if x!=y:
        h[x]=min(x,y)
        h[y]=h[x]
from collections import defaultdict
n,k,l=map(int,input().split())
a=[i for i in range(n+1)]
b=[i for i in range(n+1)]
for i in range(k):
    s,t=map(int,input().split())
    unite(s,t,a)
for i in range(l):
    s,t=map(int,input().split())
    unite(s,t,b)
d=defaultdict(int)
l=""
for i in range(1,n+1):
    d[(root(a[i],a),root(b[i],b))]+=1
for i in range(1,n+1):
    l+=str(d[(root(a[i],a),root(b[i],b))])+" "
print(l[:-1])
Buggy python submission (verdict: Time Limit Exceeded):
p=1
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p*=s[1-i[1]]
        s[1-i[1]]-=1
print(p%(10**9+7))

Fixed submission:
p=1
m=10**9+7
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p=(p*s[1-i[1]])%m
        s[1-i[1]]-=1
print(p)

Buggy python submission (verdict: Runtime Error):
p=1
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p*=s[1-i[1]]
        s[1-[i[1]]-=1
print(p%(10**9+7))

Fixed submission:
p=1
m=10**9+7
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p=(p*s[1-i[1]])%m
        s[1-i[1]]-=1
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
p=1
s=[0]*2
n=int(input())
q=sorted([[int(input()),0]for i in range(n)]+[[int(input()),1]for i in range(n)])
for i in q:
    if s[(i[1]+1)%2]==0:
        s[i[1]]+=1
    else:
        p*=s[(i[1]+1)%2]
        s[(i[1]+1)%2]-=1
print(p%(10**9+7))

Fixed submission:
p=1
m=10**9+7
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p=(p*s[1-i[1]])%m
        s[1-i[1]]-=1
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
p=1
s=[0]*2
n=int(input())
q=sorted([[int(input()),0]for i in range(n)]+[[int(input()),1]for i in range(n)])
for i in q:
    if s[(i[1]+1)%2]==0:
        s[i[1]]+=1
    else:
        p*=s[(i[1]+1)%2]
        s[(i[1]+1)%2]-=1
print(p%(10**9+7))

Fixed submission:
p=1
m=10**9+7
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p=(p*s[1-i[1]])%m
        s[1-i[1]]-=1
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input())for i in range(2**n)]
while len(a)!=1:
    s,t=a.pop(0),a.pop(0)
    a.append(max(s-t,t-s))
print(a[0])

Fixed submission:
n=int(input())
a=[int(input())for i in range(2**n)]
while len(a)>1:
    p=[]
    for s,t in zip(a[::2],a[1::2]):
        p.append(s if s==t else abs(s-t))
    a=p
print(a[0])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input())for i in range(2**n)]
while len(a)!=1:
    s,t=a.pop(0),a.pop(0)
    a.append(max(s-t,t-s))
print(a[0])

Fixed submission:
n=int(input())
a=[int(input())for i in range(2**n)]
while len(a)>1:
    p=[]
    for s,t in zip(a[::2],a[1::2]):
        p.append(s if s==t else abs(s-t))
    a=p
print(a[0])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
a=[[]for i in range(n+m)]
for i in range(n):
    s=list(map(int,input().split()))
    for j in s[1:]:
        a[i].append(j)
        a[n+j-1].append(i)
t=[False]*n
def g(x):
    t[x]=True
    for i in a[x]:
            if not t[x]:
                g(j)
g(0)
if all(t):
    print("YES")
else:
    print("NO")


Fixed submission:
h,w=map(int,input().split())
q=[list(map(str,input().split()))for i in range(h)]
p=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(h):
    for j in range(w):
        if q[i][j]=="snuke":
            print(p[j]+str(i+1))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
c=[[0,0]for i in range(n)]
p=0
mod=10**9+7
for i in range(n,0,-1):
    if a[i-1]!=a[i]:
        c[i-1]=[1,a[i]]
    else:
        c[i-1]=[0,a[i]]
for i in range(n):
    if b[i]!=b[i+1]:
        if c[i][0]==1:
            if b[i]!=c[i][1]:
                print(0)
                break
        else:
            if b[i]<=c[i][1]:
                c[i]=[1,b[i]]
            else:
                print(0)
                break
    else:
        if c[i][0]!=1:
            c[i]=[0,min(b[i],c[i][1])]
        else:
            if c[i][1]>b[i]:
                print(0)
                break
else:
    d=1
    for i in range(n):
        if c[i][0]!=1:
            d*=c[i][1]%mod
    print(d%mod)

Fixed submission:
n=int(input())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
c=[[0,0]for i in range(n)]
p=0
mod=10**9+7
d=1
for i in range(n,0,-1):
    if a[i-1]!=a[i]:
        c[i-1]=[1,a[i]]
    else:
        c[i-1]=[0,a[i]]
for i in range(n):
    if b[i]!=b[i+1]:
        if c[i][0]==1:
            if b[i]!=c[i][1]:
                print(0)
                break
        else:
            if b[i]<=c[i][1]:
                c[i]=[1,b[i]]
            else:
                print(0)
                break
    else:
        if c[i][0]!=1:
            c[i]=[0,min(b[i],c[i][1])]
        else:
            if c[i][1]>b[i]:
                print(0)
                break
    if c[i][0]!=1:
        d=d*c[i][1]%mod
else:
    print(d)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    t=e
    k=f
    while e<a or f<b:
        t+=e
        k+=f
    a=t
    b=k
print(a+b)

Fixed submission:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    if (a//e+(1 if a%e!=0 else 0))*f>=b:
        b=f*(a//e+(1 if a%e!=0 else 0))
        a=e*(a//e+(1 if a%e!=0 else 0))
    else:
        a=e*(b//f+(1 if b%f!=0 else 0))
        b=f*(b//f+(1 if b%f!=0 else 0))
print(a+b)

Buggy python submission (verdict: Runtime Error):
from math import gcd
n=int(input())
a,b=map(int,input().split())
d=a+b
for i in range(n-1):
    e,f=map(int,input().split())
    d=d*(e+f)//gcd(d,e+f)
print(d)

Fixed submission:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    if (a//e+(1 if a%e!=0 else 0))*f>=b:
        b=f*(a//e+(1 if a%e!=0 else 0))
        a=e*(a//e+(1 if a%e!=0 else 0))
    else:
        a=e*(b//f+(1 if b%f!=0 else 0))
        b=f*(b//f+(1 if b%f!=0 else 0))
print(a+b)

Buggy python submission (verdict: Runtime Error):
from itertools import gcd
n=int(input())
a,b=map(int,input().split())
d=a+b
for i in range(n-1):
    e,f=map(int,input().split())
    d=d*(e+f)//gcd(d,e+f)
print(d)

Fixed submission:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    if (a//e+(1 if a%e!=0 else 0))*f>=b:
        b=f*(a//e+(1 if a%e!=0 else 0))
        a=e*(a//e+(1 if a%e!=0 else 0))
    else:
        a=e*(b//f+(1 if b%f!=0 else 0))
        b=f*(b//f+(1 if b%f!=0 else 0))
print(a+b)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
input()
def f(s):
    if len(s)==0:
        return 0
    k=len(s)
    g=np.argmin(s)
    return s[g]*(g+1)*(k-g)+f(s[:g])+f(s[g+1:])
print(f(list(map(int,input().split()))))

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
p,q,r,d=[0]*(n+1),[i for i in range(n+2)],[i for i in range(n+2)],0
for i in range(n):
    p[s[i]]=i
for i in range(n,0,-1):
    h=p[i]
    x,y=q[h],r[h]
    d+=i*(h-x+1)*(y-h+1)
    q[y+1],r[x-1]=x,y
print(d)
Buggy python submission (verdict: Runtime Error):
n=int(input(n))
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i==a[a[i]-1]:
        c+=1
        a[i]=n+1
print(c)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i+1==a[a[i]-1]:
        c+=1
        a[i]=n+2
print(c)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as de
h,w,n=map(int,input().split())
s=[0]*10
c=de(int)
d=[]
for i in range(n):
    a,b=map(int,input().split())
    c[(a,b)]=1
    d.append([a,b])
for e,f in d:
    for i in range(3):
        for j in range(3):
            if 0<=e-i and e+2-i<h:
                if 0<=f-j and f+2-j<w:
                    p=0
                    for t in range(e-i,e+3-i):
                        for u in range(f-j,f+3-j):
                            p+=c[(t,u)]
                    else:
                        s[p]+=1
else:
    s=s[0]+[s[i]//i for i in range(1,10)]
    s[0]=(h-8)*(w-8)-sum(s)
    for i in s:
        print(i)

Fixed submission:
from collections import defaultdict as de
from collections import Counter as C
h,w,n=map(int,input().split())
s=[0]*10
c=de(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(max(2,a-1),min(a+2,h)):
        for q in range(max(2,b-1),min(b+2,w)):
            c[(j,q)]+=1
a=C(c.values())
print((h-2)*(w-2)-sum(a.values()))
for i in range(1,10):
    print(a[i])
Buggy python submission (verdict: Time Limit Exceeded):
n,a=map(int,input().split())
x=list(map(int,input().split()))
p=max(max(x),a)
s=[i-a for i in x]
def f(b,t):
    if b==0 and t==p*n:
        return 1
    elif b>0 and (t-s[b-1]<0 or t-s[b-1]>2*p*n):
        return f(b-1,t)
    elif b>0 and (0<=t-s[b-1] and t-s[b-1]<=2*p*n):
        return f(b-1,t)+f(b-1,t-s[b-1])
    else:
        return 0
print(f(n,n*p)-1)

Fixed submission:
n,a=map(int,input().split())
x=list(map(int,input().split()))
p=max(max(x),a)
s=[i-a for i in x]
dp=[[0]*(2*n*p+1) for i in range(n+1)]
dp[0][n*p]=1
for i in range(1,n+1):
    for j in range(2*n*p+1):
        if j-s[i-1]<0 or j-s[i-1]>2*p*n:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=dp[i-1][j]+dp[i-1][j-s[i-1]]
print(dp[n][n*p]-1)