Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

count = [[100000] * W for _ in range(W)]

def dfs(h,w,p):
    if h >= H or w >= W:
        return
    else:
        if S[h][w] == ".":
            count[h][w] = min(count[h][w], p)
            dfs(h+1, w, p)
            dfs(h, w+1, p)
        else:
            count[h][w] = min(count[h][w], p+1)
            dfs(h+1, w, p+1)
            dfs(h, w+1, p+1)

dfs(0,0,0)

print(count[H-1][W-1])

Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

count = [[100000] * W for _ in range(W)]
count[0][0] = 0 if S[0][0] == "." else 1


for i in range(H):
    for j in range(W):
        if i + j == 0:
            continue
        X, Y = 10**6, 10**6
        if i > 0:
            if S[i][j] == "#" and S[i-1][j] == ".":
                X = count[i-1][j] + 1
            else:
                X = count[i-1][j]
        if j > 0:
            if S[i][j] == "#" and S[i][j-1] == ".":
                Y = count[i][j-1] + 1
            else:
                Y = count[i][j-1]
        count[i][j] = min(X, Y)

print(count[H-1][W-1])

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

count = [[100000] * W for _ in range(W)]

def dfs(h,w,p):
    if h >= H or w >= W:
        return
    else:
        if S[h][w] == ".":
            count[h][w] = min(count[h][w], p)
            dfs(h+1, w, p)
            dfs(h, w+1, p)
        else:
            count[h][w] = min(count[h][w], p+1)
            dfs(h+1, w, p+1)
            dfs(h, w+1, p+1)

dfs(0,0,0)

print(count[H-1][W-1])

Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

count = [[100000] * W for _ in range(W)]
count[0][0] = 0 if S[0][0] == "." else 1


for i in range(H):
    for j in range(W):
        if i + j == 0:
            continue
        X, Y = 10**6, 10**6
        if i > 0:
            if S[i][j] == "#" and S[i-1][j] == ".":
                X = count[i-1][j] + 1
            else:
                X = count[i-1][j]
        if j > 0:
            if S[i][j] == "#" and S[i][j-1] == ".":
                Y = count[i][j-1] + 1
            else:
                Y = count[i][j-1]
        count[i][j] = min(X, Y)

print(count[H-1][W-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = int(input())

Q = [list(input().split()) for _ in range(N)]

count = 0
c = 0
for q in Q:
    if q[0] == "1":
        count += 1
        c = count % 2
    else:
        if (c == 0 and q[1] == "1") or (c == 1 and q[1] == "2"):
            S.insert(0, q[2])
        elif (c == 0 and q[1] == "2") or (c == 1 and q[1] == "1"):
            S.append(q[2])

if count % 2  == 1:
    print("".join(S[::-1]))
else:
    print("".join(S))

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

Q = [list(input().split()) for _ in range(N)]

count = 0
c = 0

ans_append = []
ans_insert = []

for q in Q:
    if q[0] == "1":
        count += 1
        c = count % 2
    else:
        if (c == 0 and q[1] == "1") or (c == 1 and q[1] == "2"):
            ans_insert.append(q[2])
        elif (c == 0 and q[1] == "2") or (c == 1 and q[1] == "1"):
            ans_append.append(q[2])


if count % 2  == 1:
    ans = ans_append[::-1] + S[::-1] + ans_insert
    print("".join(ans))
else:
    ans = ans_insert[::-1] + S + ans_append
    print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = int(input())

Q = [list(input().split()) for _ in range(N)]
direction = 0
count = 0
for q in Q:
    if q[0] == "1":
        direction = abs(direction*1 - 1)
        count += 1
    else:
        if (direction == 0 and q[1] == "1") or (direction == 1 and q[1] == "2"):
            S.insert(0, q[2])
        elif (direction == 0 and q[1] == "2") or (direction == 1 and q[1] == "1"):
            S.append(q[2])

if count % 2  == 1:
    print("".join(S[::-1]))
else:
    print("".join(S))

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

Q = [list(input().split()) for _ in range(N)]

count = 0
c = 0

ans_append = []
ans_insert = []

for q in Q:
    if q[0] == "1":
        count += 1
        c = count % 2
    else:
        if (c == 0 and q[1] == "1") or (c == 1 and q[1] == "2"):
            ans_insert.append(q[2])
        elif (c == 0 and q[1] == "2") or (c == 1 and q[1] == "1"):
            ans_append.append(q[2])


if count % 2  == 1:
    ans = ans_append[::-1] + S[::-1] + ans_insert
    print("".join(ans))
else:
    ans = ans_insert[::-1] + S + ans_append
    print("".join(ans))
Buggy python submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())
def lcm(a, b):
    g = math.gcd(a, b)
    L = a * b // g
    return L

print(lcm(A, B))

Fixed submission:
import fractions

A, B = map(int, input().split())
def lcm(a, b):
    g = fractions.gcd(a, b)
    L = a * b // g
    return L

print(lcm(A, B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))

count = 0
for i,a in enumerate(L[:N-2]):
    for j in range(i+1, N-1):
        before = abs(a-L[j])
        after = a+L[j]
        for c in L[j+1:]:
            if before < c < after:
                count += 1

print(count)

Fixed submission:
"""
素直に実装するとN**9
"""

import bisect
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
ans = 0
for ai in range(N):
    for bi in range(ai+1, N):
        ci = bisect.bisect_left(L, L[ai]+L[bi])
        if ci > bi:
            ans += ci - bi - 1
        else:
            pass
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))

count = 0
for i,a in enumerate(L[:N-2]):
    for j in range(i+1, N-1):
        for c in L[j+1:]:
            if abs(a-L[j]) < c < a+L[j]:
                count += 1

print(count)

Fixed submission:
"""
素直に実装するとN**9
"""

import bisect
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
ans = 0
for ai in range(N):
    for bi in range(ai+1, N):
        ci = bisect.bisect_left(L, L[ai]+L[bi])
        if ci > bi:
            ans += ci - bi - 1
        else:
            pass
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
L = list(map(int, input().split()))

C = list(itertools.combinations(L, 3))

count = 0
for a,b,c in C:
    if a < b + c and b < c + a and c < b + a:
        count += 1 
    
print(count)

Fixed submission:
"""
素直に実装するとN**9
"""

import bisect
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
ans = 0
for ai in range(N):
    for bi in range(ai+1, N):
        ci = bisect.bisect_left(L, L[ai]+L[bi])
        if ci > bi:
            ans += ci - bi - 1
        else:
            pass
 
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
L = len(S)
count = 0
changed = [0]*L

i = 0
while i < L-1:
    if S[i] == S[i+1]:
        changed[i+1] = 1
        i += 2
        count += 1
    else:
        i += 1

if changed[1] == 0 and changed[L-1] == 0 and S[0] == S[L-1]:
    ans = count * K + K -1
else:
    ans = count * K


print(ans)

Fixed submission:
S = list(input())
K = int(input())

if len(set(S)) == 1:
    print((len(S)*K)//2)
    exit()

def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x

print(n_change(S) + (K-1) * (n_change(2*S) - n_change(S)))
Buggy python submission (verdict: Time Limit Exceeded):
"""
マスターオブ整数
公約数の問題
公約数とは最大公約数の約数であるという性質がある
"""
import fractions
A, B = map(int, input().split())

# まず公約数を列挙したくなる
# 最大公約数を求めてその約数を列挙する
# 最大公約数はユークリッドの互除法で求めることができる

ans = 1
gcd_value = fractions.gcd(A, B)
for i in range(2, gcd_value + 1):
    if gcd_value == 1:
        break
    if gcd_value % i == 0:
        ans += 1
        while gcd_value % i == 0:
            gcd_value //= i

# divisorリストの中からどの二つ互いに素となるようにいくつか選ぶ
# 素因数の数+1を答えれば良い

print(ans)

Fixed submission:
"""
マスターオブ整数
公約数の問題
公約数とは最大公約数の約数であるという性質がある
"""
import fractions
A, B = map(int, input().split())

# まず公約数を列挙したくなる
# 最大公約数を求めてその約数を列挙する
# 最大公約数はユークリッドの互除法で求めることができる

ans = 1
gcd_value = fractions.gcd(A, B)
for i in range(2, int(gcd_value**0.5) + 1):
    if gcd_value % i == 0:
        ans += 1
        while gcd_value % i == 0:
            gcd_value //= i

# divisorリストの中からどの二つ互いに素となるようにいくつか選ぶ
# 素因数の数+1を答えれば良い
if gcd_value != 1:
    ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
"""
マスターオブ整数
公約数の問題
公約数とは最大公約数の約数であるという性質がある
"""
import math
A, B = map(int, input().split())

# まず公約数を列挙したくなる
# 最大公約数を求めてその約数を列挙する
# 最大公約数はユークリッドの互除法で求めることができる

ans = 1
gcd_value = math.gcd(A, B)
for i in range(2, gcd_value + 1):
    if gcd_value == 1:
        break
    if gcd_value % i == 0:
        ans += 1
        while gcd_value % i == 0:
            gcd_value //= i

# divisorリストの中からどの二つ互いに素となるようにいくつか選ぶ
# 素因数の数+1を答えれば良い

print(ans)

Fixed submission:
"""
マスターオブ整数
公約数の問題
公約数とは最大公約数の約数であるという性質がある
"""
import fractions
A, B = map(int, input().split())

# まず公約数を列挙したくなる
# 最大公約数を求めてその約数を列挙する
# 最大公約数はユークリッドの互除法で求めることができる

ans = 1
gcd_value = fractions.gcd(A, B)
for i in range(2, int(gcd_value**0.5) + 1):
    if gcd_value % i == 0:
        ans += 1
        while gcd_value % i == 0:
            gcd_value //= i

# divisorリストの中からどの二つ互いに素となるようにいくつか選ぶ
# 素因数の数+1を答えれば良い
if gcd_value != 1:
    ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(1,int(input()))))

Fixed submission:
N = int(input())
print((N-1) * N // 2)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7
result = 0
count = [0] * N
for a in A:
    count[a-1] += 1
    result += K * sum(count[a:])
    result %= mod

kn = 0
total = sum(count) % mod
for i in range(N):
    total -= count[i]
    kn += total
    kn %= mod

result += kn * K*(K-1)//2
result %= 10**9 + 7

print(result)


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

mod = 10**9 + 7
result = 0
count = [0] * 2001

# リスト内での繰り返し
for a in A:
    count[a-1] += 1
    result += K * sum(count[a:])
    result %= mod

kn = 0
# 前のループに存在する自分より大きい数
count = [i for i in count if i != 0]
total = sum(count) % mod

for i in count:
    total -= i
    kn += total * i
    kn %= mod

result += kn * K*(K-1)//2
result %= 10**9 + 7

print(result)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,q=list(map(int, input().split()))
result = {i+1:0 for i in range(n)}
ar = np.eye(n)

for i in range(n-1):
    a,b = list(map(int, input().split()))
    ar[0:a,a-1:b] += 1
for i in range(q):
    a,b = list(map(int, input().split()))
    m = ar[a-1]
    for j in range(len(m)):
        if m[j] != 0:
            result[j+1] += b
        else:
            result[j+1] += 0
r = list(result.values())
res = map(str, r)
print(' '.join(res))

Fixed submission:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print('red')
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]

l = M
result = 0
while l > 0:
    index_lis = [i for i, v in enumerate(X) if v[1] == max(X, key=lambda xx: xx[1])[1]]
    if len(index_lis) >= 2:
        a = max(X, key=lambda xx: xx[index_lis][0])
    else:
        a = X[index_lis[0]]
    if a[0] > l:
        X.remove(a)
    elif a[0] <= l:
        result += a[1]
        l -= 1
        X.remove(a)
print(result)

Fixed submission:
import sys
import heapq
 
N, M = list(map(int, input().split()))
jobs = []

#上限内で報酬を得られる単発を一度リストに入れる。
for line in sys.stdin:
    A, B = map(int, line.split())
    if A > M:
        continue
    jobs.append((A, B))

#逆順にsort
jobs.sort(reverse=True)

#heatpqでpriority quene，最大値を取り出すときは-qを加えて挿入し，-1をかけて取り出す
q = []
ans = 0
#後ろの日にちから回す
for i in range(1, M + 1):
    #日数が足りる単発をheatpqのリストに加えていく
    while jobs and jobs[-1][0] <= i:
        A, B = jobs.pop()
        heapq.heappush(q, -B)
 
    if q:
        #できる仕事がある場合，最大の給料のを取り出す
        ans += -heapq.heappop(q)
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int, input().strip())
print(C-(A-B))

Fixed submission:
A,B,C = map(int, input().split())
print(C-min(A-B, C))
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())

if (a + b) % 2 != 0:
  print("IMPOSSIBLE")
else:
  print(abs((b**2-a**2)/2(a+b)))
  

Fixed submission:
a,b = map(int, input().split())
 
if (a + b) % 2 != 0:
    print("IMPOSSIBLE")
else:
    print(abs(a+b)//2)
Buggy python submission (verdict: Runtime Error):
N = input()
print(3 * N**2)

Fixed submission:
N = int(input())
print(3 * N**2)
Buggy python submission (verdict: Runtime Error):
import numpy as np
 
N, D = list(map(int, input().split()))
full_list = []
for i in range(N):
  full_list.append(list(map(int, input().split())))
 
result = 0
 
for i in range(N):
  for j in range(N-i-1):
    length = 0
    for s in range(D):
      length += (full_list[i][s] - full_list[j][s]) ** 2
    result += 1 if np.sqrt(length).is_integer() else 0
 
print(result)

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

Buggy python submission (verdict: Runtime Error):
import numpy as np
 
N, D = list(map(int, input().split()))
full_list = []
for i in range(N):
  full_list.append(list(map(int, input().split())))
 
result = 0
 
for i in range(N):
  for j in range(N-i-1):
    length = 0
    for s in range(D):
      length += (full_list[i][s] - full_list[j][s]) ** 2
    result += 1 if np.sqrt(length).is_integer() == True else 0
 
print(result)

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

Buggy python submission (verdict: Runtime Error):
ソースコード 

Copy
Copy
import numpy as np
 
N, D = list(map(int, input().split()))
full_list = []
for i in range(N):
  full_list.append(list(map(int, input().split())))
 
result = 0
 
for i in range(N):
  for j in range(N-i-1):
    length = 0
    for s in range(D):
      length += (full_list[i][s] - full_list[j][s]) ** 2
    result += 1 if np.sqrt(length).is_integer() == True else 0
 
print(result)

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

Buggy python submission (verdict: Runtime Error):
N,A,B = map(int, input())

print(min(N*A, B))

Fixed submission:
N,A,B = map(int, input().split())
 
print(min(N*A, B))
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

"""
両方に関して割り切れるものの個数から公倍数で割り切れるものを除けばいい
"""
import math

C = b//c - (a-1)//c
D = b//d - (a-1)//d

# 最小公倍数を求める
CD = math.gcd(c, d)
lcm = (c * d) // CD

G = b//lcm - (a-1)//lcm


count = C + D - G
print(b - a + 1 - count)

Fixed submission:
a, b, c, d = map(int, input().split())

"""
両方に関して割り切れるものの個数から公倍数で割り切れるものを除けばいい
"""
import fractions

C = b//c - (a-1)//c
D = b//d - (a-1)//d

# 最小公倍数を求める
CD = fractions.gcd(c, d)
lcm = (c * d) // CD

G = b//lcm - (a-1)//lcm


count = C + D - G
print(b - a + 1 - count)
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

if W / x == 2 and H / y == 2:
    print(W * H / 2, 1)
elif W == H:
    print(W * H / 2, 0)
elif W / x == 2 or H / y == 2:
    print(W * H / 2, 0 )
else:
    h = max(x, W - x)
    w = max(y, H - y)
    print(H/h * W/w /2)
    

Fixed submission:
W, H, x, y = map(int, input().split())

"""
直方体は中身を通る線で半分に割ることができる
"""

if W/2 == x and H/2 == y:
    print(W * H / 2, 1)
else:
    print(W * H / 2, 0)

Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

if W / x == 2 and H / y == 2:
    print(W * H / 2, 1)
elif W / x == 2 or H / y == 2:
    print(W * H / 2, 0 )
else:
    h = max(x, W - x)
    w = max(y, H - y)
    print(H/h * W/w /2)
    

Fixed submission:
W, H, x, y = map(int, input().split())

"""
直方体は中身を通る線で半分に割ることができる
"""

if W/2 == x and H/2 == y:
    print(W * H / 2, 1)
else:
    print(W * H / 2, 0)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

"""
DPを考える
"""

result = [0] * (N+1)
result[0] = 1
mod = 10**9 + 7
for i in range(N+1):
    if i not in A:
        if i >= 2:
            result[i] = (result[i-1] + result[i-2])%mod
        if i == 1:
            result[i] = 1

print(result[N])

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])

"""
DPを考える
"""

result = [0] * (N+1)
result[0] = 1
if 1 not in A:
    result[1] = 1
mod = 10**9 + 7
for i in range(2,N+1):
    if i not in A:
        result[i] = (result[i-1] + result[i-2])

print(result[N]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
"""
3000以下なので全探索を考える。
まず，全探索できるものは全探索から考える必要がある。
"""

count = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        n_b = (N - r*R - g*G)
        if n_b % B == 0 and n_b >= 0:
            count += 1
print(count)

Fixed submission:
R, G, B, N = map(int, input().split())
"""
3000以下なので全探索を考える。
まず，全探索できるものは全探索から考える必要がある。
オーダーを計算し，いけそうならそれで行くべき。今回は固定を順にしていくので間に合う
そこから探索する範囲を絞り込んで
"""

count = 0
for r in range(N//R+1):
    rest = N - r*R
    for g in range(rest//G+1):
        n_b = (rest - g*G)
        if n_b % B == 0 and n_b >= 0:
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

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

print(gcd(*A))

Fixed submission:
import fractions
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd_list(A))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

inf = float("INF")
dp = [inf] * N
dp[0] = 0
for i in range(N):
    for j in range(i+1,min(i+K+1, N)):
        dp[j] = min(dp[j], dp[i] + abs(H[i] - H[j]))

print(dp[N-1])

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

inf = float("INF")
dp = [inf] * N
dp[0] = 0
for i in range(N):
    for j in range(i+1,min(i+K+1, N)):
        dp[j] = min(dp[j], dp[i] + abs(H[i] - H[j]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
ans = 0

while True:
    count = 0
    for i in range(0, len(S)-1):
        if S[i] == "B" and S[i+1] == "W":
            count += 1
            S[i] = "W"
            S[i+1] = "B"
    if count > 0:
        ans += count
    else:
        print(ans)
        exit()

Fixed submission:
S = input()
ans = 0
count = [0] * len(S)
tmp = 0
for i in reversed(range(len(S))):
    if S[i] == "B":
        count[i] = tmp
    else:
        tmp += 1

print(sum(count))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
N, M = map(int, input().split())
S = input()
T = input()

G = N * M // fractions.gcd(N, M)
slist = [i*(G//N) for i in range(N)]
mlist = [i*(G//M) for i in range(M)]
sm = set(slist) & set(mlist)
for i in sm:
    si = slist.index(i)
    mi = mlist.index(i)
    if S[si] != T[mi]:
        print(-1)
        exit()

print(G)

Fixed submission:
import fractions
N, M = map(int, input().split())
S = input()
T = input()

G = N * M // fractions.gcd(N, M)
slist = [i*(G//N) for i in range(N)]
mlist = [i*(G//M) for i in range(M)]
sm = set(slist) & set(mlist)
for i in sm:
    si = slist.index(i)
    mi = mlist.index(i)
    if S[si] != T[mi]:
        print(-1)
        exit()

print(G)

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

G = N * M // math.gcd(N, M)
slist = [i*(G//N) for i in range(N)]
mlist = [i*(G//M) for i in range(M)]
sm = set(slist) & set(mlist)
for i in sm:
    si = slist.index(i)
    mi = mlist.index(i)
    if S[si] != T[mi]:
        print(-1)
        exit()

print(G)

Fixed submission:
import fractions
N, M = map(int, input().split())
S = input()
T = input()

G = N * M // fractions.gcd(N, M)
slist = [i*(G//N) for i in range(N)]
mlist = [i*(G//M) for i in range(M)]
sm = set(slist) & set(mlist)
for i in sm:
    si = slist.index(i)
    mi = mlist.index(i)
    if S[si] != T[mi]:
        print(-1)
        exit()

print(G)
Buggy python submission (verdict: Time Limit Exceeded):
"""
3*10**5
単純に両側の差を全探索だと間に合わないO(N*2)

情報を先に保存しておきそれを使う
"""

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

E_list = [0]
W_list = [0]

n = 0
for i in range(1,N):
    if S[i-1] == "W":
        n += 1
        W_list.append(n)
    else:
        W_list.append(n)

n = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        n += 1
        E_list.insert(0,n)
    else:
        E_list.insert(0,n)

ans = []
for i in range(N):
    ans.append(E_list[i] + W_list[i])
print(min(ans))


Fixed submission:
"""
3*10**5
単純に両側の差を全探索だと間に合わないO(N*2)

情報を先に保存しておきそれを使う
"""

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

E_list = [0] * N 
W_list = [0] * N

n = 0
for i in range(1,N):
    if S[i-1] == "W":
        n += 1
        W_list[i] = n
    else:
        W_list[i] = n

n = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        n += 1
        E_list[i] = n
    else:
        E_list[i] = n

print(min([e+w for e,w in zip(E_list, W_list)]))

Buggy python submission (verdict: Time Limit Exceeded):
"""
3*10**5
単純に両側の差を全探索だと間に合わないO(N*2)

情報を先に保存しておきそれを使う
"""

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

E_list = [0]
W_list = [0]

n = 0
for i in range(1,N):
    if S[i-1] == "W":
        n += 1
        W_list.append(n)
    else:
        W_list.append(n)

n = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        n += 1
        E_list.insert(0,n)
    else:
        E_list.insert(0,n)

ans = 10*6
for i in range(N):
    ans = min(E_list[i] + W_list[i], ans)

print(ans)

Fixed submission:
"""
3*10**5
単純に両側の差を全探索だと間に合わないO(N*2)

情報を先に保存しておきそれを使う
"""

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

E_list = [0] * N 
W_list = [0] * N

n = 0
for i in range(1,N):
    if S[i-1] == "W":
        n += 1
        W_list[i] = n
    else:
        W_list[i] = n

n = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        n += 1
        E_list[i] = n
    else:
        E_list[i] = n

print(min([e+w for e,w in zip(E_list, W_list)]))

Buggy python submission (verdict: Time Limit Exceeded):
"""
3*10**5
O(NlogN)まで
"""

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

count = []
for i in range(N):
    count.append(S[0:i].count("W") + S[i+1:].count("E"))

print(min(count))

Fixed submission:
"""
3*10**5
単純に両側の差を全探索だと間に合わないO(N*2)

情報を先に保存しておきそれを使う
"""

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

E_list = [0] * N 
W_list = [0] * N

n = 0
for i in range(1,N):
    if S[i-1] == "W":
        n += 1
        W_list[i] = n
    else:
        W_list[i] = n

n = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        n += 1
        E_list[i] = n
    else:
        E_list[i] = n

print(min([e+w for e,w in zip(E_list, W_list)]))
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
T = [int(input()) for _ in range(N)]

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

def lcm(L):
    return reduce(lcm_base, L, 1)

print(lcm(T))

Fixed submission:
import fractions
from functools import reduce

N = int(input())
T = [int(input()) for _ in range(N)]

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(L):
    return reduce(lcm_base, L, 1)

print(lcm(T))