Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M=list(map(int,input().split()))

keys=[[] for _ in range(N)]
dp=[-1]*(2**N)
dp[0]=0

for _ in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    op=2**N-1

    for cc in c:
        op-=2**(cc-1)

    for cc in c:
        keys[cc-1].append((op,a))


def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        if minc==-1:
            continue
        ret=min(ret,a+minc)
    
    if ret==10**10:
        dp[current]=-1
        return -1
    
    dp[current]=ret
    return ret

print(rec(2**N-1))

Fixed submission:
N,M=list(map(int,input().split()))

keys=[[] for _ in range(N)]
dp=[-1]*(2**N)
dp[0]=0

for _ in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    op=2**N-1

    for cc in c:
        op-=2**(cc-1)

    for cc in c:
        keys[cc-1].append((op,a))


def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret

print(rec(2**N-1))
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,open(0).read().split())

if r-l>=2019:
    print(0)

m=[]
for i in range(l,r+1):
    m.append(i%2019)

n=len(m)
ans=2019

for i in range(n):
    for j in range(i+1,n):
        ans=min(ans,(m[i]*m[j])%2019)
    
print(ans)

Fixed submission:
l,r=map(int,open(0).read().split())

if r-l>=2019:
    print(0)
    exit(0)

m=[]
for i in range(l,r+1):
    m.append(i%2019)

n=len(m)
ans=2019

for i in range(n):
    for j in range(i+1,n):
        ans=min(ans,(m[i]*m[j])%2019)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=list(map(int,input().split()))

node=(N-1)*(N-2)//2

if K>node:
    print(-1)
    exit(0)

g=[[] for _ in range(N+1)]
M=0

for i in range(2,node+2):
    g[1].append(i)
    M+=1

for i in range(node-K):
    g[i+2].append(i+3)
    M+=1
print(M)
for i in range(1,N+1):
    for j in g[i]:
        print('{} {}'.format(i,j))

Fixed submission:
from itertools import combinations

N,K=list(map(int,input().split()))

node=(N-1)*(N-2)//2

if K>node:
    print(-1)
    exit(0)

g=[[] for _ in range(N+1)]
M=0

for i in range(2,N+1):
    g[1].append(i)
    M+=1

cnt=node-K

for u,v in combinations(range(2,N+1),2):
    if cnt==0:
        break
    g[u].append(v)
    
    M+=1
    cnt-=1


print(M)
for i in range(1,N+1):
    for j in g[i]:
        print('{} {}'.format(i,j))
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=list(map(int,input().split()))
s=input()

if c<d:
    for i in range(b+1,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(a+1,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    print('Yes')
else:
    for i in range(b,min(d+1,n)):
        if s[i]=='#':
            continue

        if s[i-1]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a+1,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(b+1,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')


Fixed submission:
n,a,b,c,d=list(map(int,input().split()))
s=input()

if c<d:
    for i in range(a-1,d-1):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    print('Yes')
else:
    for i in range(b-1,d):
        if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a-1,c-1):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')

Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=list(map(int,input().split()))
s=input()

if c<d:
    for i in range(b+1,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(a+1,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    print('Yes')
else:
    for i in range(b,d+1):
        if s[i]=='#':
            continue

        if s[i-1]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(b,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')


Fixed submission:
n,a,b,c,d=list(map(int,input().split()))
s=input()

if c<d:
    for i in range(a-1,d-1):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    print('Yes')
else:
    for i in range(b-1,d):
        if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a-1,c-1):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')
Buggy python submission (verdict: Runtime Error):
from collections import deque
from copy import deepcopy
import heapq

N,K=list(map(int,input().split()))
V=deque(list(map(int,input().split())))

minus=[[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

for left in range(N+1):
    for right in range(N-left+1):
        v=deepcopy(V)
        q=[]

        tleft=left
        while tleft>0:
            vi=deque.popleft(v)
            if vi<0:
                heapq.heappush(q,vi)
            tleft-=1
        
        tright=right

        while tright>0:
            vj=deque.pop(v)
            if vj<0:
                heapq.heappush(q,vj)
            tright-=1
        
        for k in range(1,N+1):
            if len(q)>0:
                minus[k][left][right]=minus[k-1][left][right]-heapq.heappop(q)
            else:
                minus[k][left][right]=minus[k-1][left][right]

leftacum=[0]*(N+1)
rightacum=[0]*(N+1)

vl=deepcopy(V)
vr=deepcopy(V)

for i in range(N):
    leftacum[i+1]=leftacum[i]+vl.popleft()
    rightacum[i+1]=rightacum[i]+vr.pop()

ans=-10**10

for left in range(N+1):
    for right in range(N-left+1):
        k=K-left-right
        if k<0:
            continue

        ans=max(ans,leftacum[left]+rightacum[right]+minus[k][left][right])

print(ans)

Fixed submission:
from collections import deque
from copy import deepcopy
import heapq

N,K=list(map(int,input().split()))
V=list(map(int,input().split()))

minus=[[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

vdeque=deque(V)

for left in range(N+1):
    for right in range(N-left+1):
        v=deepcopy(vdeque)
        q=[]

        tleft=left
        while tleft>0:
            vi=deque.popleft(v)
            if vi<0:
                heapq.heappush(q,vi)
            tleft-=1
        
        tright=right

        while tright>0:
            vj=deque.pop(v)
            if vj<0:
                heapq.heappush(q,vj)
            tright-=1
        
        for k in range(1,N+1):
            if len(q)>0:
                minus[k][left][right]=minus[k-1][left][right]-heapq.heappop(q)
            else:
                minus[k][left][right]=minus[k-1][left][right]

leftacum=[0]*(N+1)
rightacum=[0]*(N+1)

for i in range(N):
    leftacum[i+1]=leftacum[i]+V[i]
    rightacum[i+1]=rightacum[i]+V[N-i-1]

ans=-10**10

for left in range(N+1):
    for right in range(N-left+1):
        k=min(N,K-left-right)
        if k<0:
            continue

        ans=max(ans,leftacum[left]+rightacum[right]+minus[k][left][right])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M=list(map(int,input().split()))
A=list(map(int,input().split()))

heapq.heapify(A)

for _ in range(M):
    b,c=list(map(int,input().split()))

    i=0
    while i<b:
        a=heapq.heappop(A)

        if a>=c:
            heapq.heappush(A,a)
            break

        heapq.heappush(A,c)
        i+=1

print(sum(A))


Fixed submission:
N,M=list(map(int,input().split()))
A=sorted(list(map(int,input().split())))
bc=[list(map(int,input().split())) for _ in range(M)]
bc.sort(key=lambda x: x[1],reverse=True)

D=[0]*N
i=0
for b,c in bc:
    cnt=0
    while i<N and cnt<b:
        D[i]=c
        i+=1
        cnt+=1
    if i==N:
        break

E=[max(A[i],D[i]) for i in range(N)]
print(sum(E))
Buggy python submission (verdict: Runtime Error):
n=int(input())

t1=2
comb=set()
while t1*t1<=n:
    if n%t1==0:
        t2=n//t1

        m=t1-1
        if t2==n%m:
            comb.add(m)
        m=t2-1
        if t1==n%m:
            comb.add(m)
    t1+=1

m=n-1
print(sum(comb)+n-1 if n==(m+1)*(n%m) else sum(comb))

Fixed submission:
n=int(input())

t1=2
comb=set()
while t1*t1<=n:
    if n%t1==0:
        t2=n//t1

        m=t1-1
        if t2==n%m:
            comb.add(m)
        m=t2-1
        if t1==n%m:
            comb.add(m)
    t1+=1

if n>2:
    print(sum(comb)+n-1)
else:
    print(sum(comb))
Buggy python submission (verdict: Runtime Error):
A,B=list(map(int,input().split()))
A=A-1
B=[int(c) for c in format(B,'b')]
A=[int(c) for c in format(A,'b')]

n=len(B)
dp=[[0,0] for _ in range(n+1)]
dp[0][0]=1

cnt=[0]*(n+1)

s=''

for i in range(1,n+1):
    dp=[[0,0] for _ in range(n+1)]
    dp[0][0]=1
    for j in range(n):
        for k in range(2):
            if i==j+1:
                dp[j+1][k]=0 if B[j]==0 and k==0 else dp[j][k]
            else:
                for l in range(0,2 if k==1 else B[j]+1):
                    dp[j+1][k or l<B[j]]+=dp[j][k]
    
    cnt[i]=dp[n][0]+dp[n][1]

if sum(A)>=0:
    n=len(A)
    for i in range(1,n+1):
        dp=[[0,0] for _ in range(n+1)]
        dp[0][0]=1
        for j in range(n):
            for k in range(2):
                if i==j+1:
                    dp[j+1][k]=0 if A[j]==0 and k==0 else dp[j][k]
                else:
                    for l in range(0,2 if k==1 else A[j]+1):
                        dp[j+1][k or l<A[j]]+=dp[j][k]
        
        cnt[i+len(B)-n]-=dp[n][0]+dp[n][1]

for i in range(1,len(B)+1):
    if cnt[i]%2==0:
        s+='0'
    else:
        s+='1'

print(int(s,2))


Fixed submission:
A,B=list(map(int,input().split()))

B=[int(c) for c in format(B,'b')]

n=len(B)
dp=[[0,0] for _ in range(n+1)]
dp[0][0]=1

cnt=[0]*(n+1)

s=''

for i in range(1,n+1):
    dp=[[0,0] for _ in range(n+1)]
    dp[0][0]=1
    for j in range(n):
        for k in range(2):
            if i==j+1:
                dp[j+1][k]=0 if B[j]==0 and k==0 else dp[j][k]
            else:
                for l in range(0,2 if k==1 else B[j]+1):
                    dp[j+1][k or l<B[j]]+=dp[j][k]
    
    cnt[i]=dp[n][0]+dp[n][1]

if A>1:
    A-=1
    A=[int(c) for c in format(A,'b')]
    n=len(A)
    
    for i in range(1,n+1):
        dp=[[0,0] for _ in range(n+1)]
        dp[0][0]=1
        for j in range(n):
            for k in range(2):
                if i==j+1:
                    dp[j+1][k]=0 if A[j]==0 and k==0 else dp[j][k]
                else:
                    for l in range(0,2 if k==1 else A[j]+1):
                        dp[j+1][k or l<A[j]]+=dp[j][k]
        
        cnt[i+len(B)-n]-=dp[n][0]+dp[n][1]

for i in range(1,len(B)+1):
    if cnt[i]%2==0:
        s+='0'
    else:
        s+='1'

print(int(s,2))
Buggy python submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
edge=[list(map(int,input().split())) for _ in range(M)]

current=N*(N-1)//2
ret=[0]*M

par=list(range(N+1))
cnt=[1]*(N+1)

def find(x):
    if x==par[x]:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def same(x,y):
    return find(x)==find(y)

def size(x):
    return cnt[find(x)]

def unite(x,y):
    x=find(x)
    y=find(y)

    if x==y:
        return
    
    cnt[x]+=size(y)
    par[y]=x


for i in range(M-1,-1,-1):
    ret[i]=current

    a,b=edge[i]

    if not same(a,b):
        current-=size(a)*size(b)
        unite(a,b)

for r in ret:
    print(r)

Fixed submission:
N,M=list(map(int,input().split()))
edge=[list(map(int,input().split())) for _ in range(M)]

current=N*(N-1)//2
ret=[0]*M

par=list(range(N+1))
cnt=[1]*(N+1)
rank=[0]*(N+1)

def find(x):
    if x==par[x]:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def same(x,y):
    return find(x)==find(y)

def size(x):
    return cnt[find(x)]

def unite(x,y):
    x=find(x)
    y=find(y)

    if x==y:
        return 0
    
    if rank[x]<rank[y]:
        cnt[y]+=size(x)
        par[x]=y
    else:
        cnt[x]+=size(y)
        par[y]=x
        if rank[x]==rank[y]:rank[x]+=1


for i in range(M-1,-1,-1):
    ret[i]=current

    a,b=edge[i]

    if not same(a,b):
        current-=size(a)*size(b)
        unite(a,b)

for r in ret:
    print(r)
Buggy python submission (verdict: Runtime Error):
import math

n,_,*a=map(int,open(0).read().split())
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a=sorted(a)

num=[0]*8

for d in a:
    num[match[d]]=d

dig=set(num)
dig.remove(0)
dig=sorted(list(dig),reverse=True)

dp=[-10**10]*(n+1)
dp[0]=0

for i in range(n+1):
    for d in dig:
        if i-match[d]<0:
            continue

        dp[i]=max(dp[i],dp[i-match[d]]+1)

ans=''

i=n
while i>0:
    for d in dig:
        if dp[i]==dp[i-match[d]]+1:
            ans=ans+str(d)
            break
    
    i-=match[d]

print(ans)

Fixed submission:
import math

n,_,*a=map(int,open(0).read().split())
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a=sorted(a)

num=[0]*8

for d in a:
    num[match[d]]=d

dig=set(num)
dig.remove(0)
dig=sorted(list(dig),reverse=True)

dp=[-10**10]*(n+1)
dp[0]=0

for i in range(n+1):
    for d in dig:
        if i-match[d]<0:
            continue

        dp[i]=max(dp[i],dp[i-match[d]]+1)

ans=''

i=n
while i>0:
    for d in dig:
        if i-match[d]<0:
            continue
        if dp[i]==dp[i-match[d]]+1:
            ans=ans+str(d)
            break
    
    i-=match[d]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
kind={}

for i in range(1,10):
    for aa in a:
        if i==aa:
            kind[match[i]]=i
m=len(kind)

inf=10**10

dp=[[-inf]*(n+1) for _ in range(m+1)]
cnt=[[0]*(n+1) for _ in range(m+1)]

dp[0][0]=0

a=sorted(list(kind.values()),reverse=True)
cost=[match[aa] for aa in a]
for i in range(m):
    cm=cost[i]

    for j in range(n+1):
        dp[i+1][j]=dp[i][j]

        if j>=cm and dp[i+1][j]<dp[i+1][j-cm]+1:
            dp[i+1][j]=dp[i+1][j-cm]+1

maxlen=dp[m][n]

def rec(x,i,s):
    if x==0 and len(s)==maxlen:
        print(s)
        exit(0)
    if i==m:
        return

    j=x//cost[i]
    while j>=0:
        rec(x-j*cost[i],i+1,s+''.join([str(a[i]) for _ in range(j)]))
        j-=1
    
rec(n,0,'')

Fixed submission:
import math

n,_,*a=map(int,open(0).read().split())
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a=sorted(a)

num=[0]*8

for d in a:
    num[match[d]]=d

dig=set(num)
dig.remove(0)
dig=sorted(list(dig),reverse=True)

dp=[-10**10]*(n+1)
dp[0]=0

for i in range(n+1):
    for d in dig:
        if i-match[d]<0:
            continue

        dp[i]=max(dp[i],dp[i-match[d]]+1)

ans=''

i=n
while i>0:
    for d in dig:
        if i-match[d]<0:
            continue
        if dp[i]==dp[i-match[d]]+1:
            ans=ans+str(d)
            break
    
    i-=match[d]

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
p=[]
dp=[[0]*100 for _ in range(100)]
dp[0][1]=1

for i in range(2,N+1):
    ti=i
    for j in range(2,i+1):
        while ti%j==0:
            p.append(j)
            ti//=j

cnt=Counter(p)

for i,v in enumerate(cnt.values()):
    for j in range(100):
        for k in range(1,v+2):
            dp[i+1][min(76,j*k)]+=dp[i][j]
    ans=dp[i+1][75]

print(ans)

Fixed submission:
from collections import Counter
N=int(input())
p=[]
dp=[[0]*100 for _ in range(100)]
dp[0][1]=1

for i in range(2,N+1):
    ti=i
    for j in range(2,i+1):
        while ti%j==0:
            p.append(j)
            ti//=j

cnt=Counter(p)
ans=0
for i,v in enumerate(cnt.values()):
    for j in range(100):
        for k in range(1,v+2):
            dp[i+1][min(76,j*k)]+=dp[i][j]
    ans=dp[i+1][75]

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(n+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

print('Yes')
print(m)
for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))

Fixed submission:
n=int(input())

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(m+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

print('Yes')
print(m)
for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))

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

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(n+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))

Fixed submission:
n=int(input())

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(m+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

print('Yes')
print(m)
for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))
Buggy python submission (verdict: Runtime Error):
s=input()
k=input()

if s[0]=='1':
    print(s[1])
else:
    print(s[0])

Fixed submission:
s=input()
k=int(input())

cntone=0
while len(s)>cntone and s[cntone]=='1':
    cntone+=1

if k>cntone:
    print(s[cntone])
else:
    print(s[0])
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left,bisect_right

N,M,Q=list(map(int,input().split()))
t=[list(map(int,input().split())) for _ in range(M)]
query=[list(map(int,input().split())) for _ in range(Q)]

train=[[0]*(N+1) for _ in range(N+1)]
c=[[0]*(N+1) for _ in range(N+1)]

for l,r in t:
    train[l][r]+=1

for l in range(1,N+1):
    for r in range(1,N+1):
        c[l][r]=c[l][r-1]+train[l][r]

for p,q in query:
    tmp=0
    for l in range(p,q+1):
        tmp+=c[l][q]-c[l][p-1]
    
    print(tmp)

Fixed submission:
N,M,Q=list(map(int,input().split()))
t=[list(map(int,input().split())) for _ in range(M)]
query=[list(map(int,input().split())) for _ in range(Q)]

train=[[0]*(N+1) for _ in range(N+1)]
c=[[0]*(N+1) for _ in range(N+1)]

for l,r in t:
    train[l][r]+=1

for l in range(1,N+1):
    for r in range(1,N+1):
        c[l][r]=c[l][r-1]+train[l][r]

for p,q in query:
    tmp=0
    for l in range(p,q+1):
        tmp+=c[l][q]-c[l][p-1]
    
    print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
d,g=[int(c) for c in input().split(" ")]

p=[0]*d
c=[0]*d

for i in range(d):
    pp,cc=[int(c) for c in input().split(" ")]
    p[i]=pp
    c[i]=cc

ans=1001

def calc(g,n):
    if g<=0:
        return 0
    elif n==d:
        return 100001
    cnt=100001
    for i in range(p[n]):
        cnt=min(cnt,i+calc(g-100*i*(n+1),n+1))
    cnt=min(cnt,p[n]+calc(g-p[n]*(n+1)*100-c[n],n+1))

    return cnt

print(calc(g,0))


Fixed submission:
import numpy as np

d,g=[int(c) for c in input().split(" ")]

p=[0]*(d+1)
c=[0]*(d+1)

for i in range(1,d+1):
    pp,cc=[int(c) for c in input().split(" ")]
    p[i]=pp
    c[i]=cc

def rec(i,g,flag):
    if i==d+1:
        cnt=0
        if g<=0:
            return 0

        for j in range(d,0,-1):
            bit=flag%2
            flag//=2

            if bit==0:
                ptsperprob=j*100
                psolved=min(p[j]-1,int(np.ceil(g/ptsperprob)))

                g-=psolved*ptsperprob
                cnt+=psolved

                if g<=0:
                    return cnt
        
        return 10000

    return min(p[i]+rec(i+1,g-c[i]-p[i]*100*i,2*flag+1),rec(i+1,g,2*flag))

print(rec(1,g,0))
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
q=s.count('?')

mod=10**9+7

target='ABC'
ans=0
for i in range(2**3):
    bdp=[1]*(n+1)
    cnt=0
    for j in range(2,-1,-1):
        if (i>>j)&1==1:
            c='?'
            cnt+=1
        else:
            c=target[j]
        
        cdp=[0]*(n+1)
        for k in range(n):
            if s[k]==c:
                cdp[k]=bdp[k+1]
        
        for k in range(n,0,-1):
            cdp[k-1]+=cdp[k]
            cdp[k-1]%=mod
        
        bdp=cdp
    
    ans+=bdp[0]*pow(3,q-cnt,mod)
    ans%=mod

print(ans)

Fixed submission:
s=input()
n=len(s)
q=s.count('?')

mod=10**9+7

target='ABC'
ans=0
for i in range(2**3):
    bdp=[1]*(n+1)
    cnt=0
    for j in range(2,-1,-1):
        if (i>>j)&1==1:
            c='?'
            cnt+=1
        else:
            c=target[j]
        
        cdp=[0]*(n+1)
        for k in range(n):
            if s[k]==c:
                cdp[k]=bdp[k+1]
        
        for k in range(n,0,-1):
            cdp[k-1]+=cdp[k]
            cdp[k-1]%=mod
        
        bdp=cdp
    
    if q>=cnt:
        ans+=bdp[0]*pow(3,q-cnt,mod)
        ans%=mod

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
s=np.array([[x for x in input()] for i in range(h)])
d=[[0]*w for i in range(h)]

q=deque([[1,0,0]])

while True:
    cnt,hh,ww=deque.popleft(q)

    if hh==h-1 and ww==w-1:
        nblack=np.sum(s=="#",dtype=np.int)
        print(h*w-nblack-cnt)
        exit(0)
    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        if 0>nh or nh>=h or 0>nw or nw>=w or d[nh][nw]==1 or s[nh][nw]=='#':
            continue
        d[nh][nw]=1
        deque.append(q,[cnt+1,nh,nw])

Fixed submission:
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
s=np.array([[x for x in input()] for i in range(h)])
d=[[0]*w for i in range(h)]

q=deque([[1,0,0]])

while len(q)>0:
    cnt,hh,ww=deque.popleft(q)

    if hh==h-1 and ww==w-1:
        nblack=np.sum(s=="#",dtype=np.int)
        print(h*w-nblack-cnt)
        exit(0)
    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        if 0>nh or nh>=h or 0>nw or nw>=w or d[nh][nw]==1 or s[nh][nw]=='#':
            continue
        d[nh][nw]=1
        deque.append(q,[cnt+1,nh,nw])

print(-1)