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

N, Q = map(int, input().split())
S = input()

for i in range(Q):
	count = 0
	l, r = map(int, input().split())
	Sr = S[l-1:r]
	j = 0
	while (j < (len(Sr)-1)):
		if(Sr[j] == 'A' and Sr[j+1] == 'C'):
			count += 1
			j += 1
		elif(Sr[j+1] != 'A'):
			j += 1
		elif(j+2!=len(Sr) and Sr[j+2] != 'C'):
			j += 2
		j += 1
	print(count)
	

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
### BUGGY CODE ###

k = int(input())

def gcd(a,b,c):
  s = [a,b,c]
  s.sort()
  a,b,c = s
  for n in range(1,a+1):
    if a % n == 0 and b % n == 0 and c % n == 0:
      yakusu = n
  return yakusu

total = 0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      total += gcd(x,y,z)
      
print(total)
      
      
      
      



### FIXED CODE ###

import math
k = int(input())


total = 0

for x in range(1,k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x == y == z:
                total += x
            elif x == y or y == z:
                total += 3 * math.gcd(math.gcd(x,y),z)
            else:
                total += 6 * math.gcd(math.gcd(x,y),z)

print(total)
### BUGGY CODE ###

import sys
readline = sys.stdin.buffer.readline
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = []
    B = []
    C = []
    for _ in range(N-1):
        a,b,c = map(int, readline().split())
        a -= 1
        b -= 1
        A += [a,b]
        B += [b,a]
        C += c,c

    Q,K = map(int, readline().split())
    L = dijkstra(csr_matrix((C, (A, B)), shape=(N, N)),indices=K-1)
    for _ in range(Q):
        x,y = map(int, readline().split())
        print(int(L[x-1]+L[y-1]))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    G = [[] for i in range(N)]
    for i in range(N - 1):
        a, b, c = map(int, readline().split())
        G[a-1].append((b-1, c))
        G[b-1].append((a-1, c))

    dist = [-1 for i in range(N)]
    Q, K = map(int, readline().split())
    dist[K-1] = 0
    q = deque([[K - 1, 0, -1]])
    while q:
        v, d, parent = q.popleft()
        dist[v] = d
        for child in G[v]:
            if child[0] == parent:
                continue
            q.append([child[0], d + child[1], v])

    for i in range(Q):
        x, y = map(int, readline().split())
        print(dist[x - 1] + dist[y - 1])


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

#Union Find
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,M,K = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*(N+1)

friends = [[]for i in range(0,N+1,1)]
block = [[]for i in range(0,N+1,1)]
for i in range(0,M,1):
    a,b = map(int,input().split())
    friends[a].append(b)
    friends[b].append(a)
    unite(a,b)
for i in range(0,K,1):
    a,b=map(int,input().split())
    block[a].append(b)
    block[b].append(a)

countmem = [0]*N
for i in range(1,N+1,1):
    count = size(i)-1
    mem = []
    ma = mem.append
    for j in range(0,len(friends[i]),1):
        if same(i,friends[i][j]):
            count -=1
            ma(friends[i][j])
    for j in range(0,len(block[i]),1):
        if same(i,block[i][j]) and not(block[i][j] in mem):
            count -=1
    countmem[i-1]=count

print(*countmem)

### FIXED CODE ###

#Union Find
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,M,K = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*(N+1)

friends = [[]for i in range(0,N+1,1)]
block = [[]for i in range(0,N+1,1)]
for i in range(0,M,1):
    a,b = map(int,input().split())
    friends[a].append(b)
    friends[b].append(a)
    unite(a,b)
for i in range(0,K,1):
    a,b=map(int,input().split())
    block[a].append(b)
    block[b].append(a)

for i in range(1,N+1,1):
    friends[i].extend(block[i])
    set(friends[i])

countmem = [0]*N
for i in range(1,N+1,1):
    count = size(i)-1
    for j in range(0,len(friends[i]),1):
        if same(i,friends[i][j]):
            count -=1
    countmem[i-1]=count

print(*countmem)
### BUGGY CODE ###

s = list(input())

q = int(input())

cnt = 0

for i in range(q):
    t = list(input().split())
    
    if t[0] == "1":
        cnt += 1
    else:
        f = t[1]
        c = t[2]
        if f == "1":
            if cnt%2 == 0:
                s.insert(0,c)
            else:
                s.append(c)
        else:
            if cnt%2 == 0:
                s.append(c)
            else:
                s.insert(0,c)
                
if cnt%2 == 1:
    s.reverse()
            
for i in s:
    print(i,end = "")

### FIXED CODE ###

s = list(input())

q = int(input())

before = []

after = []

cnt = 0

for i in range(q):
    t = list(input().split())
    
    if t[0] == "1":
        cnt += 1
    else:
        f = t[1]
        c = t[2]
        if f == "1":
            if cnt%2 == 0:
                before.append(c)                      
            else:
                after.append(c)
        else:
            if cnt%2 == 0:
                after.append(c)
            else:
                before.append(c)
                
if cnt%2 == 1:
    s.reverse()
    after.reverse()
    #before.reverse()
    for i in after:
        print(i,end = "")
    for i in s:
        print(i,end = "")
    for i in before:
        print(i,end = "")
else:
    before.reverse()
    before.extend(s)
    before.extend(after)
            
    for i in before:
        print(i,end = "")
### BUGGY CODE ###

num = int(input())
numbers_row = input().split(" ")
numbers = []
for i in numbers_row:
  numbers.append(int(i))
  
noBool = "YES"
 
for i, number in enumerate(numbers):
  for j in numbers[i+1:]:
    if j == number:
      noBool = "NO"
      break
print(noBool)

### FIXED CODE ###

num = int(input())
numbers_row = input().split(" ")
numbers = []
for i in numbers_row:
  numbers.append(int(i))
  
Bool = len(numbers) != len(set(numbers))

if Bool == True:
    print("NO")
else:
    print("YES")
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
UV = zip(m,m)

if N == 1:
    print(0)
    exit()

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append(v)
    graph[v].append(u)

deg = [len(x) for x in graph]

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

parent,order

# dp1：その頂点に上から辿り着いてきたとする。残り回数期待値
dp1 = [0.0]*(N+1)
for v in order[::-1]:
    d = deg[v]
    if v != root and d == 1:
        continue
    x = sum(dp1[c] for c in graph[v])
    if v == root:
        dp1[v] = x/deg[v] + 1
    else:
        dp1[v] = x/(deg[v]-1) + 1

# dp2：その頂点から上に進んだとする。残り回数期待値。上移動を含まない。
dp2 = [0.0] * (N+1)
for v in order:
    d = deg[v]
    n_child = d if v == root else d-1
    S = dp1[v] * n_child # 子に進んだ場合の値の総和
    if v != root:
        S += dp2[v]+1# あらゆる移動の値の総和
    for c in graph[v]:
        if c == parent[v]:
            continue
        if d == 1:
            dp2[c] = 0
        else:
            dp2[c] = (S-dp1[c]-1) / (d-1)

answer = []
for v in range(1,N+1):
    d = deg[v]
    n_child = d if v == root else d-1
    S = dp1[v] * n_child
    if v != root:
        S += dp2[v]+1# あらゆる移動の値の総和
    answer.append(S/d)

print('\n'.join(map(str,answer)))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
UV = zip(m,m)

if N == 1:
    print(0)
    exit()

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append(v)
    graph[v].append(u)

deg = [len(x) for x in graph]

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

parent,order

# dp1：その頂点に上から辿り着いてきたとする。残り回数期待値
dp1 = [0.0]*(N+1)
for v in order[::-1]:
    d = deg[v]
    if v != root and d == 1:
        continue
    x = sum(dp1[c] for c in graph[v])
    if v == root:
        dp1[v] = x/deg[v] + 1
    else:
        dp1[v] = x/(deg[v]-1) + 1

# dp2：その頂点から上に進んだとする。残り回数期待値。上移動を含まない。
dp2 = [0.0] * (N+1)
for v in order:
    d = deg[v]
    n_child = d if v == root else d-1
    S = dp1[v] * n_child # 子に進んだ場合の値の総和
    if v != root:
        S += dp2[v]+1# あらゆる移動の値の総和
    for c in graph[v]:
        if c == parent[v]:
            continue
        if d == 1:
            dp2[c] = 0
        else:
            dp2[c] = (S-dp1[c]-1) / (d-1)

answer = []
for v in range(1,N+1):
    d = deg[v]
    n_child = d if v == root else d-1
    S = dp1[v] * n_child
    if v != root:
        S += dp2[v]+1# あらゆる移動の値の総和
    answer.append(S/d)

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

n = int(input())
h = list(map(int,input().split()))
dp = [10001] * n 
dp[0] = 0
dp[1] = abs(h[1] - h[0])
a = [[-1] * n for i in range(n)]
def chmin(a, b):
    if a <= b:
        pass
    else:
        a = b
    return a

for i in range(2, n):
    if a[i - 2][i] == -1:
        a[i][i - 2] = a[i - 2][i] = abs(h[i - 2] - h[i])
    if a[i - 1][i] == -1:
        a[i][i - 1] = a[i - 1][i] = abs(h[i - 1] - h[i])
    
    dp[i] = chmin(dp[i],dp[i - 2] + a[i - 2][i])
    dp[i] = chmin(dp[i],dp[i - 1] + a[i - 1][i])
    
print(dp[n - 1])




### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
INF = float('inf')
dp = [INF] * n 
dp[0] = 0
dp[1] = abs(h[1] - h[0])

def chmin(a, b):
    if a <= b:
        return a
    else:
        return b 
    

for i in range(2, n):

    dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]))
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]))
    
print(dp[n - 1])
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    right_set = set()
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            right_set.add(right)
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right in right_set:
                print(-1)
                return

if __name__ == "__main__":
    run()
### BUGGY CODE ###

n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [[0 for i in range(n+1)] for i in range(k+2)]

for i in range(1, k+2):
    dp[i][0] = 1

for i in range(1, k+2):
    for j in range(1, n+1):
        K = i-1
        if K < arr[j-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[0][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-arr[j-1]-1][j-1]
        

print((dp[-1][-1]-dp[-2][-1])%1000000007)

### FIXED CODE ###

mod = 1000000007
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [[0 for i in range(n+1)] for i in range(k+2)]

for i in range(1, k+2):
    dp[i][0] = 1

for i in range(1, k+2):
    for j in range(1, n+1):
        K = i-1
        if K < arr[j-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[0][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-arr[j-1]-1][j-1]
        
        dp[i][j] %= mod


print((dp[-1][-1]-dp[-2][-1] + mod)%mod)
### BUGGY CODE ###

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i


n, m = list(map(int, input().split()))
sss = list(map(int, input().split()))
ttt = list(map(int, input().split()))

bit = Bit(n + 1)

for t in ttt:
    for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1) + 1)

print(bit.sum(n + 1) + 1)


### FIXED CODE ###

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i


n, m = list(map(int, input().split()))
sss = list(map(int, input().split()))
ttt = list(map(int, input().split()))

bit = Bit(n + 1)

for t in ttt:
    for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1) + 1)

print(bit.sum(n + 1) + 1)
### BUGGY CODE ###

import numpy as np

N,M,L,R = map(int,input().split())

MOD = 10 ** 9 + 7

U = 6*10**5 + 100
fact = [1] * (U+1)
for n in range(1,U+1):
    fact[n] = fact[n-1]*n%MOD
fact_inv = [1] * (U+1)
fact_inv[U] = pow(fact[U],MOD-2,MOD)
for n in range(U,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD
fact = np.array(fact,dtype=np.int64)
fact_inv = np.array(fact_inv,dtype=np.int64)

U = N - M
comb = fact[U] * fact_inv[:U+1] % MOD * fact_inv[U::-1] % MOD
comb[1::2] *= (-1)

F = np.zeros(N+M+1,dtype=np.int64)
F[M:N+1] = comb

P = np.zeros(R+1,dtype=np.int64)
for i,x in enumerate(F[1:],1):
    P[::i] += x

P[:M-1:-1] -= P[-M-1::-1]
P %= MOD

# (1-x)^{N+1}で割る
Q = fact[N:N+R+1] * fact_inv[:R+1] % MOD * fact_inv[N] % MOD

def f(R):
    total = fact[R+N] * fact_inv[R] % MOD * fact_inv[N] % MOD
    x = (Q[R::-1] * P[:R+1] % MOD).sum() % MOD
    coef = fact[N] * fact_inv[M] % MOD * fact_inv[N-M] % MOD
    return (total - x*coef)%MOD

answer = (f(R) - f(L-1))%MOD
print(answer)

### FIXED CODE ###

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

import numpy as np

N,M,L,R = map(int,input().split())

MOD = 10 ** 9 + 7

U = 6*10**5 + 100
fact = [1] * (U+1)
for n in range(1,U+1):
    fact[n] = fact[n-1]*n%MOD
fact_inv = [1] * (U+1)
fact_inv[U] = pow(fact[U],MOD-2,MOD)
for n in range(U,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD

fact = np.array(fact,dtype=np.int64)
fact_inv = np.array(fact_inv,dtype=np.int64)


U = N - M
comb = fact[U] * fact_inv[:U+1] % MOD * fact_inv[U::-1] % MOD
comb[1::2] *= (-1)

P = np.zeros(R+1,dtype=np.int64)
for i,x in enumerate(comb,M):
    P[::i] += x


P[M:] -= P.copy()[:-M]
P %= MOD

# (1-x)^{N+1}で割る
Q = fact[N:N+R+1] * fact_inv[:R+1] % MOD * fact_inv[N] % MOD

def f(R):
    total = fact[R+N] * fact_inv[R] % MOD * fact_inv[N] % MOD
    x = (Q[R::-1] * P[:R+1] % MOD).sum() % MOD
    coef = fact[N] * fact_inv[M] % MOD * fact_inv[N-M] % MOD
    return (total - x*coef)%MOD

answer = (f(R) - f(L-1))%MOD
print(answer)
### BUGGY CODE ###

H,W=map(int, input().split())
A=[list(map(str,list(input()))) for i in range(H)]

black_list=[[]]
del black_list[0]

def paint_center(a,b):
  paint_point(a-1,b)
  paint_point(a+1,b)
  paint_point(a,b-1)
  paint_point(a,b+1)

def paint_point(a,b):
  if 0<=a and a<H:
    if 0<=b and b<W:
      A[a][b]="#"

#黒いマスを探してその周りを黒く塗る


count=0
flag=False #白があればTrue
end_flag=False

while end_flag==False:
  #全マスが黒かどうかのチェック
  flag=False

  for i in range(0,H):
    for j in range(0,W):
      if A[i][j]==".":
        flag=True
      else:
        pass

  
  if flag==True:
    for i in range(0,H):
      for j in range(0,W):
        if A[i][j]=="#":
          black_list.append([i,j])
    for i,j in black_list:
      paint_center(i,j)
    count=count+1
    
  else:
    print(count)
    break

### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]
z= [[False for _ in range(W)] for _ in range(H)]
ans=0

v=deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            v.append( [i,j] )
            z[i][j]=True
            d[i][j]=0
while v:
    a=v.popleft()
    #print(a,v)
    for mv in move:
        s=a[0]+mv[0]
        t=a[1]+mv[1]
        if 0<=s<H and 0<=t<W:
            if z[s][t]==False:
                z[s][t]=True
                d[s][t]=d[a[0]][a[1]]+1
                v.append([s,t])
                ans=max(ans,d[s][t])
#print(d)
print(ans)
### BUGGY CODE ###

n=int(input())
c = list(map(int, input().rstrip().split()))
a=0
b=10**9+7
for i in range(len(c)):
    for j in range(i+1,n):
        
        f=(c[i]*c[j])%b
        a=a+f
        
print(a%b)

### FIXED CODE ###

n=int(input())
c = list(map(int, input().rstrip().split()))
ans=0
b=10**9+7
sum1=0
for i in range(n):
    ans=(ans+c[i]*sum1)%b
    sum1=(sum1+c[i])%b

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

l,r = map(int,input().split())

m = 2000000001
for i in range(l,r+1):
      for j in range(i+1,r+1):
            if (i*j)%2019 < m:
                  m = (i*j)%2019            
print(m)


### FIXED CODE ###

from itertools import combinations

l,r = map(int,input().split())

if r - l >= 2019:
    print(0)
else:
    m = 2019
    for i, j in combinations(range(l, r+1),2):
        tmp = i*j % 2019
        if m > tmp:
            m = tmp
    print(m)
### BUGGY CODE ###

n = int(input())
a = [0] + list(map(int,input().split())) + [0]
sa = [abs(a[i]-a[i+1]) for i in range(n+1)]

for i in range(n):
    p = list(range(n+1)) + [0]
    p.pop(i+1)

    yen = sum(sa) + abs(a[p[i+1]] - a[p[i]]) - sa[i] - sa[i+1]
    print(yen)

### FIXED CODE ###

n = int(input())
a = [0] + list(map(int,input().split())) + [0]
sa = [abs(a[i]-a[i+1]) for i in range(n+1)]
sum_sa = sum(sa)

for i in range(n):
    yen = sum_sa + abs(a[i+2]-a[i]) - sa[i] - sa[i+1]
    print(yen)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans=1
for i in a:
  ans *= i
if ans>10**18:
  ans=-1
print(ans)


### FIXED CODE ###

def pyn():
  n = int(input())
  a = list(map(int, input().split()))
  if 0 in a:
    print(0)
    return
    
  ans=1
  for i in a:
    ans *= i
    if ans>10**18:
      print(-1)
      return
  print(ans)

pyn()
### BUGGY CODE ###

N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
for n in range(N):
    print(sum(cost[:n] + [abs(A[n] - A[n + 2])] + cost[n + 2:]))


### FIXED CODE ###

N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = [abs(A[i] - A[i + 1]) for i in range(N + 1)]
start = 0
end = sum(cost[2:])
for n in range(N):
    print(start + abs(A[n] - A[n + 2]) + end)
    if n != N - 1:
        start += cost[n]
        end -= cost[n + 2]
### BUGGY CODE ###

import sys
def check(S):
    stop = True
    if len(S) < 2:
        print(base_S_length - len(S))
        sys.exit()
    for i in range(len(S) - 1):
        if (S[i] + S[i + 1]) == 1:
            S[i] = S[i + 1] = 2
            stop = False    
    if stop:
        print(base_S_length - len(S))
        sys.exit()
    S = [i for i in S if i < 2]
    check(S)

S = list(map(int, list(input())))
base_S_length = len(S)
check(S)

### FIXED CODE ###

def main():
    S = list(map(int, list(input())))

    cnt1 = sum(S)
    cnt0 = len(S) - cnt1
    print(2 * min(cnt0, cnt1))


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

n = int(input())
v = list(map(int,input().split()))

def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a

l_ans = [0] * n
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[j])
    l_ans[i] = g
r_ans = [0] * n
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[n-1-j])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)


### FIXED CODE ###

n = int(input())
v = list(map(int,input().split()))

def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a

l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

b = set(a)

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

for k in a:
    ans = 0
    for i in b:
        if i != k:
            ans += c[i]*(c[i]-1)//2
        else:
            ans += (c[i]-1)*(c[i]-2)//2
    print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

ways = 0
for i in c:
    ways += c[i]*(c[i]-1)//2

for k in a:
    ans = ways-c[k]+1
    print(ans)
### BUGGY CODE ###

s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = []
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu.append(i)
      ans += 2
      q = True
      break
  if kesu:
    for i in kesu:
      del slist[i-1:i+1]
print(ans)


### FIXED CODE ###

s = input()
cnt1 = s.count('1')
cnt0 = s.count('0')
print(len(s)-abs(cnt1-cnt0))
### BUGGY CODE ###

n = int(input())
S = list(input())
ans = float('inf')
for i in range(n):
  tmp = S[:i].count('W') + S[i+1::].count('E') 
  ans = min(tmp, ans)
print(ans)

### FIXED CODE ###

n = int(input())
S = input()
E = [0]*n
W = [0]*n
ans = n
for i in range(n):
  if S[i]=='E':
    E[i] = 1
  else:
    W[i] = 1

for i in range(1, n):
  W[i] += W[i-1]
  E[i] += E[i-1]

for i in range(n):
  tmp = 0
  if i:
    tmp += W[i-1]
  tmp += E[n-1] - E[i]
  ans = min(ans, tmp)
print(ans)