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

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
n=int(input())
ans=[0]*n
count=[0]*n

a=list(map(int,input().split()))
for i in range(n,0,-1):
    if count[i-1]%2!=a[i-1]:
        ans[i-1]=1
        b=make_divisors(i)
        for j in b:
            count[j-1]+=1
print(sum(ans))
kai=[]
for i in range(n):
    if ans[i]==1:
        kai.append(i+1)
print(*kai)

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

ans=[0]*n
count=[0]*n
n=int(input())
a=list(map(int,input().split()))
for i in range(n,0,-1):
    if count[i-1]%2!=a[i-1]:
        ans[i-1]=1
        b=make_divisors(i)
        for j in b:
            count[b-1]+=1
print(sum(ans))
kai=[]
for i in range(n):
    if ans[i]==1:
        kai.append(i+1)
print(*kai)
Problem p02983 (python)

Fixed submission:
l,r=map(int,input().split())
r=min(r,l+2020)
  
ans=10**9
c=0
for i in range(l,r+1):
    for j in range(l,r+1):
        if i!=j:
            ans=min(ans,(i*j)%2019)
        c+=1
print(ans)

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())

ans=10**9
c=0
for i in range(l,r+1):
    for j in range(l,r+1):
        if i!=j:
            ans=min((i*j)%2019)
        c+=1
        if c>2019**2:
            continue
print(ans)
Problem p02985 (python)

Fixed submission:
from collections import deque
n,k=map(int,input().split())
if n==1 and k==1:
    print(1)
    exit()
if k==1:
    print(0)
    exit()
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
mod=10**9+7
ans=k
q=deque([0])
v=[0]*n
v[0]=1
vc=1
while q and vc<n:
    s=q.popleft()
    c=0
    if s==0:
        kai=k-1
    else:
        kai=k-2
    for es in g[s]:
        if v[es]==0:
            v[es]=1
            vc+=1
            c+=1
            q.append(es)
            ans*=kai
            ans%=mod
            kai-=1
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
mod=10**9+7
pk2=[0]*(k-1)
pk2[0]=1
for i in range(k-2):
    pk2[i+1]=pk2[i]*(k-2-i)%mod
def p(n,r):
    if n<r:
        return 0
    return pk2[r]
ans=k
q=[0]
v=[0]*n
v[0]=1
while len(q)>0:
    s=q.pop(0)
    c=0
    for es in g[s]:
        if v[es]==0:
            v[es]=1
            c+=1
            q.append(es)
    if s==0:
        for i in range(k-c,k):
            ans*=i
            ans%=mod
        ans%=mod
    else:
        ans*=p(k-2,c)
        ans%=mod
print(ans%mod)
Problem p02993 (python)

Fixed submission:
s=list(input())
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
    print('Bad')
else:
    print('Good')

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if (n-2)*(n-1)//2<k:
    print(-1)
else:
    print(n-1+(n-2)*(n-1)//2-k)
    for i in range(2,n+1):
        print(1,i)
    c=0
    for i in range(2,n+1):
        for j in range(2,n+1):
            if i<j:
                print(i,j)
                c+=1
                if c==(n-2)*(n-1)//2-k:
                    exit()
Problem p03014 (python)

Fixed submission:
h,w=map(int,input().split())

s=[]
for i in range(h):
    s.append(list(input()))

l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]

for i in range(h):
    f=0
    for j in range(w):
        if s[i][j]=='#':
            f=0
            l[i][j]=0
        else:
            f+=1
            l[i][j]=f
            
for i in range(h):
    f=0
    for j in range(w-1,-1,-1):
        if s[i][j]=='#':
            f=0
            r[i][j]=0
        else:
            f+=1
            r[i][j]=f
            
for j in range(w):
    f=0
    for i in range(h):
        if s[i][j]=='#':
            f=0
            u[i][j]=0
        else:
            f+=1
            u[i][j]=f
    
for j in range(w):
    f=0
    for i in range(h-1,-1,-1):
        if s[i][j]=='#':
            f=0
            d[i][j]=0
        else:
            f+=1
            d[i][j]=f

ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

s=[]
for i in range(h):
    s.append(list(map(int,input().split())))

l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]

for i in range(h):
    f=0
    for j in range(w):
        if s[i][j]=='#':
            f=0
            l[i][j]=0
        else:
            f+=1
            l[i][j]=f
            
for i in range(h):
    f=0
    for j in range(w-1,-1,-1):
        if s[i][j]=='#':
            f=0
            r[i][j]=0
        else:
            f+=1
            r[i][j]=f
            
for j in range(w):
    f=0
    for i in range(h):
        if s[i][j]=='#':
            f=0
            u[i][j]=0
        else:
            f+=1
            u[i][j]=f
    
for j in range(w):
    f=0
    for i in range(h-1,-1,-1):
        if s[i][j]=='#':
            f=0
            d[i][j]=0
        else:
            f+=1
            d[i][j]=f

ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)
Problem p03026 (python)

Fixed submission:
n=int(input())
g=[[] for i in range(n)]
ro=[0]*n
for i in range(n-1):
    a,b=map(int,input().split())
    ro[a-1]+=1
    ro[b-1]+=1
    g[a-1].append(b-1)
    g[b-1].append(a-1)
c=list(map(int,input().split()))
c.sort(reverse=True)
m=max(ro)
mi=ro.index(m)
q=[mi]
ans=[0]*n
v=[0]*n
v[mi]=1
ans[mi]=c.pop(0)
while len(q)>0:
    s=q.pop()
    for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop(0)
            q.append(i)
print(sum(ans)-max(ans))
print(*ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
g=[[] for i in range(n)]
ro=[0]*n
c=list(map(int,input().split()))
c.sort(reverse=True)
for i in range(n-1):
    a,b=map(int,input().split())
    ro[a-1]+=1
    ro[b-1]+=1
    g[a-1].append(b-1)
    g[b-1].append(a-1)
m=max(ro)
mi=ro.index(m)
q=[mi]
ans=[0]*n
v=[0]*n
v[mi]=1
ans[mi]=c.pop()
while len(q)>0:
    s=q.pop()
    for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop()
            q.append(i)
print(sum(ans)-max(ans))
print(*ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
g=[[] for i in range(n)]
ro=[0]*n
c=list(map(int,input().split()))
c.sort(reverse=True)
for i in range(n-1):
    a,b=map(int,input().split())
    ro[a-1]+=1
    ro[b-1]+=1
    g[a-1].append(b-1)
    g[b-1].append(a-1)
m=max(ro)
mi=ro.index(m)
q=[mi]
ans=[0]*n
v=[0]*n
v[mi]=1
ans[mi]=c.pop()
while len(q)>0:
    s=q.pop()
    for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop()
            q.append(i)
print(sum(c)-max(c))
print(*ans)
Problem p03029 (python)

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

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

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        tmp=sum(q)
        q.sort()
        for l in range(ki-i):
            if l<len(q) and q[l]<0:
                tmp-=q[l]
        ans=max(ans,tmp)
        
print(ans)
Problem p03031 (python)

Fixed submission:
n,m=map(int,input().split())
s=[]
for i in range(m):
    s.append(list(map(int,input().split())))
p=list(map(int,input().split()))

onoff=[["0"],["1"]]

for i in range(n-1):
    tmp=[]
    for j in onoff:
        tmp.append(j+["0"])
        tmp.append(j+["1"])
    onoff=tmp

ans=0
for i in onoff:
    f=0
    for j in range(m):
        c=0
        for k in range(s[j][0]):
            if i[s[j][1+k]-1]=='1':
                c+=1
        if c%2!=p[j]:
            f+=1
    if f==0:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=[]
for i in range(m):
    s.append(list(map(int,input().split())))
p=list(map(int,input().split()))

onoff=[["0"],["1"]]

for i in range(n):
    tmp=[]
    for j in onoff:
        tmp.append(j+["0"])
        tmp.append(j+["1"])
    onoff=tmp

ans=0
for i in onoff:
    f=0
    for j in range(m):
        c=0
        for k in range(s[j][0]):
            if onoff[s[j][i+k]-1]=="1":
                c+=1
        if c%2!=p[j]:
            f+=1
    if f==0:
        ans+=1
print(ans)
Problem p03032 (python)

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

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        tmp=sum(q)
        q.sort()
        for l in range(ki-i):
            if l<len(q) and q[l]<0:
                tmp-=q[l]
        ans=max(ans,tmp)
        
print(ans)

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

m=min(n,k)
ans=0

for i in range(m):
    for j in range(i):
        q=[]
        tmp=0
        for k in range(j):
            q.append(v.pop(0))
        for k in range(i-j):
            q.append(v.pop(-1))
        q.sort()
        for l in range(len(q)):
            if q[i]>0:
                tmp+=q[i]
        ans=max(ans,tmp)
print(ans)
Problem p03048 (python)

Fixed submission:
r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
    for j in range(3001):   
        if (n-r*i-g*j)>=0 and (n-r*i-g*j)%b==0:
                ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
r,g,b,n=map(int,input().split())
ans=0
for i in range(n+1):
    for j in range(n+1-i):   
        if (n-r*i-g*j-b*(n-i-j)==0:
                ans+=1
print(ans)
Problem p03050 (python)

Fixed submission:
n=int(input())
y=[]
for i in range(1,round(n**0.5)+1):
    if n%i==0:
        y.append(i)
        y.append(n//i)
ans=0
for i in y: 
    if i>1 and n//(i-1)==n%(i-1):
        ans+=(i-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
y=[]
for i in range(1,round(n**0.5)+1):
    if n%i==0:
        y.append(i)
ans=0
for i in y:
    if n//(i-1)==n%(i-1):
        ans+=(i-1)
print(ans)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

#####segfunc######                                                              
def segfunc(x,y):
    return gcd(x,y)

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n=int(input())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(map(int,input().split()))
init(a)
ans=0
for i in range(n):
    ans=max(gcd(query(0,i),query(i+1,n)),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

#####segfunc######                                                              
def segfunc(x,y):
    return gcd(x,y)

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
	seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
	k=(k-1)//2
	seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
	return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
	if p&1==0:
            res=segfunc(res,seg[p])
	if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
	p=p//2
	q=(q-1)//2
    if p==q:
	res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n=int(input())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(map(int,input().split()))

ans=0
for i in range(n):
    ans=min(gcd(query(0,i),query(i+1,n)),ans)
print(ans)
Problem p03069 (python)

Fixed submission:
n=int(input())
s=list(input())
rw=[0]*(n+1)
lb=[0]*(n+1)
for i in range(n):
    if s[i]=='#':
        lb[i+1]=lb[i]+1
    else:
        lb[i+1]=lb[i]
for i in range(n):
    if s[n-i-1]=='.':
        rw[n-i-1]=rw[n-i]+1
    else:
        rw[n-i-1]=rw[n-i]
ans=100000000000
for i in range(n+1):
    ans=min(ans,lb[i]+rw[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
w=0
for i in s:
    if i=='.':
        w+=1
b=n-a
if s[-1]=='#':
    print(min(w,b-1))
else:
    print(min(w,b))
Problem p03074 (python)

Fixed submission:
n,k=map(int,input().split())
s=list(input())
a=[]
f=1
s.append(2)
for i in range(n):
    if s[i]==s[i+1]:
        f+=1
    else:
        a.append(f)
        f=1
g=len(a)
r=[0]*(g+1)
for i in range(g):
    r[i+1]=r[i]+a[i]
if s[0]=='1':
    ans=sum(a[0:2*k+1])
    if s[-2]=='0':
        ans=max(ans,sum(a[max(0,g-2*k):g]))
    for i in range(g):
        if 2*i+2*k+1<g+1:
            ans=max(ans,r[2*i+2*k+1]-r[2*i])
        else:
            break
    print(ans)
else:
    ans=sum(a[0:2*k])
    if s[-2]=='0':
        ans=max(ans,sum(a[max(0,g-2*k):g]))
    for i in range(g):
        if 2*i+2*k+2<g+1:
            ans=max(ans,r[2*i+2*k+2]-r[2*i+1])
        else:
            break
    print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(input())
a=[]
f=1
s.append(2)
for i in range(n):
    if s[i]==s[i+1]:
        f+=1
    else:
        a.append(f)
        f=1
g=len(a)
r=[0]*(g+1)
for i in range(g):
    r[i+1]=r[i]+a[i]
if s[0]=='1':
    ans=sun(a[2*i:2*i+2*k+1])
    for i in range(g):
        if 2*i+2*k+1<g+1:
            ans=max(ans,r[2*i+2*k+1]-r[2*i])
        else:
            break
    print(ans)
else:
    ans=sum(a[0:2*k])
    for i in range(g):
        if 2*i+2*k+2<g+1:
            ans=max(ans,r[2*i+2*k+2]-r[2*i+1])
        else:
            break
    print(ans)
Problem p03078 (python)

Fixed submission:
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
aa=[]
for i in range(k):
    if x*y-i-1>=0:
        aa.append(ab[x*y-i-1])
ans=[]
for i in range(len(aa)):
    for j in range(z):
        ans.append(aa[i]+c[j])
ans.sort()
for i in range(k):
    print(ans[len(ans)-i-1])

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
aa=[]
for i in range(k):
    if x*y-i>=0:
        aa.append(ab[x*y-i])
ans=[]
for i in range(len(aa)):
    for j in range(z):
        ans.append(aa[i]+c[j])
ans.sort()
for i in range(k):
    print(ans[len(ans)-i-1])

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
aa=[]
for i in range(k):
    if x*y-i>=0:
        aa.append(ab[x*y-i])
ans=[]
for i in range(len(aa)):
    for j in range(z):
        ans.append(aa[i]+c[j])
ans.sort()
for i in range(k):
    print(ans[len(ans)-i-1]

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
aa=[]
for i in range(k):
    if x*y-i>=0:
        aa.append(ab[x*y-i])
ans=[]
for i in range(len(aa)):
    for j in range(z):
        ans.append(aa[i]+c[j])
ans.sort()
for i in range(k):
    print(ans[len(ans)-i]
Problem p03089 (python)

Fixed submission:
n=int(input())
b=list(map(int,input().split()))
if b[0]!=1:
    print(-1)
else:
    ans=[1]
    for j in range(len(b)-1):
        for i in range(len(b)-1,-1,-1):
            if i==0 and b[0]==1 and b[1]==1:
                ans+=[b.pop(i)]
                break
            if b[i]==i+1 and i>0:
                ans+=[b.pop(i)]
                break    
    if len(ans)!=n:  
        print(-1)
    else:
        print(1)
        for i in range(n-1,0,-1):
            print(ans[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
b=list(map(int,input().split()))
if b[0]!=1:
    print(-1)
else:
    ans=[1]
    for j in range(len(b)-1):
        for i in range(len(b)-1,-1,-1):
            if i==0 and b[0]==1:
                ans+=[b.pop(i)]
                break
            if b[i]==i+1:
                ans+=[b.pop(i)]
                break                
if len(ans)!=n:  
    print(-1)
else:
    print(1)
    for i in range(n-1,0,-1):
        print(ans[i])
Problem p03095 (python)

Fixed submission:
n=int(input())
s=list(input())
mod=10**9+7
z=list(set(s))
ans=1

m=len(z)
for i in range(m):   
    ans*=(s.count(z[i])+1)%mod
    ans=ans%mod
print((ans-1)%mod)

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

mod=10**9+7
z=list(set(s))
m=len(z)
for i in range(m):   
    ans*=(s.count(z[i])+1)%mod
    ans%=mod
print((ans-1)%mod)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(map(int,input().split()))
ans=0
z=list(set(s))
m=len(z)
for i in range(m):
    ans+=s.count(z[i])*(2**(m-1))
print(ans-m+1)
Problem p03103 (python)

Fixed submission:
import numpy as np
n,m=map(int,input().split())
a=np.zeros(n)
b=np.zeros(n)
for i in range(n):
    a[i],b[i]=map(int,input().split())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    m-=b[x[i]]
    i+=1
print(int(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m=map(int,input().split())
a=np.zeros(n)
b=np.zeros(n)
for i in range(n):
    a[i],b[i]=map(int,input().split())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    i+=1
    m-=b[x[i]]
print(round(ans))
Problem p03112 (python)

Fixed submission:
import bisect
a,b,q=map(int,input().split())
s=[]
t=[]
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
for i in range(q):
    x=int(input())
    si=bisect.bisect_left(s,x)
    ti=bisect.bisect_left(t,x)
    if si==a:
        sk=[s[a-1]]
    elif si==0:
        sk=[s[0]]
    else:
        sk=[s[si-1],s[si]]
    if ti==0:
        tk=[t[0]]
    elif ti==b:
        tk=[t[b-1]]
    else:
        tk=[t[ti-1],t[ti]]
    ans=1000000000000
    for f in sk:
        for g in tk:
            ans=min(ans,abs(x-f)+abs(f-g),abs(x-g)+abs(g-f))
    print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
a,b,q=map(int,input().split())
s=[]
t=[]
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
for i in range(q):
    x=int(input())
    si=bisect.bisect_left(s,x)
    ti=bisect.bisect_left(t,x)
    if si==a:
        sk=[s[a-1]]
    elif si==0:
        sk=[s[0]]
    else:
        sk=[s[si-1],s[si]]
    if ti==0:
        tk=[t[0]]
    else:
        tk=[t[ti-1],t[ti]]
    ans=1000000000000
    for f in sk:
        for g in tk:
            ans=min(ans,abs(x-f)+abs(f-g),abs(x-g)+abs(g-f))
print(ans)
Problem p03126 (python)

Fixed submission:
import numpy as np
n,m = map(int,input().split())
a=np.zeros(m,dtype=np.int64)
for i in range(n):
    li=[]
    li = list(map(int,input().split()))
    
    for j in range(li[0]):
        a[li[j+1]-1]=a[li[j+1]-1]+1
        
ans=0
for i in range(m):
    if a[i]==n:
        ans=ans+1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
a=np.zeros(m,dtype=int64)
for i in range(n):
    li = list(map(int,input().split()))
    for j in range(li[0]):
        a[li[j+1]-1]=a[li[j+1]-1]+1
ans=0
for i in range(m):
    if a[i]==n:
        ans=ans+1
print(ans)
Problem p03130 (python)

Fixed submission:
ans=[0]*4

for i in range(3):
    a,b=map(int,input().split())
    ans[a-1]+=1
    ans[b-1]+=1

f1=0
f2=0
for i in range(4):
    if ans[i]==1:
        f1+=1
    if ans[i]==2:
        f2+=1
if f1==2 and f2==2:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
ans=[0]*4

for i in range(3):
    a,b=map(int,input())
    ans[a-1]+=1
    ans[b-1]+=1

f1=0
f2=0
for i in range(4):
    if ans[i]==1:
        f1+=1
    if ans[i]==2:
        f2+=1
if f1==2 and f2==2:
    print('YES')
else:
    print('NO')
Problem p03138 (python)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*14
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(13,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)
Problem p03139 (python)

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

ans=[0,0]

ans[0]=min(a,b)
ans[1]=max(0,a+b-n)
print(*ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
g=[[] for i in range(n)]
ro=[0]*n
for i in range(n+m-1):
    a,b=map(int,input().split())
    g[a-1].append(b)
    ro[b-1]+=1
for i in range(n):
    if ro[i]==0:
        r=i
ans=[0]*n
q=[r]
while len(q)>0:
    u=q.pop()
    for v in g[u]:
        ans[v-1]=u+1
        q.append(v-1)
for i in ans:
    print(i)
Problem p03145 (python)

Fixed submission:
li=list(map(int,input().split()))
s=sum(li)
t=min(li)
l=s-t-max(li)
print(t*l//2)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
s=sum(a,b,c)
t=min(a,b,c)
l=s-t-max(a,b,c)
print(t*l//2)