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

Fixed submission:
a,b,c=map(int,input().split())
if a==b==c:
  print(1)
elif a==b or b==c or c==a:
  print(2)
else:
  print(3)

Buggy submission (verdict: Runtime Error):
a,b.c=map(int,input().split())
L=[a,b,c]
L.sort()
if L[0]==L[2]:
  print(1)
elif　L[0]<L[1]<L[2]:
  print(3)
else:
  print(2)

Buggy submission (verdict: Runtime Error):
a,b.c=map(int,input().split())
L=list[a,b,c]
L.sort()
if L[0]==L[2]:
  print(1)
elif　L[0]<L[1]<L[2]:
  print(3)
else:
  print(2)
Problem p02694 (python)

Fixed submission:
x=int(input())
s=0
temp=100
while temp<x:
    s+=1
    temp=int(temp*1.01)
print(s)

Buggy submission (verdict: Runtime Error):
    s=0
    temp=100
    while temp<x:
        s+=1
        temp=int(temp*1.01)
    print(s)
Problem p02690 (python)

Fixed submission:
def main():
  from itertools import combinations
  x = int(input())
  ls = [0]
  a = 0
  b = 0
  if x == 1:
    print(0, -1)
    exit()
  for i in range(1, 200):
    ls.append(i**5)
    ls.append(-i**5)
  ls.sort()
  for b in ls:
    if x + b in ls:
      a = x + b  
      break
  if a < 0:
    print(-1*int(pow(-a, 0.2)), end=' ')
  else:
    print(int(pow(a, 0.2)), end=' ')
  if b < 0:
    print(-1*int(pow(-b, 0.2)), end=' ')
  else:
    print(int(pow(b, 0.2)), end=' ')
  


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  from itertools import combinations
  x = int(input())
  ls = [0]
  if x == 1:
    print(0, -1)
    exit()
  for i in range(1, 100):
    ls.append(i**5)
    ls.append(-i**5)
  ls.sort()
  for b in ls:
    if x + b in ls:
      a = x + b  
      break
  if a < 0:
    print(-1*int(pow(-a, 0.2)), end=' ')
  else:
    print(int(pow(a, 0.2)), end=' ')
  if b < 0:
    print(-1*int(pow(-b, 0.2)), end=' ')
  else:
    print(int(pow(b, 0.2)), end=' ')
  


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  from itertools import combinations
  x = int(input())
  ls = [0]
  if x == 1:
    print(0, -1)
  for i in range(1, 100):
    ls.append(i**5)
    ls.append(-i**5)
  ls.sort()
  for b in ls:
    if x + b in ls:
      a = x + b  
      break
  if a < 0:
    print(-1*int(pow(-a, 0.2)), end=' ')
  else:
    print(int(pow(a, 0.2)), end=' ')
  if b < 0:
    print(-1*int(pow(-b, 0.2)), end=' ')
  else:
    print(int(pow(b, 0.2)), end=' ')
  


if __name__ == '__main__':
  main()
Problem p02713 (python)

Fixed submission:
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)

n= 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(i, j, k)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

n= 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(i, j, k)
print(ans)
Problem p02714 (python)

Fixed submission:
n = int(input())
s = input()
 
r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
 
for i in range(n):
  for j in range(i+2, n, 2):
    if s[i] != s[j] and s[i] != s[int((i+j)/2)] and s[int((i+j)/2)] != s[j]:
      ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
 
r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
 
for i in range(n):
  for j in range(i+1, n, 2):
    if s[i] != s[j] and s[i] != s[(i+j)/2] and s[(i+j)/2] != s[j]:
      count -= 1
print(count)

Buggy submission (verdict: Runtime Error):
n, s = input().split(' ')
n = int(n)

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n):
  for j in range(i+1, n, 2):
    if s[i] != s[j] and s[i] != s[(i+j)/2] and s[(i+j)/2] != s[j]:
      count -= 1
print(count)
Problem p02720 (python)

Fixed submission:
from collections import deque
 
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
 
for i in range(k):
  a = q.popleft()
  if a % 10 == 0:
    q.append(10*a)
    q.append(10*a + 1)
  elif a % 10 == 9:
    q.append(10*a + 8)
    q.append(10*a + 9)
  else:
    q.append(10*a + a%10 - 1)
    q.append(10*a + a%10)
    q.append(10*a + a%10 + 1)
else:
  print(a)

Buggy submission (verdict: Runtime Error):
from collections import deque


k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(k):
  a = q.popleft()
  if a % 10 == 1:
    q.append([10*a, 10*a+1])
  elif a % 10 == 9:
    q.append([10*a + 8, 10*a + 9])
  else:
    q.append([10*a + a - 1, 10*a + a, 10*a + a + 1])
else:
  print(a)

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

i = 0
lun_ls = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 0
while n < 9991:
  i += 1
  s = str(i)
  for j in range(len(s)-1):
    if (int(s[j]) - int(s[j+1])) not in [-1, 0, 1]:
      break
    else:
      lun_ls.append(i)
      n += 1

print(lun_ls[k-1])
Problem p03471 (python)

Fixed submission:
n, y = map(int, (input().split()))
 
for i in range(n+1):
  for j in range(n+1-i):
    k = n - i - j
    if 10000*i + 5000*j + 1000*k == y:
      print(i, j, k)
      break
  else:
    continue
  break
else:
  print(-1, -1, -1)

Buggy submission (verdict: Runtime Error):
  for j in range(n+1-i):
    k = n - i - j
    if 10000*i + 5000*j + 1000*k == y:
      print(i, j, k)
      break
  else:
    continue
  break
Problem p03231 (python)

Fixed submission:
n,m = map(int,input().split())
s = input()
t = input()

def gcd(a, b):
    if b > a:
        a,b = b,a
    a,b = b,a % b
    if b == 0:
        return a
    else:
        return gcd(a,b)
def lcm(a, b):
	return a * b // gcd (a, b)

if s[0] != t[0]:
    print(-1)
    exit()
if gcd(n,m) == 1:
    print(lcm(n,m))
    exit()

ans = lcm(n,m)
nn = ans//n
mm = ans//m
e = lcm(nn,mm)
for i in range(1,ans,e):
    # print(i // (ans//n),i // (ans//m))
    # print(s[i // (ans//n)],t[i // (ans//m)])
    if s[i // (ans//n)] != t[i // (ans//m)]:
        print(-1)
        exit()
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = input()
t = input()

def gcd(a, b):
    if b > a:
        a,b = b,a
    a,b = b,a % b
    if b == 0:
        return a
    else:
        return gcd(a,b)
def lcm(a, b):
	return a * b // gcd (a, b)

if s[0] != t[0]:
    print(-1)
    exit()
if gcd(n,m) == 1:
    print(lcm(n,m))
    exit()

ans = lcm(n,m)
nn = ans/n
mm = ans//m
e = max(nn,mm)
for i in range(1,ans,e):
    if i % (ans//n) != 0 or i%(ans//m) != 0:
        continue
    if s[i // nn] != t[i // mm]:
        print(-1)
        exit()
print(ans)
Problem p03240 (python)

Fixed submission:
n = int(input())
xyh = []
for i in range(0,n):
    X,Y,h = map(int,input().split())
    xyh.append((X,Y,h))
from operator import itemgetter
xyh.sort(key=itemgetter(2))
xyh.reverse()

ans = ()
for i in range(0,101):
    for j in range(0,101):
        flag = "f"
        x,y,h = xyh[0]
        H = h + abs(x-i)+abs(y-j)
        for x,y,h in xyh:
            if H ==  h + abs(x-i)+abs(y-j) and h != 0:
                flag = "t"
            elif H <=  h + abs(x-i)+abs(y-j) and h == 0:
                flag = "t"
            else:
                flag = "f"
                break
        if flag == "t":
            ans = (i,j,H)
Cx,Cy,H = ans
print(Cx,Cy,H)

Buggy submission (verdict: Runtime Error):
n = int(input())
xyh = []
xyh0 = []
for i in range(0,n):
    X,Y,h = map(int,input().split())
    if h != 0:
        xyh.append((X,Y,h))
    else:
        xyh0.append((X,Y))
ans = []
for i in range(0,101):
    for j in range(0,101):
        flag = "f"
        if len(xyh)>0:
            x,y,h = xyh[0]
            H = h + abs(x-i)+abs(y-j)
            flag = "t"
        for x,y,h in xyh:
            if H !=  h + abs(x-i)+abs(y-j):
                flag = "f"
                break
        if flag == "t":
            ans.append((i,j,H))
if len(ans) > 0:
    for i,j,H in ans:
        flag == "f":
        for x,y in xyh0:
            flag = "t"
            if H < h + abs(x-i)+abs(y-j):
                flag = "f"
                break
        if flag == "t":
            ans = [(i,j,H)]
        if len(ans) == 1:
            break
print(x,y,h)













#
Problem p03347 (python)

Fixed submission:
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if next - a[i] >= 2:
        flag = False
        break
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    if next - a[i] >= 2:
        flag = False
        break
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    #print(ans)
else:
    #print(-1)
print(-1)
Problem p03356 (python)

Fixed submission:
n,m = map(int,input().split())
p = list(map(int, input().split()))
g = [[] for _ in range(0,n+1)]
visit = [None] * (n+1)
ans = 0
for _ in range(0,m):
    x,y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
for i in range(1,n+1):
    if visit[i] is not None:
        continue
    stack = [i]
    part = [i]
    visit[i] = 0
    while len(stack) > 0:
        q = stack.pop()
        for qq in g[q]:
            if visit[qq] is None:
                visit[qq] = 0
                part.append(qq)
                stack.append(qq)
    part2 = []
    for i in part:
        part2.append(p[i-1])
    ans += len(list(set(part) & set(part2)))
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
p = list(map(int, input().split()))
g = [[] for _ in range(0,n+1)]
visit = [None] * (n+1)
ans = 0
for _ in range(0,m):
    x,y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
for i in range(1,n+1):
    if visit[i] is not None:
        continue
    stack = [i]
    part = [i]
    visit[i] = 0
    while len(stack) > 0:
        q = stack.pop()
        for qq in g[q]:
            if visit[qq] is None:
                visit[qq] = 0
                part.append(qq)
                stack.append(qq)
    if len(part) >= 2:
        part2 = []
        for i in part:
            part2.append(p[i-1])
        for i in part:
            if i in part2:
                ans += 1
    else:
        if(i == p[i] - 1):
            ans += 1
print(ans)
Problem p03361 (python)

Fixed submission:
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["."for i in range(0,w+2)]
c[h+1] = ["."for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append(".")
    d.insert(0,".")
    c[i] = d
for j in range(1,h+1):
    for i in range(1,w+1):
        if c[j][i] == "#":
            flag = "No"
            if(c[j][i-1] == "#"):
                flag = "Yes"
            if(c[j][i+1] == "#"):
                flag = "Yes"
            if(c[j-1][i] == "#"):
                flag = "Yes"
            if(c[j+1][i] == "#"):
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["#"for i in range(0,w+2)]
c[h+1] = ["#"for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append("#")
    d.insert(0,"#")
    c[i] = d
for i in range(1,h+1):
    for j in range(1,w+1):
        if c[j][i] == "#":
            flag = "No"
            if(c[j][i-1] == "#"):
                flag = "Yes"
            if(c[j][i+1] == "#"):
                flag = "Yes"
            if(c[j-1][i] == "#"):
                flag = "Yes"
            if(c[j+1][i] == "#"):
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["."for i in range(0,w+2)]
c[h+1] = ["."for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append(".")
    d.insert(0,".")
    c[i] = d
for i in range(1,h+1):
    for j in range(1,w+1):
        if c[j][i] == "#":
            flag = "No"
            if(c[j][i-1] == "#"):
                flag = "Yes"
            if(c[j][i+1] == "#"):
                flag = "Yes"
            if(c[j-1][i] == "#"):
                flag = "Yes"
            if(c[j+1][i] == "#"):
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)
Problem p02806 (python)

Fixed submission:
#第六回ドワンゴからの挑戦状　A

N=int(input())

largelist=[]

for i in range(N):
    S=input().split()
    #print(S)
    largelist.append(S)

#print(largelist)

X=input()
answer=0

for i in range(N):
    if X==largelist[i][0]:
        for j in range(i+1,N):
            #print("now j")
            #print(j)
            answer+=int(largelist[j][1])
        
    else:
        temp=0

print(answer)

Buggy submission (verdict: Runtime Error):
第六回ドワンゴからの挑戦状　A

N=int(input())

largelist=[]

for i in range(N):
    S=input().split()
    #print(S)
    largelist.append(S)

#print(largelist)

X=input()
answer=0

for i in range(N):
    if X==largelist[i][0]:
        for j in range(i+1,N):
            answer+=int(largelist[j][1])
        
    else:
        temp=0

print(answer)
Problem p02812 (python)

Fixed submission:
#ABC144 B
N=int(input())
S=input()
#print(N)
result=0

for i in range(N-2):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        #print(i)
        result+=1
    else:
        #print("after"+str(i))
        p=1

print(result)

Buggy submission (verdict: Runtime Error):
#ABC144 B
N=int(input())
S=input()
#print(N)
result=0

for i in range(N-1):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        print(i)
        result+=1
    else:
        print("after"+str(i))
        p=1

print(result)

Buggy submission (verdict: Runtime Error):
#ABC144 B
N=int(input())
S=input()
#print(N)
result=0

for i in range(N):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        #print(i)
        result+=1
    else:
        #print("after"+str(i))
        p=1

print(result)
Problem p02718 (python)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int, input().split()))
num=sum(a)
tmp=float(num)/float(4.0*m)
count=0
for i in range(n):
  if a[i]>=tmp:
    count+=1
if count>=m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*n
for i in range(n):
  a[i]=int(input().split())
num=sum(a)
tmp=num//(4*m)
count=0
for i in range(n):
  if a[i]>=tmp:
    count+=1
if count==m:
  print("Yes")
else:
  print("No")
Problem p02731 (python)

Fixed submission:
L=int(input())
print((L**3)/27)

Buggy submission (verdict: Runtime Error):
L=int(input())
ans=0
tmp=0
d=3
for i in range(int(L*d/1.45):
  for j in range(int((L*d-i)/1.45)):
    tmp=(i/d)*(j/d)*(L-(i/d)-(j/d))
    ans=max(ans,tmp,0)
print(ans)

Buggy submission (verdict: Runtime Error):
L=int(input())
ans=0
tmp=0
d=3
for i in range(L*d/2):
  for j in range(L*d-i):
    tmp=(i/d)*(j/d)*(L-(i/d)-(j/d))
    ans=max(ans,tmp,0)
print(ans)
Problem p02747 (python)

Fixed submission:
s=str(input())
if len(s)%2==1:
    print("No")
else:
    is_hitachi=1
    for i in range(int(len(s)/2)):
        if s[2*i]!="h" or s[2*i+1]!="i":
            is_hitachi=0
            break
    if is_hitachi==1:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
s=str(input())
if len(s)%2==1:
    print("No")
else:
    is_hitachi=1
    for i in range(int(len(s)/2)):
        if s[2i]!="h" or s[2i+1]!="i":
            is_hitachi=0
            break
    if is_hitachi==1:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
s=str(input())
if len(s)%2==1:
    print("No")
else:
    is_hitachi=1
    for i in range(len(s)/2):
        if s[2i]!="h" or s[2i+1]!="i":
            is_hitachi=0
            break
    if is_hitachi==1:
        print("Yes")
    else:
        print("No")
Problem p02748 (python)

Fixed submission:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
min_price=min(a)+min(b)
for i in range(M):
    tmp_price=10000
    m=list(map(int,input().split()))
    tmp_price=a[m[0]-1]+b[m[1]-1]-m[2]
    if min_price>tmp_price:
        min_price=tmp_price
print(min_price)

Buggy submission (verdict: Runtime Error):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
min_price=min(a)+min(b)
for i in range(M):
    m=list(map(int,input().split()))
    tmp_price=a[m[0]]+b[m[1]]-m[2]
    if min_price>tmp_price:
        min_price=tmp_price
print(min_price)

Buggy submission (verdict: Runtime Error):
A,B,M=map(int,input().split())
a=list(map(int,input().split())
b=list(map(int,input().split())
min_price=min(a)+min(b)
for i in range(M):
    m=list(map(int,input().split())
    tmp_price=a[m[0]]+b[m[1]]-m[2]
    if min_price>tmp_price:
        min_price=tmp_price
print(min_price)
Problem p02767 (python)

Fixed submission:
N=number=int(input())
X_list=list(map(int, input().split()))
min_pow=0
if N==1:
    print("0")
else:
    X_min=min(X_list)
    X_max=max(X_list)
    for i in range(X_min,X_max):
        sum_pow=0
        for j in range(N):
            sum_pow+=(X_list[j]-i)**2
        if i==X_min:
            min_pow=sum_pow
        if min_pow>sum_pow:
            min_pow=sum_pow
    print(min_pow)

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

if N==1:
    print("0")
else:
    X_min=min(X_list)
    X_max=max(X_list)
    for i in range(X_min,X_max):
        sum_pow=0
        for j in range(N):
            sum_pow+=(X_list[j]-i)**2
        if i==X_min:
            min_pow=sum_pow
        if min_pow>sum_pow:
            min_pow=sum_pow
    print(min_pow)

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

for i in range(1,100):
    sum_pow=0
    for j in range(N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

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

X_min=min(X_list)
X_max=max(X_list)
for i in range(X_min,X_max):
    sum_pow=0
    for j in range(N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

Buggy submission (verdict: Runtime Error):
N=2
X_list=list(1,4)

X_min=min(X_list)
X_max=max(X_list)
for i in range(X_min,X_max):
    sum_pow=0
    for j in range(N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

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

X_min=min(X_list)
X_max=max(X_list)
for i in range(X_min,X_max):
    sum_pow=0
    for j in range(1,N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)
Problem p03339 (python)

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

#毎ステップ毎にカウントする処理→TLE
# ans=10**6
# for i in range(1,N):
#   ans=min(ans,s[:i-1].count("W")+s[i+1:].count("E"))
# print(ans)
ans=[]
ans.append(s[1:].count("E"))
tmp=ans[0]
for i in range(1,n):
  if s[i]=="E":
    tmp-=1
  if s[i-1]=="W":
    tmp+=1
  ans.append(tmp)
print(min(ans))

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

#毎ステップ毎にカウントする処理→TLE
# ans=10**6
# for i in range(1,N):
#   ans=min(ans,s[:i-1].count("W")+s[i+1:].count("E"))
# print(ans)
ans=[]
ans.append(s[1:].count("E"))
tmp=ans[0]
for i in range(1:N):
  if s[i]=="E":
    tmp-=1
  if s[i-1]=="W":
    tmp+=1
  ans.append(tmp)
print(min(ans))

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

#毎ステップ毎にカウントする処理→TLE
# ans=10**6
# for i in range(1,N):
#   ans=min(ans,s[:i-1].count("W")+s[i+1:].count("E"))
# print(ans)
ans=[]
ans[0]=s[1:].count("E")
tmp=ans[0]
for i in range(1:N):
  if s[i]=="E":
    tmp-=1
  if s[i-1]=="W":
    tmp+=1
  ans.append(tmp)
print(min(ans))
Problem p03449 (python)

Fixed submission:
N=int(input())
A=[]
for i in range(2):
    A_ = list(map(int, input().split()))
    A.append(A_)
    A[i].append(0)
A.append([0]*(N+1))
# A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
# A[0]=list(map(int,input().split()))
# A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    for j in range(x,N):
      ans_can+=A[1][j]
    max_candidate.append(ans_can)
    ans+=A[0][x+1]
    x+=1
print(max(max_candidate))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(2):
    A_ = list(map(int, input().split()))
    A.append(A_)
    A[i].append(0)
A.append([0]*(N+1))
# A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
# A[0]=list(map(int,input().split()))
# A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    # for j in range(x,N):
    #   ans_can+=A[1][j]
    ans_can+=A[1][3]
    ans_can+=A[1][4]
    max_candidate.append(ans_can)
    x+=1
print(max(max_candidate))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(2):
    A_ = list(map(int, input().split()))
    A.append(A_)
    A[i].append(0)
A.append([0]*(N+1))
# A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
# A[0]=list(map(int,input().split()))
# A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    for j in range(x,N):
      ans_can+=A[1][j]
    max_candidate.append(ans_can)7
    x+=1
print(max(max_candidate))

Buggy submission (verdict: Runtime Error):
N=int(input)
A=[]
for i in range(2):
    A_ = list(map(int, input().split()))
    A.append(A_)
    A[i].append(0)
A.append([0]*(N+1))
# A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
# A[0]=list(map(int,input().split()))
# A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    for i in range(x,N):
      ans_can+=A[1][i]
    max_candidate.append(ans_can)
print(max(max_candidate))

Buggy submission (verdict: Runtime Error):
N=int(input)
A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
A[0]=list(map(int,input().split()))
A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    for i in range(x,N):
      ans_can+=A[1][i]
    max_candidate.append(ans_can)
print(max(max_candidate))