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

Fixed submission:
B,W=map(int,input().split())
mod=10**9+7
kaijo={0:1}
Xdiv={0:1}
two=pow(2,mod-2,mod)
for i in range(1,1+B+W):
    kaijo[i]=(kaijo[i-1]*i)%mod
    Xdiv[i]=(Xdiv[i-1]*two)%mod
gyaku={B+W:pow(kaijo[B+W],mod-2,mod)}
for i in range(B+W,0,-1):
    gyaku[i-1]=(gyaku[i]*i)%mod
def conb(a,b):
    if a<b:return 0
    return (kaijo[a]*gyaku[a-b]*gyaku[b])%mod
Blost,Wlost=0,0
for k in range(1,B+W):
    print(((1+Wlost-Blost)*two)%mod)
    Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
    Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
print(((1+Wlost-Blost)*two)%mod)

Buggy submission (verdict: Runtime Error):
B,W=map(int,input().split())
mod=10**9+7
kaijo=[1]
for i in range(1,1+B+W):
    kaijo.append((kaijo[-1])*i%mod)
from collections import deque
gyaku=deque()
gyaku.append(pow(kaijo[B+W],mod-2,mod))
for i in range(B+W,0,-1):
    gyaku.appendleft((gyaku[0]*i)%mod)
def conb(a,b):
    return (kaijo[a]*gyaku[a-b]*gyaku[b])%mod
Blost,Wlost=[0],[0]
Xdiv=[pow(pow(2,i,mod),mod-2,mod) for i in range(1+B+W)]
for k in range(1,B+W):
    if k<B:
        Blost.append(0)
    elif k>=B:
        Blost.append((Blost[-1]++conb(k-1,B-1)*Xdiv[k])%mod)
    if k<W:
        Wlost.append(0)
    elif k>=W:
        Wlost.append((Wlost[-1]+conb(k-1,W-1)*Xdiv[k])%mod)
Blost.append(1)
Wlost.append(1)
for k in range(1,B+W+1):
    print(((1+Wlost[k-1]-Blost[k-1])*two)%mod)
Problem p03125 (python)

Fixed submission:
a,b=map(int,input().split())
if b%a==0:print(a+b)
else:print(b-a)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
num=[0,2,5,5,4,5,6,3,7,6]
canmake=dict()
b=[]
for i in a:
    b.append(num[i])
    if num[i] not in canmake.keys():
        canmake[num[i]]=i
b.sort()
c=[]
d=[]
amari=n%b[0]
longest=n//b[0]
if amari==0:print(str(b[0])*(n//b[0]))
#何ケタ減らすと丁度になるか求める
for i in range(1,len(b)):
    count=0
    now=amari
    while True:
        count+=1
        now+=b[0]
        if count>b[i]:break
        if now%b[i]==0:
            c.append(count-now//b[i])
            d.append((count,now//b[i],b[i]))
            break
res=min(c)
ans=[]
for i in range(c.count(res)):
    an=dict()
    idx=c.index(res)
    an[b[0]]=longest-d[idx][0]
    an[d[idx][2]]=d[idx][1]
    ans.append(an)
    c[idx]=-1

result=0
for i in ans:
    x=[]
    for i in an.keys():
        x.append((canmake[i],an[i]))
    x.sort(key=lambda y:y[0])
    re=''
    for i in range(len(x)):
        y=x.pop()
        re+=str(y[0])*y[1]
    ima=int(re)
    if ima>result:result=ima
        
if amari!=0:print(result)
Problem p03128 (python)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
match=[0,2,5,5,4,5,6,3,7,6]
make=dict()
for a in A:
    make[a]=match[a]
dp=[-1]*(N+1)
dp[0]=0
for k in range(1,1+N):
    for d,m in make.items():
        if k-m<0 or dp[k-m]==-1:continue
        dp[k]=max(dp[k],dp[k-m]+1)
        
ans=''
now=N
for k in range(dp[N]):
    res=(0,0)
    for d,m in make.items():
        if now-m<0:continue
        if dp[now-m]+1==dp[now] and res[0]<d:
            res=(d,m)
    ans+=str(res[0])
    now-=res[1]
print(int(ans))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
match=[0,2,5,5,4,5,6,3,7,6]
make=dict()
for a in A:
    make[a]=match[a]
dp=[-1]*(N+1)
dp[0]=0
for k in range(1,1+N):
    for d,m in make.items():
        if k-m<0 or dp[k-m]==-1:continue
        dp[k]=max(dp[k],dp[k-m]+1)
        
ans=''
now=N
if 
for k in range(dp[N]):
    res=(0,0)
    for d,m in make.items():
        if now-m<0:continue
        if dp[now-m]+1==dp[now] and res[0]<d:
            res=(d,m)
    ans+=str(res[0])
    now-=res[1]
print(int(ans))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
match=[0,2,5,5,4,5,6,3,7,6]
make=dict()
for a in A:
    make[a]=match[a]
dp=[-1]*(N+1)
dp[0]=0
for k in range(1,1+N):
    for d,m in make.items():
        if k-m<0 or dp[k-m]==-1:continue
        dp[k]=max(dp[k],dp[k-m]+1)
        
ans=''
now=N
for k in range(dp[N]):
    res=(0,0)
    for d,m in make.items():
        if dp[now-m]+1==dp[now] and res[0]<d:
            res=(d,m)
    ans+=str(res[0])
    now-=res[1]
print(int(ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
num=[0,2,5,5,4,5,6,3,7,6]
canmake=dict()
b=[]
for i in a:
    b.append(num[i])
    if num[i] not in canmake.keys():
        canmake[num[i]]=i
b.sort()
c=[]
d=[]
amari=n%b[0]
longest=n//b[0]
if amari==0:print(str(b[0])*(n//b[0]))
#何ケタ減らすと丁度になるか求める
for i in range(1,len(b)):
    count=0
    now=amari
    while True:
        count+=1
        now+=b[0]
        if count>b[i]:break
        if now%b[i]==0:
            c.append(count-now//b[i])
            d.append((count,now//b[i],b[i]))
            break
res=min(c)
ans=[]
for i in range(c.count(res)):
    an=dict()
    idx=c.index(res)
    an[b[0]]=longest-d[idx][0]
    an[d[idx][2]]=d[idx][1]
    ans.append(an)
    c[idx]=-1

result=0
for i in ans:
    x=[]
    for i in an.keys():
        x.append((canmake[i],an[i]))
    x.sort(key=lambda y:y[0])
    re=''
    for i in range(len(x)):
        y=x.pop()
        re+=str(y[0])*y[1]
    ima=int(re)
    if ima>result:result=ima
        
if amari!=0:print(result)
Problem p03142 (python)

Fixed submission:
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
from collections import defaultdict
OUT=defaultdict(set)
IN=defaultdict(int)
for i in range(N+M-1):
    a,b=map(int,input().split())
    OUT[a-1]|={b-1}
    IN[b-1]+=1
P=[0]*N
start={i for i in range(N) if IN[i]==0}
while len(start)>0:
    now=start.pop()
    for nex in OUT[now]:
        IN[nex]-=1
        if IN[nex]==0:
            start|={nex}
            P[nex]=now+1
[print(p) for p in P]

Buggy submission (verdict: Runtime Error):
#include <math.h>
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <iostream>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;


int main()
{
    int N, M;
    cin >> N >> M;
    map<int, set<pair<int, int>>> OUT;
    map<int, set<int>> IN;
    set<int> start;
    FOR (i,0,N){
        start.insert(i);
    }
    FOR(i,0,N+M-1){
        int a, b;
        cin >> a >> b;
        start.erase(b - 1);
        OUT[a - 1].insert(make_pair(i, b - 1));
        IN[b - 1].insert(i);
    }
    vector<int> P(N, 0);
    while (start.size()>0){
        int now = *start.begin();
        start.erase(now);
        for (auto x:OUT[now]){
            int b = x.first;
            int nex = x.second;
            IN[nex].erase(b);
            if (IN[nex].size()==0){
                start.insert(nex);
                P[nex] = now + 1;
            }
        }
    }
    FOR(i,0,N){
        cout << P[i] << endl;
    }
}

Buggy submission (verdict: Runtime Error):
\import sys
input=sys.stdin.readline
N,M=map(int,input().split())
from collections import defaultdict
OUT=defaultdict(set)
IN=defaultdict(set)
start={i for i in range(N)}
for i in range(N+M-1):
    a,b=map(int,input().split())
    start-={b-1}
    OUT[a-1]|={(i,b-1)}
    IN[b-1]|={i}
P=[0]*N
while len(start)>0:
    now=start.pop()
    for b,nex in OUT[now]:
        IN[nex].remove(b)
        if not IN[nex]:
            start|={nex}
            P[nex]=now+1
for p in P:
    print(p)
Problem p03152 (python)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
import bisect
ans=1
mod=10**9+7
start=0
if len(set(A))!=len(A) or len(set(B))!=len(B):
    ans=0
if A[-1]<N*M or B[-1]<N*M:
    ans=0
for k in range(N*M,0,-1):
    if ans==0:break
    Aidx=bisect.bisect_left(A,k)
    Bidx=bisect.bisect_left(B,k)
    if A[Aidx]==k and B[Bidx]==k:
        continue
    elif A[Aidx]==k:
        ans=(ans*(M-Bidx))%mod
    elif B[Bidx]==k:
        ans=(ans*(N-Aidx))%mod
    else:
        if (N-Aidx)*(M-Bidx)-(N*M-k)<=0:
            ans=0
        ans=(ans*((N-Aidx)*(M-Bidx)-(N*M-k)))%mod
    if Aidx==0 and Bidx==0:
        start=k
        break
for i in range(start-1,0,-1):
    ans=(ans*i)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
import bisect
ans=1
mod=10**9+7
start=0
if len(set(A))!=len(A) or len(set(B))!=len(B):
    ans=0
for k in range(N*M,0,-1):
    if ans==0:break
    Aidx=bisect.bisect_left(A,k)
    Bidx=bisect.bisect_left(B,k)
    if A[Aidx]==k and B[Bidx]==k:
        continue
    elif A[Aidx]==k:
        ans=(ans*(M-Bidx))%mod
    elif B[Bidx]==k:
        ans=(ans*(N-Aidx))%mod
    else:
        if (N-Aidx)*(M-Bidx)-(N*M-k)<=0:
            ans=0
        ans=(ans*((N-Aidx)*(M-Bidx)-(N*M-k)))%mod
    if Aidx==0 and Bidx==0:
        start=k
        break
for i in range(start-1,0,-1):
    ans=(ans*i)%mod
print(ans)
Problem p03477 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
if a+b==c+d:
  print('Balanced')
elif a+b>c+d:
  print('Left')
else:
  print('Right')

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
if a+b=c+d:
  print('Balanced')
elif a+b>c+d:
  print('Left')
else:
  print('Right')
Problem p03550 (python)

Fixed submission:
N,Z,W=map(int,input().split())
A=list(map(int,input().split()))
if N>=2:
    print(max(abs(A[-1]-W),abs(A[-2]-A[-1])))
elif N==1:
    print(abs(A[-1]-W))

Buggy submission (verdict: Runtime Error):
N,Z,W=map(int,input().split())
A=list(map(int,input().split()))
print(max(abs(A[-1]-W),abs(A[-2]-A[-1]))
Problem p03565 (python)

Fixed submission:
#ABC076C
s=input()
t=input()
can=[]
for i in range(1+len(s)-len(t)):
    check=0
    for j in range(len(t)):
        if s[i+j]!=t[j] and s[i+j]!='?':
            check=1
            break
    if check==0:can.append(i)
if len(can)==0:print('UNRESTORABLE')
else:
    ans=can[-1]
    res=s[:ans]+t+s[ans+len(t):]
    print(res.replace('?','a'))

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
def check(i):
    flag=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag=False
            break
    return flag
def search(S,T):
    for i in range(len(S)-len(T),-1,-1):
        if check(i):return i
    return -1
def main(S,T):
    ans=''
    if T not in S:
        idx=search(S,T)
        if idx==-1:
            return 'UNRESTORABLE'
    S=S[:idx]+T+S[idx+len(T):]
    for s in S:
        if s=='?':ans+='a'
        else:ans+=s
    return ans
print(main(S,T))
Problem p03600 (python)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
dist=[list(map(int,input().split())) for i in range(N)]
ans=sum([sum(dist[i]) for i in range(N)])
for i in range(N):
    dist[i][i]=float('inf')
ans//=2
def main(ans):
    for i in range(N):
        for j in range(i+1,N):
            Min=min(map(sum,zip(dist[i],dist[j])))
            if Min<dist[i][j]:
                return -1
            if Min==dist[i][j]:
                ans-=dist[i][j] 
    return ans
print(main(ans))

Buggy submission (verdict: Runtime Error):
N=int(input())
dist=[list(map(int,input().split())) for i in range(N)]
ans=sum([sum(dist[i]) for i in range(N)])
ans//=2
for i in range(N):
    if ans<0:break
    for j in range(i+1,N):
        if ans<0:break
        for k in range(j+1,N):
            S=sum([dist[i][j],dist[i][k],dist[j][k]])/2
            M=max([dist[i][j],dist[i][k],dist[j][k]])
            if S==M:ans-=max(a,b,c)
            elif S<M:
                ans=-1*float('inf')
                break
if ans<0:ans=-1
print(ans)
Problem p03682 (python)

Fixed submission:
N=int(input())
city=[]
for i in range(N):
    x,y=map(int,input().split())
    city.append((i,x,y))

data=[]
city.sort(key=lambda x:x[1])
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][1]-city[i][1]))
city.sort(key=lambda y:y[2])
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][2]-city[i][2]))
data.sort(key=lambda d:d[2])

idx=[-1]*N
def find(idx,x):
    if idx[x]<0:
        return x
    elif idx[x]>=0:
        idx[x]=find(idx,idx[x])
        return idx[x]

ans=0
for q in range(len(data)):
    i,j,d=data[q]
    iidx=find(idx,i)
    jidx=find(idx,j)
    if iidx==jidx:
        continue
    elif idx[iidx]<=idx[jidx]:
        idx[iidx]+=idx[jidx]
        idx[jidx]=iidx
        ans+=d
    elif idx[iidx]>idx[jidx]:
        idx[jidx]+=idx[iidx]
        idx[iidx]=jidx
        ans+=d
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
city=[]
for i in range(N):
    x,y=map(int,input().split())
    city.append((i,x,y))
city.sort(key=lambda x:x[1])
data=[]
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][1]-city[i][1]))
city.sort(key=lambda y:y[2])
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][2]-city[i][2]))
data.sort(key=lambda d:d[2])
idx=[-1]*N
def find(idx,x):
    if idx[x]<0:
        return x
    elif idx[x]>=0:
        idx[x]=find(idx,idx[x])
        return idx[x]
ans=0
for q in range(len(data)):
    i,j,d=data[q]
    iidx=find(idx,i)
    jidx=find(idx,j)
    if iidx==jidx:
        continue
    elif idx[iidx]>=idx[jidx]:
        idx[iidx]+=idx[jidx]
        idx[jidx]=iidx
        ans+=d
    elif idx[iidx]<idx[jidx]:
        idx[jidx]+=idx[iidx]
        idx[iidx]=jidx
        ans+=d
print(ans)
Problem p03684 (python)

Fixed submission:
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]<=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]>root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)

Buggy submission (verdict: Runtime Error):
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]>=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]<root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)
Problem p03921 (python)

Fixed submission:
N,M=map(int,input().split())
from collections import defaultdict
lang=[-1]*(M+1)
data=defaultdict(int)
def search(l):
    if lang[l]>=0:
        lang[l]=search(lang[l])
    elif lang[l]<0:
        return l
    return lang[l]
def union(i,j,lang):
    iidx=search(i)
    jidx=search(j)
    if iidx==jidx:
        return lang
    elif lang[iidx]<=lang[jidx]:
        lang[iidx]+=lang[jidx]
        lang[jidx]=iidx
    else:
        lang[jidx]+=lang[iidx]
        lang[iidx]=jidx
    return lang
for i in range(N):
    line=list(map(int,input().split()))
    data[line[1]]+=1
    for k in range(1,line[0]):
        data[line[k+1]]+=1
        lang=union(line[k],line[k+1],lang)
L=set()
for k in range(1,1+M):
    if data[k]==0:continue
    L|={search(k)}
if len(L)>1:
    print('NO')
elif len(L)==1:
    print('YES')

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
from collections import defaultdict
dist=[d]*N
branch=defaultdict(set)
lang=defaultdict(set)
inp=[]
for i in range(N):
    X=list(map(int,input().split()))
    for k in range(X[0]):
        lang[X[k+1]]|={i}
    inp.append(X[1:])
for i in range(N):
    for l in inp[i]:
        branch[i]|=lang[l]
checked={0}
check={0}
while len(check)>0:
    now=check.pop()
    check|=branch[now]-checked
    checked|=branch[now]
    if len(checked)==N:
        break
if len(checked)==N:
    print('YES')
else:
    print('NO')
Problem p03994 (python)

Fixed submission:
#CODEFESTIVAL2016qualA
alpha='abcdefghijklmnopqrstuvwxyz'
S=input()
K=int(input())
ans=''
for s in S:
    idx=alpha.index(s)
    if idx==0 or 26-idx>K:
        ans+=s
        continue
    else:
        K-=26-idx
        ans+='a'
if K>0:
    tar=ans[-1]
    idx=alpha.index(tar)
    ans=ans[:-1]+alpha[(idx+K)%26]
print(ans)

Buggy submission (verdict: Runtime Error):
alpha='abcdefghijklmnopqrstuvwxyz'
S=input()
K=int(input())
ans=''
for s in S:
    idx=alpha.index(s)
    if idx==0 or 26-idx>K:
        ans+=s
        continue
    else:
        K-=26-idx
        ans+='a'
if K>0:
    tar=ans[-1]
    idx=alpha.index(tar)
    ans=ans[:-1]+alpha[idx+K]
print(ans)
Problem p04001 (python)

Fixed submission:
#2-1-1 #ARC061C
s=input()
lenth=len(s)
kugiri=set()
def roop(before,now,kugiri):
    if now==lenth:
        kugiri|={before,}
        return kugiri
    kugiri = roop(before+(0,),now+1,kugiri)
    kugiri = roop(before+(1,),now+1,kugiri)
    return kugiri


def calc(ans,kugiri,s):
    test=s
    now=test[0]
    test=test[1:]
    for i in range(len(s)-1):
        k=kugiri[i]
        if k==0:
            now+=test[0]
        elif k==1:
            ans+=int(now)
            now=test[0]
        test=test[1:]
        if i==len(s)-2:ans+=int(now)
    return ans
            
ans=0
if len(s)!=1:
    kugiri = roop((0,),2,kugiri)
    kugiri = roop((1,),2,kugiri)
    for i in kugiri:
        ans=calc(ans,i,s)
    print(ans)
elif len(s)==1:print(int(s))

Buggy submission (verdict: Runtime Error):
#2-1-1 #ABC045C
s=input()
lenth=len(s)
kugiri=set()
def roop(before,now,kugiri):
    if now==lenth:
        kugiri|={before,}
        return kugiri
    kugiri = roop(before+(0,),now+1,kugiri)
    kugiri = roop(before+(1,),now+1,kugiri)
    return kugiri
kugiri = roop((0,),2,kugiri)
kugiri = roop((1,),2,kugiri)
def calc(ans,kugiri,s):
    test=s
    now=test[0]
    test=test[1:]
    for i in range(len(s)-1):
        k=kugiri[i]
        if k==0:
            now+=test[0]
        elif k==1:
            ans+=int(now)
            now=test[0]
        test=test[1:]
        if i==len(s)-2:ans+=int(now)
    return ans
            
ans=0
for i in kugiri:
    ans=calc(ans,i,s)
print(ans)
Problem p04013 (python)

Fixed submission:
N,A=map(int,input().split())
x=input().split()

for i in range(N):
    x[i]=int(x[i])
X=max(max(x),A)
for i in range(N):
    x[i]=x[i]-A
dp=[[0 for t in range(2*N*X+1)] for j in range(N+1)]

for j in range(N+1):
    for t in range(2*N*X+1):
        if j==0 and t==N*X:dp[j][t]=1
        elif j>=1:
            if t-x[j-1]<0 or t-x[j-1]>2*N*X:
                dp[j][t]=dp[j-1][t]
            elif t-x[j-1]>=0 and t-x[j-1]<=2*N*X:
                dp[j][t]=dp[j-1][t]+dp[j-1][t-x[j-1]]
print(dp[N][N*X]-1)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf

Buggy submission (verdict: Runtime Error):
N,A=map(int,input().split())
x=input().split()
for i in range(N):
    x[i]=int(x[i])
ans=0
y=[0 for i in range(N)]
def check(ans,y):
    ave=0
    for i in range(N):
        ave+=x[i]*y[i]
    if sum(y)!=0:
        ave=ave/sum(y)
    if sum(y)==0:
        ave=0
    if ave==A:ans+=1
    return ans

def branch(ans,now,pre,y):
    if now==0 and pre==-1:
        if y[now]==0:
            y[now]=1
            now+=1
            pre=1
            ans,now,pre=branch(ans,now,pre,y)
        elif y[now]==1:
            return ans,now,pre

    elif now==N-1:
        ans,now,pre=last(ans,now,pre,y)
        ans,now,pre=branch(ans,now,pre,y)
    
    elif now!=0 and pre==-1:
        if y[now]==0:
            y[now]=1
            pre=1
            now+=1
            ans,now,pre=branch(ans,now,pre,y)
        elif y[now]==1:
            y[now]=0
            now-=1
            ans,now,pre=branch(ans,now,pre,y)
    elif pre==1 and now!=N-1:
        now+=1
        ans,now,pre=branch(ans,now,pre,y)
    return ans,now,pre

def last(ans,now,pre,y):
    y[-1]=0
    ans = check(ans,y)
    y[-1]=1
    ans = check(ans,y)
    y[-1]=0
    pre=-1
    now-=1
    return ans,now,pre
now=0
pre=1
ans,now,pre=branch(ans,now,pre,y)
print(ans)
Problem p04043 (python)

Fixed submission:
x = input().split()
five = x.count('5')
seven = x.count('7')
if five==2 and seven==1:print('YES')
else:print('NO')

Buggy submission (verdict: Runtime Error):
mondai = input(),split()
if mondai.count('5')==2 and mondai.count('7')==1:print('Yes')
else:print('No')
Problem p04046 (python)

Fixed submission:
H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
 
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
    X[i] = X[i - 1] * i % mod
 
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
    Y[i - 1] = i * Y[i] % mod
 
 
def comb(x, y):
    return X[x] * Y[y] * Y[x - y] % mod
 
 
ans = 0
for i in range(B, min(B + H - A, W)):
    ans += comb(H - A + B - 1, i) * comb(W + A - B - 1, W - i - 1)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
def kaijo(a):
    x=1
    for i in range(a):
       x=x*(i+1)
    return x
def con(a,b):
    x=kaijo(a)
    y=kaijo(b)
    z=kaijo(a-b)
    res = x/y/z
    return res

def calc(x,y):
    res = con(x+y-2,x-1)
    return res

all = calc(H,W)
for i in range(B):
    x=i+1
    k = calc(x,H-A)*calc(A,W-x)
    all=all-k
result=int(all)%(7+10**9)
print(result)

Buggy submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
def kaijo(a):
    x=1
    for i in range(a):
       x=x*(i+1)
    return x
def con(a,b):
    x=kaijo(a)
    y=kaijo(b)
    z=kaijo(a-b)
    res = x/y/z
    return res

def calc(x,y):
    res = con(x+y-2,x-1)
    return res

all = calc(H,W)
for i in range(B):
    x=i+1
    k = calc(x,H-A)*calc(A,W-x)
    all=all-k
print(int(all))
Problem p03648 (python)

Fixed submission:
def show1(n, ans):
    for i in xrange(n):
        print ans[i],
    print

def show2(n, m, l, ans):
    for i in xrange(l):
        print ans[i] + m + 1,
    for i in xrange(l, n):
        print ans[i] + m ,
    print

k = int(raw_input())
n = 50
ans = [0] * n
print n
if k <= n:
    for i in xrange(k):
        ans[i] = n - i
    show1(n, ans)
else:
    ans = range(50, 0, -1)
    m = k / 50 - 1
    l = k % 50
    show2(n, m, l, ans)

Buggy submission (verdict: Runtime Error):
def show1(n, ans):
    for i in xrange(n):
        print ans[i],
    print

def show2(n, m, l, ans):
    for i in xrange(l):
        print ans[i] * m + 1,
    for i in xrange(l, n):
        print ans[i] * m,
    print

k = int(raw_input())
n = 50
ans = [0] * n
print n
if k <= n:
    for i in xrange(k):
        ans[i] = n - i
    show(n, ans)
else:
    ans = range(50, 0, -1)
    m = k / 50
    l = k % 50
    show2(n, m, l, ans)
Problem p03658 (python)

Fixed submission:
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort(reverse = True)
ans = 0
for i in xrange(k):
    ans += a[i]
print ans

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort(reverse = True)
ans = 0:
for i in xrange(k):
    ans += a[i]
print ans