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

Fixed submission:
import math

n = int(input())
list = {}
flag = True
while flag:
    flag = False
    for i in range(2,int(math.sqrt(n)+2)):
        if n%i==0:
            if i in list:
                list[i] = list[i]+1
            else:
                list[i] = 1
            n /= i
            flag = True
            break
if n>1:
    if n in list:
        list[n] = list[n]+1
    else:
        list[n] = 1
ans = 0
for i in list.keys():
    m = list[i]
    for j in range(1,m+1):
        if not j>m:
            ans += 1
            m -= j
        else:
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
list = {}
while n>1:
    for i in range(math.sqrt(n)):
        if n%i==0:
            if i in list:
                list[i] = list[i]+1
            else:
                list[i] = 1
            break
if n%i==0:
    if i in list:
        list[i] = list[i]+1
    else:
        list[i] = 1
ans = 0
for i in list.keys():
    m = list[i]
    for j in range(m):
        if not j>m:
            ans += j
            m -= j
        else:
            break
print(ans)
Problem p02706 (python)

Fixed submission:
j=list(map(int,input().split())) 
n=j[0]
a=list(map(int,input().split()))
s=sum(a)
if n-s<0:
  print(-1)
else:
  print(n-s)

Buggy submission (verdict: Runtime Error):
j=list(map(int,input().split())) 
n=j[0]
m=j[1]
a=list(map(int,input().split()))
s=int(0)
for i in range[0,m]:
  s+=a[i]
if n-s<0:
  print(-1)
else:
  print(n-s)
Problem p02934 (python)

Fixed submission:
n=int(input())
a=[]
p=[int(e) for e in input().split()]
i=0
while i<n:
  a=a+[1/p[i]]
  i+=1
x=sum(a)
print(1/x)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
  p=float(input())
  p=1/p
  a=a+[p]
 
x=sum(a)
print(1/x)
Problem p02613 (python)

Fixed submission:
ac=0
wa=0
tle=0
re=0
n=int(input())
for _ in range(n):
  x=input()
  if x=='AC':
    ac+=1
  elif x=='WA':
    wa+=1
  elif x=='TLE':
    tle+=1
  elif x=='RE':
    re+=1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Buggy submission (verdict: Runtime Error):
ac=0
wa=0
tle=0
re=0
n=int(input())
for _ in range(n):
  x=input()
  if x=='AC':
    ac+=1
  elif x=='WA':
    wa+=1
  elif x=='TLE':
    tle+=1
  elif x=='RE':
    RE+=1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)
Problem p02687 (python)

Fixed submission:
s=input()
print('ARC' if s=='ABC' else 'ABC')

Buggy submission (verdict: Runtime Error):
s=input()
print('ARC' if s='ABC' else 'ABC')
Problem p02714 (python)

Fixed submission:
import bisect
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
for i in g:
  for j in b:
    i+j=a
    if a%2==0 and (a//2 in r):
      ans-=1
for i in r:
  for j in b:
    i+j=a
    if a%2==0 and (a//2 in g):
      ans-=1
for i in g:
  for j in r:
    i+j=a
    if a%2==0 and (a//2 in b):
      ans-=1
print(ans)
Problem p02727 (python)

Fixed submission:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
p.append(10**9)
q.append(10**9)
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
if i==x:
  p1=0
else:
  p1=sum(p[i:x])
if j==y:
  q1=0
else:
  q1=sum(q[j:y])
print(ans+p1+q1)

Buggy submission (verdict: Runtime Error):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
if i==x:
  p1=0
else:
  p1=sum(p[i:])
if j==y:
  q1=0
else:
  q1=sum(q[j:])
print(ans+p1+q1)

Buggy submission (verdict: Runtime Error):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))

Buggy submission (verdict: Runtime Error):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))
Problem p02741 (python)

Fixed submission:
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())-1
print(l[k])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
s=(c-a-b)*(c-a-b)-4*a*b
if s>0 and c-a-b>0:
  print('Yes')
else:
  print('No')
Problem p02756 (python)

Fixed submission:
s=input()
n=int(input())
q=[list(map(str,input().split())) for i in range(n)]
atama=0
x=0
for i in range(n):
  if q[i][0]=='2':
    x+=1

oshiri=len(s)+x-1
ans=[]
for i in range(len(s)+x):
    ans.append('x')
x=0
for i in range(n)[::-1]:
  if q[i][0]=='1':
    x+=1
  else:
    if (int(q[i][1])+x)%2==0:
      ans[oshiri]=q[i][2]
      oshiri-=1
    else:
      ans[atama]=q[i][2]
      atama+=1

if x%2==1:
  s=s[::-1]

for i in range(len(s)):
  ans[i+atama]=s[i]

answer=ans[0]
for i in range(1,len(ans)):
    answer+=ans[i]
    
print(answer)

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

oshiri=len(s)+x-1
ans=[None]*(s+x)
x=0
for i in range(n)[::-1]:
  if q[i][0]==1:
    x+=1
  else:
    if (q[i][1]+x)%2==0:
      ans[oshiri]=q[i][2]
      oshiri-=1
    else:
      ans[atama]=q[i][2]
      atama+=1

if x%2==1:
  s=s[::-1]

for i in range(len(s)):
  ans[i+atama]=s[i]

print(ans,sep='')
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
x=99999
s=[list(map(int,input().split())) for i in range(m)]
s=sorted(s)
for i in range(m):
    if s[i][0]==1 and s[i][1]==0 and n!=1:
        x=-1

for i in range(m):
    for j in range(m):
        if s[i][0]==s[j][0] and s[i][1]!=s[j][1]:
            x=-1

a=[0]*n
ans=0
for i in range(m):
    a[s[i][0]-1]=s[i][1]

if a[0]==0 and n!=1:
    a[0]=1

for i in range(n):
    ans+=a[i]*(10**(n-i-1))


print(min(x,ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=9999999999999999
s=[list(map(int,input().split())) for i in range(m)]
s=sorted(s)
for i in range(m):
  if s[i][0]==1 and s[i][1]==0:
    x=-1

for i in range(m):
  for j in range(m):
    if s[i][0]==s[j][0] and s[i][1]!=s[j][1]:
      x=-1

a=[0]*n
ans=0
for i in range(n):
  a[s[i][0]-1]=s[i][1]

if a[0]==0:
  a[0]=1

for i in range(m):
  ans+=a[i]*10**(n-i-1)


print(min(x,ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=9999999999999999
s=[list(map(int,input().split())) for i in range(m)]
s=sorted(s)
for i in range(m):
  if s[i][0]==1 and s[i][1]==0:
    x=-1

for i in range(m):
  for j in range(m):
    if s[i][0]==s[j][0] and s[i][1]!=s[j][1]:
      x=-1

a=[0]*n
ans=0
for i in range(m):
  a[s[i][0]-1]=s[i][1]

if a[0]==0:
  a[0]=1

for i in range(m):
  ans+=a[i]*10**(n-i-1)


print(min(x,ans))

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

for i in range(m):
  for j in range(m):
    if s[i][0]==s[j][0] and s[i][1]!=s[j][1]:
      x=-1

a=[0]*n
for i in range(m):
  a[s[i][0]]=s[i][1]

for i in range(m):
  ans=a[i]*10**(n-i-1)
if a[0]==0:
  ans+=100
print(x,ans)
Problem p02768 (python)

Fixed submission:
n,a,b=map(int,input().split())
m=10**9+7

#(a*x)をmで割った余りが1になるようなxを求める
#aで割ったときの余りはa^(-1)をかけた余りと同じ
#逆元a^(-1)を求める
#aとmが互いに素であることが条件

def gyakugen( a, m ):
  b = m
  x, y = 1, 0
  while b>0:
    q = a // b
    a, b = b, a-q*b
    x, y = y, x-q*y
  return x if x>0 else x+m

#nPrをmで割った余りを求める(ただしn<m、mは素数)
import sys
sys.setrecursionlimit(10**9)#再帰の回数の上限を設定

def perm_remainder(n,r,m):
    if r>=1:
        return (perm_remainder(n-1,r-1,m)*n)%m
    else:
        return 1

#nCrをmで割った余りを求める(ただしn<m,mは素数)

def comb_remainder(n,r,m):
    r=min(r,n-r)
    return (perm_remainder(n,r,m)*gyakugen(perm_remainder(r,r,m),m))%m

#(a**n)を素数mで割った余りを求める
#当然aはmで割り切れない整数

def power_remainder(a,x,m):
    a=a%m
    bi=str(format(x,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %m
        if bi[i]=="1":
            res=(res*a) %m
    return res

#2^n-nCa-nCb-1を計算
print((power_remainder(2,n,m)-1-comb_remainder(n,a,m)-comb_remainder(n,b,m))%m)

Buggy submission (verdict: Runtime Error):
import math
n,a,b=map(int,input().split())
na=1
m=7+10**9
def gyakugen(a,b):
    r=[1,0,a]
    w=[0,1,b]
    while(w[2]!=1):
        q=r[2]//w[2]
        r2=w
        w2=[r[0]-q*w[0],r[i]-q*w[i],r[2]-q*w[2]]
        r=r2
        w=w2
    return (b+w[0]%b)%b
ans=1
for i in range(n):
    ans*=2
    if ans>=m:
        ans%=m

for i in range(1,n+1):
    na=na*i%m
nb=na
for i in range(1,n-a+1):
    na=na*gyakugen(i,m)%m
for i in range(1,a+1):
    na=na*gyakugen(i,m)%m
for i in range(1,n-b+1):
    nb=nb*gyakugen(i,m)%m
for i in range(1,b+1):
    nb=nb*gyakugen(i,m)%m    
ans=ans-na-nb-1
ans%=m
print(ans)
Problem p02801 (python)

Fixed submission:
c = input()
print(chr(ord(c) + 1))

Buggy submission (verdict: Runtime Error):
print chr(ord(input()) + 1)
Problem p02848 (python)

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

ss=str()

for i in s:
    t = chr(ord(i) + n)
    
    if ord(t) > ord('Z'):
        t = chr(ord(t) - ord('Z') + ord('A')-1)
    
    ss += t

print(ss)

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

t=str()

for i in s:
    x = chr(ord(i) + n)
    
    if ord(t) > ord('Z'):
        x = chr(ord(x) - ord('Z') + ord('A')-1)
    
    ss += x

print(t)
Problem p02953 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans='Yes'
a[0]-=1
for i in range(n-1):
  if a[i]>a[i+1]:
    ans='No'
  elif a[i+1]>a[i]:
    a[i+1]-=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
ans='Yes'
a[0]-=1
for i in range(n-1):
  if a[i]>a[i+1]:
    ans='No'
  elif a[i+1]>a[i]:
    a[i+1]-=1
print(ans)
Problem p02972 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
c=[]
for m in range(n):
  i=n-m
  x=n//i
  b[i-1]=a[i-1]
  for j in range(2,x+1):
    b[i-1]+=b[j*i-1]
  b[i-1]%=2
  if b[i-1]==1:
    c.append(i-1)

print(len(c))
for i in range(len(c)):
  print(c[i]+1,end=' ')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
c=[]
for m in range(n):
  i=n-m
  x=n%i
  b[i-1]=a[i-1]
  for j in range(2,x+1):
    b[i-1]+=b[j*i-1]
  b[i-1]%=2
  if b[i-1]==1:
    c.append(i-1)

print(len(c))
for i in range(len(c)):
  print(c[i]+1,end=' ')
Problem p02988 (python)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if max(p[i-1],p[i],p[i+1])!=p[i] and min(p[i-1],p[i],p[i+1])!=p[i]:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=map(int,input().split())
ans=0
for i in range(1,n-1):
  if p[i-1]<p[i] and p[i]<p[i+1]:
    ans+=1
print(ans)
Problem p03000 (python)

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))
p=[0]*(n+1)
c=1
for i in range(n):
  p[i+1]=p[i]+l[i]
  if p[i+1]<=x:
    c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
now=0
k=0
while now<=x and k<=n:
  now+=l[k]
  k+=1
print(k)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
now=0
k=0
while now<=x:
  now+=l[k]
  k+=1
print(k)
Problem p03568 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
x=0
for i in a:
  if i%2==0:
   	x+=1
print(3**n-2**x)

Buggy submission (verdict: Runtime Error):
n=map(int,input().split())
a=list(map(int,input().split()))
x=0
for i in a:
  if i%2==0:
   	x+=1
print(3**n-2**x)
Problem p03963 (python)

Fixed submission:
n,k=map(int,input().split())
print(k*(k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().spkit())
print(k*(k-1)**(n-1))
Problem p03971 (python)

Fixed submission:
n,a,b=map(int,input().split())
s=input()
all=a+b
inter=b
for i in range(n):
  if all==0:
    print('No')
  elif s[i]=='a':
    print('Yes')
    all-=1
  elif s[i]=='b' and inter>0:
    print('Yes')
    all-=1
    inter-=1
  else:
    print('No')

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
s=input()
all=a+b
in=b
for i in range(n):
  if all==0:
    print('No')
  elif s[i]=='a':
    print('Yes')
    all-=1
  elif s[i]=='b' and in>0:
    print('Yes')
    all-=1
    in-=1
  else:
    print('No')
Problem p03993 (python)

Fixed submission:
n=int(input())
a=[0]+list(map(int,input().split()))
ans=0
for i in range(1,n+1):
  if a[a[i]]==i:
    ans+=1
print(ans//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[0]+list(map(int,input().split()))
ans=0
for i in n:
  if a[a[i]]==i:
    ans+=1
print(ans)
Problem p02608 (python)

Fixed submission:
n = int(input())
arr = [0]*10100
for i in range(1,110):
    for j in range(1,110):
        for k in range(1,110):
            s = i*i+j*j+k*k+i*j+j*k+k*i;
            if s<10100:
                arr[s]+=1
for i in range(n):
    print(arr[i+1])

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = [0]*10100
for i in range(1,110):
    for j in range(1,110):
        for k in range(1,110):
            s = i*i+j*j+k*k+i*j+j*k+k*i;
            if s<10100:
                ans[s]+=1
for i in range(n):
    print(arr[i+1])
Problem p02639 (python)

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

for i in range(len(n)):
  if n[i]==0:
    print(i+1)

Buggy submission (verdict: Runtime Error):
N=list(map(int,input().splti()))]
print(15-n[01]-n[1]-n[2]-n[3]-n[4])
Problem p02946 (python)

Fixed submission:



def fun(n,num,count):

    if count == (num*2)-1:
        return
    print(n,end=" ")
    count +=1
    fun(n+1,num,count)
xnum=list(map(int,input().split()))
x=xnum[1]
num=xnum[0]

m=x-(num-1)

fun(m,num,0)

Buggy submission (verdict: Runtime Error):



def fun(n,num,count):

    if count == (num*2)-1:
        return
    print(n,end=" ")
    count +=1
    fun(n+1,num,count)
xnum=list(map(int,input().split()))
x=xnum[0]
num=snum[1]

m=x-(num-1)

fun(m,num,0)

Buggy submission (verdict: Runtime Error):
def fun(n,num,count):

    if count == (num*2)-1:
        return
    print(n,end=" ")
    count +=1
    fun(n+1,num,count)
x=int(input())
num=int(input())
m=x-(num-1)

fun(m,num,0)
Problem p02929 (python)

Fixed submission:
N = int(input())
S = input()

mod = 10 ** 9 + 7

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

ans = 1
prev_s = S[0]
prev_t = True
t_sum = 1
f_sum = 0
for i in range(1, 2*N-1):
    if S[i] == prev_s:
        t = not prev_t
    else:
        t = prev_t

    if t:
        t_sum += 1
    else:
        ans *= (t_sum - f_sum)
        ans %= mod
        f_sum += 1
    prev_s = S[i]
    prev_t = t

if t_sum != N:
    ans = 0

for i in range(1, N+1):
    ans *= i
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
def factorial(N):
    if N == 1:
        return N
    return N * factorial(N-1)

N = int(input())
S = input()

mod = 10 ** 9 + 7

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

T = [True] * 2 * N
prev = S[0]
for i in range(1, 2*N-1):
    if S[i] == prev:
        T[i] = not T[i-1]
    else:
        T[i] = T[i-1]
    prev = S[i]
T[-1] = False

ans = 1
t_sum = 0
f_sum = 0
for t in T:
    if t:
        t_sum += 1
    else:
        ans *= (t_sum - f_sum)
        f_sum += 1

if t_sum != f_sum:
    ans = 0

ans %= mod
ans *= factorial(N)
print(ans % mod)
Problem p02937 (python)

Fixed submission:
import bisect

S = input()
T = input()

d = [[] for _ in range(27)]
alpha2num = lambda c: ord(c) - ord("a") + 1

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = -1
l = 0
ans = 0
for t in T:
    dl = d[alpha2num(t)]
    if not dl:
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        l += 1
        idx = dl[0]
    else:
        idx = dl[insert_idx]
    ans = l * len(S) + idx + 1

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

d = [[] for _ in range(26)]
alpha2num = lambda c: ord(c) - ord("a") + 1
ans = 0

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = -1
for t in T:
    dl = d[alpha2num(t)]
    if not(dl):
        ans = -1
        break
    for i in dl:
        if i > idx:
            ans += i - idx
            idx = i
            break
    else:
        ans += (len(S) - idx + dl[0])
        idx = dl[0]

print(ans)
Problem p02981 (python)

Fixed submission:
N, A, B = map(int, input().split())
print(min(A*N, B))

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
mod = 2019

l = L // mod
r = R // mod

if l != r:
    print(0)
else:
    l_ = L % mod
    r_ = R % mod
    ans = 2019
    for i in range(l_, r_):
        for j in range(i+1, r_+1):
            a = i * j % mod
            ans = min(ans, a)
            if ans == 0:
                break
        if ans == 0:
            break
    print(ans)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
mod = 2019

l = L // mod
r = R // mod

if l != r:
    print(0)
else:
   l_ = L % mod
   r_ = R % mod
   ans = 2019
   for i in range(l_, r_):
       for j in range(i+1, r_+1):
           a = i * j % mod
           ans = min(ans, a)
   print(ans)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
mod = 2019

l = L // mod
r = R // mod

if l != r:
    print(0)
else:
   l_ = L % mod
   r_ = R % mod
   ans = 2019
   for i in range(l_, r_):
       for j in range(i+1, r_+1):
           a = i * j % mod
           ans = min(ans, a)
           if ans == 1:
               break
        if ans == 1:
            break
   print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

def dfs(v):
    check[v] = True
    for u, w in T[v]:
        if check[u]:
            continue
        dist[u] = dist[v] + w
        dfs(u)

N = int(input())
T = [[] for _ in range(N+1)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    T[u].append((v, w))
    T[v].append((u, w))

dist = [0] * (N + 1)
check = [False] * (N + 1)
dfs(1)

print(*[d % 2 for d in dist[1:]], sep="\n")

Buggy submission (verdict: Runtime Error):
def dfs(d, v, p):
    if (d & 1):
        C[v] = 1
    for w, u in E[v]:
        if u == p:
            continue
        dfs(d ^ w, u, v)

N = int(input())
C = [0] * N
E = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    E[u].append((w % 2, v))
    E[v].append((w % 2, u))
dfs(0, 0, -1)
print(*C, sep='\n')

Buggy submission (verdict: Runtime Error):
def dfs(v):
    check[v] = True
    for u, w in T[v]:
        if check[u]:
            continue
        dist[u] = dist[v] + w
        dfs(u)

N = int(input())
T = [[] for _ in range(N+1)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    T[u].append((v, w))
    T[v].append((u, w))

dist = [0] * (N + 1)
check = [False] * (N + 1)
dfs(1)

print(*[d % 2 for d in dist[1:]], sep="\n")
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(i, j):
    visited[i][j] = True
    res_b = 0
    res_w = 0
    if N[i][j]:
        res_b += 1
    else:
        res_w += 1
    for di, dj in d:
        if i + di < 0 or i + di >= H or j + dj < 0 or j + dj >= W:
            continue
        if N[i][j] == N[i+di][j+dj]:
            continue
        if visited[i+di][j+dj]:
            continue
        tmp_b, tmp_w = dfs(i + di, j + dj)
        res_b += tmp_b
        res_w += tmp_w
    return res_b, res_w

H, W = map(int, input().split())
N = [[False] * W for _ in range(H)]
for i in range(H):
    s = input()
    for j in range(W):
        N[i][j] = (s[j] == "#")

d = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False] * W for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if not N[i][j]:
            continue
        if visited[i][j]:
            continue
        b, w = dfs(i, j)
        ans += (b * w)

print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(i, j):
    visited[i][j] = True
    res_b = 0
    res_w = 0
    if N[i][j]:
        res_b += 1
    else:
        res_w += 1
    for di, dj in d:
        if i + di < 0 or i + di >= H or j + dj < 0 or j + dj >= W:
            continue
        if N[i][j] == N[i+di][j+dj]:
            continue
        if visited[i+di][j+dj]:
            continue
        tmp_b, tmp_w = dfs(i + di, j + dj)
        res_b += tmp_b
        res_w += tmp_w
    return res_b, res_w

H, W = map(int, input().split())
N = [[False] * W for _ in range(H)]
for i in range(H):
    s = input()
    for j in range(W):
        N[i][j] = (s[j] == "#")

d = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False] * W for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if not N[i][j]:
            continue
        if visited[i][j]:
            continue
        b, w = dfs(i, j)
        ans += (b * w)

print(ans)
Problem p03160 (python)

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

dp = [sum(H) + 1] * N
dp[0] = 0

for i in range(1, N):
    if i - 2 >= 0:
        dp[i] = min(dp[i-2] + abs(H[i] - H[i-2]), dp[i])
    dp[i] = min(dp[i-1] + abs(H[i] - H[i-1]), dp[i])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
INF = sum(H) + 1

dp = [INF] * N

def rec(i):
    if dp[i] < sum(H) + 1:
        return dp[i]
    if i == 0:
        return 0
    res = INF
    res = min(res, rec(i-1) + abs(H[i] - H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    dp[i] = res
    return dp[i]

print(rec(N-1))

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
INF = sum(H) + 1

dp = [INF] * N

def rec(i):
    if dp[i] < sum(H) + 1:
        return dp[i]
    if i == 0:
        return 0
    res = INF
    res = min(res, rec(i-1) + abs(H[i] - H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    dp[i] = res
    return dp[i]

print(rec(N-1))