Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
a = [input() for i in range(int(input()))]
res = 0
for i in range(len(a)):
    for j in range(i+1, len(a)):
        if sorted(a[i]) == sorted(a[j]):
            res += 1
print(res)


Fixed submission:
def p2(num):
    if num == 0:
        return 0
    else:
        return (num * (num - 1)) // 2


a = [sorted(input()) for i in range(int(input()))]
sorted_arr = sorted(a)

tmp = [""]
tmp_num = 0
tmp_arr = []
for i in sorted_arr:
    if i != tmp:
        tmp = i
        tmp_arr.append(tmp_num)
        tmp_num = 1
    else:
        tmp_num += 1
tmp_arr.append(tmp_num)
res = 0
for i in tmp_arr:
    res += p2(i)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
a = [int(input()) for i in range(int(input()))]
for i in range(len(a)):
    print(max(a[:i]+a[i+1:]))


Fixed submission:
a = [int(input()) for i in range(int(input()))]
sortedA = sorted(a, reverse=True)
for i in range(len(a)):
    if a[i] == sortedA[0]:
        print(sortedA[1])
    else:
        print(sortedA[0])
Buggy python submission (verdict: Time Limit Exceeded):
lr = [int(i) for i in input().split()]
res = []
for i in range(lr[0], lr[1]+1):
    for j in range(i+1, lr[1]+1):
        res.append((i*j) % 2019)
print(min(res))


Fixed submission:
lr = [int(i) for i in input().split()]
res = []
for i in range(lr[0], lr[1]+1):
    for j in range(i+1, lr[1]+1):
        tmp = (i*j) % 2019
        if tmp == 0:
            print(0)
            exit()
        res.append(tmp)
print(min(res))
Buggy python submission (verdict: Runtime Error):
s = input().strip()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print("Bad")
        exit(1)
print("Good")


Fixed submission:
s = input().strip()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print("Bad")
        exit()
print("Good")

Buggy python submission (verdict: Runtime Error):
s = input()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print("Bad")
        exit(1)
print("Good")


Fixed submission:
s = input().strip()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print("Bad")
        exit()
print("Good")
Buggy python submission (verdict: Runtime Error):
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)

print(b-a+1 - ((b+1)//c - a//c) - ((b+1)//d - a//d) + ((b+1)//cd - a//cd))


Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)
print(b-a-(b//c-((a-1)//c + 1))-(b//d - ((a-1)//d + 1))+(b//cd-((a-1)//cd + 1)))

Buggy python submission (verdict: Runtime Error):
import math
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = (c*d)//math.gcd(c, d)
print(b-a+1 - ((b+1)//c - a//c) - ((b+1)//d - a//d) + ((b+1)//cd - a//cd))


Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)
print(b-a-(b//c-((a-1)//c + 1))-(b//d - ((a-1)//d + 1))+(b//cd-((a-1)//cd + 1)))

Buggy python submission (verdict: Runtime Error):
import math
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = (c * d) // math.gcd(c, d)
print(b-a+1 - ((b+1)//c - a//c) - ((b+1)//d - a//d) + ((b+1)//cd - a//cd))


Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)
print(b-a-(b//c-((a-1)//c + 1))-(b//d - ((a-1)//d + 1))+(b//cd-((a-1)//cd + 1)))
Buggy python submission (verdict: Runtime Error):
ap=input().split()
print((int(ap[0])＊3+int(ap[1]))//2)


Fixed submission:
ap = input().split()
print((int(ap[0])*3+int(ap[1]))//2)
Buggy python submission (verdict: Runtime Error):

args = {}

l = ["a", "b", "c", "d", "e", "k"]
for i in range(len(l)):
    args[l[i]] = int(input())


# 5-4
# 5-3
# 5-2
# 5-1

# 4-3
# 4-2
# 4-1

# 3-2
# 3-1

# 2-1

for i in range(len(l) - 1):
    j = 5-i
    for m in range(len(l) - 2):
        n = j - (m+1)
        if n <= 0:
            continue
        if l[j] - l[n] > l["k"]:
            print(':(')
            exit()
print("Yay!")


Fixed submission:
args = {}
l = ["a", "b", "c", "d", "e", "k"]
for i in range(len(l)):
    args[l[i]] = int(input())
for i in range(len(l) - 1):
    j = 5-i
    for m in range(len(l) - 2):
        n = j - (m+1)
        if n <= 0:
            continue
        if args[l[j-1]] - args[l[n-1]] > args["k"]:
            print(':(')
            exit()
print("Yay!")
Buggy python submission (verdict: Runtime Error):
N = input()
A="No"
for i in range(len(N)):
    if N[i]="7":
        A = "Yes"
        break
        
    

print(A)
  
  


Fixed submission:
N = input()
A="No"
for i in range(len(N)):
    if N[i]=="7":
        A = "Yes"
        break
        
    
 
print(A)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))

X.sort()

Xmin = min(X)
Xmax = max(X)

#print(Xmin,Xmax)

T =[]

for i in range(Xmin+1,Xmax+1):
    HP = 0
    for j in X:
        HP = HP + (i-j)**2
    T.append(HP)
print(min(T))

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

X.sort()

Xmin = min(X)
Xmax = max(X)

#print(Xmin,Xmax)

T =[]

for i in range(1,101):
    HP = 0
    for j in X:
        HP = HP + (i-j)**2
    T.append(HP)
print(min(T))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    P[i] = (1+P[i])/2
A = 0
for i in range(N-K+1):
    B = 0
    for j in range(i,i+K):
        B = B+P[j]
    if A < B:
        A = B
print(A)

Fixed submission:
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    P[i] = (1+P[i])/2
A = 0
for i in range(K):
    A = A+P[i]
    B = A
for i in range(1,N-K+1):
    B = B-P[i-1]+P[i+K-1]
    if A < B:
        A = B
print(A)
Buggy python submission (verdict: Runtime Error):
N = int(input())
f = 0
a = N//100
b = (N-a*100)//10
c = N-a*100-b*10
if a == 7 or b == 7 or c == 7:
    f = 1
if f == 1:
    print(Yes)
else:
    print(No)

Fixed submission:
N = int(input())
f = 0
a = N//100
b = (N-a*100)//10
c = N-a*100-b*10
if a == 7 or b == 7 or c == 7:
    f = 1
if f == 1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):


N, K = map(int, input().split())

if N > K:
    N = N - K*(N//K)

if N=K:
    print(0)
else:
    print(K-N)

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

if N > K:
    N = N - K*(N//K)

if N==K:
    print(0)
else:
    print(min(N,K-N))

Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())

k = math.gcd(N, K)

if K == 1:
    print(0)
else:
    print(k)


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

if N > K:
    N = N - K*(N//K)

if N==K:
    print(0)
else:
    print(min(N,K-N))

Buggy python submission (verdict: Runtime Error):

import math
N, K = map(int, input().split())

#M=N

#for i in range(100000):
#    M = min(N,M)
#    N = abs(N-K)

#print(M)


k = math.gcd(N, K)

if K == 1:
    print(0)
else:
    print(k)


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

if N > K:
    N = N - K*(N//K)

if N==K:
    print(0)
else:
    print(min(N,K-N))
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
N = a[0]
X = a[1]
Y = a[2]
ans = []
for k in range(1,N+1):
  ans[k] = N-k

for i in range(1,N):
  for j in range(2,N+1):
    k = min(j-i,abs(X-i)+1+abs(j-Y))
    ans[k] = ans[k]+1

for dist in ans:
  print(dist)
      




Fixed submission:
a = list(map(int,input().split()))
N = a[0]
X = a[1]
Y = a[2]
ans = list(range(N))
for k in range(1,N):
  ans[k] = 0
 
for i in range(1,N):
  for j in range(i+1,N+1):
    k = min(j-i,abs(X-i)+1+abs(j-Y))
    ans[k] = ans[k]+1
 
for t in range(1,N):
  print(ans[t])
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int, input().split())
if D<A or B<C: print("0")
elif A<C and D<B: print(D-C)
elif C<A and B<D: print(B-A)
elif D-A < B-C: print(D-A)
else: print(B-C)

Fixed submission:
N = input()
if N[0] == N[2]: print("Yes")
else: print("No")

Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int, input().split())
if D<A or B<C: print("0")
else if D-A < B-C: print(D-A)
else: print(B-C)

Fixed submission:
N = input()
if N[0] == N[2]: print("Yes")
else: print("No")

Buggy python submission (verdict: Runtime Error):
N = input()
if N[0] == N[2]: print(Yes)

Fixed submission:
N = input()
if N[0] == N[2]: print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
m,n = int(input().split())
print((m-1)*(n-1))

Fixed submission:
m,n = map(int, input().split())
print((m-1)*(n-1))
Buggy python submission (verdict: Runtime Error):
inp = input().split
A = int(inp[0])
B = int(inp[1])
if(A+B >= 10):
  print('error')
else:
  print(A+B)

Fixed submission:
inp = input().split()
A = int(inp[0])
B = int(inp[1])
if A+B >= 10:
  print('error')
else:
  print(A+B)
Buggy python submission (verdict: Runtime Error):
a = []
for _ in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

check = [[False] * 3 for _ in range(3)]

for b_one in b:
    for i in range(3):
        for j in range(3):
            if a[i][j] == b_one:
                check[i][j] = True

if check[0][0] and check[0][1] and check[0][2]:
    print('Yes')
    return
if check[1][0] and check[1][1] and check[1][2]:
    print('Yes')
    return
if check[2][0] and check[2][1] and check[2][2]:
    print('Yes')
    return
if check[0][0] and check[1][0] and check[2][0]:
    print('Yes')
    return
if check[0][1] and check[1][1] and check[2][1]:
    print('Yes')
    return
if check[0][2] and check[1][2] and check[2][2]:
    print('Yes')
    return
if check[0][0] and check[1][1] and check[2][2]:
    print('Yes')
    return
if check[0][2] and check[1][1] and check[2][0]:
    print('Yes')
    return

print('No')

Fixed submission:
def resolve():
    a = []
    for _ in range(3):
        a.append(list(map(int, input().split())))
    n = int(input())
    b = []
    for _ in range(n):
        b.append(int(input()))

    check = [[False] * 3 for _ in range(3)]

    for b_one in b:
        for i in range(3):
            for j in range(3):
                if a[i][j] == b_one:
                    check[i][j] = True

    if check[0][0] and check[0][1] and check[0][2]:
        print('Yes')
        return
    if check[1][0] and check[1][1] and check[1][2]:
        print('Yes')
        return
    if check[2][0] and check[2][1] and check[2][2]:
        print('Yes')
        return
    if check[0][0] and check[1][0] and check[2][0]:
        print('Yes')
        return
    if check[0][1] and check[1][1] and check[2][1]:
        print('Yes')
        return
    if check[0][2] and check[1][2] and check[2][2]:
        print('Yes')
        return
    if check[0][0] and check[1][1] and check[2][2]:
        print('Yes')
        return
    if check[0][2] and check[1][1] and check[2][0]:
        print('Yes')
        return

    print('No')

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
k = min(k, n - 1)
p = 10 ** 9 + 7
size = n * 2
f_list = [1] * size
for i in range(1, size):
    f_list[i] = (f_list[i - 1] * i) % p

def cmb(n, r):
    return f_list[n] * pow(f_list[r], p-2, p) * pow(f_list[n - r], p-2, p) % p

# 初期値は0人の部屋が0個の場合
ans = 1
for i in range(1, k + 1):
    ans += cmb(n, i) * cmb(n - 1, i)
    ans = ans % p
print(ans)

Fixed submission:
n, k = map(int, input().split())
k = min(k, n - 1)
p = 10 ** 9 + 7
size = n + 100
f_list = [1] * size
if_list = [1] * size
for i in range(1, size):
    f_list[i] = (f_list[i - 1] * i) % p
    if_list[i] = pow(f_list[i], p-2, p)

def cmb(n, r):
    return f_list[n] * if_list[r] * if_list[n-r] % p

# 初期値は0人の部屋が0個の場合
ans = 1
for i in range(1, k + 1):
    ans += cmb(n, i) * cmb(n - 1, i)
    ans = ans % p
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
s.reverse()
s.append('0')

dp = [[1000000000] * 2 for _ in range(1000005)]
dp[0][0] = 0
n = len(s)
for i in range(n):
    for j in range(2):
        x = int(s[i])
        x += j
        if x < 10:
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)
        if x > 0:
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))

ans = dp[n][0]
print(ans)

Fixed submission:
s = list(input())
s.reverse()
s.append('0')

dp = [[1000000000] * 2 for _ in range(1000005)]
dp[0][0] = 0
n = len(s)
for i in range(n):
    for j in range(2):
        x = int(s[i])
        x += j
        if x < 10:
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)
        if x > 0:
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))

ans = dp[n][0]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
s.reverse()
s.append('0')

dp = [[1000000000] * 2 for _ in range(1000005)]
dp[0][0] = 0
n = len(s)
for i in range(n):
    for j in range(2):
        x = int(s[i])
        x += j
        for a in range(10):
            nj = 0
            otsuri = a - x
            if otsuri < 0:
                nj = 1
                otsuri += 10
            dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + a + otsuri)

ans = dp[n][0]
print(ans)

Fixed submission:
s = list(input())
s.reverse()
s.append('0')

dp = [[1000000000] * 2 for _ in range(1000005)]
dp[0][0] = 0
n = len(s)
for i in range(n):
    for j in range(2):
        x = int(s[i])
        x += j
        if x < 10:
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)
        if x > 0:
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))

ans = dp[n][0]
print(ans)
Buggy python submission (verdict: Runtime Error):
import copy
n = input()
k = int(input())

n_list = []
for a in n:
    n_list.append(int(a))
n_num = len(n_list)

dp = [[0] * 2 for _ in range(n_num)]
dp[0][0] = 1
for i in range(n_num):
    nxt = [[0] * 2 for _ in range(n_num + 1)]
    for j in range(n_num):
        for l in range(2):
            lim = 9 if l else n_list[i]
            for x in range(lim + 1):
                if x != 0:
                    ns = j + 1
                else:
                    ns = j
                nlt = l | (x < n_list[i])
                nxt[ns][nlt] += dp[j][l]
    dp = copy.deepcopy(nxt)
ans = dp[k][0] + dp[k][1]
print(ans)

Fixed submission:
s, t = input().split()
a, b = map(int, input().split())
u = input()

if u == s:
    a -= 1
elif u == t:
    b -= 1

print('{0} {1}'.format(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)

a_max = 10000
dp_max = 100000000
dp = [dp_max] * (h + a_max + 1)
dp[0] = 0

for i in range(h):
    if dp[i] == dp_max:
        continue
    for j in range(n):
        a_current = a[j]
        b_current = b[j]
        if dp[i] + b_current < dp[i + a_current]:
            dp[i + a_current] = dp[i] + b_current

dp_min = dp_max
for i in range(h, h + a_max + 1):
    if dp[i] < dp_min:
        dp_min = dp[i]

print(dp_min)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)

a_max = 10000
dp_max = 100000000
dp = [dp_max] * (h + a_max + 1)
dp[0] = 0

for i in range(h):
    if dp[i] == dp_max:
        continue
    for j in range(n):
        a_current = a[j]
        b_current = b[j]
        if dp[i] + b_current < dp[i + a_current]:
            dp[i + a_current] = dp[i] + b_current

dp_min = dp_max
for i in range(h, h + a_max + 1):
    if dp[i] < dp_min:
        dp_min = dp[i]

print(dp_min)

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)

a_max = max(a)
dp_max = 100000000
dp = [dp_max] * (h + a_max + 1)
dp[0] = 0

for i in range(h):
    if dp[i] == dp_max:
        continue
    for j in range(n):
        a_current = a[j]
        b_current = b[j]
        if dp[i] + b_current < dp[i + a_current]:
            dp[i + a_current] = dp[i] + b_current

dp_min = dp_max
for i in range(h, h + a_max + 1):
    if dp[i] < dp_min:
        dp_min = dp[i]

print(dp_min)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)

a_max = 10000
dp_max = 100000000
dp = [dp_max] * (h + a_max + 1)
dp[0] = 0

for i in range(h):
    if dp[i] == dp_max:
        continue
    for j in range(n):
        a_current = a[j]
        b_current = b[j]
        if dp[i] + b_current < dp[i + a_current]:
            dp[i + a_current] = dp[i] + b_current

dp_min = dp_max
for i in range(h, h + a_max + 1):
    if dp[i] < dp_min:
        dp_min = dp[i]

print(dp_min)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
robot = []
for _ in range(n):
    x, l = map(int, input().split())
    arm_left = x - l
    arm_right = x + l
    robot.append([arm_left, arm_right])

robot.sort(key=lambda x: x[1])
count = 0
while True:
    if len(robot) == 0:
        break
    count += 1
    current_right = robot[0][1]
    robot = [i for i in robot if i[0] >= current_right]

print(count)

Fixed submission:
n = int(input())
robot = []
for _ in range(n):
    x, l = map(int, input().split())
    arm_left = x - l
    arm_right = x + l
    robot.append([arm_left, arm_right])

robot.sort(key=lambda x: x[1])
count = 0
current_right = -1000000000
for i in range(n):
    if robot[i][0] >= current_right:
        count += 1
        current_right = robot[i][1]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
robot = []
for _ in range(n):
    x, l = map(int, input().split())
    arm_left = x - l
    arm_right = x + l
    robot.append([arm_left, arm_right])

robot.sort(key=lambda x: x[1])
count = 0
while True:
    if len(robot) == 0:
        break
    count += 1
    current_right = robot[0][1]
    robot = [i for i in robot if i[0] >= current_right]

print(count)

Fixed submission:
n = int(input())
robot = []
for _ in range(n):
    x, l = map(int, input().split())
    arm_left = x - l
    arm_right = x + l
    robot.append([arm_left, arm_right])

robot.sort(key=lambda x: x[1])
count = 0
current_right = -1000000000
for i in range(n):
    if robot[i][0] >= current_right:
        count += 1
        current_right = robot[i][1]

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
sys.setrecursionlimit(1000000)
h, w = map(int, input().split())
field = []
for _ in range(h):
    field.append(list(input()))

dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]
distance = [[-1] * w for i in range(h)]

que = deque([])
for y in range(h):
    for x in range(w):
        if field[y][x] == '.':
            continue
        que.append([y, x])
        distance[y][x] = 0

while que:
    q = que.popleft()
    for i in range(4):
        now_y = q[0] + dy[i]
        now_x = q[1] + dx[i]
        if now_y < 0 or now_y >= h or now_x < 0 or now_x >= w or field[now_y][now_x] == '#':
            continue
        if distance[now_y][now_x] != -1:
            continue
        que.append([now_y, now_x])
        distance[now_y][now_x] = distance[q[0]][q[1]] + 1

draw_count = 0
for y in range(h):
    for x in range(w):
        draw_count = max(draw_count, distance[y][x])
print(draw_count)

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(1000000)
h, w = map(int, input().split())
field = []
for _ in range(h):
    field.append(list(input()))

dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]
distance = [[-1] * w for i in range(h)]

que = deque([])
for y in range(h):
    for x in range(w):
        if field[y][x] == '.':
            continue
        que.append([y, x])
        distance[y][x] = 0

while que:
    q = que.popleft()
    for i in range(4):
        now_y = q[0] + dy[i]
        now_x = q[1] + dx[i]
        if now_y < 0 or now_y >= h or now_x < 0 or now_x >= w or field[now_y][now_x] == '#':
            continue
        if distance[now_y][now_x] != -1:
            continue
        que.append([now_y, now_x])
        distance[now_y][now_x] = distance[q[0]][q[1]] + 1

draw_count = 0
for y in range(h):
    for x in range(w):
        draw_count = max(draw_count, distance[y][x])
print(draw_count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

# 累積和を求めておく
cumsum_e = 0
cumsum_w = 0
for i in range(n):
    if s[i] == 'E':
        cumsum_e += 1
    else:
        cumsum_w += 1

min_change = n + 1
for i in range(n):
    temp_change = 0
    if s[i] == 'E':
        temp_cumsum_e = cumsum_e - 1
        temp_cumsum_w = cumsum_w
    else:
        temp_cumsum_e = cumsum_e
        temp_cumsum_w = cumsum_w - 1

    current_w = 0
    current_e = 0
    for j in range(i):
        if s[j] == 'W':
            current_w += 1

    current_e = i - current_w
    migi_e = temp_cumsum_e - current_e
    temp_change = current_w + migi_e

    if temp_change < min_change:
        min_change = temp_change

print(min_change)

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

# 累積和を求めておく
cumsum_e = 0
cumsum_w = 0
for i in range(n):
    if s[i] == 'E':
        cumsum_e += 1
    else:
        cumsum_w += 1

min_change = n + 1
current_e = 0
current_w = 0
for i in range(n):
    temp_change = 0
    migi_e = cumsum_e - current_e
    if s[i] == 'E':
        migi_e -= 1
    temp_change = current_w + migi_e

    if temp_change < min_change:
        min_change = temp_change

    if s[i] == 'E':
        current_e += 1
    else:
        current_w += 1

print(min_change)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

min_change = n + 1
for i in range(n):
    temp_change = 0
    for j in range(i - 1):
        if s[j] == 'W':
            temp_change += 1
    for k in range(i + 1, n, 1):
        if s[k] == 'E':
            temp_change += 1
    if temp_change < min_change:
        min_change = temp_change

print(min_change)

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

# 累積和を求めておく
cumsum_e = 0
cumsum_w = 0
for i in range(n):
    if s[i] == 'E':
        cumsum_e += 1
    else:
        cumsum_w += 1

min_change = n + 1
current_e = 0
current_w = 0
for i in range(n):
    temp_change = 0
    migi_e = cumsum_e - current_e
    if s[i] == 'E':
        migi_e -= 1
    temp_change = current_w + migi_e

    if temp_change < min_change:
        min_change = temp_change

    if s[i] == 'E':
        current_e += 1
    else:
        current_w += 1

print(min_change)