Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n, m =  map(int, input().split())
py = [map(int, input().split()) for _ in range(m)]
p, y = [list(i) for i in zip(*py)]
pre = {}
for i in range(m):
    if p[i] not in pre.keys():
        pre[p[i]] = []
    pre[p[i]].append(y[i])
for i in pre.keys():
    pre[i].sort()
for i in range(m):
    print(str(p[i]*(10**6)+(pre[p[i]].index(y[i])+1)).zfill(12))

### FIXED CODE ###

import sys
n,m = map(int, sys.stdin.readline().rstrip("\n").split())
city = {}
yton = {}
for i in range(m):
    p,y = map(int, sys.stdin.readline().rstrip("\n").split())
    if p not in city.keys():
        city[p] = []
        city[p].append(y)
        yton[y] = i
    else:
        city[p].append(y)
        yton[y] = i
ans = [None]*m
for p in city.keys():
    city[p].sort()
    for i,y in enumerate(city[p]):
        ans[yton[y]] = str(p*(10**6)+i+1).zfill(12)
print(*ans, sep = '\n')
### BUGGY CODE ###

from functools import lru_cache


CHECK = False

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

MOD = 10 ** 9 + 7


@lru_cache(maxsize=None)
def modInverse(a, p):
    # Fermat's little theorem, a**(p-1) = 1 mod p
    return pow(a, p - 2, p)


fact = [1]
for i in range(1, 2 * N + 1):
    fact.append((fact[-1] * i) % MOD)


@lru_cache(maxsize=None)
def nCr(n, r, p=MOD):
    # Modulo binomial coefficients
    numerator = fact[n]
    d1 = fact[r]
    d2 = fact[n - r]
    return (numerator * modInverse(d1, p) * modInverse(d2, p)) % p


if N - 1 < K:
    # Any combo is achievable so this is stars and bars
    # N people into N rooms, which means N - 1 dividers
    stars = N
    bars = N - 1
    print(nCr(stars + bars, bars))
else:
    # Group by number of empty rooms
    # With K moves there can only be at most K empty rooms
    # Max of N - 1 empty rooms in general
    assert K + 1 <= N
    tot = 0
    for numEmpty in range(K + 1):
        way2 = nCr(N, numEmpty) * nCr(N - 1, numEmpty)
        if CHECK:

            numNonEmpty = N - numEmpty
            stars = numEmpty  # Everyone moving into an occupied room
            bars = numNonEmpty - 1
            way1 = nCr(stars + bars, bars) * nCr(N, numEmpty)
            assert way1 == way2

        tot += way2
    print(tot % MOD)


### FIXED CODE ###

from functools import lru_cache


CHECK = False

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

MOD = 10 ** 9 + 7


@lru_cache(maxsize=None)
def modInverse(a, p):
    # Fermat's little theorem, a**(p-1) = 1 mod p
    return pow(a, p - 2, p)


if N - 1 <= K or CHECK:
    fact = [1]
    for i in range(1, 2 * N + 1):
        fact.append((fact[-1] * i) % MOD)

    def nCr(n, r, p=MOD):
        # Modulo binomial coefficients
        return (fact[n] * modInverse(fact[r], p) * modInverse(fact[n - r], p)) % p


if N - 1 <= K:
    # Any combo is achievable so this is stars and bars
    # N people into N rooms, which means N - 1 dividers
    stars = N
    bars = N - 1
    print(nCr(stars + bars, bars))
else:
    # Group by number of empty rooms
    # With K moves there can only be at most K empty rooms
    # Max of N - 1 empty rooms in general
    assert K + 1 < N
    tot = 0
    comb1 = 1
    comb2 = 1
    for numEmpty in range(K + 1):
        way3 = comb1 * comb2
        if CHECK:
            numNonEmpty = N - numEmpty
            stars = numEmpty  # Everyone moving into an occupied room
            bars = numNonEmpty - 1  # Number of dividers
            way1 = nCr(stars + bars, bars) * nCr(N, numEmpty)

            way2 = nCr(N, numEmpty) * nCr(N - 1, numEmpty)

            assert way1 % MOD == way2 % MOD == way3 % MOD
        tot += way3

        j = numEmpty + 1
        invJ = modInverse(j, MOD)
        comb1 = (N + 1 - j) * comb1 * invJ % MOD
        comb2 = (N - j) * comb2 * invJ % MOD
    print(tot % MOD)
### BUGGY CODE ###

import math

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

result = 1
for A in Alist:
  result *= A

if result > 1000000000000000000:
  print("-1")
else:
  print(result)

### FIXED CODE ###

import math

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

result = 1
for A in Alist:
  result *= A
  if result > 1000000000000000000:
    if 0 in Alist:
      result = 0
    break

if result > 1000000000000000000:
  print("-1")
else:
  print(result)
### BUGGY CODE ###

N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,100):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j
for i in range(100,N // 100 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)

### FIXED CODE ###

N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,1000000):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j
for i in range(1000000,N // 1000000 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:dp[i]=0
print(dp[n])

### FIXED CODE ###

n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])#setにしないとTLEになる
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:
        dp[i]=0
print(dp[n])
# 入力
# 6 1
# 3
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
for i in range(N-K+1):
  p = P[i:i+K]
  sum_ = (sum(p)+K)/2
  if i == 0:
    ans = sum_
  else:
    if sum_ > ans:
      ans = sum_
    else:
      continue
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
if N == K:
  answer = (sum(p)+K)/2
else:
  for i in range(N-K):
    out_ += P[i+K]-P[i]
    if i == 0:
      ans = out_
    else:
      if out_ > ans:
        ans = out_
      else:
        continue
  answer = (base+ans+K)/2
print(answer)
### BUGGY CODE ###

import math

q= int(input())
lrs = [list(map(int,input().split())) for l in range(q)]

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

primes = [0]
for i in range(1,10**5+3):
    if is_prime(i):
        primes.append(1)
    else:
        primes.append(0)

like20 = [0]
for i in range(1,10**5+3):
    if primes[i] == 1 and primes[(i+1) // 2] == 1:
        like20.append(1)
    else:
        like20.append(0)

for lr in lrs:
    l = lr[0]
    r = lr[1]
    print(sum(like20[l:r+1]))
    

### FIXED CODE ###

import math

q= int(input())
lrs = [list(map(int,input().split())) for l in range(q)]

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

primes = [0]
for i in range(1,10**5+3):
    if is_prime(i):
        primes.append(1)
    else:
        primes.append(0)

like20 = [0]
for i in range(1,10**5+3):
    if primes[i] == 1 and primes[(i+1) // 2] == 1:
        like20.append(like20[i-1]+1)
    else:
        like20.append(like20[i-1])

for lr in lrs:
    print(like20[lr[1]] - like20[lr[0]-1])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if x + y + z == S:
                    cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if z >= 0 and z <= K:
                cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
li = [i for i in s]
pos = []
for i in range(len(li)-1):
    if li[i ]== "A" and li[i+1] == "C":
        pos.append(i)


for i in range(q):
    l, r = map(int, input().split())
    pos_copy=pos.copy()
    pos_copy.append(l-1)
    pos_copy.append(r-1)
    pos_copy.sort()
    print(pos_copy.index(r-1)  - pos_copy.index(l-1) - 1)


### FIXED CODE ###


n, q= map(int, input().split())
s = input()

li = [list(map(int, input().split())) for _ in range(q)]
pos = [0]*n
count=0
for i in range(1, n):   
    if s[i-1] == "A" and s[i]=="C":
        count+=1
    pos[i] = count

for i in li:
    print(pos[i[1]-1]-pos[i[0]-1])
### BUGGY CODE ###

input()
ls = tuple(map(int,input().split()))
n = 0
for i in set(ls):
    count = ls.count(i)
    if count == 0:
        pass
    elif count > i:
        n += count - i
    elif count < i:
        n += count
print(n)

### FIXED CODE ###

from collections import Counter
input()
a = map(int,input().split())

result = 0
for k, v in Counter(a).items():
    if k > v:
        result += v
    elif k < v:
        result += v-k
print(result)
### BUGGY CODE ###

# Different Strokes
n = int(input())
a, b = list(), list()
for _ in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
a_sort = sorted(a)
b_sort = sorted(b)
ans = 0
while True:
    const = b_sort.pop()
    indexes = list()
    for i in range(len(b)):
        if b[i] == const:
            indexes.append(i)
    m = 0
    ind = 0
    for i in indexes:
        if a[i] >= m:
            ind = i
            m = a[i]
    ans += m
    a_sort.remove(m)
    del a[ind]
    del b[ind]
    if not a:
        exit(print(ans))

    const = a_sort.pop()
    indexes = list()
    for i in range(len(a)):
        if a[i] == const:
            indexes.append(i)
    m = 0
    ind = 0
    for i in indexes:
        if b[i] >= m:
            ind = i
            m = b[i]
    ans -= m
    b_sort.remove(m)
    del a[ind]
    del b[ind]
    if not a:
        exit(print(ans))


### FIXED CODE ###

# Different Strokes
n = int(input())
a, b = list(), list()
ab = list()
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
    ab.append((a_, b_))
ans = 0
ab.sort(key=(lambda x: sum(x)), reverse=True)
for i, ab_ in enumerate(ab):
    if i % 2 == 0:
        ans += ab_[0]
    else:
        ans -= ab_[1]
print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
query = [input().split() for i in range(Q)]

for i in range(Q):
    print(S[int(query[i][0])-1:int(query[i][1])].count('AC'))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
query = [input().split() for i in range(Q)]
AC = [0 for i in range(N+1)]

for i in range(N):
    AC[i+1] = AC[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    L, R = int(query[i][0]), int(query[i][1])
    print(AC[R-1] - AC[L-1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=set(a)
cnt=0
for i in b:
  if i<=a.count(i):
    cnt+=(a.count(i)-i)
  else:
    cnt+=a.count(i)
print(cnt)
    


### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=set(a)
b=Counter(a)
cnt=0
for i in c:
  if i<=b[i]:
    cnt+=b[i]-i
  else:
    cnt+=b[i]
print(cnt)
### BUGGY CODE ###

import numpy as np

N = int(input())

A_list = []
B_list = []
takahashi_list = []
aoki_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
    takahashi_list.append(B - A)
    aoki_list.append(B - A)

A_list = np.array(A_list)
B_list = np.array(B_list)
takahashi_list = np.array(takahashi_list)
aoki_list = np.array(aoki_list)

takahashi_score = 0
aoki_score = 0
for i in range(N):
    if len(takahashi_list) != 0:
        dish_index = takahashi_list.argmax()
        score = A_list[dish_index]
        takahashi_score += score

        A_list = np.delete(A_list, dish_index, 0)
        B_list = np.delete(B_list, dish_index, 0)
        takahashi_list = np.delete(takahashi_list, dish_index, 0)
        aoki_list = np.delete(aoki_list, dish_index, 0)

    if len(aoki_list) != 0:
        dish_index = aoki_list.argmax()
        score = B_list[dish_index]
        aoki_score += score

        A_list = np.delete(A_list, dish_index, 0)
        B_list = np.delete(B_list, dish_index, 0)
        takahashi_list = np.delete(takahashi_list, dish_index, 0)
        aoki_list = np.delete(aoki_list, dish_index, 0)

print(takahashi_score - aoki_score)


### FIXED CODE ###

N = int(input())

A_list = []
B_list = []
dif_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
    dif_list.append(A + B)

my_list = [[dif, a, b] for dif, a, b in zip(dif_list, A_list, B_list)]
my_list.sort(reverse=True)

takahashi_score = 0
aoki_score = 0

for i, list_items in enumerate(my_list):
    a = list_items[1]
    b = list_items[2]
    if i % 2 == 0:
        takahashi_score += a
    else:
        aoki_score += b

print(takahashi_score - aoki_score)
### BUGGY CODE ###

def main():
    n = int(input())
    s = list(str(n))
    s.reverse()
    s += ['0']
    s = [int(c) for c in s]
    m = len(s)

    dp = [[10**7, 10**7] for _ in range(len(s)+5)]
    # dp[i][0]: 繰り下がりなし
    # dp[i][1]: 繰り下がりあり

    dp[0][0] = 0

    for i in range(m):
        for j in range(2):
            nd = s[i]
            if j == 1:
                nd += 1
            for a in range(10):
                ni = i+1
                nj = 0
                b = a-nd
                if b < 0:
                    nj = 1
                    b += 10
                if dp[ni][nj] >= dp[i][j]+a+b:
                    dp[ni][nj] = dp[i][j]+a+b
    #print(dp)
    print(dp[m][0])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    s = list(str(input()))
    s.reverse()
    for i in range(len(s)):
        s[i] = int(s[i])
    s += [0]
    m = len(s)

    dp = [[10**7, 10**7] for _ in range(len(s)+5)]
    # dp[i][0]: 繰り下がりなし
    # dp[i][1]: 繰り下がりあり

    dp[0][0] = 0

    for i in range(m):
        for j in range(2):
            nd = s[i]
            if j == 1:
                nd += 1
            if dp[i+1][0] >= dp[i][j]+nd:
                dp[i+1][0] = dp[i][j]+nd
            if dp[i+1][1] >= dp[i][j]+10-nd:
                dp[i+1][1] = dp[i][j]+10-nd
    #print(dp)
    print(dp[m][0])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7

D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1

for l in L[1:]:
    ND=[[0]*(X+1) for i in range(N//2+1)]

    for c in range(1,N//2+1):
        for s in range(X+1):
            if D[c][s]==0:
                continue
            
            k=D[c][s]

            if s+l+c<=X and c+1<=N//2:
                ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
            ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod

            for i in range(1,min(X-s-c+2,l+1)):
                ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod

            if c==1:
                continue

            for i in range(1,min(X-s-c+3,l+1)):
                ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
    D=ND

print(D[1][X])

### FIXED CODE ###

N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7

D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1

for l in L[1:]:
    ND=[[0]*(X+1) for i in range(N//2+1)]

    for c in range(1,N//2+1):
        for s in range(X+1):
            if D[c][s]==0:
                continue
            
            k=D[c][s]

            if s+l+c<=X and c+1<=N//2:
                ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
            ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod

            for i in range(1,min(X-s-c+2,l+1)):
                ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod

            if c==1:
                continue

            for i in range(1,min(X-s-c+3,l+1)):
                ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
    D=ND

print(D[1][X])
### BUGGY CODE ###

n, c = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]

re_lst = []
for i in reversed(range(n)):
    re_lst.append([abs(c-lst[i][0]), lst[i][1]])

r_accum = []
s = 0
for i in range(n):
    s += lst[i][1]
    r_accum.append(s)

l_accum = []
s = 0
for i in range(n):
    s += re_lst[i][1]
    l_accum.append(s)

r_max = 0
for i in range(n):
    r_max = max(r_max, r_accum[i] - lst[i][0])
    
l_max = 0
for i in range(n):
    l_max = max(l_max, l_accum[i] - re_lst[i][0])

rd_max = 0
for i in range(n):
    for j in range(n-i-1):
        pt = r_accum[i] - 2*lst[i][0]
        pt += l_accum[j] - re_lst[j][0]
        if pt > rd_max:
            rd_max = pt
            

ld_max = 0
for i in range(n):
    for j in range(n-i-1):
        pt = l_accum[i] - 2*re_lst[i][0]
        pt += r_accum[j] - lst[j][0]
        if pt > ld_max:
            ld_max = pt

print(max(r_max, l_max, rd_max, ld_max))

### FIXED CODE ###

n, c = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]

re_lst = []
for i in reversed(range(n)):
    re_lst.append([abs(c-lst[i][0]), lst[i][1]])

r_accum = []
s = 0
for i in range(n):
    s += lst[i][1]
    r_accum.append(s)

l_accum = []
s = 0
for i in range(n):
    s += re_lst[i][1]
    l_accum.append(s)

r_max = 0
r_max_lst = []
for i in range(n):
    r_max = max(r_max, r_accum[i] - lst[i][0])
    r_max_lst.append(r_max)
    
l_max = 0
l_max_lst = []
for i in range(n):
    l_max = max(l_max, l_accum[i] - re_lst[i][0])
    l_max_lst.append(l_max)

rd_max = 0
for i in range(n-1):
    pt = r_accum[i] - 2*lst[i][0]
    pt += l_max_lst[(n-1)-i-1]
    if pt > rd_max:
        rd_max = pt
            

ld_max = 0
for i in range(n-1):
    pt = l_accum[i] - 2*re_lst[i][0]
    pt += r_max_lst[(n-1)-i-1]
    if pt > ld_max:
        ld_max = pt

print(max(r_max, l_max, rd_max, ld_max))
### BUGGY CODE ###

#
N=int(input())
S=[]
for i in range(N):
    S.append(input())
ans=[]

#
while len(S):
    if len(S)==1:
        x = [S.pop(), 1]
        ans.append(x)
        break
    x = [S.pop(), 1]
    for i in S[:]:
        if x[0] == i:
            S.remove(i)
            x[1]+=1
    ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])







### FIXED CODE ###

#
N=int(input())
S={}
for i in range(N):
    x=input()
    if x in S:
        S[x]+=1
    else:
        S[x]=1
t=max(S.values())
ans=[k for (k,v) in S.items() if v==t]
ans.sort()

for i in ans:
    print(i)
""""
#
while len(S):
    if len(S)==1:
        x = [S.pop(), 1]
        ans.append(x)
        break
    x = [S.pop(), 1]
    for i in S[:]:
        if x[0] == i:
            S.remove(i)
            x[1]+=1
    ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])



import queue

q=queue.Queue()
for i in S:
    q.put(i)

while not q.empty():
    x = [q.get(), 1]
    if len(ans)==0:
        ans.append(x)
        continue
    t=0
    for i in range(len(ans)):
        if x[0] == ans[i][0]:
            ans[i][1]+=1
            t+=1
            break
    if t==0:
        ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])

"""
### BUGGY CODE ###

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

mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    ones = 0
    for a in A:
        # 数列Aの全要素の(二進法表記の)i桁目の１の数を集計する
        if a & (1 << i):
            ones += 1
    # Aの要素から任意の2つを選んで排他的論理和をとってできた数列をBとすると、
    # 数列Bの全要素のi桁目の合計は、(Aのi桁目の１の数)*(0の数)となる
    # 選んだ２つのAの要素が(0,1)の組み合わせになっている場合(XOR)だけに、Bの桁を構成する要素になるため
    ans = (ans + ones * (N - ones) * (1 << i)) % mod

print(ans)


### FIXED CODE ###

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

mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    ones = 0
    for a in A:
        # 数列Aの全要素の(二進法表記の)i桁目の１の数を集計する
        if a & (1 << i):
            ones += 1
    # Aの要素から任意の2つを選んで排他的論理和をとってできた数列をBとすると、
    # 数列Bの全要素のi桁目の合計は、(Aのi桁目の１の数)*(0の数)となる
    # 選んだ２つのAの要素が(0,1)の組み合わせになっている場合(XOR)だけに、Bの桁を構成する要素になるため
    ans = (ans + ones * (N - ones) * (1 << i)) % mod

print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
ans=10**9
for i in range(n-k+1):
    cnt=max(h[i:i+k])-min(h[i:i+k])
    ans=min(cnt,ans)
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
ans=10**9
for i in range(n-k+1):
    ans=min(h[k+i-1]-h[i],ans)
print(ans)
### BUGGY CODE ###


def Attention():
    N = int(input())
    S = list(input())
    ans = 300000

    for i in range(N):
        count = 0
        for a in S[:i-1]:
            if a == 'W':count+=1
        for a in S[i+1:]:
            if a == 'E':count+=1
        ans = min(ans, count)
    print(ans)

Attention()


### FIXED CODE ###


def Attention():
    N = int(input())
    S = input()
    ans = 300000

    Wcount = [0]
    Ecount = [0]
    cnt = 0
    for i in range(N):
        if S[i] == 'W':
            cnt += 1
        Wcount.append(cnt)
    cnt = 0
    for i in range(N):
        if S[(i + 1) * -1] == 'E':
            cnt += 1
        Ecount.append(cnt)

    for i in range(N):
        cnt = Wcount[i] + Ecount[(i + 2) * -1]
        ans = min(cnt, ans)
    print(ans)

Attention()
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
MOD = 10 ** 9 + 7

for digit in range(60):
    one = sum((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD

print(ans)


### FIXED CODE ###

import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
MOD = 10 ** 9 + 7

for digit in range(60):
    one = np.count_nonzero((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD

print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(n):
    if a[i]==j+1 and a[j]==i+1:
      ans+=1
print(ans//2)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[a[i]-1]==i+1:
    ans+=1
print(ans//2)
### BUGGY CODE ###

import sys

S=input()
if len(S)<2: print(0),sys.exit()
elif len(S)==3:
    print(1 if S=="ABC" else 0)
    sys.exit()

s=[]
a=[]
x=ord("A")
l=len(S)
for i in range(l-2):
    s.append(ord(S[i])-x)
    if S[i:i+3]=="ABC": a.append(i)
s.append(ord(S[l-2])-x)
s.append(ord(S[l-1])-x)
s.append
a=[a[i] for i in range(len(a)-1,-1,-1)]


tmp=0
abc,bca=[0,1,2],[1,2,0]
ans=0
while True:
    if a==[] or a[-1]>=len(s)-2: break
    tmp=a[-1]
    if s[tmp:tmp+3]==abc:
        s[tmp:tmp+3]=bca
        a.append(tmp+2)
        if tmp>0: a.append(tmp-1)
        ans+=1
    else: a.pop(-1)

print(ans)

### FIXED CODE ###

import sys

S=input()
if len(S)<2: print(0),sys.exit()
elif len(S)==3:
    print(1 if S=="ABC" else 0)
    sys.exit()



s=[S[i] for i in range(len(S))]
tmp=0
abc,bca=["A","B","C"],["B","C","A"]
ans=0
a,bc=0,0
i=0
while i<len(s)-1:
    if s[i]=="A": a+=1
    elif s[i]=="B" and s[i+1]=="C":
        bc+=1
        i+=1
        ans+=a
    
    else:
        a,bc=0,0
    i+=1
print(ans)