Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03569 (python)

Fixed submission:
s=input()
i=0
j=len(s)-1
c=0
while i<j:
    if s[i]!=s[j]:
        c+=1
        if s[i]=="x":
            i+=1
        elif s[j]=="x":
            j-=1
        else:
            print(-1)
            break
    else:
        i+=1
        j-=1
else:
    print(c)

Buggy submission (verdict: Runtime Error):
s=input()
i=0
j=len(s)-1
c=0
while i>=j:
    if s[i]!=s[j]:
        c+=1
        if s[i]=="x":
            i+=1
        elif s[j]=="x":
            j-=1
        else:
            print(-1)
            break
    else:
        i+=1
        j-=1
else:
    print(c)

Buggy submission (verdict: Runtime Error):
s=input()
i=0
j=len(s)-1
c=0
while i!=j:
    if s[i]!=s[j]:
        c+=1
        if s[i]=="x":
            i+=1
        elif s[j]=="x":
            j-=1
        else:
            print(-1)
            break
    else:
        i+=1
        j-=1
else:
    print(c)
Problem p03579 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
c=[0]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
def dfs(v,t):
    c[v]=t
    for i in s[v]:
        if c[i]==t:
            return False
        if c[i]==0 and not dfs(i,-t):
            return False
    else:
        return True
if dfs(1,1):
    q=c.count(1)
    print((n-q)*q-m)
else:
    print((n*(n-1)//2)-m)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
c=[0]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
def dfs(v,t):
    c[v]=t
    for i in s[v]:
        if c[i]==t:
            return false
        if c[i]==0 and not dfs(i,-t):
            return false
    else:
        return True
if dfs(1,1):
    q=c.count(1)
    print((n-q)*q-m)
else:
    print((n*(n-1)//2)-m)
Problem p03583 (python)

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 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()
Problem p03593 (python)

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 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")
Problem p03600 (python)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall as wf
n=int(input())
s=np.array([list(map(int,input().split()))for i in range(n)])
if np.any(s!=wf(s,directed=False)):
    print(-1)
else:
    c=0
    for i in range(n):
        s[i][i]=10**10
    for i in range(n):
        for j in range(i+1,n):
            d=np.min(s[i]+s[j])
            if s[i,j]!=d:
                c+=s[i,j]
    else:
        print(c)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall as wf
n=int(input())
s=[list(map(float,input().split()))for i in range(n)]
a=wf(s,directed=False).tolist()
if s!=a:
    print(-1)
else:
    c=0
    for i in range(n-1):
        for j in range(i+1,n):
            for d in range(n):
                if d!=i and d!=j:
                    if s[i][j]>=s[i][d]+s[d][j]:
                        break
            else:
                c+=int(s[i][j])
else:
    print(c)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall as wf
n=int(input())
s=[list(map(float,input().split()))for i in range(n)]
a=wf(s,directed=False).tolist()
if s!=a:
    print(-1)
else:
    c=0
    for i in range(n-1):
        for j in range(i+1,n):
            for d in range(n):
                if d!=i and d!=j:
                    if s[i][j]>=s[i][d]+s[d][j]:
                        break
            else:
                c+=int(s[i][j])
print(c)
Problem p03608 (python)

Fixed submission:
from itertools import permutations as pe
from scipy.sparse.csgraph import floyd_warshall as wf
n,m,r=map(int,input().split())
s=[[(0 if i==j else float("inf"))for j in range(n+1)]for i in range(n+1)]
g=list(pe(list(map(int,input().split()))))
for i in range(m):
    a,b,c=map(int,input().split())
    s[a][b]=c
    s[b][a]=c
s=wf(s,directed=False)
k=float("inf")
for i in range(len(g)):
    d=g[i]
    c=0
    for j in range(1,len(d)):
        c+=s[d[j-1]][d[j]]
        if c>=k:
            break
    else:
        k=min(c,k)
print(int(k))

Buggy submission (verdict: Runtime Error):
from itertools import permutations as pe
n,m,r=map(int,input().split())
s=[[(0 if i==j else float("inf"))for j in range(n+1)]for i in range(n+1)]
g=list(pe(list(map(int,input().split()))))
for i in range(n):
    a,b,c=map(int,input().split())
    s[a][b]=c
    s[b][a]=c
for h in range(n):
    for i in range(n):
        for j in range(n):
            if s[i][j]>s[i][h]+s[h][j]:
                s[i][j]=s[i][h]+s[h][j]
k=float("inf")
for i in range(len(g)):
    d=g[i]
    c=0
    for j in range(1,len(d)):
        c+=s[d[j-1]][d[j]]
        if c>k:
            break
    else:
        k=min(c,k)
print(k)
Problem p03612 (python)

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 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)
Problem p03633 (python)

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 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)
Problem p03651 (python)

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 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")
Problem p03660 (python)

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 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")
Problem p03674 (python)

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 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)
Problem p03682 (python)

Fixed submission:
n=int(input())
a=sorted([[i]+list(map(int,input().split()))for i in range(n)],key=lambda x:x[1])
s=[]
for i in range(n-1):
    s.append((a[i+1][1]-a[i][1],a[i][0],a[i+1][0]))
a=sorted(a,key=lambda x:x[2])
for i in range(n-1):
    s.append((a[i+1][2]-a[i][2],a[i][0],a[i+1][0]))
s.sort()
t=[i for i in range(n)]
def f(x):
    if x==t[x]:
        return x
    t[x]=f(t[x])
    return f(t[x])
c=0
for i,j,h in s:
    j,h=f(j),f(h)
    if h!=j:
        t[j]=h
        c+=i
print(c)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=sorted([[i]+list(map(int,input().split()))for i in range(n)],key=lambda x:x[1])
s=[]
for i in range(n-1):
    s.append((a[i+1][1]-a[i][1],a[i][0],a[i+1][0]))
a=sorted(a,key=lambda x:x[2])
for i in range(n-1):
    s.append((a[i+1][2]-a[i][2],a[i][0],a[i+1][0]))
s.sort()
t=[i for i in range(n)]
def f(x):
    if x==t[x]:
        return x
    x=t[x]
    return f(t[x])
c=0
for i,j,h in s:
    j,h=f(j),f(h)
    if h!=j:
        t[j]=h
        c+=i
print(c)
Problem p03687 (python)

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 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)
Problem p03698 (python)

Fixed submission:
a=input()
print("no"if len(set(a))!=len(a)else"yes")

Buggy submission (verdict: Runtime Error):
print("no"if len(set(input()))!=len(input()) else"yes")
Problem p03701 (python)

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 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)
Problem p03703 (python)

Fixed submission:
n,k=map(int,input().split())
b=[0]*(n+1)
for i in range(n):
    b[i+1]=b[i]+int(input())-k
a=sorted(set(b))
s={a[i-1]:i for i in range(1,len(a)+1)}
c=[]
for i in b:
    c.append(s[i])
b=[0]*(len(a)+1)
def f(x):
    c=0
    while x>0:
        c+=b[x]
        x-=x&-x
    return c
def g(x):
    while x<len(a)+1:
        b[x]+=1
        x+=x&-x
e=0
for i in range(n+1):
    e+=f(c[i])
    g(c[i])
print(e)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
b=[0]*(n+1)
for i in range(n):
    b[i+1]=b[i]+int(input())-k
a=sorted(set(b))
s={a[i-1]:i for i in range(1,len(a)+1)}
c=[]
for i in b:
    c.append(s[i])
b=[0]*(n+1)
def f(x):
    c=0
    while x>0:
        c+=b[x]
        x-=x&-x
    return c
def g(x):
    while x<n+1:
        b[x]+=1
        x+=x&-x
e=0
for i in range(n+1):
    e+=f(c[i])
    g(c[i])
print(e)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
b=[0]*(n+1)
for i in range(n):
    b[i+1]=b[i]+int(input())-k
a=sorted(set(b))
s={a[i-1]:i for i in range(1,len(a)+1)}
c=[]
for i in b:
    c.append(s[i])
b=[0]*(n+1)
def f(x):
    c=0
    while x>0:
        c+=b[x]
        x-=x&-x
    return c
def g(x):
    while x<n+1:
        b[x]+=1
        x+=x&-x
e=0
for i in range(n+1):
    e+=f(c[i])
    g(c[i])
print(e)
Problem p03722 (python)

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 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])
Problem p03732 (python)

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 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()))
Problem p03746 (python)

Fixed submission:
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
a,b=[],[]
p=1
t[1]=0
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            a.append(i)
            break
    else:
        break
p=1
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            b.append(i)
            break
    else:
        break
print(1+len(a)+len(b))
t=a[::-1]+[1]+b
print(*t)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
p=0
for i in range(m):
    a,b=map(int,input().split())
    if i==0:
        k=[a,b]
        t[a],t[b]=0,0
    else:
        if a==k[0] and t[b]==1:
            k=[b]+k
        elif b==k[0] and t[a]==1:
            k=[a]+k
        elif a==k[1] and t[b]==1:
            k.append(b)
        elif b==k[1] and t[a]==1:
            k.append(a)
        else:
            s[a].append(b)
            s[b].append(a)
p=len(k)
while p!=n:
    for i in s[k[-1]]:
        if t[i]:
            t[i]=0
            k.append(i)
            p+=1
            break
    else:
        c=1
    for i in s[k[0]]:
        if t[i]:
            t[i]=0
            k=[i]+k
            p+=1
            break
    else:
        c+=1
        if c==2:
            break
print(p)
print(*k)
Problem p03760 (python)

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 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])
Problem p03840 (python)

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 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))
Problem p03855 (python)

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 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])
Problem p03878 (python)

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 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))
Problem p03919 (python)

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 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")
Problem p03921 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
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+n-1)
        a[n+j-1].append(i)
t=[False]*(n+m)
def g(x):
    t[x]=True
    for i in a[x]:
            if not t[i]:
                g(i)
g(0)
if all(t[:n]):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
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+n-i)
        a[n+j-1].append(i)
t=[False]*(n+m)
def g(x):
    t[x]=True
    for i in a[x]:
            if not t[i]:
                g(i)
g(0)
if all(t[:n]):
    print("YES")
else:
    print("NO")

Buggy 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].append(i)
t=[False]*n
def g(x):
    if not t[x]:
        t[x]=False:
            for i in a[x]:
                for j in a[i+n]:
                    g(j)
g(0)
if all(t):
    print("YES")
else:
    print("NO")
Problem p03966 (python)

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 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)

Buggy 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)
Problem p03993 (python)

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 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)
Problem p04000 (python)

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 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)
Problem p04019 (python)

Fixed submission:
a=list(input())
if ("N" in a and"S"in a)or(not"N" in a and not "S" in a):
    if ("W" in a and"E"in a)or(not"W" in a and not "E" in a):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
print(sum([1 for j in [int(input()) for i in range(int(input()))][::2] if j%2!=1]))

Buggy submission (verdict: Runtime Error):
if ("N" in a and"S"in a)or(not"N" in a and not "S" in a):
    if ("W" in a and"E"in a)or(not"W" in a and not "E" in a):
        print("Yes")
    else:
        print("No")
else:
    print("No")