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

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

readline = sys.stdin.readline
n, q = list(map(int, readline().split()))
# 双方向に張る
tree = [[] for _ in range(n)]
for i in range(n-1):
    a, b = list(map(int, readline().split()))
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

# queryのスコア表を作る
total = [0 for _ in range(n)]
for i in range(q):
    p, x = list(map(int, readline().split()))
    total[p - 1] += x

# dfs
ans = [0 for _ in range(n)]
def dfs(v, p, value):
    value += total[v]
    ans[v] = value
    for c in tree[v]:
        if c == p: continue
        dfs(c, v, value)

dfs(0, -1, 0)
print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
# 双方向に張る
tree = [[] for _ in range(N)]
for i in range(N-1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

# queryのスコア表を作る
total = [0 for _ in range(N)]
for i in range(Q):
    p, x = list(map(int, input().split()))
    total[p - 1] += x

# dfs
ans = [0 for _ in range(N)]
def dfs(v, p, value):
    value += total[v]
    ans[v] = value
    for c in tree[v]:
        if c == p: continue
        dfs(c, v, value)

dfs(0, -1, 0)
print(" ".join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
tree = {}
for i in range(N-1):
    a, b = list(map(int, input().split()))
    items = tree.get(a, [])
    items.append(b)
    tree[a] = items

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

ans = [0] * (N + 1)

def recc_sum(p, x, tree_p):
    for i in range(len(tree_p)):
        index = tree_p[i]
        ans[index] += x
        if tree.get(index, None) != None:
            recc_sum(index, x, tree[index])

for i in range(Q):
    p = q[i][0]
    x = q[i][1]
    ans[p] += x
    if tree.get(p, None) != None:
        recc_sum(p, x, tree[p])

print(" ".join(list(map(str, ans[1:]))))
Problem p02947 (python)

Fixed submission:
def cmb(n, r):
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n

  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]

  for p in range(2,r+1):
      pivot = denominator[p - 1]
      if pivot > 1:
          offset = (n - r) % p
          for k in range(p-1,r,p):
              numerator[k - offset] /= pivot
              denominator[k] /= pivot

  result = 1
  for k in range(r):
      if numerator[k] > 1:
          result *= int(numerator[k])

  return result

N = int(input())
s = {}
h = {'a': 2, 'b': 3, 'c': 5, 'd': 7, 'e':11, 'f':13, 'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
for i in range(N):
    total = 1
    chs = list(input())
    for j in range(10):
        total *= h[chs[j]]
    s[total] = s.get(total, 0) + 1

cnt = 0
for v in s.values():
    if v < 2: continue
    a = cmb(v, 2)
    cnt += a

print(int(cnt))

Buggy submission (verdict: Runtime Error):
from math import factorial

N = int(input())
s = {}
h = {'a': 2, 'b': 3, 'c': 5, 'd': 7, 'e':11, 'f':13, 'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
for i in range(N):
    total = 1
    chs = list(input())
    for j in range(10):
        total *= h[chs[j]]
    s[total] = s.get(total, 0) + 1

cnt = 0
for v in s.values():
    if v < 2: continue
    a = factorial(v) / factorial(2) / factorial(v - 2)
    cnt += a

print(int(cnt))
Problem p02995 (python)

Fixed submission:
# (A ~ B までの個数) - (Cで割り切れるもの + Dで割り切れるもの - CDの最小公倍数で割り切れるもの)
A,B,C,D = list(map(int, input().split()))

def euc(a, b):
    a, b = [max(a, b), min(a, b)]
    if b == 0:
        return a
    else:
        return euc(b, a % b)

Cdiv = (B // C) - ((A-1) // C)
Ddiv = (B // D) - ((A-1) // D)
E = (C * D) // euc(C, D)
CDdiv = (B // E) - ((A-1) // E)

print((B - A + 1) - (Cdiv + Ddiv - CDdiv))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = list(map(int, input().split()))

cd = int((C * D) / math.gcd(C, D))

bc = B // C
bd = B // D
bcd = B // cd
ac = (A - 1) // C
ad = (A - 1) // D
acd = (A - 1) // cd

bdiv = bc + bd - bcd
adiv = ac + ad - acd

alldiv = bdiv - adiv

ans = B - A + 1 - alldiv

print(int(ans))
Problem p03061 (python)

Fixed submission:
def gcd(a, b):
  a, b = [max(a,b), min(a,b)]
  if b == 0:
      return a
  else:
      return gcd(b, a % b)

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

left = [0]*(n+1)
for i in range(n):
    left[i+1] = gcd(left[i], a[i])
right = [0]*(n+1)

for i in range(n-1, -1, -1):
    right[i] = gcd(right[i+1], a[i])

ans = 0
for i in range(n):
    ans = max(gcd(left[i], right[i+1]), ans)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
import functools
n = int(input())
*a, = map(int, input().split())

left = [0]*(n+1)
for i in range(n):
    left[i+1] = math.gcd(left[i], a[i])
right = [0]*(n+1)
for i in range(n-1, -1, -1):
    right[i] = math.gcd(right[i+1], a[i])

ans = 0
for i in range(n):
    ans = max(math.gcd(left[i], right[i+1]), ans)

print(ans)
Problem p03425 (python)

Fixed submission:
N = int(input())
inis = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        inis[s[0]] += 1

ans = 0
march = ["M","A","R","C","H"]
for i in range(len(march)):
    for j in range(i, len(march)):
        for k in range(j, len(march)):
            if march[i] != march[j] and march[i] != march[k] and march[j] != march[k]:
                ans += inis[march[i]] * inis[march[j]] * inis[march[k]]

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
inis = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        inis[s[0]] += 1

ans = 0
march = ["M","A","R","C","H"]
for i in range(N):
    for j in range(i, N):
        for k in range(j, N):
            if march[i] != march[j] and march[i] != march[k] and march[j] != march[k]:
                ans += inis[march[i]] * inis[march[j]] * inis[march[k]]

print(ans)
Problem p02713 (python)

Fixed submission:
from math import gcd

K = int(input())
ans = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(gcd(i, j), k)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

K = int(input())
ans = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(gcd(i, j), k)

print(ans)
Problem p02741 (python)

Fixed submission:
S = "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".split(",")
for i in range(len(S)):
  S[i] = S[i].strip(" ")
K = int(input())
print(S[K-1])

Buggy submission (verdict: Runtime Error):
S = "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".split(",")
for i in rangeAC(len(S)):
  S[i] = S[i].strip(" ")
K = int(input())
print(S[K-1])
Problem p03470 (python)

Fixed submission:
N = int(input())
d = list(map(int, [input() for i in range(N)]))
d.sort()
count = 1

for i in range(0, N-1):
  if d[i] < d[i+1]:
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(map(int, [input() for i in range(N)]))

bucket = {}
for i in range(N):
  if(i in bucket) == False:
    bucket[d[i]] = []
  bucket[d[i]].append(d[i])

print(len(bucket))
Problem p03502 (python)

Fixed submission:
X = int(input())

def Sum_Digit(X):
  SUM = 0
  while X >= 1:
    SUM += X%10
    X = int((X - X%10)/10)
  return SUM

S = Sum_Digit(X)
if X%S == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
X = int(input())

def Sum_Digit(X):
  SUM = 0
  while X >= 1:
    SUM += X%10
    X = int((X - X%10)/10)
  return SUM

print(S)
if X%S == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
X = int(input())

def Sum_Digit(X):
  SUM = 0
  while X > 1:
    SUM += X%10
    X = int((X - X%10)/10)
  return SUM

S = Sum_Digit(X)
if X%S == 0:
  print("Yes")
else:
  print("No")
Problem p03720 (python)

Fixed submission:
[N, M] = list(map(int, input().split()))
[s, e] = [ [], [] ]
for _ in range(M):
  input_line = list(map(int, input().split()))
  s.append(input_line[0])
  e.append(input_line[1])
bucket = {}
for i in range(1, N+1):
  bucket[i] = []

for i in range(M):
  if s[i] in bucket and e[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]].append(e[i])
  elif s[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]] = [e[i]]
  elif e[i] in bucket:
    bucket[s[i]] = [s[i]]
    bucket[e[i]].append(e[i])
  else:
    bucket[s[i]] = [s[i]]
    bucket[e[i]] = [e[i]]

for i in range(1, N+1):
  print(len(bucket[i]))

Buggy submission (verdict: Runtime Error):
[N, M] = list(map(int, input().split()))
[s, e] = [ [], [] ]
for _ in range(M):
  input_line = list(map(int, input().split()))
  s.append(input_line[0])
  e.append(input_line[1])
bucket = {}

for i in range(M):
  if s[i] in bucket and e[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]].append(e[i])
  elif s[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]] = [e[i]]
  elif e[i] in bucket:
    bucket[s[i]] = [s[i]]
    bucket[e[i]].append(e[i])
  else:
    bucket[s[i]] = [s[i]]
    bucket[e[i]] = [e[i]]

for i in range(1, N+1):
  print(len(bucket[i]))

Buggy submission (verdict: Runtime Error):
[N, M] = list(map(int, input().split()))
[s, e] = [ [], [] ]
for _ in range(N):
  input_line = list(map(int, input().split()))
  s.append(input_line[0])
  e.append(input_line[1])
bucket = {}

for i in range(N):
  if s[i] in bucket and e[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]].append(e[i])
  elif s[i] in bucket:
    bucket[s[i]].append(s[i])
    bucket[e[i]] = [e[i]]
  elif e[i] in bucket:
    bucket[s[i]] = [s[i]]
    bucket[e[i]].append(e[i])
  else:
    bucket[s[i]] = [s[i]]
    bucket[e[i]] = [e[i]]

for i in range(1, N+1):
  print(len(bucket[i]))
Problem p02843 (python)

Fixed submission:
X=int(input())
m=X%100
nmin=0
for i in range(5,0,-1):
    nmin+=m//i
    m=m-(m//i)*i
if nmin>(X//100):
    print("0")
else:
    print("1")

Buggy submission (verdict: Runtime Error):
X=int(input())
ldp=[0 for i in range(X+1)]
for i in range(100,106):
    ldp[i]=1
for i in range(106,X+1):
    if sum(ldp[i-105:i-99])>=1:
        ldp[i]=1
print(ldp[X])
Problem p02855 (python)

Fixed submission:
H,W,K=map(int,input().split())
ls=[]
for i in range(H):
    ls.append(input())
ld=[]
#f=0
f=-1
#n=1
ns=0
for i in range(H):
    nstmp=0
    ld.append([])
    for j in range(W):
        if ls[i][j]=="#":
            nstmp+=1
            ns+=1
            if nstmp==2:
                #ld[i].append(j)
                #n+=1
                #ld[i].append((j,ns))
                ld[i].append((j,ns-1))#jより小さいところはns-1区画
                nstmp=1
                #n+=1
    #print("j",j)
    if nstmp==1:
        ld[i].append((j+1,ns))
    if not ld[i]:
        if i==0:
            f=0
        elif not ld[i-1]:
            f+=1
        else:
            ld[i]=ld[i-1]
    #n+=1
#if f==1:
    #ld[0]=ld[1]
if f>-1:
    for i in range(f,-1,-1):
        ld[i]=ld[i+1]
#print(ld)
for i in range(H):
    k=0
    for j in range(W):
        if j<ld[i][k][0]:
            print(ld[i][k][1],end=" ")
        else:
            k+=1
            print(ld[i][k][1],end=" ")
    print("")

Buggy submission (verdict: Runtime Error):
H,W,K=map(int,input().split())
ls=[]
for i in range(H):
    ls.append(input())
ld=[]
f=0
#n=1
ns=0
for i in range(H):
    nstmp=0
    ld.append([])
    for j in range(W):
        if ls[i][j]=="#":
            nstmp+=1
            ns+=1
            if nstmp==2:
                #ld[i].append(j)
                #n+=1
                #ld[i].append((j,ns))
                ld[i].append((j,ns-1))#jより小さいところはns-1区画
                nstmp=1
                #n+=1
    if nstmp==1:
        ld[i].append((j+1,ns))
    if not ld[i]:
        if i==0:
            f=1
        else:
            ld[i]=ld[i-1]
    #n+=1
if f==1:
    ld[0]=ld[1]
#print(ld)
for i in range(H):
    k=0
    for j in range(W):
        if j>=ld[i][k][0]:
            k+=1
        print(ld[i][k][1],end=" ")
    print("")
Problem p02866 (python)

Fixed submission:
N=int(input())
ld=list(map(int,input().split()))
def modpow(a,n,p):#a^n mod p
    res=1
    while n>0:
        if n&1:#１とのビット論理積が１、つまり奇数
            res=res*a%p
        a=a*a%p
        n>>=1
        #ビットの右シフト_2進数表記のnを小数点を固定して右に１桁ずらす_１桁小さくなる
    return res
if ld[0]!=0:
    print(0)

else:
    dd={}
    for i in range(N):
        if ld[i] in dd:
            dd[ld[i]]+=1
        else:
            dd[ld[i]]=1

    if dd[0]!=1:
        print(0)
    else:
        DV=998244353
        ans=1
        for i in range(0,len(dd)-1):
            #mul=dd[i]**dd[i+1]%DV
            if i in dd and i+1 in dd:
                mul=modpow(dd[i],dd[i+1],DV)
                #ans*=dd[i]**dd[i+1]
                ans*=mul
                ans%=DV
            else:
                print(0)
                break
        else:
            print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ld=list(map(int,input().split()))
def modpow(a,n,p):#a^n mod p
    res=1
    while n>0:
        if n&1:#１とのビット論理積が１、つまり奇数
            res=res*a%p
        a=a*a%p
        n>>=1
        #ビットの右シフト_2進数表記のnを小数点を固定して右に１桁ずらす_１桁小さくなる
    return res
if ld[0]!=0:
    print(0)

else:
    dd={}
    for i in range(N):
        if ld[i] in dd:
            dd[ld[i]]+=1
        else:
            dd[ld[i]]=1
    if dd[0]!=1:
        print(0)
    else:
        DV=998244353
        ans=1
        for i in range(0,len(dd)-1):
            #mul=dd[i]**dd[i+1]%DV
            mul=modpow(dd[i],dd[i+1],DV)
            #ans*=dd[i]**dd[i+1]
            ans*=mul
            ans%=DV
        print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ld=list(map(int,input().split()))
if ld[0]!=0:
    print(0)
else:
    dd={}
    for i in range(N):
        if ld[i] in dd:
            dd[ld[i]]+=1
        else:
            dd[ld[i]]=1
    if dd[0]!=1:
        print(0)
    else:
        DV=998244353
        ans=1
        for i in range(0,len(dd)-1):
            mul=dd[i]**dd[i+1]%DV
            #ans*=dd[i]**dd[i+1]
            ans*=mul
            ans%=DV
        print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ld=list(map(int,input().split()))
if ld[0]!=0:
    print(0)
else:
    dd={}
    for i in range(N):
        if ld[i] in dd:
            dd[ld[i]]+=1
        else:
            dd[ld[i]]=1
    if dd[0]!=1:
        print(0)
    else:
        DV=998244353
        ans=1
        for i in range(0,len(dd)-1):
            ans*=dd[i]**dd[i+1]
            ans%=DV
        print(ans)
Problem p02888 (python)

Fixed submission:
from bisect import bisect_left
N=int(input())
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    for j in range(i+1,N):
        if j==i+1:
            delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2
            if delta>0:
                ans+=delta
            in_b=delta+i+1+1
        else:
            if in_b!=N:
                delta=bisect_left(ll,ll[i]+ll[j],lo=in_b)-j-1
            else:
                delta=N-j-1
            if delta>0:
                ans+=delta
            in_b=delta+j+1
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N=int(input())
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2
    if delta>0:
        ans+=delta
    in_b=delta+i+1+1
    for j in range(i+2,N):
        if in_b!=N:
            delta=bisect_left(ll,ll[i]+ll[j],lo=in_b)-j-1
        else:
            delta=N
        if delta>0:
            ans+=delta
        in_b=delta+j+1
print(ans)
Problem p02936 (python)

Fixed submission:
#import collections
N,Q=map(int,input().split())
lc=[[] for i in range(N)]#二重リストで木を表現
for i in range(N-1):
    a,b=map(int,input().split())
    lc[a-1].append(b-1)
    lc[b-1].append(a-1)
lv=[0 for i in range(N)]#値のリスト
for i in range(Q):
    p,x=map(int,input().split())
    lv[p-1]+=x
lf=[0 for i in range(N)]#訪れたかどうか
#d=collections.deque([0])
lp=[0]
lf[0]=1
#for i in range(N):
while len(lp)>0:
    #p=lp[-1]
    p=lp.pop()
    for c in lc[p]:
        if lf[c]==0:
            lv[c]+=lv[p]
            lf[c]=1
            lp.append(c)
for i in range(N-1):
    print(lv[i],end=" ")
print(lv[N-1])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N,Q=map(int,input().split())
dg={i:[[],0] for i in range(1,N+1)}
for i in range(1,N):
    a,b=map(int,input().split())
    dg[a][0].append(b)
    dg[b][0].append(a)
#print(dg)
def habatan(p,me):
    if me!=1:
        dg[me][0].remove(p)
    for c in dg[me][0]:
        habatan(me,c)

habatan(0,1)#dg親消し
#print(dg)
#dv={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x=map(int,input().split())
    #dv[p]+=x
    dg[p][1]+=x
#dans={}
def habatan1(p,me):
    if me!=1:
        #dv[me]+=
        dg[me][1]+=dg[p][1]
    #for c in dg[me]:
    for c in dg[me][0]:
        habatan1(me,c)
habatan1(0,1)
for i in range(1,N+1):
    #print(dv[i],end=" ")
    print(dg[i][1],end=" ")
print("")

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
dg={i:[] for i in range(1,N+1)}
for i in range(1,N):
    a,b=map(int,input().split())
    dg[a].append(b)
    dg[b].append(a)
#print(dg)
def habatan(p,me):
    if me!=1:
        dg[me].remove(p)
    for c in dg[me]:
        habatan(me,c)

habatan(0,1)#dg親消し
#print(dg)
dv={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x=map(int,input().split())
    dv[p]+=x
#dans={}
def habatan1(p,me):
    if me!=1:
        dv[me]+=dv[p]
    for c in dg[me]:
        habatan1(me,c)
habatan1(0,1)
for i in range(1,N+1):
    print(dv[i],end=" ")
print("")
Problem p03219 (python)

Fixed submission:
l=list(map(int,input().split()))
x=l[0]
y=l[1]
print(int(x+y/2))

Buggy submission (verdict: Runtime Error):
nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]
py=[]
y=[]
for i in range(m):
    py.append([])
for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])
for i in range(n):
    y[i].sort()
#print(py)
#print(y)
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    else:
        print(str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
Problem p03282 (python)

Fixed submission:
ss=input()
k=int(input())
s=[int(i) for i in ss ]
#ls=len(s)
j=0
q=0
w=0
while q==0:
    if s[j]==1:
        w+=1
        if k<=w:
            print(1)
            q=1
        j+=1
    else:
        print(s[j])
        q=1

Buggy submission (verdict: Runtime Error):
l=list(map(int,input().split()))
n=l[0]
m=l[1]
q=l[2]
lr=[]
pq=[]
for i in range(m):
    lr.append(input())
for i in range(q):
    pq.append(input())
w=0    
for i in range(q):
    ppqq=list(map(int,pq[i].split()))
    w=0
    for j in range(m):
        llrr=list(map(int,lr[j].split()))
        if llrr[0]>= ppqq[0] and llrr[1]<=ppqq[1]:
            w+=1
    print(w)
Problem p03341 (python)

Fixed submission:
n=int(input())
s=input()
k=0
l=[]
for i in range(n):
    if s[i]=="W":
        k+=1
    l.append(k)
#print(l)
#既に追加されたものまで変更されはしなかった
w=n
for i in range(n):
    if i==0:
        #if s[i]=="W":
        #    v=n-l[n-1]+1
        #else:
        #    v=n-l[n-1]
        #下のようにすれば分ける必要はない
        v=n-1-l[n-1]+l[0]
    else:
        v=l[i-1]+n-1-i-(l[n-1]-l[i])


    if v<w:
        w=v
print(w)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
k=n
for i in range(n):
    a=s[:i]
    b=s[i+1:]
    l=a.count("W")+b.count("E")
    if l<k:
        k=l
print(k
Problem p03351 (python)

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


if abs(lst[0]-lst[2])<=lst[3] or (abs(lst[0]-lst[1])<=lst[3] and abs(lst[2]-lst[1])<=lst[3]):
    print("Yes")
else:
    print("No")

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


if abs(lst[0]-lst[2])<=lst[3] or (abs(lst[0]-lst[1])<=lst[3] and abs(lst[2]-lst[1])<=lst[3]:
    print("Yes")
else:
    print("No")
Problem p03476 (python)

Fixed submission:
import sys
input=sys.stdin.readline
from bisect import bisect_left, bisect_right

Q=int(input())
llr=[]
maxr=1
for i in range(Q):
    l,r=map(int,input().split())
    if r>maxr:
        maxr=r
    llr.append([l,r])
def isprime(n):
    if n==1:
        return 0
    m=int(n**(1/2))
    for i in range(2,m+1):
        if n%i==0:
            return 0
            break
    return 1
l2017=[]
for i in range(1,maxr+1,2):
    if isprime(i) and isprime((i+1)/2):
        l2017.append(i)
for i in range(Q):
    il=bisect_left(l2017,llr[i][0])
    ir=bisect_right(l2017,llr[i][1])
    print(ir-il)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
from bisect import bisect_left, bisect_right

Q=int(input())
llr=[]
maxr=1
for i in range(Q):
    l,r=map(int,input().split())
    if r>maxr:
        maxr=r
    llr.append([l,r])
def isprime(n):
    if n==1:
        return 0
    m=int(n**(1/2))
    for i in range(2,m+1):
        if n%i==0:
            return 0
            break
    return 1
l2017=[]
for i in range(1,maxr+1,2):
    if isprime(i) and isprime((i+1)/2):
        l2017.append(i)
for i in range(Q):
    il=bisect_left(l2017,llr[i][0])
    ir=bisect_right(l2017,llr[i][1])
    print(ir-il

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
from bisect import bisect_left, bisect_right

Q=int(input())
llr=[]
maxr=1
for i in range(Q):
    l,r=map(int,input().split())
    if r>maxr:
        maxr=r
    llr.append([l,r])
def isprime(n):
    m=int(n**(1/2))
    for i in range(2,m+1):
        if n%i==0:
            return 0
            break
    return 1
l2017=[]
for i in range(3,maxr+1,2):
    if isprime(i) and isprime((i+1)/2):
        l2017.append(i)
for i in range(Q):
    il=bisect_left(l2017,llr[i][0])
    ir=bisect_right(l2017,llr[i][1])
    print(ir-il
Problem p02885 (python)

Fixed submission:
n,p=map(int,input().split())
if(n>2*p):
    print(n-2*p)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n,l=(int,input().split())
if(n>2*l):
    print(n-2*l)
else:
    print(0)