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

Fixed submission:
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a-b,a+b])
l.sort(key=lambda x: x[1])
ans=1
nl=l[0][0]
nr=l[0][1]
for i in range(1,n):
    if l[i][0]<nr:
        continue
    else:
        nr=l[i][1]
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a-b+1,i])
    l.append([a+b,i])
l.sort()
re=0
c=[0]*n
f=0
mf
di=set([])
for i in range(n*2):
    p=l[i][0]
    j=l[i][1]
    if c[j]==0:
        c[j]+=1
        f+=1
        mf=max(mf,f)
        #di.add(j)
    else:
        f-=1 
        if f==0:
            re+=mf-1
        mf=0
            
        #f=0
print(n-re)
Problem p02801 (python)

Fixed submission:
al=list('abcdefghijklmnopqrstuvwxyz')
a=input()
print(al[al.index(a)+1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
for i in range(h):
    for j in range(w):
        if l[i][j]=='.':
            s=[i,j]
v=[[0 for i in range(w)] for j in range(h)]       
v[s[0]][s[1]]=1
mc=0
ms=s
q=[[s,0]]
while q:
    p=q.pop(0)
    x=p[0][0]
    y=p[0][1]
    c=p[1]
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    for j in k:
        nx=x+j[0]
        ny=y+j[1]
        if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
            v[nx][ny]=1
            q.append([[nx,ny],c+1])
            if mc<c+1:
                mc=c+1
                ms=[nx,ny]
v=[[0 for i in range(w)] for j in range(h)]       
v[ms[0]][ms[1]]=1
ans=0
q=[[ms,0]]
while q:
    p=q.pop(0)
    x=p[0][0]
    y=p[0][1]
    c=p[1]
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    for j in k:
        nx=x+j[0]
        ny=y+j[1]
        if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
            v[nx][ny]=1
            q.append([[nx,ny],c+1])
            ans=max(ans,c+1)
                #ms=[nx,ny]
print(ans)
Problem p02806 (python)

Fixed submission:
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(str,input().split())))
x=input()
ans=0
f=0
for i in l:
    if f==1:
        ans+=int(i[1])
    if i[0]==x:
        f=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(str,input().split())))
x=input()
ans=0
f=0
for i in l:
    if f==1:
        ans+=int(l[1])
    if i[0]==x:
        f=1
print(ans)
Problem p02844 (python)

Fixed submission:
n=int(input())
t=list(str(input()))
s=[]
for i in range(n):
    s.append(int(t[i]))
g=[[0 for i in range(10)] for j in range(10)]
r=[0 for j in range(n+1)]
l=[0 for j in range(n+1)]
for i in range(n):
    if r[i]&(2**s[i])==0:
        r[i+1]=r[i]+2**s[i]
    else:
        r[i+1]=r[i]
    if l[n-i]&(2**s[n-i-1])==0:
        l[n-i-1]=l[n-i]+2**s[n-i-1]
    else:
        l[n-i-1]=l[n-i]
ans=[[[0 for i in range(10)] for j in range(10)] for k in range(10)]
for i in range(n):
    for j in range(10):
        for k in range(10):
            if r[i]&(2**j) and l[i+1]&(2**k):
                ans[j][s[i]][k]+=1
kai=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if ans[i][j][k]>0:
                kai+=1
print(kai)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(str(input()))
for i in range(n):
    s[i]=int(s[i])
g=[[0 for i in range(10)] for j in range(10)]
r=[0 for j in range(n+1)]
l=[0 for j in range(n+1)]
for i in range(n):
    if r[i]&(2**s[i])==0:
        r[i+1]=r[i]+2**s[i]
    else:
        r[i+1]=r[i]
    if l[n-i]&(2**s[n-i])==0:
        l[n-i-1]=l[n-i]+2**s[i]
    else:
        l[n-i-1]=l[n-i]
ans=[[[0 for i in range(10)] for j in range(10)] for k in range(10)]
for i in range(n):
    for j in range(10):
        for k in range(10):
            if r[i]&(2**j)==1 and l[i+1]&(2**k)==1:
                ans[j][s[i]][k]+=1
kai=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if ans[i][j][k]>0:
                kai+=1
print(kai)
Problem p02845 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
ans=1
rgb=[0]*3
for i in range(n):
    f=0
    for j in range(3):
        if l[i]==rgb[j]:
            if f==0:
                rgb[j]+=1
            f+=1
    ans*=f
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
n=int(input())
l=list(map(int,input().split()))
ans=1
rgb=[0,0,0]
for i in range(n):
    c=0
    for j in range(3):
        if l[i]==rgb[j]:
            c+=1
    p=rgb.index(l[i])
    if not 0<=p<=2:
        print(0)
        exit()
    rgb[p]+=1
    ans*=c
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
n=int(input())
l=list(map(int,input().split()))
ans=1
rgb=[0,0,0]
for i in range(n):
    c=0
    for j in range(3):
        if l[i]==rgb[j]:
            c+=1
    p=rgb.index(l[i])
    rgb[p]+=1
    ans*=c
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
n=int(input())
l=list(map(int,input().split()))
ans=1
rgb=[0,0,0]
for i in range(n):
    for j in range(3):
        c=0
        if l[i]==rgb[j]:
            c+=1
    p=rbg.index(l[i])
    rgb[p]+=1
    ans*=c
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
n=int(input())
l=list(map(int,input().split()))
ans=1
rgb=[0,0,0]
for i in range(n):
    for j in range(3):
        c=0
        if l[i]==rgb[0]:
            c+=1
    p=rbg.index(l[i])
    rgb[p]+=1
    ans*=c
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
ans=1
rgb=[0]*3
for i in range(n):
    f=0
    for i in range(3):
        if l[i]==rgb[i]:
            if f==0:
                rgb[i]+=1
            f+=1
    ans*=f
    ans%=mod
print(ans)
Problem p02852 (python)

Fixed submission:
n,m=map(int,input().split())
s=list(str(input()))
f=0
mf=0
for i in range(n+1):
    if s[i]=='1':
        f+=1
        mf=max(mf,f)
    else:
        f=0
if mf>=m:
    print(-1)
    exit()
reans=[]
s.reverse()
nk=0
while nk<n:
    for i in range(min(n-nk,m),0,-1):
        if s[nk+i]=='0':
            nk=nk+i
            reans.append(i)
            break
reans.reverse()
print(*reans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=list(str(input()))
f=0
mf=0
for i in range(n+1):
    if s[i]=='1':
        f+=1
        mf=max(mf,f)
    else:
        f=0
if mf>=m:
    print(-1)
    exit()
reans=[]
s.reverse()
nk=-1
while nk<n+1:
    for i in range(min(n+1-nk,m),0,-1):
        if s[nk+i]=='0':
            nk=nk+i
            reans.append(i)
            break
reans.reverse()
print(*reans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=list(str(input()))
f=0
mf=0
for i in range(n):
    if s[i]=='1':
        f+=1
        mf=max(mf,f)
    else:
        f=0
if mf>=m:
    print(-1)
    exit()
reans=[]
s.reverse()
nk=-1
while nk<n:
    for i in range(m,0,-1):
        if s[nk+i]=='0':
            nk=nk+i
            reans.append(i)
            break
reans.reverse()
print(*reans)
Problem p02856 (python)

Fixed submission:
m=int(input())
d=[]
c=[]
z=0
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
    z+=a*b
ans=0
print(sum(c)-1+(z-1)//9)
exit()
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        i5=0
        for i in range(len(s)):
            s[i]=int(s[i])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>=10:
                #ret+=1
                g+=2
            else:
                g+=1
        z=sum(s)
        ret+=(z-10)//10
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)[0]+len(ka)-1)

Buggy submission (verdict: Runtime Error):
m=int(input())
d=[]
c=[]
z=0
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
    z+=c*d
ans=0
print(sum(d)-1+z//9)
exit()
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        i5=0
        for i in range(len(s)):
            s[i]=int(s[i])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>=10:
                #ret+=1
                g+=2
            else:
                g+=1
        z=sum(s)
        ret+=(z-10)//10
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)[0]+len(ka)-1)

Buggy submission (verdict: Runtime Error):
m=int(input())
d=[]
c=[]
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
p=[0]*10
for i in range(m):
    p[d[i]]+=c[i]
ans=0
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        for i in range(len(s)):
            s[i]=int(s[i])
        z=sum(s)
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)+len(ka-1))
Problem p02868 (python)

Fixed submission:
import heapq
def dijkstra_heap(s,g):
    used = [True] * n #True:未確定
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,[e[0],e[1]])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        if v==g:
            return minedge[0]
        kai=minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[kai+e[0],e[1]])                   
    return -1

################################
n,m = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
l=[]
for i in range(m):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
    l.append([x-1,y-1])
zeroedge=[0]*n
l.sort()
l.append([10**10,10**10+1])
i=0
nl=l[i][0]
r=l[i][1]
while i<m+1:
    if l[i][0]>r:
        for j in range(nl,r):
            edge[j+1].append([0,j])
        nl=l[i][0]
        r=l[i][1]
        i+=1
    else:
        r=max(r,l[i][1])
        i+=1       
print(dijkstra_heap(0,n-1))

Buggy submission (verdict: Runtime Error):
#O(ElogV)
import heapq
def dijkstra_heap(s,g):
    used = [True] * n #True:未確定
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,[[0,e[0]],e[1]])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        if v==g:
            return (minedge[0][0]+1)*k
        nl = minedge[0][1]
        kai=minedge[0][0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                if e[0]==nl:
                    heapq.heappush(edgelist,[[kai,e[0]],e[1]])
                else:
                    heapq.heappush(edgelist,[[kai+1,e[0]],e[1]])
                    
    return -1

################################
n,m = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
l=[]
for i in range(m):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
    l.append([x-1,y-1])
zeroedge=[0]*n
l.sort()
l.append([10**10,10**10+1])
i=0
nl=l[i][0]
r=l[i][1]
while i<n+1:
    if l[i][0]>r:
        for j in range(nl,r):
            edge[j+1].append([0,j])
        nl=l[i][0]
        r=l[i][1]
        i+=1
    else:
        r=max(r,l[i][1])
        i+=1       
print(dijkstra_heap(0,n-1))
Problem p02883 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

a = []
f = []
n = 0

def rec(l, r, k):
    if l+1 < r:
        mid = (l + r) // 2
        s = 0
        for i in range(n):
            s += max(a[i] - mid // f[i], 0)
        if s <= k:
            return rec(l, mid, k)
        else:
            return rec(mid, r, k)
    else:
        return r

def main():
    global a, f, n
    n, k = map(int, input().strip().split())
    a = list(map(int, input().strip().split()))
    f = list(map(int, input().strip().split()))
    a = sorted(a)
    f = sorted(f, reverse=True)
    print(rec(-1, 10**12, k))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long long int n,k;
    long long int a[200010],f[200010];
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i<n; i++) cin >> f[i];
    sort(a,a+n);
    sort(f, f + n, greater<int>());
    long long int left=0;
    long long int right=1000000000000;
    while(left<=right){
    long long int m=(left+right)/2;
    long long int c=0;
    for(int i=0;i<n;i++){
        c+=a[i]-m/f[i];
    }
    if(c<=k) right=m;
      else left=m+1;
    }
    cout << right << endl;
}

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
m=0
a=np.array(a)
f=np.array(f)
for i in range(n):
    m=max(m,a[i]*f[i])
x=m//2
l=0
r=m
def check(x):
    x=np.array([x]*n)
    p=np.sum(np.max(0,a-x//f))
    if p>k:
        return False
    else:
        return True
while l<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
print(r)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
m=(r+l)//2
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
            if p>k:
                return False
    if p>k:
        return False
    else:
        return True
while l<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
print(r)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
m=0
for i in range(n):
    m=max(m,a[i]*f[i])
x=m//2
l=0
r=m
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
    if p>k:
        return False
    else:
        return True
while l<r:
    if check(x):
        l=x
        x=(r-l)//2
    else:
        r=x
        x=(r-l)//2
return(x)
Problem p02903 (python)

Fixed submission:
h,w,a,b=map(int,input().split())

for i in range(b):
    ans=''
    for j in range(a):
        ans+='0'
    for k in range(w-a):
        ans+='1'
    print(ans)
    
for i in range(h-b):
    ans=''
    for j in range(a):
        ans+='1'
    for k in range(w-a):
        ans+='0'
    print(ans)

Buggy submission (verdict: Runtime Error):
h,w,a,b=map(int,input().split())

for i in range(b):
    ans=''
    for j in range(a):
        ans+='0'
    for k in range(w-a):
        ans+='1'
    print(ans)
    
for i in range(h-b):
    ans+=''
    for j in range(a):
        ans+='1'
    for k in range(w-a):
        ans+='0'
    print(ans)
Problem p02926 (python)

Fixed submission:
import numpy as np

n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))

def naiseki(a,b):
    if (a[0]*b[0]+a[1]*b[1])>0.0:
        return True
    else:
        return False
    
ans=0

for i in range(1001):
    xl=np.cos(np.pi*2.0*i/1000.0)
    yl=np.sin(np.pi*2.0*i/1000.0)
    x=0
    y=0
    for j in range(n):
        if naiseki([xl,yl],xy[j]):
            x+=xy[j][0]
            y+=xy[j][1]
    ans=max(ans,np.sqrt(x**2+y**2))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))

def naiseki(a,b):
    if (a[0]*b[0]+a[1]*b[1])>0.0:
        return True
    else:
        return False
    
ans=0

for i in range(10001):
    xl=np.cos(np.pi*2.0*i/10000.0)
    yl=np.sin(np.pi*2.0*i/10000.0)
    x=0
    y=0
    for j in range(n):
        if naiseki([xl,yl],xy[j]):
            x+=xy[j][0]
            y+=xy[j][1]
    ans=max(ans,np.sqrt(x**2+y**2))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))

def naiseki(a,b):
    if (a[0]*b[0]+a[1]*b[1])>0.0:
        return True
    else:
        return False
    
ans=0

for i in range(10001):
    x=np.cos(np.pi*2.0*i/10000.0)
    y=np.sin(np.pi*2.0*i/10000.0)
    for j in range(n):
        if i!=j and naiseki(xy[i],xy[j]):
            x+=xy[j][0]
            y+=xy[j][0]
    ans=max(ans,np.sqrt(x**2+y**2))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))

ans=0

x=0
y=0
for i in range(n):
    if xy[0]>=0 and xy[1]>=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))

x=0
y=0
for i in range(n):
    if xy[0]>=0 and xy[1]<=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))

x=0
y=0
for i in range(n):
    if xy[0]<=0 and xy[1]>=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))

x=0
y=0
for i in range(n):
    if xy[0]<=0 and xy[1]<=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))

x=0
y=0
for i in range(n):
    if xy[0]>=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))
x=0
y=0
for i in range(n):
    if xy[0]<=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))
x=0
y=0
for i in range(n):
    if xy[1]>=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))
x=0
y=0
for i in range(n):
    if xy[1]<=0:
        x+=xy[0]
        y+=xy[1]
ans=max(ans,np.sqrt(x**2+y**2))

print(ans)
Problem p02928 (python)

Fixed submission:
n,k=map(int,input().split())

l=list(map(int,input().split()))
mod=10**9+7

ain=0
aout=0

for i in range(n):
    for j in range(n):
        if l[i]>l[j]:
            aout+=1
            if i<j:
                ain+=1
ain*=k
aout*=k*(k-1)//2

print((ain+aout)%mod)

Buggy submission (verdict: Runtime Error):
mod=1e9+7
n,k=map(int,input().split())

l=list(map(int,input().split()))
ans=0
for i in range(len(l)):
    for j in range(i):
        if l[j]>l[i]:
            ans+=1
ans*=k

l.sort()

a=0
f=0
for i in range(n-1):
    if l[i]==l[i+1]:
        a+=f
    else:
        f+=1
a+=f
print(ans+a*k(k-1)//2)
Problem p02929 (python)

Fixed submission:
n=int(input())
s=list(input())
m=2*n
mod=10**9+7

if s[0]=="W" or s[m-1]=="W":
    print(0)
    exit()

rl=["L"]
for i in range(1,m):
    if s[i-1]==s[i]:
        if rl[i-1]=="R":
            rl.append("L")
        else: 
            rl.append("R")
    else:
        if rl[i-1]=="L":
            rl.append("L")
        else: 
            rl.append("R")
if rl[m-1]=="L":
    print(0)
    exit()
nl=0
for i in range(m):
    if rl[i]=="L":
        nl+=1
if nl!=n:
    print(0)
    exit()
    
ans=1
li=0
ri=0
for i in range(m):
    if rl[i]=="L":
        li+=1
    else:
      if li-ri<0:
          ans=0
      ans*=li-ri
      ans=ans%mod
      ri+=1
    if i>=1 and i<=n:
        ans*=i
        ans=ans%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
m=2*n
mod=10**9+7

if s[0]=="W" or s[m-1]=="W":
    print(0)
    exit()

rl=[L]
for i in range(1,m):
    if s[i-1]==s[i]:
        if rl[i-1]=="L":
            rl.append("L")
        else: 
            rl.append("R")
    else:
        if rl[i-1]=="R":
            rl.append("L")
        else: 
            rl.append("R")
if rl[m-1]=="L":
    print(0)
    exit()
nl=0
for i in range(m):
    if rl[i]=="L":
        nl+=1
if nl!=n:
    print(0)
    exit()
    
ans=1
li=0
ri=0
for i in range(m):
    if rl[i]=="L":
        li+=1
    else:
      if li-ri<0:
          ans=0
      ans*=li-ri
      ans=ans%mod
      ri+=1
    if i>=1 and i<=n:
        ans*=i
        ans=ans%mod
print(ans)
Problem p02936 (python)

Fixed submission:
from collections import deque

n,q=map(int,input().split())
tr=[[] for i in range(n)]
for i in range(n-1):
    b,c=map(int,input().split())
    tr[b-1].append(c-1)
    tr[c-1].append(b-1)

a=[0]*n
for i in range(q):
    b,c=map(int,input().split())
    a[b-1]+=c
    
d=deque([0])
f=[0]*n
f[0]=1
while d:
    p=d.pop()
    f[p]=1
    for c in tr[p]:
        if f[c]==1:
            continue
        a[c]+=a[p]
        d.append(c)
print(*a)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input(),split())
tr=[]
for i in range(n-1):
    tr.append(list(map(int,input().split())))
tr.sort()
a=[0]*n
for i in range(q):
    b,c=map(int,input().split())
    a[b-1]+=c
for i in range(n-1):
    a[tr[i][1]-1]+=a[tr[i][0]-1]
print(*a)
Problem p02947 (python)

Fixed submission:
n=int(input())
li=[]
for i in range(n):
    s=list(input())
    s.sort()
    li.append(s)
li.sort()

ans=0
f=1
for i in range(n-1):
    if li[i]==li[i+1]:
        f+=1
    else:
        ans+=f*(f-1)//2
        f=1
print(ans+f*(f-1)//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
li=[]
for i in range(n):
    s=list(input())
    s.sorted()
    li.append(s)
li.sorted()

ans=0
f=1
for i in range(n-1):
    if li[i]==li[i+1]:
        f+=1
    else:
        ans+=f*(f-1)//2
        f=1
print(ans+f*(f-1)//2)
Problem p02957 (python)

Fixed submission:
a,b=map(int,input().split())
if (a+b)%2==1:
    print("IMPOSSIBLE")
else:
    print((a+b)//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(n):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    print('YES')
else:
    print('NO')
Problem p02958 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(n):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')
Problem p02960 (python)

Fixed submission:
mod=10**9+7
r=[[(j-k)*9%13 for j in range(10)] for k in range(13)]
dp=[1]+[0]*12
for c in input():
  dp = [sum(dp[j] for j in k)%mod for k in r] if c>'9' else [dp[(int(c)-k)*9%13] for k in range(13)]
print(dp[5])

Buggy submission (verdict: Runtime Error):
mod=10**9+7
r=[[(j-k)*9%13 for j in range(10)] for k in range(13)]
dp=[1]+[0]*12
for c in input():
  dp = [sum(dp[j] for j in k)%mod for k in r] if c>'9' else [dp[(int(c)-k)*9%13] for k in range(13)]
print(d[5])

Buggy submission (verdict: Runtime Error):
s=list(input())
n=len(s)
mod=10**9 + 7
dp=[[0]*(n) for i in range(13)]

if s[n-1]=='?':
    for i in range(10):
        dp[0][i]+=1
else:
    dp[0][s[n-1]]+=1

for i in range(n-1):
    if s[n-2-i]=='?':
        for j in range(13):
            if dp[i][j]>0:
                for k in range(10):
                    dp[i+1][(j+(10**i)*k)%13]+=1
                    dp[i+1][(j+(10**i)*k)%13]%=mod
    else:
        for j in range(13):
            if dp[i][j]>0:
                dp[i+1][j+(10**i)*s[n-2-i]]+=1
                dp[i+1][j+(10**i)*s[n-2-i]]%=mod
print(dp[n-1][5]%mod)