Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100
vs = set()
vs.add(0)
dp[0] = 0

for i in range(N):
    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()
    for vv in list(vs):
        if dp[vv + v] > dp[vv] + w:
            # print(
            #     "(w,v)=({0},{1}): dp[{2}]:{3} dp[{4}]:{5} --> {6}".format(w, v, vv, dp[vv], vv + v, dp[vv + v],
            #                                                                dp[vv] + w))
            tmpDP[vv + v] = dp[vv] + w
            vs.add(vv + v)
    dp = tmpDP

# for i in range(len(dp)):
#     if dp[i] < float('inf'):
#         print("{}, {}".format(i, dp[i]))

ans = 0
for v in list(vs):
    # print("{}, {}".format(v, dp[v]))
    if dp[v] <= W:
        ans = max(ans, v)
print(ans)


Fixed submission:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100*10
vs = set()
vs.add(0)
dp[0] = 0

for i in range(N):
    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()
    for vv in list(vs):
        if dp[vv + v] > dp[vv] + w:
            tmpDP[vv + v] = dp[vv] + w
            vs.add(vv + v)
    dp = tmpDP


ans = 0
for v in list(vs):
    if dp[v] <= W:
        ans = max(ans, v)
print(ans)
Buggy python submission (verdict: Runtime Error):



import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

N = int(input())
S = input()
Q = int(input())
K = [int(x) for x in input().split()]


for k in K:
    ret = 0
    d = 0
    m = 0
    dm = 0

    for i in range(N):
        s = S[i]

        if s == "C":
            ret += dm

        if s == "D":
            d += 1
        elif s == "M":
            m += 1
            dm += d

        j = i - k + 1
        if j >= 0:
            s2 = S[j]
            if s2 == "D":
                d -= 1
                dm -= m
            elif s2 == "M":
                m -= 1
    print(ret)



sys.exit(0)

Fixed submission:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N = int(input())
A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

ave = sum(A)/N

d = [abs(a - ave) for a in A]
mi = min(d)

for i in range(N):
    if d[i] == mi:
        print(i)
        sys.exit(0)

sys.exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
import bisect


MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]

# KenList = [{} for _ in range(N)]
KenList = [[] for _ in range(N)]


PYlist = [None] * M
for i in range(M):
    P, Y = [int(x) for x in input().split()]
    P = P - 1
    PYlist[i] = (P, Y)
    KenList[P].append((i, Y))


for i in range(N):
    KenList[i] = sorted(KenList[i], key=lambda x: x[1])

for i in range(M):
    ken = PYlist[i][0]
    idx = 0
    kl = KenList[ken]
    for j in range(len(kl)):
        if kl[j][0] == i:
            idx = j
            break
    print("{0:06d}{1:06d}".format(ken+1, idx+1))


sys.exit(0)


Fixed submission:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
import bisect


MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]

KenList = [[] for _ in range(N)]

PYlist = [None] * M
for i in range(M):
    P, Y = [int(x) for x in input().split()]
    P = P - 1
    PYlist[i] = (P, Y)
    KenList[P].append((i, Y))


for i in range(N):
    KenList[i] = sorted(KenList[i], key=lambda x: x[1])

cityOrder = [None] * N
for i in range(N):
    kl = KenList[i]
    dic = {}
    for j in range(len(kl)):
        city = kl[j][0]
        dic[city] = j
    cityOrder[i] = dic


for i in range(M):
    ken = PYlist[i][0]
    kl = KenList[ken]
    idx = cityOrder[ken][i]
    # for j in range(len(kl)):
    #     if kl[j][0] == i:
    #         idx = j
    #         break

    print("{0:06d}{1:06d}".format(ken+1, idx+1))


sys.exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))

'''
def calcCenterHeight(X, Y, Cx, Cy, Ch):
    return Ch + abs(X - Cx) + abs(Y - Cy)
'''


def calcCenterHeight(X, Y, Cx, Cy, Ch):
    s = set()
    H = Ch + abs(X - Cx) + abs(Y - Cy)
    s.add(H)
    if Ch == 0:
        for h in range(0, H):
            s.add(h)
    return s


from functools import reduce

for X in range(0, 101):
    for Y in range(0, 101):
        s = [calcCenterHeight(X, Y, Cx, Cy, Ch) for Cx, Cy, Ch in list]
        a = reduce(lambda a, b: a & b, s)
        # print(X, Y, s, a)
        if len(a) == 1:
            print(X, Y, a.pop())
            exit


Fixed submission:
import sys

N = int(input())

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))
    # if (h != 0):
    # list.append((x, y, h))

for X in range(0, 101):
    for Y in range(0, 101):
        b = True
        H = 0
        for Cx, Cy, Ch in list:
            if Ch != 0:
                H = Ch + abs(X - Cx) + abs(Y - Cy)
        for Cx, Cy, Ch in list:
            h = max(H - abs(X - Cx) - abs(Y - Cy), 0)
            if Ch != h:
                b = False
        if b == True:
            print(X, Y, H)
            sys.exit(0)

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

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))

'''
def calcCenterHeight(X, Y, Cx, Cy, Ch):
    return Ch + abs(X - Cx) + abs(Y - Cy)
'''


def calcCenterHeight(X, Y, Cx, Cy, Ch):
    s = set()
    H = Ch + abs(X - Cx) + abs(Y - Cy)
    s.add(H)
    if Ch == 0:
        for h in range(0, H):
            s.add(h)
    return s


from functools import reduce

for X in range(0, 101):
    for Y in range(0, 101):
        s = [calcCenterHeight(X, Y, Cx, Cy, Ch) for Cx, Cy, Ch in list]
        a = reduce(lambda a, b: a & b, s)
        # print(X, Y, s, a)
        if len(a) == 1:
            print(X, Y, a.pop())


Fixed submission:
import sys

N = int(input())

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))
    # if (h != 0):
    # list.append((x, y, h))

for X in range(0, 101):
    for Y in range(0, 101):
        b = True
        H = 0
        for Cx, Cy, Ch in list:
            if Ch != 0:
                H = Ch + abs(X - Cx) + abs(Y - Cy)
        for Cx, Cy, Ch in list:
            h = max(H - abs(X - Cx) - abs(Y - Cy), 0)
            if Ch != h:
                b = False
        if b == True:
            print(X, Y, H)
            sys.exit(0)
Buggy python submission (verdict: Runtime Error):
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque

MOD = 10 ** 9 + 7

N = int(input())

XY = []
for _ in range(N):
    X, Y = [int(x) for x in input().split()]
    XY.append((X, Y))


ma = 0
even = odd = 0
for xy in XY:
    s = xy[0] + xy[1]
    ma = max(s, ma)
    if s % 2:
        even += 1
    else:
        odd += 1

if not (even == N or odd == N):
    print(-1)
    sys.exit(0)

print(ma)
print(" ".join(map(str, [1] * ma)))

for xy in XY:
    x = xy[0]
    y = xy[1]

    cu = cd = cr = cl = 0
    if x < 0:
        cl = abs(x)
    else:
        cr = abs(x)
    if y < 0:
        cd = abs(y)
    else:
        cu = abs(y)
    s = ma - sum([cl, cr, cd, cu])
    cl = cl + s // 2
    cr = cr + s // 2

    print("{}{}{}{}".format("L"*cl, "R"*cr, "D"*cd, "U"*cu))

sys.exit(0)


Fixed submission:
import sys


# 一つ前の座標と、方向を返す
def f(x, y, i):
    d = 1 << i
    if y > x and y > -x:
        return x, y - d, "U"
    elif y < x and y > -x:
        return x - d, y, "R"
    elif y < x and y < -x:
        return x, y + d, "D"
    else:
        return x + d, y, "L"


N = int(input())
X = []
Y = []
mx = 0
for i in range(N):
    x, y = [int(x) for x in input().split()]
    mx = max(abs(x) + abs(y), mx)
    X.append(x)
    Y.append(y)

s = (X[0] + Y[0]) % 2
for i in range(N):
    if s != (X[i] + Y[i]) % 2:
        print(-1)
        sys.exit(0)

# s == 1 のとき：D:[1,2,4,8,...]
# s == 0 のとき：D:[1,1,2,4,8,...]

if s == 0:
    X = [x - 1 for x in X]

D = []
d = 1
while d < mx:
    D.append(d)
    d = d * 2

m = len(D)
print(m if s != 0 else m + 1)
if s == 0:
    D = [1] + D
print(" ".join([str(d) for d in D]))

for i in range(N):
    x, y = X[i], Y[i]
    dirs = []
    for j in range(m - 1, -1, -1):
        x, y, dir = f(x, y, j)
        dirs.append(dir)
    if s == 0:
        dirs.append("R")
    print("".join(dirs[::-1]))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


SS = stdin.readline().rstrip()
TT = stdin.readline().rstrip()

S = list(SS)
T = list(TT)

N = len(S)

ret = "Yes"

for i in range(0, N):
    if ret == "No":
        break

    for j in range(i+1, N):
        if S[i] == S[j]:
            if T[i] != T[j]:
                ret = "No"
        if T[i] == T[j]:
            if S[i] != S[j]:
                ret = "No"

print(ret)

Fixed submission:
S = input()
T = input()

d1 = dict()
d2 = dict()

ret = "Yes"

for s, t in zip(S, T):
    #print("{}-->{}".format(s, t))
    tmp1 = d1.get(s, None)
    tmp2 = d2.get(t, None)
    if (tmp1 == None or tmp1 == t) and (tmp2 == None or tmp2 == s):
        d1[s] = t
        d2[t] = s
    else:
        ret = "No"

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


S = stdin.readline().rstrip()
T = stdin.readline().rstrip()

N = len(S)

ret = "Yes"

for i in range(0, N):
    if ret == "No":
        break

    for j in range(i+1, N):
        if S[i] == S[j]:
            if T[i] != T[j]:
                ret = "No"
        if T[i] == T[j]:
            if S[i] != S[j]:
                # print("type2:",i,j, S[j],T[j])
                ret = "No"

print(ret)

Fixed submission:
S = input()
T = input()

d1 = dict()
d2 = dict()

ret = "Yes"

for s, t in zip(S, T):
    #print("{}-->{}".format(s, t))
    tmp1 = d1.get(s, None)
    tmp2 = d2.get(t, None)
    if (tmp1 == None or tmp1 == t) and (tmp2 == None or tmp2 == s):
        d1[s] = t
        d2[t] = s
    else:
        ret = "No"

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


S = stdin.readline().rstrip()
T = stdin.readline().rstrip()

N = len(S)

ret = "Yes"

for i in range(0, N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            if T[i] != T[j]:
                # print("type1:",i,j, S[j],T[j])
                ret = "No"
        if T[i] == T[j]:
            if S[i] != S[j]:
                # print("type2:",i,j, S[j],T[j])
                ret = "No"

print(ret)


Fixed submission:
S = input()
T = input()

d1 = dict()
d2 = dict()

ret = "Yes"

for s, t in zip(S, T):
    #print("{}-->{}".format(s, t))
    tmp1 = d1.get(s, None)
    tmp2 = d2.get(t, None)
    if (tmp1 == None or tmp1 == t) and (tmp2 == None or tmp2 == s):
        d1[s] = t
        d2[t] = s
    else:
        ret = "No"

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
# import math


def make_divisor_list(num):
    if num <= 0:
        # return []
        return make_divisor_list(-num)
    elif num == 1:
        return [1]
    else:
        divisor_list = [1]
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
        return divisor_list


# print(make_divisor_list(24))

N, X = [int(x) for x in input().split()]
xlist = [int(x) for x in input().split()]

# print(xlist)

shiftedX = [x - X for x in xlist]

# print(shiftedX)

divisor_set_list = [set(make_divisor_list(x)) for x in shiftedX]
# print(divisor_set_list)

div_set = divisor_set_list[0]

for s in divisor_set_list:
    div_set = div_set & s

# print(div_set)

print(max(div_set))


Fixed submission:
# import math


def gcd(a, b):
    a = abs(a)
    b = abs(b)
    if b > a:
        return gcd(b, a)
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

# print(make_divisor_list(24))


N, X = [int(x) for x in input().split()]
xlist = [int(x) for x in input().split()]

# print(xlist)

shiftedX = [x - X for x in xlist]

# print(shiftedX)

maxDivisor = shiftedX[0]
for n in shiftedX:
    maxDivisor = gcd(maxDivisor, n)

print(maxDivisor)
Buggy python submission (verdict: Runtime Error):

def next(i, j):
    nextI = i
    nextJ = j
    if i % 2 == 0:
        nextJ = j + 1
    else:
        nextJ = j - 1
    if nextJ < 0 or nextJ >= W:
        nextJ = J
        nextI = i+1
    return nextI, nextJ


H, W = [int(x) for x in input().split()]
a = []
for n in range(0, H):
    a.append([int(x) for x in input().split()])


isFinded = (a[0][0] % 2 == 1)

cI, cJ = 0, 0
for n in range(0, H*W-1):
    nextI, nextJ = next(cI, cJ)
    if (isFinded):
        print("{},{},{},{}".format(cI, cJ, nextI, nextJ))
    if (a[nextI][nextJ] % 2 == 1):
        isFinded = not (isFinded)
    cI, nJ = nextI, nextJ


'''
print(next(0, 0))
print(next(0, 2))
print(next(1, 1))
print(next(1, 0))
print(next(2, 2))
'''


Fixed submission:

def next(i, j):
    nextI = i
    nextJ = j
    if i % 2 == 0:
        nextJ = j + 1
    else:
        nextJ = j - 1
    if nextJ < 0 or nextJ >= W:
        nextJ = j
        nextI = i+1
    return nextI, nextJ


H, W = [int(x) for x in input().split()]
a = []
for n in range(0, H):
    a.append([int(x) for x in input().split()])


isFinded = (a[0][0] % 2 == 1)
cI, cJ = 0, 0

list = []
for n in range(0, H*W-1):
    nextI, nextJ = next(cI, cJ)
    if (isFinded):
        # print("{},{},{},{}".format(cI+1, cJ+1, nextI+1, nextJ+1))
        list.append("{} {} {} {}".format(cI+1, cJ+1, nextI+1, nextJ+1))
    if (a[nextI][nextJ] % 2 == 1):
        isFinded = not (isFinded)
    cI = nextI
    cJ = nextJ

print(len(list))
for l in list:
    print(l)
Buggy python submission (verdict: Runtime Error):
import sys

N, K = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]

r = 0
for idx, xi in enumerate(x):
    r = idx


list = []

S = r - K
if x[r] == 0:
    S += 1
S = max(S, 0)

for s in range(S, r+1):
    e = s + K - 1
    if len(x) <= e:
        break
    list.append(abs(x[e] - x[s]) + abs(x[s]))
    list.append(abs(x[e] - x[s]) + abs(x[e]))

print(min(list))

sys.exit(0)


Fixed submission:
N, i = [int(x) for x in input().split()]

print(N - i + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, M = [int(x) for x in input().split()]
AB = []
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a - 1, b - 2))

AB.sort(key=lambda x: -x[0])

cnt = 0
while len(AB) != 0:
    cut = AB[0][0]
    # print("AB:{}, cut:{}".format(AB, cut))
    # print(AB)
    newAB = []
    for (a,b) in AB:
        if a <= cut and cut <= b:
            pass
        else:
            newAB.append((a, b))
    AB = newAB
    cnt += 1

print(cnt)


Fixed submission:
N, M = [int(x) for x in input().split()]

AB = []
for i in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a, b))

AB.sort(key=lambda x: x[1])

ans = 0
while len(AB) != 0:
    cut = AB[0][1]
    newAB = []
    ans += 1
    for a, b in AB:
        if a < cut:
            pass
        else:
            newAB.append((a, b))
    AB = newAB

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(x) for x in input().split()]

AB = []
for i in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a, b))

AB.sort(key=lambda x: x[1])

ans = 0
while len(AB) != 0:
    cut = AB[0][1]
    newAB = []
    ans += 1
    for a, b in AB:
        if a < cut:
            pass
        else:
            newAB.append((a, b))
    AB = newAB

print(ans)


Fixed submission:
N, M = [int(x) for x in input().split()]

AB = []
for i in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a, b))

AB.sort(key=lambda x: x[1])

ans = 0
while len(AB) != 0:
    cut = AB[0][1]
    newAB = []
    ans += 1
    for a, b in AB:
        if a < cut:
            pass
        else:
            newAB.append((a, b))
    AB = newAB

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]

A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

i1 = int(N/2) - 1
i2 = int(N/2)


b1 = B[i1]
b2 = B[i2]


def calcSad(A2, b):
    sum = 0
    for i in A2:
        sum += abs(i - b)
    return sum


sum = 99999999999999999999999
for b in range(b1, b2+1):
    s = calcSad(B, b)
    sum = min(sum, s)

print(sum)


sys.exit(0)


Fixed submission:
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]
A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

b = B[int(N/2)]


A3 = [abs(a - b) for a in A2]

print(sum(A3))


sys.exit(0)

Buggy python submission (verdict: Runtime Error):
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]

A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

i1 = math.floor(N / 2)
i2 = math.ceil(N / 2)


b1 = B[i1]
b2 = B[i2]


def calcSad(A2, b):
    sum = 0
    for i in A2:
        sum += abs(i - b)
    return sum


sum = 99999999999999999999999
for b in range(b1, b2+1):
    s = calcSad(B, b)
    sum = min(sum, s)

print(sum)


sys.exit(0)


Fixed submission:
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]
A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

b = B[int(N/2)]


A3 = [abs(a - b) for a in A2]

print(sum(A3))


sys.exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
V = []
for i in range(1, 150):
    for j in range(15):
        val = str(i) + '9' * j
        V.append(int(val))
V = list(set(V))
V.sort()
# print(V)


# メモ化再起
from functools import lru_cache
@lru_cache(maxsize=10000000)
def f(n):
    s = sum([int(x) for x in list(str(n))])
    return n / s

ret = []
for n in range(len(V)):
    isOK = True
    for m in range(n + 1, len(V)):
        if f(V[n]) > f(V[m]):
            isOK = False
            break
    if isOK:
        ret.append(str(V[n]))

print(" ".join(ret[:K]))


Fixed submission:
K = int(input())
V = []
for i in range(1, 150):
    for j in range(15):
        val = str(i) + '9' * j
        V.append(int(val))
V = list(set(V))
V.sort()
# print(V)


# メモ化再起
from functools import lru_cache
@lru_cache(maxsize=10000000)
def f(n):
    s = sum([int(x) for x in list(str(n))])
    return n / s

ret = []
for n in range(len(V)):
    isOK = True
    for m in range(n + 1, len(V)):
        if f(V[n]) > f(V[m]):
            isOK = False
            break
    if isOK:
        ret.append(str(V[n]))

print(" ".join(ret[:K]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

from itertools import accumulate

B = list(accumulate(A, lambda a, b: a + b))
C = list(accumulate(A, lambda a, b: a ^ b))

ans = 0
for l in range(0, N):
    for r in range(l, N):
        bsum = B[r] - B[l - 1] if l != 0 else B[r]
        csum = C[r] ^ C[l - 1] if l != 0 else C[r]
        if bsum == csum:
            ans += 1

print(ans)



Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

ans_plus = ans = 0
l = r = 0
sum = A[0]
xorsum = A[0]

while 1:
    if sum == xorsum:
        ans_plus += 1
        ans += ans_plus
        if r == N - 1:
            break
        else:
            r += 1
        sum += A[r]
        xorsum ^= A[r]
    else:
        ans_plus -= 1
        sum -= A[l]
        xorsum ^= A[l]
        l += 1

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

ret = 10**10

for leader in range(len(S)):
    leftW = S[0:leader].count("W")
    rightE = S[leader+1:len(S)].count("E")
    # print("{}, {}".format(leftW, rightE))
    sum = leftW + rightE
    ret = min(ret, sum)

print(ret)


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

W = [0] * (N+2)
E = [0] * (N + 2)

s = 0
e = 0
for i in range(0, N):
    if S[i] == "W":
        s += 1
    else:
        e += 1
    W[i + 1] = s
    E[i + 1] = e

ret = 10**10
for leader in range(1, N+1):
    leftW = W[leader-1]
    rightE = E[N]-E[leader]
    # print("{}, {}".format(leftW, rightE))
    sum = leftW + rightE
    ret = min(ret, sum)

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = [int(x) for x in input().split()]

X2 = sorted(X)

for i in range(0, N):
    idx = X2.index(X[i])
    if idx < N // 2:
        print(X2[N // 2])
    else:
        print(X2[N // 2 - 1])


Fixed submission:
import bisect

N = int(input())
X = [int(x) for x in input().split()]

X2 = sorted(X)

for i in range(0, N):
    # idx = X2.index(X[i])
    idx = bisect.bisect_left(X2, X[i])
    if idx < N // 2:
        print(X2[N // 2])
    else:
        print(X2[N // 2 - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import bisect

N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

BAcnt = [0] * N

for i in range(N):
    BAcnt[i] = bisect.bisect_left(A, B[i])

ret = 0
for i in range(N):
    csize = C[i]
    for j in range(N):
        bsize = B[j]
        if bsize < csize:
            ret += BAcnt[j]

print(ret)


Fixed submission:
import math
import sys
import bisect

N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

BAcnt = [0] * N


for i in range(N):
    BAcnt[i] = bisect.bisect_left(A, B[i])

BAruiseki = [0] * N
BAruiseki[0] = BAcnt[0]
for i in range(1,N):
    BAruiseki[i] = BAruiseki[i-1] + BAcnt[i]

ret = 0
for i in range(N):
    j = bisect.bisect_left(B, C[i]) - 1
    if len(BAruiseki) > j and j>=0:
        ret += BAruiseki[j]


print(ret)