Harryxun/testdata huggingface dataset:
Buggy python 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)

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

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

Fixed submission:
a,b=map(int,input().split())
print((a*3+b)//2)
Buggy python 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)
                

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

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 python submission (verdict: Runtime Error):
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
co=0
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[co]=max(a[j],c[xc[i]])
        if a[j]>c[xc[i]]:
            break                
        co+=1
print(sum(a))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
co=0
f=0
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[co]=max(a[co],c[xc[i]])
        if a[co]>c[xc[i]]:
            f=1
            break                
        co+=1
        if co>=n:
            f=1 
            break
    if f==1:
        break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[j]=max(a[j],c[xc[i]])
    a.sort()
print(sum(a))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
co=0
f=0
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[co]=max(a[co],c[xc[i]])
        if a[co]>c[xc[i]]:
            f=1
            break                
        co+=1
        if co>=n:
            f=1 
            break
    if f==1:
        break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
for i in range(m-1,-1,0):
    for j in range(b[xc[i]]):
        a[j]=max(a[j],c[xc[i]])
    a.sort()
print(sum(a))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
co=0
f=0
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[co]=max(a[co],c[xc[i]])
        if a[co]>c[xc[i]]:
            f=1
            break                
        co+=1
        if co>=n:
            f=1 
            break
    if f==1:
        break
print(sum(a))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(input())
if s[k-1]='A':
    s[k-1]='a'
elif s[k-1]='B':
    s[k-1]='b'
else:
    s[k-1]='c'
ans=''
for i in range(n):
    ans+=s[i]
print(ans)
  

Fixed submission:
n,k=map(int,input().split())
s=list(input())
if s[k-1]=='A':
    s[k-1]='a'
elif s[k-1]=='B':
    s[k-1]='b'
else:
    s[k-1]='c'
ans=''
for i in range(n):
    ans+=s[i]
print(ans)
Buggy python 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)
                


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 python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
    for j in range(3001):
        if b==0:
            if n==r*i+g*j:
                ans+=1
        else:    
            if (n-r*i-g*j)%b==0:
                ans+=1
print(ans)
                

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

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


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

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


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 python submission (verdict: Time Limit Exceeded):
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)
if s[0]=='1':
    ans=0
    for i in range(g):
        if 2*i<g:
            ans=max(ans,sum(a[2*i:2*i+2*k+1]))
        else:
            break
    print(ans)
else:
    ans=sum(a[0:2*k])
    for i in range(g):
        if 2*i+1<g:
            ans=max(ans,sum(a[2*i+1:2*i+2*k+2]))
        else:
            break
    print(ans)

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

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 python 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]
        

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 python 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]
        

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

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

    


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

    

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

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

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

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 python submission (verdict: Runtime Error):
import math
n=int(input())
li = list(map(int,input().split()))
a=li[0]
for i in range(n):
    a=math.gcd(li[i],a)
print(a)


Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
n=int(input())
li = list(map(int,input().split()))
a=li[0]
for i in range(n):
    a=gcd(li[i],a)
print(a)

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
li = list(map(int,input().split()))
a=li[0]
for i in range(n):
    a=math.gcd(li[i],a)
print(a)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
n=int(input())
li = list(map(int,input().split()))
a=li[0]
for i in range(n):
    a=gcd(li[i],a)
print(a)
Buggy python 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')

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


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)