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

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
 
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
 
MOD = 10 ** 9 + 7
s = input().strip()
n = len(s)
if s[-1] == "?":
    tmp = [1 for i in range(10)] + [0 for i in range(3+13*(n-1))]
 
else:
    tmp = [0 for i in range(13*n)]
    # print("-------------------")
    # print(s[-1])
    # print(int(s[-1]))
    tmp[int(s[-1])] = 1
# print(len(tmp))
keta = 1
for kt, c in enumerate(s[::-1][1:]):
    keta = (keta * 10) % 13
    
    if c != "?":
        seni = int(c) * keta
        for j in range(13):
            tmp[(j + seni) % 13 + (kt + 1) * 13] += tmp[kt * 13 + j] % MOD
    else:
        for isure in range(10):
            seni = isure * keta
            for j in range(13):
                tmp[(j + seni) % 13 + (kt + 1) * 13] += tmp[kt * 13 + j] % MOD
                # print(nw)
 
    # print(tmp[(13*kt):13*(kt+1)])
    # tmp = [num % MOD for num in nw]
    # tmp = nw
print(tmp[-8] % MOD)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

MOD = 10 ** 9 + 7
s = input().strip()
if s[-1] == "?":
    tmp = [1 for i in range(10)] + [0 for i in range(3)]

else:
    tmp = [0 for i in range(13)]
    # print("-------------------")
    # print(s[-1])
    # print(int(s[-1]))
    tmp[int(s[-1])] = 1

keta = 1
for c in s[::-1][1:]:
    keta  = (keta * 10) % 13
    nw = [0 for i in range(13)]
    if c != "?":
        seni = int(c) * keta
        for j, num in enumerate(tmp):
            nw[(j+seni)%13] += num
    else:
        for isure in range(10):
            seni = int(isure) * keta
            for j, num in enumerate(tmp):
                nw[(j + seni) % 13] += num
    # print(nw)
    tmp = [num % MOD for num in nw]
    # tmp = nw
print(nw[5] % MOD)
Problem p02977 (python)

Fixed submission:
import sys
import math

input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

n = getN() #22

dig_num = math.floor(math.log2(n + 1))  # 5
# print(dig_num)
sen_end = 2 ** (dig_num) - 1  # 15

if 2 ** (dig_num) == n or n == 1:
    print("No")
    sys.exit(0)
else:
    print("Yes")

for i in range(sen_end - 1):
    print(i+1, i+2)  # 1-2, 2-3, ..., 14-15
    print(i+1+n, i+2+n)  # 23-24, 24-25, ..., 36-37

print(n + 1, sen_end)

uni_end = n
if n % 2 == 0:
    uni_end -= 1  # 21

for i in range((uni_end - sen_end) // 2):  # 3 times
    print(1, sen_end + i * 2 + 1)  # 1-16
    print(1, sen_end + i * 2 + 2 + n)  # 1-39
    print(sen_end + i * 2 + 1 + n, sen_end + i * 2 + 2 + n)  # 38-39
    print(sen_end + i * 2 + 1, sen_end + i * 2 + 2)  # 16-17

if n % 2 == 0:
    one_count = 0
    for idx, digit in enumerate(bin(n)[2:]):
        # print(digit, one_count)
        if one_count == 0:
            # print(digit)
            if digit == "1":
                one_count += 1
        else:
            if digit == "1":
                one_goal = dig_num - idx  # second "1" from upper digit
                break

    if one_goal != 1:
        print(n, 2**one_goal)
        print(2*n, n - 2**one_goal)

    else:
        print(n, 2 ** one_goal)
        print(2 * n, 2 * n - 2 ** one_goal + 1)

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

input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

n = getN() #22

dig_num = math.floor(math.log2(n))  # 5
sen_end = 2 ** (dig_num - 1) - 1  # 15

if 2 ** dig_num == n:
    print("No")
    sys.exit(0)
else:
    print("Yes")

for i in range(sen_end):
    print(i+1, i+2)  # 1-2, 2-3, ..., 14-15
    print(i+1+n, i+2+n)  # 23-24, 24-25, ..., 36-37

print(1, sen_end)

uni_end = n
if n % 2 == 0:
    uni_end -= 1  # 21

for i in range((uni_end - sen_end) // 2):  # 3 times
    print(1, sen_end + i * 2 + 1)  # 1-16
    print(1, sen_end + i * 2 + 2 + n)  # 1-39
    print(sen_end + i * 2 + 1 + n, sen_end + i * 2 + 2 + n)  # 38-39
    print(sen_end + i * 2 + 1, sen_end + i * 2 + 2)  # 16-17

if n % 2 == 0:
    one_count = 0
    for idx, digit in enumerate(bin(n)[2:]):
        # print(digit, one_count)
        if one_count == 0:
            # print(digit)
            if digit == "1":
                one_count += 1
        else:
            if digit == "1":
                one_goal = dig_num - idx  # second "1" from upper digit
                break

    print(n, 2**one_goal)
    print(2*n, n - 2**one_goal)
Problem p02985 (python)

Fixed submission:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import deque
from sys import exit

MOD = 1000000007

n, k = getList()
if n == 1:
    print(k % MOD)
    exit()
vertex = [[] for i in range(n)]

for i in range(n-1):
    a, b = getList()
    vertex[a-1].append(b-1)
    vertex[b-1].append(a-1)

for i, v in enumerate(vertex):
    if len(v) == 1:
        root = i
        break

MOD = 1000000007

# initialize
q = deque([])
q.append(vertex[root][0])
q.append(-1)
visited = [0 for i in range(n)]
visited[root] = 1
ans = k
uni = 1
while(q):
    # print(q)
    nxt = q.popleft()

    if nxt == -1:
        uni = 2
        continue
    if visited[nxt] == 1:
        continue
    for edge in vertex[nxt]:
        if visited[edge] == 0:
            q.append(edge)
    q.append(-1)
    ans *= k - uni
    ans = ans % MOD
    uni += 1
    visited[nxt] = 1
    # print(nxt, ans)

print(ans)

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import deque

n, k = getList()

vertex = [[] for i in range(n)]

for i in range(n-1):
    a, b = getList()
    vertex[a-1].append(b-1)
    vertex[b-1].append(a-1)

for i, v in enumerate(vertex):
    if len(v) == 1:
        root = i
        break

MOD = 1000000007

# initialize
q = deque([])
q.append(vertex[root][0])
q.append(-1)
visited = [0 for i in range(n)]
visited[root] = 1
ans = k
uni = 1
while(q):
    # print(q)
    nxt = q.popleft()

    if nxt == -1:
        uni = 2
        continue
    if visited[nxt] == 1:
        continue
    for edge in vertex[nxt]:
        if visited[edge] == 0:
            q.append(edge)
    q.append(-1)
    ans *= k - uni
    ans = ans % MOD
    uni += 1
    visited[nxt] = 1
    # print(nxt, ans)

print(ans)
Problem p03006 (python)

Fixed submission:
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1
#
n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

if n == 1:
    print(1)
    import sys;sys.exit()
del kumi["00"]
print(n - max(list(kumi.values())))

# for p1 in za:
#     for p2 in za:
#         steps = []
#         if p1 == p2:
#             continue
#         xa, ya = p1
#         xb, yb = p2
#         dfx = xb - xa
#         dfy = yb - ya
#         if not (dfx or dfy):
#             continue
#         for p3 in za:
#             xc, yc = p3
#             if dfx:
#                 if (xc - xa) % dfx == 0:
#                     step = (xc - xa) // dfx
#                     if yc - ya == dfy * step:
#                         steps.append(step)
#
#             else:
#                 if xc == xa:
#                     if (yc - ya) % dfy == 0:
#                         steps.append((yc - ya) // dfy)
#         tmp = valid(steps)
#         print(p1, p2, tmp, steps)
#         if tmp > ans:
#             ans = tmp
#             if tmp == 3:
#                 print(p1, p2)
#
# print(n-ans)

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1
#
n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za[i:]):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

del kumi["00"]
print(n - max(list(kumi.values())))

# for p1 in za:
#     for p2 in za:
#         steps = []
#         if p1 == p2:
#             continue
#         xa, ya = p1
#         xb, yb = p2
#         dfx = xb - xa
#         dfy = yb - ya
#         if not (dfx or dfy):
#             continue
#         for p3 in za:
#             xc, yc = p3
#             if dfx:
#                 if (xc - xa) % dfx == 0:
#                     step = (xc - xa) // dfx
#                     if yc - ya == dfy * step:
#                         steps.append(step)
#
#             else:
#                 if xc == xa:
#                     if (yc - ya) % dfy == 0:
#                         steps.append((yc - ya) // dfy)
#         tmp = valid(steps)
#         print(p1, p2, tmp, steps)
#         if tmp > ans:
#             ans = tmp
#             if tmp == 3:
#                 print(p1, p2)
#
# print(n-ans)
Problem p03087 (python)

Fixed submission:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 998244353
def solve():
    n, q = getList()
    s = input().strip()
    acc = [0]
    tmp = 0
    pred = ""
    for c in s:
        if pred == "A" and c == "C":
            tmp += 1
        acc.append(tmp)
        pred = c

    for i in range(q):
        l, r = getList()
        print(acc[r] - acc[l])

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
n, q = list(map(int, input().split()))
s = input()
tmp = "g"
acc = []
for c in s:
  if tmp = "A":
    if c == "C":
      acc.append(acc[-1] + 1)
      tmp = "G"
    elif c == "A":
      tmp = "A"
    else;
		tmp = "G"
  else:
    if c == "A":
      tmp = "A"
      
for i in range(q):
  l,r = list(map(int, input().split()))
  print(acc[r-1] - acc[l-1])
Problem p03106 (python)

Fixed submission:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


a, b, k = list(map(int, input().split()))

div = []
tmp = 0
for i in range(1,200):
    if a % i == 0 and b % i == 0:
        div.append(i)
print(div[-k])

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

tmp = 0
for i in range(200):
  if a% i == 0 and b % i == 0:
    tmp += 1
    if tmp == k:
      print(i)
Problem p03138 (python)

Fixed submission:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class BIT():
    # A1 ... AnのBIT(1-indexed)
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (n + 2)

    # A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    # Ai += x O(logN)
    def update(self, idx, x):
        # print(idx)
        while idx <= self.n:
            # print(idx)
            self.BIT[idx] += x
            idx += idx & (-idx)
        return

    def show(self):
        print(self.BIT)


def solve():
    n, k = getList()
    lis = getList()
    ans = 0
    bind = True
    dp = [-1 ,0]
    for rui in range(50, -1, -1):
        tmp = [-1 ,0]
        tgt = pow(2, rui)
        bit = tgt & k
        u, d = 0, 0
        for num in lis:
            if num & tgt == tgt:
                u += 1
            else:
                d += 1
        # print(u, d)
        if bit == 0:
            tmp[1] = dp[1] + tgt * u
            if dp[0] != -1:
                tmp[0] = dp[0] + tgt * max(u, d)
        else:
            if dp[0] != -1:
                tmp[0] = dp[0] + tgt * max(u, d)
            tmp[0] = max(dp[1] + tgt * u, tmp[0])
            tmp[1] = dp[1] + tgt * d
        dp = tmp
        # print(dp, bit, u, d)
    print(max(dp))

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import math

nin,k = getNM()
nums = getList()
dnum = math.floor(math.log2(max(nums+[k]))) + 2

onum = [0] *dnum

for n in nums:
    for i,c in enumerate(str(bin(n))[2:][::-1]):
        if c == "1":
            onum[i] += 1


znum = [nin-x for x in onum]
ans = 0
def greedy(digit):
    tmp = 0
    for i in range(digit):
        tmp += 2**i * (max([onum[i], znum[i]]))

    return tmp

def search(digit, cur):
    if (onum[digit]>=znum[digit]):
       # print("o",digit)
        return 2**digit * onum[digit] + greedy(digit)
    if (cur < 2 ** digit):
        #print(digit)
        return 2 ** digit * onum[digit] + search(digit-1, cur)
    else:
        #print("e",digit)
        e1 = 2**digit * onum[digit] + greedy(digit)
        e2 = 2**digit * znum[digit] + search(digit-1, cur-2**digit)
        return max([e1,e2])
#print(znum)
#print(onum)
print(search(dnum-1, k))
Problem p03192 (python)

Fixed submission:
s=input()
ans=0
for moji in s:
  if moji == '2':
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
ans=0
for moji in s:
  if mojl == '2':
    ans += 1
    
print(ans)
Problem p03215 (python)

Fixed submission:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class BIT():
    # A1 ... AnのBIT(1-indexed)
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (n + 2)

    # A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    # Ai += x O(logN)
    def update(self, idx, x):
        # print(idx)
        while idx <= self.n:
            # print(idx)
            self.BIT[idx] += x
            idx += idx & (-idx)
        return

    def show(self):
        print(self.BIT)


def solve():
    n, k = getList()
    lis = [0] + getList()
    for i in range(n):
        lis[i+1] += lis[i]

    ka = []
    for i in range(n):
        for j in range(i+1, n+1):
            ka.append(lis[j]-lis[i])

    ans = 0
    for rui in range(50, -1, -1):
        ok = []
        tgt = pow(2, rui)
        for kaka in ka:
            if kaka & tgt == tgt:
                ok.append(kaka)
        if len(ok) >= k:
            ans += tgt
            ka = ok

    print(ans)





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Buggy submission (verdict: Runtime Error):
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
# import math
def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d

MOD = 10**9 + 7

def main():
    n, k = getlist()
    nums = getlist()
    acc = [0]
    tmp = 0
    for num in nums:
        tmp += num
        acc.append(tmp)

    poss = []
    for r in range(n+1):
        for l in range(r):
            poss.append(acc[r] - acc[l])

    poss.sort()
    # print(poss)
    lborder, rborder = 0, (n * (n+1)) // 2

    ans, digit = 0, math.floor(math.log2(poss[-1])) + 1
    # print(digit)
    tmp = 0

    while(digit >= 0):
        tmp += 2 ** (digit - 1)
        mid = bisect.bisect_left(poss, tmp)
        if rborder - mid >= k:
            lborder = mid
        elif mid - lborder >= k:
            rborder = mid
            tmp -= 2 ** (digit - 1)
        else:
            print(tmp - 2 ** (digit - 1))
            return

        digit -= 1

    print(tmp)


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

Fixed submission:
import  math
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

n = getN()
nums = []


for i in range(n):
  nums.append(getN())

if n == 2:
    print(abs(nums[0]-nums[1]))

if n > 2:
    half = int(math.floor(n/2))
    nums.sort()
    nums1 = nums[:half]
    nums2 = nums[half:]
    nums2[1], nums2[-1] = nums2[-1], nums2[1]

    tmp = nums2[0]
    diff = 0
    diff2 = 0
    for i in range(half):
        num = nums2[i]
        diff += abs(tmp-num)
        tmp = num

        num = nums1[i]
        diff += abs(tmp - num)
        tmp = num

    if n%2 == 1:
        diff += abs(tmp-nums2[-1])

    if n%2 == 1:
        nums1 = nums[:half+1]
        nums2 = nums[half+1:]
        nums1[0], nums1[-2] = nums1[-2], nums1[0]

        tmp = nums1[0]
        for i in range(half):
            num = nums1[i]
            diff2 += abs(tmp - num)
            tmp = num

            num = nums2[i]
            diff2 += abs(tmp - num)
            tmp = num

        diff2 += abs(tmp-nums1[-1])

    #print(nums1)
    #print(nums2)
    print(max(diff, diff2))
"""
3 4 5 9
1 1 3
"""

Buggy submission (verdict: Runtime Error):
import  math
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

n = getN()
nums = []


for i in range(n):
  nums.append(getN())

half = int(math.floor(n/2))
nums.sort()
nums1 = nums[:half]
nums2 = nums[half:]
nums2[1], nums2[-1] = nums2[-1], nums2[1]

tmp = nums2[0]
diff = 0
diff2 = 0
for i in range(half):
    num = nums2[i]
    diff += abs(tmp-num)
    tmp = num

    num = nums1[i]
    diff += abs(tmp - num)
    tmp = num

if n%2 == 1:
    diff += abs(tmp-nums2[-1])

if n%2 == 1:
    nums1 = nums[:half+1]
    nums2 = nums[half+1:]
    nums1[0], nums1[-2] = nums1[-2], nums1[0]

    tmp = nums1[0]
    for i in range(half):
        num = nums1[i]
        diff2 += abs(tmp - num)
        tmp = num

        num = nums2[i]
        diff2 += abs(tmp - num)
        tmp = num

    diff2 += abs(tmp-nums1[-1])

#print(nums1)
#print(nums2)
print(max(diff, diff2))
"""
3 4 5 9
1 1 3
"""
Problem p03309 (python)

Fixed submission:
N = int(input())
nums = input().split(" ")
nums2 = [int(x)-i-1 for i,x in enumerate(nums)]
nums2.sort()
length = len(nums2)
numpre = 0
same = 1
if length == 1:
  value = nums2[0]
 
for n,m in zip(nums2[:-1],nums2[1:]):
  if n == m:
    same += 1
  else:
    impact = same + numpre
    if impact > length-impact:
      value = n
      break
    numpre += same
    same = 1
  value = m
 
answer = 0
for i in nums2:
  answer += abs(i-value)
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = input().split(" ")
nums2 = [int(x)-i-1 for i,x in enumerate(nums)]
nums2.sort()
length = len(nums2)
numpre = 0
same = 1
for n,m in zip(nums2[:-1],nums2[1:]):
  if n == m:
    same += 1
  else:
    impact = same + numpre
    if impact > length-impact:
      value = n
      break
    numpre += same
    same = 1
  value = m

answer = 0
for i in nums2:
  answer += abs(i-value)
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = input().split(" ")
nums2 = [int(x)-i-1 for i,x in enumerate(nums)]
nums2.sort()
length = len(nums2)
numpre = 0
same = 1
for n,m in zip(nums2,nums2[1:]):
  if n == m:
    same += 1
  else:
    impact = same + numpre
    if impact > length-impact:
      value = n
      break
    numpre += same
    same = 1
answer = 0
for i in nums2:
  answer += abs(i-value)
print(answer)
Problem p03339 (python)

Fixed submission:
from collections import Counter
N = int(input())
s= input()

D = Counter(s[1:])["E"]
nums = [D]
for i in range (1,N):
    temp = nums[-1]
    if s[i-1] == "W":
        temp += 1
    if s[i] == "E":
        temp -= 1
    nums.append(temp)

print(min(nums))

Buggy submission (verdict: Runtime Error):
rom collections import Counter
N = int(input())
s= input()

D = N
for i in range(N):
    L,R = s[:i],s[i+1:]
    n1,n2 = Counter(L),Counter(R)
    num = n1["W"] + n2["E"]
    if num < D:
        D = num
print(D)