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

Fixed submission:
n,k=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:-x[1])
t=[0]*(n+1)
p,q=0,0
for i in a[:k]:
    p+=i[1]
    if t[i[0]]==0:
        q+=1
    t[i[0]]+=1
s=0
d=p+q*q
c=a[:k][::-1]
for i in a[k:]:
    if t[i[0]]==0:
        while s!=k:
            if t[c[s][0]]==1:
                s+=1
            else:
                break
        if s==k:
            break
        else:
            t[i[0]]+=1
            p-=c[s][1]-i[1]
            q+=1
            d=max(d,p+q*q)
            s+=1
print(d)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=[]
d=[]
p=[]
t=[]
for i in range(n):
    a,b=map(int,input().split())
    p.append(b)
    if a not in s:
        s.append(a)
        d.append([b])
    else:
        d[s.index(a)].append(b)    
for i in range(len(s)):
    d[i].sort()
    t.append(d[i][-1])
t.sort()
p.sort()
r=[]
q=0
g=0
for i in range(k):
    if i<=len(t)+1:
        r.append(t[-1])
        q+=t[-1]
        g+=1
        p.pop(p.index(t[-1]))
        t.pop(-1)
    else:
        q+=sum(p[n-k+len(t):])
        del p[n-k+len(t):]
r.sort()
while r[0]+2*g-1<p[-1]:
    q+=p[-1]-r[0]
    g-=1
    p.pop(-1)
    r.pop(0)
print(g**2+q)
Problem p03164 (python)

Fixed submission:
import numpy as np
n,a=map(int,input().split())
s=np.full(n*1000+1,a+1)
s[0]=0
for i in range(n):
    w,v=map(int,input().split())
    s[v:]=np.minimum(s[v:],s[:-v]+w)
print(np.max(np.where(s<=a)))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as f
n,s=map(int,input().split())
k=f(int)
k[0]=0
g=0
for i in range(n):
    w,v=map(int,input().split())
    c=list(k)
    for i in range(len(c)-1,-1,-1):
        if c[k[i]+v]!=0:
            c[k[i]+v]=min(c[k[i]]+w,c[k[i]+v])
        else:
            c[k[i]+v]=c[k[i]]+w
        if c[k[i]+v]<=s:
            g=max(g,k[i]+v)
print(g)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,w=map(int,input().split())
a=np.zeros([n,w+1],dtype=int)
c,d=map(int,input().split())
a[0][c:]=d
for i in range(1,n):
    e,f=map(int,input().split())
    a[i][:e]=a[i-1][:e]
    a[i][e:]=np.maximum(a[i-1][e:],a[i-1][:-e]+f)
print(a[-1][-1])
Problem p03175 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
s=[[]for i in range(n+1)]
m=10**9+7
for i in range(n-1):
    x,y=map(int,input().split())
    s[x].append(y)
    s[y].append(x)
t=[[0,0]for i in range(n+1)]
def f(a,b):
    t[a][0]=t[a][1]=1
    for i in s[a]:
        if i!=b:
            f(i,a)
            t[a][0]*=t[i][0]+t[i][1]
            t[a][1]*=t[i][0]
f(1,0)
print(sum(t[1])%m)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
n=int(input())
s=[[]for i in range(n+1)]
m=10**9+7
for i in range(n-1):
    x,y=map(int,input().split())
    s[x].append(y)
    s[y].append(x)
t=[[0,0]for i in range(n+1)]
def f(a,b):
    t[a][0]=t[a][1]=1
    for i in s[a]:
        if i!=b:
            f(i,a)
            t[a][0]*=t[i][0]+t[i][1]
            t[a][1]*=*t[i][0]
f(1,0)
print(sum(t[1])%m)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[[]for i in range(n+1)]
m=10**9+7
for i in range(n-1):
    x,y=map(int,input().split())
    s[x].append(y)
    s[y].append(x)
t=[[0,0]for i in range(n+1)]
def f(a,b):
    t[a][0]=t[a][1]=1
    for i in s[a]:
        if i!=b:
            f(i,a)
            t[a][0]=(t[a][0]*(t[i][0]+t[i][1]))%m
            t[a][1]=(t[a][1]*t[i][0])%m
f(1,0)
print(sum(t[1]))
Problem p03231 (python)

Fixed submission:
from fractions import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)
n,m=map(int,input().split())
s=input()
t=input()
d=lcm(n,m)
p=d//n
q=d//m
h=lcm(p,q)
l=d//h
for i in range(0,l):
    g=i*h
    if s[g//p]!=t[g//q]:
        print(-1)
        break
else:
    print(d)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)
n,m=map(int,input().split())
s=input()
t=input()
w=min(m,n)
l=w//gcd(m,n)
d=lcm(m,n)
p=d//n
q=d//m
h=lcm(p,q)
for i in range(0,l-1):
    g=i*h
    if s[g//p]!=t[g//q]:
        print(-1)
        break
else:
    print(d)

Buggy submission (verdict: Runtime Error):
from flactions import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)
n,m=map(int,input().split())
s=input()
t=input()
w=min(m,n)
l=w//gcd(m,n)
d=lcm(m,n)
p=d//n
q=d//m
h=lcm(p,q)
for i in range(0,l-1):
    g=i*h
    if s[g//p]!=t[g//q]:
        print(-1)
        break
else:
    print(d)

Buggy submission (verdict: Runtime Error):
from fraction import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)
n,m=map(int,input().split())
s=input()
t=input()
if s[0]!=t[0]:
    print(-1)
else:
    d=lcm(m,n)
    f=max(m,n)%min(m,n)
    if f!=0:
        print(d)
    else:
        g=max(m,n)//min(m,n)
        if max(m,n)==m:
            k=t
            q=s
            l=n
        else:
            k=s
            q=t
            l=m
        for i in range(0,l):
            if k[g*i]!=q[i]:
                print(-1)
                break
        else:
            print(m+n-l)
Problem p03238 (python)

Fixed submission:
n=int(input())
if n==1:
  print("Hello World")
else:
  t=[int(input()) for i in range(2)] 
  print(t[0]+t[1])

Buggy submission (verdict: Runtime Error):
n, m = list(map(int,input().split()))
def solve():
    for i in range(m//n, 0, -1):
        if m % i == 0:
            print(i)
            break
solve()
Problem p03240 (python)

Fixed submission:
n=int(input())
e = [[int(i) for i in input().split()] for i in range(n)]
h=0
for a in range(n):
    if e[a][2]>0:
        s=a
        break
for x in range(0,101):
    for y in range(0,101):
            k=abs(x-e[s][0])+abs(y-e[s][1])+e[s][2]
            for i in range(0,n):
                if e[i][2]!=max(k-abs(x-e[i][0])-abs(y-e[i][1]),0):
                    break
            else:
                print(x,y,k)

Buggy submission (verdict: Runtime Error):
n=int(input())
e = [[int(i) for i in input().split()] for i in range(n)]
h=0
for x in range(0,101):
    for y in range(0,101):
        f=0
        if e[f][2]==0:
            f+=1
        else:
            k=abs(x-e[f][0])+abs(y-e[f][1])+e[f][2]
        for i in range(0,len(e)):
            if e[i][2]!=max(k-abs(x-e[i][0])-abs(y-e[i][1]),0):
                break
        else:
            print(x,y,k)
Problem p03241 (python)

Fixed submission:
n, m = list(map(int,input().split()))
def solve():
    for i in range(m//n, 0, -1):
        if m % i == 0:
            if m//i>= n:
                print(i)
                break
solve()

Buggy submission (verdict: Runtime Error):
n, m = list(map(int,input().split()))
def solve():
    for i in range(m//n, 0, -1):
        if m % i == 0:
			print(i)
            break
solve()

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=[]
for i in range(1,int(m**2)+1):
    if m%i==0 and i=<n:
        s.append(i)
        if m/i=<n:
           s.append(m/i)
print(max(s))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=[]
for i in range(1,int(m**2)+1):
    if m%i==0 and i<n:
        s.append(i)
        if m/i<n:
           s.append(m/i)
print(max(s))
Problem p03262 (python)

Fixed submission:
from fractions import gcd 
n,x=map(int,input().split())
s=list(map(int,input().split()))
b=s[0]
t=abs(b-x)
for i in range(1,n):
    t=gcd(t,abs(s[i]-x))   
print(t)

Buggy submission (verdict: Runtime Error):
from function import gcd
n,x=map(int,input().split())
s=list(map(int,input().split()))
b=s[0]
t=abs(b-x)
for i in range(1,n):
    t=gcd(t,abs(s[i]-x))   
print(t)

Buggy submission (verdict: Runtime Error):
import math
n,x=map(int,input().split())
s=list(map(int,input().split()))
b=s[0]
t=abs(b-x)
for i in range(1,n):
    t=math.gcd(t,abs(s[i]-x))   
print(t)

Buggy submission (verdict: Runtime Error):
import math
n,x=map(int,input().split())
s=list(map(int,input().split()))
b=s[0]
t=abs(s[0]-x)
for i in range(1,n):
    t=math.gcd(t,abs(s[i]-x))   
print(t)
Problem p03276 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[]
if n==1:
    print(a[0])
else:
    for i in range(n-k+1):
        if a[i]<=0 and 0<=a[i+k-1]:
            s.append(min(2*a[i+k-1]-a[i],a[i+k-1]-2*a[i]))
        elif a[i+k-1]<=0:
            s.append(-a[i])
        else:
            s.append(a[i+k-1])
    print(min(s))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[]
if n==1:
    print(a[0])
else:
    for i in range(n-k+1):
        if a[i]<=0 and 0<=a[i+k-1]:
            s.append(min(2*a[i+k-1]-a[i],a[i+k-1]-2*a[i]))
        elif a[i+k]<=2:
            s.append(-a[i])
        else:
            s.append(a[i+k-1])
    print(min(s))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[]
if n==1:
    print(a[0])
else:
    for i in range(n-k):
        if a[i]<=0 and 0<=a[i+k-1]:
            s.append(min(2*a[i+k-1]-a[i],a[i+k-1]-2*a[i]))
        elif a[i+k]<=2:
            s.append(-a[i])
        else:
            s.append(a[i+k-1])
    print(min(s))
Problem p03290 (python)

Fixed submission:
a,b=map(int,input().split())
c=[0]+[list(map(int,input().split()))for i in range(a)]
def f(t,s):
    if t==0:
        return 10**9
    l=min(s//(t*100),c[t][0])
    k=100*t*l
    if l==c[t][0]:
        k+=c[t][1]
    if k<s:
        l+=f(t-1,s-k)
    return min(l,f(t-1,s))
print(f(a,b))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=[0]+[list(map(int,input().split()))for i in range(a)]
def f(t,s):
    if t==0:
        return 10000007
    else:
        l=min(s//(t*100),c[t][0])
        k=100*i*l
        if n==c[t][0]:
            l+=s[t][1]
        if l<G:
            n+=f(t-1,s-l)
        return min(n,f(t-1,s))
print(f(a,b))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=[0]+[list(map(int,input().split()))for i in range(n)]
def f(s,t):
    if t==0:
        return 10000007
    else:
        l=min(s//(i*100),c[i][0])
        k=100*i*l
        if n==c[i][0]:
            l+=s[i][1]
        if l<G:
            n+=f(s-l,i-1)
        return min(n,f(s,i-1))
print(f(b,a))

Buggy submission (verdict: Runtime Error):
a,b=int(input())
c=[0]+[list(map(int,input().split()))for i in range(n)]
def f(s,t):
    if t==0:
        return 10000007
    else:
        l=min(s//(i*100),c[i][0])
        k=100*i*l
        if n==c[i][0]:
            l+=s[i][1]
        if l<G:
            n+=f(s-l,i-1)
        return min(n,f(s,i-1))
print(f(b,a))
Problem p03311 (python)

Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]-i-1
a.sort()
k=a[n//2]
c=0
for i in range(n):
    c+=abs(a[i]-k)
print(c)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]-i-1
a.sort()
if n%2==1:
    p=a[n//2]
    print(abs(sum(a[:n//2])-p*(n//2))+sum(a[n//2+1:])-p*(n//2))
else:
    l=a[n//2-1]+a[n//2]
    s=math.fllor(l/2)
    t=math.ceil(l/2)
    print(min(abs(sum(a[:n//2]))-s*n//2+sum(a[n//2:])-s*(n//2),abs(sum(a[:n//2]))-t*n//2+sum(a[n//2:])-t*(n//2)))
Problem p03338 (python)

Fixed submission:
p=int(input())
a=input()
b=[]
for i in range(0,p):
    c=0
    t=list(set(a[:i]))
    k=a[i:]
    for j in range(len(t)):
        if t[j]in k:
            c+=1
    b.append(c)
print(max(b))

Buggy submission (verdict: Runtime Error):
p=int(input())
a=input()
b=[]
for i in range(1,p-1):
    c=0
    t=list(set(a[:i]))
    k=a[i:]
    for j in range(len(t)):
        if t[j]in k:
            c+=1
    b.append(c)
print(max(b))
Problem p03377 (python)

Fixed submission:
a,b,x=map(int,input().split())
print("YES"if a+b>=x>=a else"NO")

Buggy submission (verdict: Runtime Error):
input();a=sorted(list(map(int,input().split())));print(a[-1],sorted(a,key=lambda x:abs(a[-1]-2*x))[0])

Buggy submission (verdict: Runtime Error):
input();a=list(map(int,input().split()))[::-1];print(a[0],min(sorted(a,key=lambda x:abs(a[0]-2*x))))

Buggy submission (verdict: Runtime Error):
input();a=list(map(int,input().split()))[::-1];print(a[0],sorted(a,key=lambda x:abs(a[0]-2*x))[0])
Problem p03380 (python)

Fixed submission:
input();a=sorted(list(map(int,input().split())));print(a[-1],sorted(a,key=lambda x:abs(a[-1]-2*x))[0])

Buggy submission (verdict: Runtime Error):
input();a=list(map(int,input().split()))[::-1];print(a[0],sorted(a,key=lambda x:abs(a[0]-2*x))
Problem p03393 (python)

Fixed submission:
n=input()
a=["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"]
if n=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(n)==26:
        q=a.index(n[-1])
        c=0
        d=[n[-1]]
        for i in range(24,-1,-1):
            c+=1
            d.append(n[i])
            d.sort()
            if d.index(n[i])<len(d)-1:
                print(n[:26-c-1]+d[d.index(n[i])+1])
                break
    else:
        for i in range(len(n)):
            a.pop(a.index(n[i]))
        print(n+a[0])

Buggy submission (verdict: Runtime Error):
n=input()
a=["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"]
if n=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(n)==26:
        q=a.index(n[-1])
        c=0
        d=[n[-1]]
        for i in range(24,0,-1):
            c+=1
            d.append(n[i])
            d.sort()
            if d.index(n[i])<len(d)-1:
                print(n[:26-c-1]+d[d.index(n[i])+1])
                break
        else:
            print(a[a.index(n[i])+1])
    else:
        for i in range(len(n)):
            a.pop(a.index(n[i]))
        print(n+a[0])
Problem p03437 (python)

Fixed submission:
x,y=map(int,input().split())
print(x if x%y!=0else-1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as d
p=d(str)
n=int(input())
print(0, flush = True)
s = input()
if s == "Vacant": exit()
else:
    print(n-1,flush=True)
    t=input()
    if t == "Vacant": exit()
    else:
        p[0]=s
        p[n-1]=t
        l=0
        r=n-1
        while 1:
            g=(l+r)//2
            if p[l]=="":
                print(l, flush = True)
                s = input()
                p[l]=s
                if s == "Vacant": exit()
                else:
                    s=p[l]
            if p[g]=="":
                print(g, flush = True)
                t = input()
                p[g]=t
                if t == "Vacant": exit()
                else:
                    t=p[g]
            if ((g-l)%2!=0 and s!=t) or ((g-l)%2!=1 and s==t):
                l=g+1
            else:
                r=g-1
Problem p03450 (python)

Fixed submission:
n,m=map(int,input().split())
a=[[]for i in range(n+1)]
b=[""]*(n+1)
for i in range(m):
    l,r,d=map(int,input().split())
    a[l].append([r,d])
    a[r].append([l,-d])
for i in range(1,n+1):
    if b[i]=="":
        b[i]=0
        k=[i]
        while k:
            s=k.pop()
            for x,y in a[s]:
                if b[x]=="":
                    k.append(x)
                    b[x]=b[s]+y
c="Yes"
for i in range(1,n+1):
    for p,q in a[i]:
        if b[i]+q!=b[p]:
            c="No"
print(c)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[[]for i in range(n+1)]
b=[""]*(n+1)
for i in range(m):
    l,r,d=map(int,input().split())
    a[l].append([r,d])
    a[r].append([l,-d])
for i in range(1,n+1):
    if b[i]=="":
        b[i]=0
        k=[i]
        while k:
            s=k.pop(i)
            for x,y in a[s]:
                if b[x]=="":
                    k.append(x)
                    b[x]=b[i]+y
c="Yes"
for i in range(1,n+1):
    for p,q in a:
        if a[i]+q!=p:
            c="No"
print(c)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[[]for i in range(n+1)]
b=[]for i in range(n):
for i in range(n):
    l,r,d=map(int,input().split())
    a[l].append([r,d])
    a[r].append([l,-d])
for i in range(1,n+1):
    if b[i]==None:
        b[i]=0
        k=[i]
        while k:
            s=k.pop(i)
            for x,y in a[s]:
                if b[x]==None:
                    k.append(x)
                    b[x]=b[i]+y
c="Yes"
for i in range(1,n+1):
    for p,q in a:
        if a[i]+q!=p:
            c="No"
print(c)
Problem p03470 (python)

Fixed submission:
n=int(input())
print(len(set([int(input())for i in range(n)])))

Buggy submission (verdict: Runtime Error):
print(len(set([input()for i in range(n)])))
Problem p03501 (python)

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

Buggy submission (verdict: Runtime Error):
from heapq import *
from itertools import accumulate as ac
n,c=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
b=[[]for i in range(c+1)]
for i,j,h in a:
    if len(b[h])>0:
        if b[h][-1][1]==i:
            b[h][-1][1]=j
    else:
        b[h].append([i,j])
s=[0]*(2*10**5+2)
for i in b:
    for h,w in i:
        s[2*h-1]+=1
        s[2*w+1]-=1
print(max(list(ac(s))))
Problem p03504 (python)

Fixed submission:
from heapq import *
from itertools import accumulate as ac
n,c=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
b=[[]for i in range(c+1)]
for i,j,h in a:
    if len(b[h])>0:
        if b[h][-1][1]==i:
            b[h][-1][1]=j
        else:
            b[h].append([i,j])
    else:
        b[h].append([i,j])
s=[0]*(2*10**5+2)
for i in b:
    for h,w in i:
        s[2*h-1]+=1
        s[2*w+1]-=1
print(max(list(ac(s))))

Buggy submission (verdict: Runtime Error):
from heapq import *
from itertools import chain
n,c=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
b=[[]for i in range(c+1)]
for i,j,h in a:
    if len(b[h])>0:
        if b[h][-1][1]==i:
            b[h][-1][1]=j
    else:
        b[h].append([i,j])
d=sorted(chain.from_iterable(b))
b=[d[0][1]]
for i,j in d[1:]:
    s=heappop(b)
    if i<=s:
        heappush(b,s)
        heappush(b,j)
    else:
        heppush(b,j)
print(len(b))
Problem p03505 (python)

Fixed submission:
k,a,b=map(int,input().split());print(1+2*((k-a-1)//(a-b)+1)if a-b>0 else(1 if k<=a else -1))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate as ac
n=int(input())
a,b=[],[]
for i in range(n):
    x,s=map(int,input().split())
    a.append(x)
    b.append(s)
r=[0]+list(ac(b))
l=r[:]
for i in range(n):
    r[i]+=-a[i]
    l[i+1]+=-a[i]
q,d=r[0],0
for i in range(1,n+1):
    d=max(l[i]-q,d)
    q=min(q,r[i-1])
print(d)

Buggy submission (verdict: Runtime Error):
k,a,b=map(int,input().split());print(-1if a<b else 2*((k-1)//(a-b))+1)
Problem p03506 (python)

Fixed submission:
n,q=map(int,input().split())
if n==1:
    for i in range(q):
        v,w=map(int,input().split())
        print(min(v,w))
else:
    for i in range(q):
        v,w=map(int,input().split())
        while v!=w:
            if v>w:v,w=w,v
            w=(w+n-2)//n
        print(v)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
if n==1:
    for i in range(q):
        v,w=map(int,input().split())
        print(min(v,w))
for i in range(q):
    v,w=map(int,input().split())
    while v!=w:
        if v>w:
            v=(v+n-2)//n
        else:
            w=(w+n-2)//n
    print(v)
Problem p03508 (python)

Fixed submission:
n,m=map(int,input().split())
a=[i for i in range(n+1)]
b=[0]*(n+1)
def f(x):
    if a[x]==x:
        return x
    x=a[x]
    return(f(x))
def s(x,y):
    x=f(x)
    y=f(y)
    if x!=y:
        if b[x]<b[y]:
            a[x]=y
            b[y]+=1
        else:
            a[y]=x
            b[x]+=1
for i in range(m):
    c,d=map(int,input().split())
    s(c,d)
for i in range(1,n+1):
    a[i]=f(i)
d=a.count(a[2])
s=a.count(a[1])
print(max(((n-d)*(n-d-1)//2)-m+(d*(d-1)//2),((n-s)*(n-s-1)//2)-m+(s*(s-1)//2)))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n,m=map(int,input().split())
a=[i for i in range(n+1)]
b=[0]*(n+1)
def f(x):
    if a[x]==x:
        return x
    x=a[x]
    return(f(x))
def s(x,y):
    x=f(x)
    y=f(y)
    if x!=y:
        if b[x]>b[y]:
            a[y]=x
            b[y]+=1
        else:
            a[x]=y
            b[x]+=1
for i in range(m):
    c,d=map(int,input().split())
    s(c,d)
for i in range(1,n+1):
    a[i]=f(i)
d=a.count(a[2])
print(((n-d)*(n-d-1)//2)-m+(d*(d-1)//2))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n,m=map(int,input().split())
a=[i for i in range(n+1)]
b=[0]*(n+1)
def f(x):
    if a[x]==x:
        return x
    x=a[x]
    return(f(x))
def s(x,y):
    x=f(x)
    y=f(y)
    if x!=y:
        if b[x]>b[y]:
            a[y]=x
            b[y]+=1
        else:
            a[x]=y
            b[x]+=1
for i in range(m):
    c,d=map(int,input().split())
    s(c,d)
for i in range(1,n+1):
    a[i]=f(i)
d=a.count(a[2])
print(((n-d)*(n-d-1)//2)-m+(d*(d-1)//2))
Problem p03510 (python)

Fixed submission:
from itertools import accumulate as ac
n=int(input())
a,b=[],[]
for i in range(n):
    x,s=map(int,input().split())
    a.append(x)
    b.append(s)
r=[0]+list(ac(b))
l=r[:]
for i in range(n):
    r[i]+=-a[i]
    l[i+1]+=-a[i]
q,d=r[0],0
for i in range(1,n+1):
    d=max(l[i]-q,d)
    q=min(q,r[i])
print(d)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate as ac
n=int(input())
a,b=[],[]
for i in range(n):
    x,s=map(int,input().split())
    a.append(x)
    b.append(s)
r=[0]+list(ac(b))
l=b[:]
for i in range(n):
    r[i]+=-a[i]
    l[i+1]+=-a[i]
q,d=0,0
for i in range(1,n+1):
    d=max(l[i]-q,d)
    q=min(q,r[i-1])
print(d)
Problem p03524 (python)

Fixed submission:
s=input()
a,b,c=s.count("a"),s.count("b"),s.count("c")
print("NO" if max(a,b,c)-min(a,b,c)>1 else"YES")

Buggy submission (verdict: Runtime Error):
s=input()
a,b=s.count("a"),s.count("b"),s.count("c")
print("NO" if max(a,b,c)-min(a,b,c)>1 else"YES")

Buggy submission (verdict: Runtime Error):
s=input()
a,b=s.count("a"),s.count("b"),s.count("c")
print("NO" if max(a,b,c)-min(a,b,c)>1 else"YES")
Problem p03545 (python)

Fixed submission:
s=input()
c=0
l=["+","-"]
for i in range(2):
  if c!=0:
  	break
  for j in range(2):
    if c!=0:
      	break
    for p in range(2):
      if eval(s[0]+l[i]+s[1]+l[j]+s[2]+l[p]+s[3])==7:
        print(s[0]+l[i]+s[1]+l[j]+s[2]+l[p]+s[3]+"=7")
        c=1
        break

Buggy submission (verdict: Runtime Error):
s=input()
c=0
l=["+","-"]
for i in range(2):
  if c!=0
  	break
  for j in range(2):
    	if c!=0
      		break
    for p in range(2):
      if eval(s[0]+l[i]+s[1]+l[j]+s[2]+l[p]+s[3])==7:
        print(s[0]+l[i]+s[1]+l[j]+s[2]+l[p]+s[3]+"=7")
        c=1
        break

Buggy submission (verdict: Runtime Error):
s=input()
l=["+","-"]
for i in range(1):
  for j in range(i):
    for p in range(1):
      if eval(s[0]+l[i]+s[1]+l[j]+s[2]+l[p]+s[3])==7:
        break
print(s[0]+l[i]+s[1]+l[j]+s[2]+l[p]+s[3]+"=7")
Problem p03561 (python)

Fixed submission:
a,n=map(int,input().split())
if a%2==0:
    print(*[a//2]+[a]*(n-1))
else:
    d=[(a+1)//2]*n
    for i in range(n//2):
        if d[-1]==1:
            d.pop()
        else:
            d[-1]-=1
            d.extend([a]*(n-len(d)))
    print(" ".join(str(i)for i in d))

Buggy submission (verdict: Runtime Error):
a,n=map(int,input().split())
if a%2==0:
    print(" ".join(str(a//2)+str(a)*(n-1)))
else:
    d=[(a+1)//2]*n
    r=n-1
    for i in range((n-1)//2+1):
        if d[r]==1:
            d[r]=0
            r-=1
        else:
            d=d[:r]+[d[r]-1]+[a]*(n-r-1)
            r=n-1
    while d[-1]==0:
        d.pop()
    print(" ".join(str(i)for i in d))
Problem p03563 (python)

Fixed submission:
a=int(input())
b=int(input())
print(2*b-a)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate as ac
n=int(input())+2
t=[0]+list(map(int,input().split()))+[0]
v=[0]+list(map(int,input().split()))+[0]
s=[0]+list(ac(t))
def f(i,x):
    if s[i]<=x<=s[i+1]:return v[i]
    elif x<s[i]:return v[i]+s[i]-x
    else:return v[i]+x-s[i+1]
c=float("INF")
for i in range(n):
    c=min(c,f(i,0))
e=0
for i in range(1,2*s[-1]+1):
    i=i/2
    d=float("INF")
    for j in range(n):
        d=min(d,f(j,i))
    e+=0.25*(c+d)
    c=d
print(e)