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

Fixed submission:
class BinaryIndexedTree():
  def __init__(self,n):self.bit=[0]*n
  def add(self,i,x):
    i+=1
    while i<=len(self.bit):
      self.bit[i-1]+=x
      i+=i&-i
  def sum_1(self,i):
    a=0
    i+=1
    while i:
      a+=self.bit[i-1]
      i-=i&-i
    return a
  def sum(self,i,j):
    a=self.sum_1(j-1)
    if i!=0:a-=self.sum_1(i-1)
    return a
def tentousu(a):
  bit=BinaryIndexedTree(n)
  b=[0]*n
  for i in range(n):
    b[a[i]]=i
  ans=0
  for i in range(n):
    j=b[i]+bit.sum(b[i]+1,n)
    ans+=j-i
    bit.add(b[i],1)
  return ans
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(1,n,2):a[i],b[i]=b[i],a[i]
ans=inf=float('inf')
for i in range(2**n):
  s=bin(i)[2:].zfill(n)
  if s.count("0")!=n//2:continue
  ac=[]
  bc=[]
  for j in range(n):
    if s[j]=="1":ac.append((a[j],j))
    else:bc.append((b[j],j))
  ac.sort()
  bc.sort()
  x=[]
  for j in range(n):
    if j%2:x.append(bc[j//2])
    else:x.append(ac[j//2])
  f=False
  for j in range(1,n):
    if x[j-1][0]>x[j][0]:f=True
  if f:continue
  m=[]
  for j in range(n):m.append(x[j][1])
  ans=min(ans,tentousu(m))
if ans==inf:ans=-1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
class BinaryIndexedTree():
  def __init__(self,n):self.bit=[0]*n
  def add(self,i,x):
    i+=1
    while i<=len(self.bit):
      self.bit[i-1]+=x
      i+=i&-i
  def sum_1(self,i):
    a=0
    i+=1
    while i:
      a+=self.bit[i-1]
      i-=i&-i
    return a
  def sum(self,i,j):
    a=self.sum_1(j-1)
    if i!=0:a-=self.sum_1(i-1)
    return a
def tentousu(a):
  bit=BinaryIndexedTree(n)
  b=[0]*n
  for i in range(n):
    b[a[i]]=i
  ans=0
  for i in range(n):
    j=b[i]+bit.sum(b[i]+1,n)
    ans+=j-i
    bit.add(b[i],1)
  return ans
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
import itertools
xx=[i for i in range(n)]
for i in range(1,n,2):a[i],b[i]=b[i],a[i]
ans=inf=float('inf')
for i in itertools.combinations(xx,(n+1)//2):
  s=set(i)
  ac=[]
  bc=[]
  for j in range(n):
    if j in s:ac.append((a[j],j))
    else:bc.append((b[j],j))
  ac.sort()
  bc.sort()
  x=[]
  m=[]
  for j in range(n):
    if j%2:
      x.append(bc[j//2][0])
      m.append(bc[j//2][1])
    else:
      x.append(ac[j//2][0])
      m.append(ac[j//2][1])
  f=False
  for j in range(1,n):
    if x[j-1][0]>x[j][0]:f=True
  if f:continue
  ans=min(ans,tentousu(m))
if ans==inf:ans=-1
print(ans)
Problem p02830 (python)

Fixed submission:
n=int(input())
s,t=input().split()
a=""
for i,j in zip(s,t):a+=i+j
print(a)

Buggy submission (verdict: Runtime Error):
ans=""
n=input()
s=input()
t=input()
for i in range(len(s)):
  ans+=s[i]+t[i]
print(ans)
Problem p02846 (python)

Fixed submission:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
x=(a1-b1)*t1
y=(a2-b2)*t2
if x>0:
  x*=-1
  y*=-1
if x+y<0:print(0)
elif x+y==0:print("infinity")
else:
  ans=(-x)//(x+y)
  if (-x)%(x+y):print(ans*2+1)
  else:print(ans*2)

Buggy submission (verdict: Runtime Error):
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
a=t1*(a1-b1)
b=t2*(a2-b2)
if a+b==0:print("infinity");exit()
if a*b>=0:print(0);exit()
x,y=abs(a-b),abs(a+b)
print(x,y)
print(int(0--(x)//y)-0.5)-1)
Problem p02848 (python)

Fixed submission:
n=int(input())
s=input()
t=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2)
a=""
for i in s:a+=t[t.index(i)+n]
print(a)

Buggy submission (verdict: Runtime Error):
t="ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2
n=int(input())
print(t[t.index(input())+n])
Problem p02852 (python)

Fixed submission:
n,m=map(int,input().split())
s=input()
x=n
a=[]
while x!=0:
  for i in range(min(m,x),0,-1):
    if s[x-i]=="0":
      x-=i
      a.append(i)
      break
    if i==1:print(-1);exit()
print(*a[::-1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
x=n
a=0
while x!=0:
  for i in range(m,0,-1):
    if s[x-i]=="0":
      x-=i
      a=a*10+i
      break
    if i==1:print(-1);exit()
print(*list(str(a))[::-1])
Problem p02853 (python)

Fixed submission:
x,y=map(int,input().split())
a=0
x=min(x,4)
y=min(y,4)
if x==y==1:a=400000
a+=100000*((4-x)+(4-y))
print(a)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
a=0
if x==y==1:a=40000
a+=10000*((4-x)+(4-y))x,y=map(int,input().split())
a=0
x=min(x,4)
y=min(y,4)
if x==y==1:a=400000
a+=100000*((4-x)+(4-y))
print(a)
Problem p02855 (python)

Fixed submission:
h,w,k=map(int,input().split())
s=[list(input())for _ in range(h)]
b=[w*[0]for _ in range(h)]
c=[]
d=-1
bb=[]
for i in range(h):
  if "#" not in s[i]:
    c.append(0)
    if d>-1:
      b[i]=b[d]
    else:bb.append(i)
  else:
    c.append(1)
    d=i
    if len(bb)>0:
      for j in bb:b[j]=b[d]
      bb=[]
a=1
for i in range(h):
  f=False
  if c[i]==0:continue
  for j in range(w):
    if s[i][j]=="#":
      if f:a+=1
      f=True
    b[i][j]=a
  if f:
    a+=1
    m=i
for i in b:print(*i)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
b=[input()for _ in range(h)]
ans=[w*[0]for _ in range(h)]
f=[1]*h
j=-1
bb=[]
for i in range(h):
  if "#"in b[i]:
    f[i]=0
    j=i
    if len(bb)==0:continue
    for k in bb:b[k]=b[j]
    bb=[]
  else:
    if j<0:s.append(i)
    else:b[i]=b[j]
a=1
for i in range(h):
  if f[i]:continue
  fl=False
  for j in range(w):
    if b[i][j]=="#":
      a+=1
      fl=True
    ans[i][j]=a
  if f:a+=1
for i in ans:print(*i)
Problem p02909 (python)

Fixed submission:
L=lambda:list(map(int,input().split()))
I=lambda:input()
s=I()
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])

Buggy submission (verdict: Runtime Error):
L()=lambda:list(map(int,input().split()))
I()=lambda:input()
s=I()
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])

Buggy submission (verdict: Runtime Error):
L()=lambda:list(map(int,input().split()))
I()=lambda:input()
s=int(I())
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])
Problem p02924 (python)

Fixed submission:
n=int(input());print(n*(n-1)//2)

Buggy submission (verdict: Runtime Error):
n=int(input())print(n*(n-1)//2)
Problem p02927 (python)

Fixed submission:
I=lambda:input()
L=lambda:list(map(int,I().split()))
m,d=L()
a=0
for i in range(1,m+1):
  for j in range(10,d+1):
    if i==(j//10)*(j%10)and j//10>1 and j%10>1:a+=1
print(a)

Buggy submission (verdict: Runtime Error):
m=int(input())
d=int(input())
ans=0
for i in range(1,m+1):
  for j in range(10,d+1):
    if i==(j//10)*(j%10) and j//10>1 and j%10>1:ans+=1
print(ans)
Problem p02934 (python)

Fixed submission:
L=lambda:list(map(int,input().split()))
n=int(input())
a=L()
b=0
for i in a:b+=1/i
print(1/b)

Buggy submission (verdict: Runtime Error):
L=lambda:list(map(int,input().split()))
n=int(input())
a=L()
b=0
for i in a:b+=1/a
print(1/b)
Problem p02961 (python)

Fixed submission:
k=int(input())
x,y=map(int,input().split())
if x<0:fx=-1
else:fx=1
if y<0:fy=-1
else:fy=1
ax,ay=abs(x),abs(y)
if ax<ay:
  x,y=y,x
  ax,ay=ay,ax
  fx,fy=fy,fx
  flag=1
else:flag=0
r=ax+ay
if k%2==0 and r%2==1:print(-1);exit()
if r==k:
  print(1)
  if flag:x,y=y,x
  print(x,y)
  exit()
if r%2==1 and r<k:
  print(3)
  anss=[]
  anss.append(((ax+(k-ay))//2,(k-(ax+(k-ay))//2)))
  anss.append((ax+(k-ay),0))
  anss.append((ax,ay))
  for i,j in anss:
    ii,jj=i*fx,j*fy
    if flag:ii,jj=jj,ii
    print(ii,jj)
  exit()
if r%2==0 and r<k:
  rm=(2*k-ax-ay)//2
else:
  rn=(k-(r%k))%k
  if rn%2==1:rn+=k
  rm=rn//2
ans=(r+rm*2)//k
anss=[]*ans
print(ans)
first=[0,-rm]
second=[ax,-rm]
third=[ax,ay]
xx=yy=0
while yy>first[1]:
  if yy-k<=first[1]:
    xx+=k-(yy-first[1])
    yy=first[1]
  else:
    yy-=k
  anss.append((xx*fx,yy*fy))
while xx<second[0]:
  if xx+k>=second[0]:
    yy+=k-(second[0]-xx)
    xx=second[0]
  else:
    xx+=k
  anss.append((xx*fx,yy*fy))
while yy!=third[1]:
  yy+=k
  anss.append((xx*fx,yy*fy))
for i,j in anss:
  ii,jj=i,j
  if flag:ii,jj=jj,ii
  print(ii,jj)

Buggy submission (verdict: Runtime Error):
LI=lambda:list(map(int,input().split()))
MI=lambda:map(int,input().split())
I=lambda:input()
k=int(I())
x,y=MI()
if abs(x+y)%2==1 and k%2==0:print(-1);exit()
ans=[]
xx=yy=0
if x<0:vx=-1
elif x>0:vx=1
if y<0:vy=-1
elif y>0:vy=1

while (abs(xx-x)+abs(yy-y))>k*3:
  if abs(xx-x)>=k:xx+=k*vx;ans.append([xx,yy])
  elif abs(yy-y)>=k:yy+=k*vy;ans.append([xx,yy])
  else:break
c=abs(xx-x)+abs(yy-y)
d=k*(0--c//k)
e=d-c
xx=x+e
yy=y+(k-e)*vy
ans.append([xx,yy])
while abs(yy-y)>=k:yy+=k*vy;ans.append([xx,yy])
print(len(ans)+1)
for i in ans:print(*i)
print(x,y)

Buggy submission (verdict: Runtime Error):
LI=lambda:list(map(int,input().split()))
MI=lambda:map(int,input().split())
I=lambda:input()
k=int(I())
x,y=MI()
if abs(x+y)%2==1 and k%2==0:print(-1);exit()
ans=[]
xx=yy=0
if x<0:vx=-1
elif x>0:vx=1
if y<0:vy=-1
elif y>0:vy=1

while (abs(xx-x)+abs(yy-y))>k*3:
  if abs(xx-x)>=k:xx+=k*vx;ans.append([xx,yy])
  elif abs(yy-y)>=k:yy+=k*vy;ans.append([xx,yy])
  else:break
c=abs(xx-x)+abs(yy-y)
d=k*(0--c//k)
e=d-c
xx=x+e
yy=y+(k-e)*vy
ans.append([xx,yy])
while abs(yy-y)>=k:yy+=k*vy;ans.append([xx,yy])
print(len(ans)+1)
for i in ans:print(*i)
print(x,y)
Problem p02975 (python)

Fixed submission:
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
else:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")

Buggy submission (verdict: Runtime Error):
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
elif:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=set(a)
l=len(b)
if l==1:
  if a[0]==0:print("Yes")
  else:print("No")
  exit()
elif l==2 and 0 in b and n%3==0:
  if a[n//2-1]!=a[n//2]:print("Yes")
  else:print("No")
elif l!=3:print("No");exit()
if n%3!=0:print("No");exit()
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
d=sorted(ecount(a))
if b.pop()^b.pop()==b.pop() and d[0]==d[2]:print("Yes")
else:print("No")
Problem p02999 (python)

Fixed submission:
x,a=map(int,input().split())
print((x>=a)*10)

Buggy submission (verdict: Runtime Error):
x,a-map(int,input().split())
print((x>=a)*10)
Problem p03001 (python)

Fixed submission:
w,h,x,y=map(int,input().split())
a=w*h/2
s=0
if w==x*2 and h==y*2:s=1
print(a,s)

Buggy submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
a=w*h/2
s=0
if w==x*2 and h=y*2:s=1
print(a,s)
Problem p03021 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
s=list(map(int,list(input()[:-1])))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(lrc):
  l1,r1,c1,x1=lrc[0]
  for l2,r2,c2,x2 in lrc[1:]:
    l1,r1=max(max(l1,l2)-min(r1,r2),0),r1+r2
    if r1%2!=l1%2:l1+=1
    c1+=c2
    x1+=x2
  return [l1,r1,c1,x1]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(map(int,list(input())))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(lrc):
  l1,r1,c1,x1=lrc[0]
  for l2,r2,c2,x2 in lrc[1:]:
    l1,r1=max(max(l1,l2)-min(r1,r2),0),r1+r2
    if r1%2!=l1%2:l1+=1
    c1+=c2
    x1+=x2
  return [l1,r1,c1,x1]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(map(int,list(input())))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(a):
  l,r,c,x=a[0]
  for u,v,d,y in a[1:]:l,r=max(max(l,u)-min(r,v),0)+((l^u)&1),r+v;c+=d;x+=y
  return [l,r,c,x]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
s=list(map(int,list(input())))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(lrc):
  l1,r1,c1,x1=lrc[0]
  for l2,r2,c2,x2 in lrc[1:]:
    l1,r1=max(max(l1,l2)-min(r1,r2),0),r1+r2
    if r1%2!=l1%2:l1+=1
    c1+=c2
    x1+=x2
  return [l1,r1,c1,x1]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)
Problem p03050 (python)

Fixed submission:
import math
n,a=int(input()),0
if n<3:print(0);exit()
for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
    m=n//i-1
    if n//m==n%m:a+=n//i-1
print(a)

Buggy submission (verdict: Runtime Error):
import math
n,a=int(input()),0
for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
    m=n//i-1
    if n//m==n%m:a+=n//i-1
print(a)
Problem p03061 (python)

Fixed submission:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(max(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n=int(input())
a=list(map(int,input().split()))
left=[a[0]]
for i in range(1,n):left.append(gcd(left[-1],a[i]))
right=[a[n-1]]
for i in range(n-2,-1,-1):right.append(gcd(right[-1],a[i]))
right.reverse()
ans=max(right[1],left[n-2])
print(max(ans,max(gcd(left[i-1],right[i+1])for i in range(1,n-1))))

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  for i in range(n-1):b.append(gcd(a[i],a[i+1]))
  b.append(gcd(a[0],a[-1]))
  print(max(no,on),sorted(b)[2])
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split());ans=0
if a<b:ans+=b;b-=1
else:ans+=a;a-=1
ans+=max(a,b)
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input());ans=0
if a<b:ans+=b;b-=1
else:ans+=a;a-=1
ans+=max(a,b)
print(ans)
Problem p03078 (python)

Fixed submission:
from heapq import heappop,heappush;import sys;input=sys.stdin.readline
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
q,h,l=[],[],0
for i in a:
  for j in b:heappush(q,-(i+j));l+=1
for _ in range(min(l,k)):
  t=heappop(q)
  for i in c:heappush(h,t-i)
for i in range(k):print(-heappop(h))

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()));a.sort(reverse=1);b.sort(reverse=1);c.sort(reverse=1);ma=a[0]+b[0]+c[0];d=[[0],[0],[0]]
for i in range(len(a)-1):d[0].append(d[0][-1]+a[i]-a[i+1])
for i in range(len(b)-1):d[1].append(d[1][-1]+b[i]-b[i+1])
for i in range(len(c)-1):d[2].append(d[2][-1]+c[i]-c[i+1])
e=d[0]+d[1]+d[2]
if x*y*z>3000:
  f,i=[0,0,0],0
  while f[0]*f[1]*f[2]<3000:
    for z in range(3):
      if f[z]<len(d[z]):
        while d[z][f[z]]==i:
          f[z]+=1
          if f[z]==len(d[z]):break
    i=min(d[0][f[0]],min(d[1][f[1]],d[2][f[2]]))
  for i in range(3):d[i]=d[i][:f[i]+1]
s=[]
for i in d[0]:
  for j in d[1]:
    for h in d[2]:s.append(i+h+j)
s.sort()
for i in range(k):print(ma-s[i])
Problem p03081 (python)

Fixed submission:
n,q=map(int,input().split())
s=input()
td=[input().split()for _ in range(q)]
def check(i,x):
  for t,d in td:
    if s[i]==t:
      if d=="L":i-=1
      else:i+=1
    if i==x:return True
    if i==-1 or i==n:return False
  return False
ok=-1
ng=n
while ok+1!=ng:
  mid=(ok+ng)//2
  if check(mid,-1):ok=mid
  else:ng=mid
ans=ng
ok=-1
ng=n
while ok+1!=ng:
  mid=(ok+ng)//2
  if check(mid,n):ng=mid
  else:ok=mid
ans+=(n-ng)
print(max(0,n-ans))

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
td=[input().split()for _ in range(q)]
def check(i,x):
  for t,d in td:
    if s[i]==t:
      if d=="L":i-=1
      else:i+=1
    if i==x:return True
  return False
ok=-1
ng=n
while ok+1!=ng:
  mid=(ok+ng)//2
  if check(mid,-1):ok=mid
  else:ng=mid
ans=ng
ok=-1
ng=n
while ok+1!=ng:
  mid=(ok+ng)//2
  if check(mid,n):ng=mid
  else:ok=mid
ans+=(n-ng)
print(max(0,n-ans))
Problem p03086 (python)

Fixed submission:
s,x=input(),["A","C","G","T"]
a,b,c="",0,0
for i in range(len(s)):
  if s[i] in x:
    a+=s[i]
    c+=1
  else:
    a=""
    c=0
  if b<c:b=c
print(b)

Buggy submission (verdict: Runtime Error):
s,a,x=input(),[],["A","C","G","T"]
b=""
for i in range(len(s)):
  if s[i] in x:b+=s[i]
  else:
    a.append(b)
    b=""
a.sort()
print(len(a[-1]))
Problem p03090 (python)

Fixed submission:
n,a,b=int(input()),[],[]
m=n+(n%2==0)
for i in range(1,n):
  for j in range(i+1,n+1):
    if i+j!=m:a.append(i);b.append(j)
l=len(a)
print(l)
for i in range(l):print(a[i],b[i])

Buggy submission (verdict: Runtime Error):
n,a,b=int(input()),[],[]
for i in range(1,n+1):
  for j in range(i,n+1):
    if i!=j and i+j!=n:
      a.append(i)
      b.append(j)
print(len(a))
for i,j in a,b:print(i,j)
Problem p03106 (python)

Fixed submission:
A,B,K=map(int,input().split())
for i in range(100):
  if A%(100-i)==0 and B%(100-i)==0:
    K-=1
    if K==0:
      print(100-i)
      break

Buggy submission (verdict: Runtime Error):
if 7/0>1:print(1)
Problem p03110 (python)

Fixed submission:
n,ans=int(input()),0
for i in range(n):
  a,b=input().split();a=float(a)
  if b=="JPY":ans+=a
  else:ans+=a*380000
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
ans=0
b=380000
for i in range(n):
  x,u=input().split()
  if u=="JPY":
    ans+=int(x)
  else:
    ans+=int(x)*b
print(ans)

Buggy submission (verdict: Runtime Error):
n,ans=int(input()),0
for i in range(n):
  a,b=input().split();a=int(a)
  if b=="JPY":ans+=a
  else:ans+=a*380000
print(ans)

Buggy submission (verdict: Runtime Error):
n,ans=int(input()),0
for i in range(n):
  a,b=map(int,input().split())
  if b=="JPY":ans+=a
  else:ans+=a*380000
print(ans)
Problem p03136 (python)

Fixed submission:
n,ans,l=int(input()),"Yes",list(map(int,input().split()))
for i in l:
  if sum(l)<=i*2:ans="No"
print(ans)

Buggy submission (verdict: Runtime Error):
n,ans,l=int(input()),"Yes",list(map(int,input()))
for i in l:
  if sum(l)<i*2:ans="No"
print(ans)
Problem p03147 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
ans=0
while h!=[0]*n:
  b=(h[0]!=0)+0
  for i in range(n):
    if b==1 and h[i]==0:ans+=1;b=0
    if h[i]!=0:h[i]-=1;b=1
  if b==1:ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
ans=0
while h!=[0]*n:
  b=(h[0]!=0)+0
  for i in range(n):
    if b==1 and h[i]==0:ans+=1;b=0
    if h[i]!=0:h-=1;b=1
  if b==1:ans+=1
print(ans)
Problem p03148 (python)

Fixed submission:
n,k=map(int,input().split())
a=[]
for _ in range(n):a.append(tuple(list(map(int,input().split()))[::-1]))
a.sort(reverse=1)
x,y=[],[]
s=set()
for i in range(k):
  d,t= a[i]
  if t in s:
    x.append(d)
  else:
    y.append(d)
    s.add(t)
xx,yy,v=sum(x),sum(y),len(y)
ans=xx+yy+v**2
for i in range(k,n):
    if len(x)==0:break
    d,t=a[i]
    if t in s:continue
    s.add(t)
    xx-=x.pop()
    yy+=d
    v+=1
    ans=max(ans,xx+yy+v**2)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
td=[list(map(int,input().split()))[::-1]for _ in range(n)]
td.sort(reverse=1)
s=set()
ss=set()
a=[]
b=[]
c=[]
for i in range(n):
  if i<k:
    d,t=td[i]
    if t in s:
      b.append(d)
    else:
      a.append(d)
      s.add(t)
      ss.add(t)
  else:
    d,t=td[i]
    if t not in ss:
      c.append(d)
      ss.add(t)
c=c[::-1]
ls=len(s)
su=sum(a)+sum(b)
ans=ls*ls+su
for i in range(len(ss)-len(s)):
  ls+=1
  su-=b.pop()
  su+=c.pop()
  ans=max(ans,ls*ls+su)
print(ans)
Problem p03157 (python)

Fixed submission:
import sys;sys.setrecursionlimit(10**9)
h,w=map(int,input().split())
b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():
    if j==".":b[-1].append(1)
    else:b[-1].append(2)
  b[-1].append(0)
b.append([0]*(w+1))
d=[[0,1],[0,-1],[1,0],[-1,0]]
a=0
def bfs(i,j):
  global br,wh
  if b[i][j]==0:return
  if b[i][j]==1:wh+=1
  elif b[i][j]==2:br+=1
  v=b[i][j]
  b[i][j]=0
  for k in d:
    if v^3!=b[i+k[0]][j+k[1]]:continue
    bfs(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):
    br=wh=0
    bfs(i,j)
    a+=br*wh
print(a)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split());b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():
    if j==".":b[-1].append(1)
    else:b[-1].append(2)
  b[-1].append(0)
b.append([0]*(w+1));d=[[0,1],[0,-1],[1,0],[-1,0]];a=0
def s(i,j):
  global B;B[b[i][j]-1]+=1;v=b[i][j];b[i][j]=0
  for k in d:
    if v^3!=b[i+k[0]][j+k[1]]:continue
    s(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):B=[0,0];s(i,j);a+=B[0]*B[1]
print(a)
Problem p03163 (python)

Fixed submission:
n,w=map(int,input().split())
dp=[[0]*w for _ in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  for j in range(w):
    if i==0:
      if j>a-2:dp[i][j]=b
    elif j>a-2:
      if j==a-1:dp[i][j]=max(b,dp[i-1][j])
      else:dp[i][j]=max(dp[i-1][j-a]+b,dp[i-1][j])
    else:dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
n,w=map(int,input().split())
dp=[[0]*w for _ in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  for j in range(w):
    if i==0:
      if j>a-2:dp[i][j]=b
    elif j>a-2:
      if j==a-1:dp[i][j]=max(b,dp[i-1],[j])
      else:dp[i][j]=max(dp[i-1][j-a]+b,dp[i-1][j])
    else:dp[i][j]=dp[i-1][j]
print(dp[-1][-1])
Problem p03169 (python)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy submission (verdict: Runtime Error):
n,a=int(input()),list(map(int,input().split()));c=[0,0,0];x=[1.0/i for i in range(1,n+1)];dp=[[[-1]*(c[2]+2) for i in range(c[1]+c[2]+2)]for i in range(n+2)]
for i in a:c[i-1]+=1
for k in range(c[2]+1):
  for j in range(c[2]+c[1]-k+1):
    for i in range(n-k-j+1):
      if i+j+k>0:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]]+1)
Problem p03200 (python)

Fixed submission:
a,s,b=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=(s[i]=="W")
print(a-((b*(b-1))//2))

Buggy submission (verdict: Runtime Error):
a,b,s=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=1
print(a-((b*(b-1))//2))