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

Fixed submission:
from heapq import heappush,heappop
n,m=map(int,input().split())
a=[[[i-1,0]]for i in range(n+1)]
a[0]=[]
for i in range(m):
    l,r,c=map(int,input().split())
    a[l].append([r,c])
q=[float("INF")]*(n+1)
q[1]=0
c=[]
heappush(c,[0,1])
while c:
    s,t=heappop(c)
    if t==n:
        print(s)
        break
    for i,j in a[t]:
        if q[i]>s+j:
            q[i]=s+j
            heappush(c,[s+j,i])
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=sorted([list(map(int,input().split()))for i in range(m)])
a=2**(n).bit_length()
b=2**31-1
s=[b]*(2*a)
def f(k,x):
    k+=a-1
    s[k]=x
    while k>=0:
        k=(k-1)//2
        s[k]=min(s[2*k+1],s[2*k+2])
def g(l,r):
    L,R=l+a,r+a
    t=b
    while L<R:
        if R&1:
            R-=1
            t=min(t,s[R-1])
        if L&1:
            t=min(t,s[L-1])
            L+=1
        L>>=1
        R>>=1
    return s
f(0,0)
for l,r,c in p:
    q=g(l-1,r-1)
    if s[r+a-2]>q+c
        f(r-1,c+q)
print(-1 if s[n+a-2]==b else s[n+a-2])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=sorted([list(map(int,input().split()))for i in range(m)])
a=2**(n-1).bit_length()
b=2**31-1
s=[b]*(2*a)
def f(k,x):
    k+=a-1
    s[k]=x
    while k>=0:
        k=(k-1)//2
        s[k]=min(s[2*k+1],s[2*k+2])
def g(l,r):
    L,R=l+a,r+a
    t=b
    while L<R:
        if R&1:
            R-=1
            t=min(t,s[R-1])
        if L&1:
            t=min(t,s[L-1])
            L+=1
        L>>=1
        R>>=1
    return s
f(0,0)
for l,r,c in p:
    q=g(l-1,r-1)
    if s[r+a-2]>q+c
        f(r-1,c+q)
print(-1 if s[n+a-2]==b else s[n+a-2])
Problem p02903 (python)

Fixed submission:
h,w,a,b=map(int,input().split())
for i in range(h):
    if i<b:
        print("0"*a+"1"*(w-a))
    else:
        print("1"*a+"0"*(w-a))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
h,w,a,b=map(int,input().split())
if a*w!=b*h:
    if h==1 and b==0:
        print("1"*a+"0"*(w-a))
    elif w==1 and a==0:
        for i in range(h):
            if i<b:
                print(1)
            else:
                print(0)
    else:
        print("No")
else:
    t=gcd(a,b)
    s="1"*(a)+"0"*(h-a)
    for i in range(w):
        print(s)
        if (i+1)%(b//t)==0:
            s=s[-(a//t):]+s[:-(a//t)]

Buggy submission (verdict: Runtime Error):
from fractions import gcd
h,w,a,b=map(int,input().split())
if a*w!=b*h:
    if h==1 and b==0:
        print("1"*a+"0"*(w-a))
    elif w==1 and a==0:
        for i in range(h):
            if i<b:
                print(1)
            else:
                print(0)
    else:
        print("No")
else:
    t=gcd(a,b)
    s="1"*(a)+"0"*(h-a)
    print(t)
    for i in range(w):
        print(s)
        if (i+1)%(b//t)==0:
            s=s[-(a//t):]+s[:-(a//t)]

Buggy submission (verdict: Runtime Error):
h,w,a,b=map(int,input().split())
if a*w!=b*h:
    if h==1 and b==0:
        print("1"*b+"0"*(w-b))
    elif w==1 and a==0:
        for i in range(h):
            if i<b:
                print(1)
            else:
                print(0)
    else:
        print("No")
else:
    s="1"*a+"0"*(h-a)
    for i in range(w):
        print(s)
        if i%b==0:
            s="0"*a+s
            s=s[:-a]
Problem p02911 (python)

Fixed submission:
n,k,q=map(int,input().split())
s=[0]*n
for i in range(q):
    s[int(input())-1]+=1
p=sum(s)
for i in range(n):
    if k>p-s[i]:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n,k,q=map(int,input().split())
s=[0]*n
for i in range(q):
    s[int(input())]+=1
p=sum(s)
for i in range(n):
    if k>p-s[i]:
        print("Yes")
    else:
        print("No")
Problem p02928 (python)

Fixed submission:
n,k=map(int,input().split())
a,b=list(map(int,input().split())),0
for i,j in enumerate(a):
    for h in a[i:]:
        if j<h:b+=k*(k-1)//2
        elif j>h:b+=k*(k+1)//2
print(b%(10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d+=e
    e+=j[1]
print(((answer*k+(d%M)*(((((k-1)*k)//2))%M))%M))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d+=e
    e+=j[1]
print(((answer*k+d*(((((k-1)*k)//2))%M))%M))

Buggy submission (verdict: Runtime Error):
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d+=e
    e+=j[1]
print(((answer*k+d*(((((k-1)*k)//2))%M))%M))

Buggy submission (verdict: Runtime Error):
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
  while x <= N:
    tree[x] += 1
    x += x&(-x)
def BIT_sum(tree,x):
  s = 0
  while x:
    s += tree[x]
    x -= x&(-x)
  return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d=(d+(((k*(k-1))//2))*e)%M
    e+=j[1]
print((answer*k+d)%M)
Problem p02957 (python)

Fixed submission:
a,b=map(int,input().split());p=abs(a-b);print(abs(max(a,b)-p//2) if p%2==0 else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
s=input()[::-1]
p=[1]+[0]*12
q=1
t=[[(i*k)%13 for i in range(10)]for k in range(13)]
for i in s:
    if i!="?":
        i=int(i)
        g=t[q][i]
        p=p[-g:]+p[:-g]
    else:
        d=[0]*13
        for j in t[q]:
            r=p[-j:]+p[:-j]
            d=[(r[i]+d[i])%(10**9+7)for i in range(13)]
        p=d
    q=(q*10)%13
print(p[5]%(10**9+7))
Problem p02963 (python)

Fixed submission:
p=int(input());s=10**9
print(0,0,1,s,0--p//s,-p%s)

Buggy submission (verdict: Runtime Error):
p=int(input()),s=10**9
print(0,0,s,1,s-p%s,p//s)
Problem p02999 (python)

Fixed submission:
x,a=map(int,input().split());print(0 if x<a else 10)

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f=[],[],[],[],[],[]
INF=10**9
for i in range(int(input())):
    s,t,u=map(str,input().split())
    if u=="R":
        a.append(int(s))
        e.append(int(t))
    elif u=="L":
        c.append(int(s))
        e.append(int(t))
    elif u=="U":
        d.append(int(t))
        b.append(int(s))
    else:
        f.append(int(t))
        b.append(int(s))
l=10**8+1
r=0
a1,a2=max(a+[-INF]),min(a+[INF])
b1,b2=max(b+[-INF]),min(b+[INF])
c1,c2=max(c+[-INF]),min(c+[INF])
d1,d2=max(d+[-INF]),min(d+[INF])
e1,e2=max(e+[-INF]),min(e+[INF])
f1,f2=max(f+[-INF]),min(f+[INF])
p,q=10,1
while l-r>10**-8:
    x2=(l*2+r)/3
    x1=(l+r*2)/3
    s1,s2=max(a1+x2,b1,c1-x2),min(a2+x2,b2,c2-x2)
    t1,t2=max(d1+x2,e1,f1-x2),min(d2+x2,e2,f2-x2)
    u1,u2=max(a1+x1,b1,c1-x1),min(a2+x1,b2,c2-x1)
    v1,v2=max(d1+x1,e1,f1-x1),min(d2+x1,e2,f2-x1)
    p,q=(s1-s2)*(t1-t2),(u1-u2)*(v1-v2)
    if (s1-s2)*(t1-t2)<=(u1-u2)*(v1-v2):
        r=x1
    else:
        l=x2
print(p)

Buggy submission (verdict: Runtime Error):
import numpy as np
a=[[[],[],[]],[[],[],[]]]
for i in range(int(input())):
    s,t,u=map(str,input().split())
    if u=="R":
        a[0][0].append(int(s))
        a[1][1].append(int(t))
    elif u=="L":
        a[0][2].append(int(s))
        a[1][1].append(int(t))
    elif u=="U":
        a[1][0].append(int(t))
        a[0][1].append(int(s))
    else:
        a[1][2].append(int(t))
        a[0][1].append(int(s))
for i in range(3):
    a[0][i]=[min(a[0][i]+[INF]),max(a[0][i]+[-INF])]
    a[1][i]=[min(a[1][i]+[INF]),max(a[1][i]+[-INF])]
l=10**8+1
r=0
while l-r>5*(10**-6:
    x2=(l*2+r)/3
    x1=(l+r*2)/3
    h=max(a[0][0][1]+x2,a[0][1]+x2,a[0][
    i=
    j=
    k=
    s=
    t=
    u=
    v=
    print(s,t,u,v)
    if (max(s)-min(s))*(max(t)-min(t))<=(max(u)-min(u))*(max(v)-min(v)):
        r=x1
    else:
        l=x2
print((max(s)-min(s))*(max(t)-min(t)))
Problem p03006 (python)

Fixed submission:
from collections import defaultdict as de
s=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))for i in range(n)])
for i in range(n):
    for j in range(i):
        s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
print(n-max(s.values(),default=0))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as de
s=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))for i in range(n)])
for i in range(n):
    for j in range(i):
        s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
print(n-max(s.values()))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as de
s=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))for i in range(n)])
for i in range(n):
    for j in range(i-1):
        s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
print(n-max(s.values()))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as de
s=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))+[0]for i in range(n)])
for i in range(n):
    for j in range(n):
        if i!=j:
            s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
print(n-max(s.values()))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as de
s=de(int)
u=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))for i in range(n)])
for i in range(n):
    u.append(a[i])
    for j in range(n):
        if i!=j:
            s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
p,q=max([(v,k) for k,v in s.items()])[1]
i=0
p=n-1
g=0
while i!=n:
    if u[a[n-1]]>0:
        u[a[n-1]]-=1
    s,t=a[n-1][0]-p,a[n-1][1]-q
    i+=1
    while u[s,t]>0:
        u[s,t]-=1
        s-=p
        t-=q
        i+=1
    else:
        g+=1
print(g)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as de
s=de(int)
n=int(input())
a=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
    for j in range(n):
        if i!=j:
            s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
p,q=max([(v,k) for k,v in s.items()])[1]
f=0
while len(a)!=0:
    b,c=a[0]
    f+=1
    g=[]
    for i in range(1,len(a)):
        d,e=a[i]
        if d-b==0:
            if q!=0:
                g.append([d,e])
        elif q==0:
            if d-b!=0:
                g.append([d,e])
        elif (e-c)/(d-b)!=q/p:
            g.append([d,e])
    else:
        a=g[:][1:]
print(f)
Problem p03007 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
s=sorted([i for i in a if i<0])
t=sorted([i for i in a if i>=0])
if len(s)==0:
    print(t[-1]-t[0]+sum(t[1:-1]))
    k=t[0]
    if n!=2:
        for i in range(1,n-1):
            print(k,t[i])
            k-=t[i]
    print(t[-1],k)
elif len(t)==0:
    d=s[-1]
    print(s[-1]-sum(s[:-1]))
    for i in range(n-1):
        print(d,s[i])
        d-=s[i]
else:
    print(t[-1]-sum(s)+sum(t[:-1]))
    p=t[-1]
    for i in range(1,len(s)):
        print(p,s[i])
        p-=s[i]
    g=s[0]
    for i in range(len(t)-1):
        print(g,t[i])
        g-=t[i]
    print(p,g)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
s=[i for i in a if i<0]
t=sorted([i for i in a if i>0])
if len(s)==0:
    print(t[-1]-t[0]+sum(t[1:-1]))
    k=t[0]
    if n!=2:
        for i in range(1,n-1):
            print(k,t[i])
            k-=t[i]
    print(t[-1],k)
elif len(t)==0:
    d=s[0]
    print(s[0]-sum(s[1:]))
    for i in range(1,n):
        print(d,s[i])
        d-=s[i]
else:
    print(t[-1]-sum(s)+sum(t[:-1]))
    p=t[-1]
    for i in range(1,len(s)):
        print(p,s[i])
        p-=s[i]
    g=s[0]
    for i in range(len(t)-1):
        print(g,t[i])
        g-=t[i]
    print(p,g)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
s=[i for i in a if i<0]
t=sorted([i for i in a if i>0])
if len(s)==0:
    print(t[-1]-t[0]+sum(t[1:-1]))
    k=t[0]
    for i in range(1,n-1):
        print(k,t[i])
        k-=t[i]
    print(t[-1],k)
elif len(t)==0:
    d=s[0]
    print(s[0]-sum(s[1:]))
    for i in range(1,n):
        print(d,s[i])
        d-=s[i]
else:
    print(t[-1]-sum(s)+sum(t[:-1]))
    p=t[-1]
    for i in range(1,len(s)):
        print(p,s[i])
        p-=s[i]
    g=s[0]
    for i in range(len(t)-1):
        print(g,t[i])
        g-=t[i]
    print(p,g)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
s=[i for i in a if i<0]
t=sorted([i for i in a if i>0])
if len(s)==0:
    print(t[-1]-t[0]+sum(t[1:-1]))
    k=t[0]
    for i in range(1,n-1):
        print(k,t[i])
        k-=t[i]
    print(t[-1],k)
elif len(t)==0:
    d=s[0]
    for i in range(1,n):
        print(d,s[i])
        d-=s[i]
else:
    print(t[-1]-sum(s)+sum(t[:-1]))
    p=t[-1]
    for i in range(1,len(s)):
        print(p,s[i])
        p-=s[i]
    g=s[0]
    for i in range(len(t)-1):
        print(g,t[i])
        g-=t[i]
    print(p,g)
Problem p03008 (python)

Fixed submission:
n=int(input())
a,b,c=map(int,input().split())
d,e,f=list(map(int,input().split()))
s=[0]*(n+1)
for i in range(a,n+1):
    s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
    s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
    s[i]=max(s[i],s[i-c]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
    s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
    s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
    s[i]=max(s[i],s[i-f]+c-f)
print(s[-1]+n)

Buggy submission (verdict: Runtime Error):
n=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())
def f(a,b,c,d,e,f,n):
    s=[[a,d-a],[b,e-b],[c,f-c]]
    s=[i for i in s if i[1]>0]
    dp=[0]*(n+1)
    if len(s)==0:
        return n
    if len(s)==1:
        return d*(n//a)+n%a
    else:
        for p,q in s:
            for j in range(a,n+1):
                dp[j]=max(dp[j],dp[j-p]+q)
        return dp[n]
print(f(gb,sb,bb,ga,sa,ba,f(ga,sa,ba,gb,sb,bb,n)))

Buggy submission (verdict: Runtime Error):
n=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())
def f(a,b,c,d,e,f,n):
    s=[[a,d-a],[b,e-b],[c,f-c]]
    s=[i for i in s if i[1]>0]
    dp=[0]*(n+1)
    if len(s)==0:
        return n
    if len(s)==1:
        return d*n//a+n%a
    else:
        for p,q in s:
            for j in range(a,n+1):
                dp[j]=max(dp[j],dp[j-p]+q)
        return dp[n]
print(f(gb,sb,bb,ga,sa,ba,f(ga,sa,ba,gb,sb,bb,n)))
Problem p03014 (python)

Fixed submission:
import numpy as np
h,w=map(int,input().split())
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(h)])
s,t,u,p=np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w))
for i in range(h):
    s[i]=(s[i-1]+1)*a[i]
    t[-i-1]=(t[-i]+1)*a[-i-1]
for i in range(w):
    u[:,i]=(u[:,i-1]+1)*a[:,i]
    p[:,-i-1]=(p[:,-i]+1)*a[:,-i-1]
print(int(np.max(s+t+u+p))-3)

Buggy submission (verdict: Runtime Error):
import numpy as np
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(h)])
s,t,u,p=np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w))
for i in range(h):
    s[i]=(s[i-1]+1)*a[i]
    t[-i-1]=(t[-i]+1)*a[-i-1]
for i in range(w):
    u[:,j]=(u[:,j-1]+1)*a[:,j]
    p[:,-j-1]=(p[:,-j]+1)*a[:,-j-1]
print(np.max(s+t+u+p)-3)
Problem p03029 (python)

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

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
g=0
for i in range(0,min(n,k)):
    for j in range(0,min(k-i,n-i)):
        s=sorted(a[:i]+a[n-j:])
        p=sum(s)
        t=i+j
        c=0
        while len(s)>=c+1 and t+1<=k:
            if s[c]<0:
                p-=s[c]
                c+=1
                t+=1
            else:
                break
        g=max(g,p)
print(g)
Problem p03046 (python)

Fixed submission:
m,k=map(int,input().split())
if 0<=k<2**m:
    if m==1:
        if k==1:print(-1)
        else:print(*[1,1,0,0])
    else:
        s=[str(i) for i in range(2**m) if i!=k]
        c=""
        for i in s:c+=i+" "
        c+=str(k)+" "
        for i in s[::-1]:c+=i+" "
        print(c+str(k))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
m,k=map(int,input().split())
if 0<=k<2**m:
    if m==1 and k==1:
        print(-1)
    else:
        s=[i for i in range(2**m) if i!=k]
        print(*s,k,*s[::-1],k)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
m,k=map(int,input().split())
if 0<=k<2**m:
    s=[i for i in range(2**m) if i!=k]
    print(*s,k,*s[::-1],k)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
m,k=map(int,input().split())
if 0<=k<2**m:
    s=[i for i in range(2**m) if i!=k]
    print(*s,k,*s[::-1],k)
else:
    print(-1)
Problem p03074 (python)

Fixed submission:
n,k=map(int,input().split())
s=input()+"d"
d=[]
r=s[0]
c=0
for i in range(n+1):
    if r==s[i]:
        c+=1
    else:
        d.append(c)
        r=s[i]
        c=1
if s[0]=="0":
        d=[0]+d
if s[-2]=="0":
    d+=[0]
if len(d)<=2*k+1:
    print(n)
else:
    l=sum(d[:2*k+1])
    p=sum(d[:2*k+1])
    for i in range((len(d)-2*k-1)//2):
        p=p-d[2*i]-d[2*i+1]+d[2*i+2*k+1]+d[2*i+2*k+2]
        l=max(l,p)
    print(l)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()+"d"
d=[]
r=s[0]
c=0
for i in range(n+1):
    if r==s[i]:
        c+=1
    else:
        d.append(c)
        r=s[i]
        c=1
if s[0]=="0":
        d=[0]+d
if s[-2]=="0":
    d+=[0]
if len(d)<=2*k+1:
    print(n)
else:
    l=sum(d[:2*k+1])
    p=sum(d[:2*k+1])
    for i in range(len(d)-2*k-3):
        p=p-d[2*i]-d[2*i+1]+d[2*i+2*k+1]+d[2*i+2*k+2]
        l=max(l,p)
    print(l)
Problem p03096 (python)

Fixed submission:
n=int(input())
s=[[]for i in range(2*10**5+1)]
d=[1]
s[int(input())].append(0)
for i in range(1,n):
    j=int(input())
    t=0
    s[j].append(i)
    if len(s[j])>1:
        if s[j][-2]!=s[j][-1]-1:
            t+=d[i-1]+d[s[j][-2]]
        else:
            t+=d[i-1]
    else: 
        t+=d[i-1]
    d.append(t)
print(d[-1]%(10**9+7))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[[]for i in range(n+1)]
d=[1]
s[int(input())].append(0)
for i in range(1,n):
    j=int(input())
    t=0
    s[j].append(i)
    if len(s[j])>1:
        if s[j][-2]!=s[j][-1]-1:
            t+=d[i-1]+d[s[j][-2]]
        else:
            t+=d[i-1]
    else: 
        t+=d[i-1]
    d.append(t)
print(d[-1]%(10**9+7))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[[]for i in range(n+1)]
d=[1]
s[int(input())].append(0)
for i in range(1,n):
    j=int(input())
    t=0
    s[j].append(i)
    if len(s[j])>1:
        if s[j][-2]!=s[j][-1]-1:
            t+=d[i-1]+d[s[j][-2]]
        else:
            t+=d[i-1]
    else: 
        t+=d[i-1]
    d.append(t)
print(d[-1]%(10**9+7))
Problem p03112 (python)

Fixed submission:
import bisect
a,b,q=map(int,input().split())
s=[int(input())for i in range(a)]
t=[int(input())for i in range(b)]
for i in range(q):
    x=int(input())
    c=bisect.bisect_left(s,x)
    d=bisect.bisect_left(t,x)
    p=[]
    if c!=a and d!=b:
        p.append(max(abs(s[c]-x),abs(t[d]-x)))
    if c!=0 and d!=0:
        p.append(max(abs(s[c-1]-x),abs(t[d-1]-x)))
    if c!=a and d!=0:
        p.append(min(abs(s[c]-x)*2+abs(t[d-1]-x),abs(s[c]-x)+2*abs(t[d-1]-x)))
    if c!=0 and d!=b:
        p.append(min(abs(s[c-1]-x)*2+abs(t[d]-x),abs(s[c-1]-x)+2*abs(t[d]-x)))
    print(min(p))

Buggy submission (verdict: Runtime Error):
import bisect
a,b,q=map(int,input().split())
s=[int(input())for i in range(a)]
t=[int(input())for i in range(b)]
for i in range(q):
    x=int(input())
    c=bisect.bisect_left(s,x)
    d=bisect.bisect_left(t,x)
    p=[]
    if c!=a and d!=b:
        p.append(min(abs(s[c]-x),abs(t[d]-x)))
    if c!=0 and d!=0:
        p.append(min(abs(s[c-1]-x),abs(t[d-1]-x)))
    if c!=a and d!=0:
        p.append(min(abs(s[c]-x)*2+abs(t[d-1]-x),abs(s[c]-x)+2*abs(t[d-1]-x)))
    if c!=0 and d!=b
        p.append(min(abs(s[c-1]-x)*2+abs(t[d]-x),abs(s[c-1]-x)+2*abs(t[d]-x)))
    print(min(p))
Problem p03128 (python)

Fixed submission:
n,m=map(int,input().split())
p=[-1]*(n+1)
a=list(map(int,input().split()))
e=[2,5,5,4,5,6,3,7,6]
p[0]=0
for i in range(n+1):
    for j in a:
        if i-e[j-1]>=0:
            p[i]=max(p[i],p[i-e[j-1]]*10+j)
print(p[-1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=[""]*(n+1)
a=sorted(list(map(int,input().split())))
e=[2,5,5,4,5,6,3,7,6]
d=[]
s=[]
for i in range(len(a)-1,-1,-1):
    if e[a[i]-1] not in s:
        s.append(e[int(a[i])-1])
        d.append(str(a[i]))
        p[e[a[i]-1]]=str(a[i])
for i in range(1,n+1):
    c=[]
    if len(p[i])!=0:
        c.append(int(p[i]))
    for j in range(len(s)):
        if i-s[j]>=0:
            if len(p[i-s[j]])!=0:
                c.append(max(int(p[i-s[j]]+d[j]),int(int(d[j]+p[i-s[j]]))))
    else:
        p[i]=("" if len(c)==0 else str(max(c)))
print(p[-1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=[""]*(n+1)
a=list(map(str,input().split()))
e=[2,5,5,4,5,6,3,7,6]
s=[]
for i in a:
    s.append(e[int(i)-1])
    p[e[int(i)-1]]=str(i)
for i in range(1,n+1):
    c=[]
    if len(p[i])!=0:
        c.append(int(p[i]))
    for j in range(m):
        if i-s[j]>=0:
            if len(p[i-s[j]])!=0:
                c.append(max(int(p[i-s[j]]+a[j]),int(int(a[j]+p[i-s[j]]))))
    else:
        p[i]=("" if len(c)==0 else str(max(c)))
print(p[-1])
Problem p03138 (python)

Fixed submission:
import numpy
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=max(a)
def p(x):
    return len(bin(x))-2
e=p(k)
f=p(d)
h=[]
if e>=f:
    for i in range(n):
        l=bin(a[i])
        h.append(list("0"*(e-len(l)+2)+l[2:]))
else:
    for i in range(n):
        l=bin(a[i])
        h.append(list("0"*(f-len(l)+2)+l[2:]))
p=numpy.array(h)
p=p.T
p=p.tolist()
c=0
if k==0:
    print(sum(a))
else:
    ans=0
    for i in range(len(p)):
        o=p[i].count("1")
        if o<n/2 and k>=2**(len(p)-i-1):
            c+=(n-o)*(2**(len(p)-i-1))
            k-=2**(len(p)-i-1)
        else:
            c+=o*(2**(len(p)-i-1))
    print(c)

Buggy submission (verdict: Runtime Error):
import numpy
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=max(a)
def p(x):
    return len(bin(x))-2
e=p(k)
f=p(d)
h=[]
if e>=f:
    for i in range(n):
        l=bin(a[i])
        h.append(list("0"*(e-len(l)+2)+l[2:]))
else:
    for i in range(n):
        l=bin(a[i])
        h.append(list("0"*(f-len(l)+2)+l[2:]))
p=numpy.array(h)
p=p.T
p=p.tolist()
c=0
if k==0:
    print(sum(a))
else:
    ans=0
    for i in range(len(p)):
        o=p[i].count("1")
        if o<n/2 and k>=2**(len(p)-i-1)
            c+=(n-o)*(2**(len(p)-i-1))
            k-=2**(len(p)-i-1)
        else:
            c+=o*(2**(len(p)-i-1))
    print(c)
Problem p03141 (python)

Fixed submission:
n=int(input())
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))

Buggy submission (verdict: Runtime Error):
input()
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))

Buggy submission (verdict: Runtime Error):
input()
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))