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

#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
count = 0
a.sort()
list.sort(b,reverse=True)
list.sort(c,reverse=True)
for ai in a:
    for bi in b:
        if ai < bi:
            for ci in c:
                if bi < ci:
                    count +=1
                else:
                    break       
        else:
            break
    
print(count)

### FIXED CODE ###

#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
ai = 0
ci = 0
for bi in b:
    while ai < N and a[ai] < bi:
        ai += 1
    while ci < N and c[ci] <= bi:
        ci += 1
    ans += ai * (N -ci)
print(ans)
### BUGGY CODE ###

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

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])

idx_sum_set = []
for i in range(len(idx_set)):
  tmp = 0
  for j in range(len(idx_set)):
    if i == j:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  idx_sum_set.append([idx_set[i][0],tmp])

for i in range(N):
  j = int(len(idx_sum_set)/2)
  while 1:
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
      break
    elif A[i] > idx_sum_set[j][0]:
      j = j + int((len(idx_sum_set)-j)/2)
    elif A[i] < idx_sum_set[j][0]:
      j = int(j/2)
"""
for i in range(N):
  for j in range(len(idx_sum_set)):
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
"""



### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

for i in range(N):
  B[A[i]]+=1
#print(B)

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))
### BUGGY CODE ###

N,K=map(int,input().split())
a=list(map(int,input().split()))
tmp=10**-10
l=[]
for i in range(N-K+1):
  s=sum(a[i:i+K])
  if s>tmp:
    l=a[i:i+K]
    tmp=s
ans=0
for i in range(K):
  v=l[i]
  ans+=((v+1)/2)
print(ans)

### FIXED CODE ###

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

from collections import deque


def getPath(adj, start, goal):
    q = deque()
    q.appendleft((start, set()))
    while len(q):
        cur, p = q.pop()
        if cur == goal:
            return p
        for nxt, npath in adj[cur]:
            if npath in p:
                continue
            npath = p | {npath}
            q.appendleft((nxt, npath))


def main():
    N = int(input())
    adj = [set() for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        adj[a-1].add((b-1, i))
        adj[b-1].add((a-1, i))
    M = int(input())
    dp = [{tuple(): set()} for _ in range(M+1)]
    for i in range(M):
        u, v = map(int, input().split())
        dp[i+1] = dict(dp[i])
        path = getPath(adj, u-1, v-1)
        for t in dp[i]:
            dp[i+1][t + (i, )] = dp[i+1][t] | path
    ans = 0
    for key in dp[M]:
        ans += (-1) ** len(key) * 2 ** (N - len(dp[M][key]) - 1)
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def getPath(adj, start, goal):
    q = deque()
    q.appendleft((start, 0))
    while len(q):
        cur, p = q.pop()
        if cur == goal:
            return p
        for nxt, nhop in adj[cur]:
            if 2**nhop & p:
                continue
            npath = p | 2**nhop
            q.appendleft((nxt, npath))


def bitcount(x):
    return bin(x).count("1")


def main():
    N = int(input())
    adj = [set() for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        adj[a-1].add((b-1, i))
        adj[b-1].add((a-1, i))
    M = int(input())
    dp = [0] * (2**M)
    for i in range(M):
        u, v = map(int, input().split())
        path = getPath(adj, u-1, v-1)
        for j in range(2**i):
            dp[j + 2**i] = dp[j] | path
    ans = 0
    for i in range(2**M):
        ans += (-1) ** bitcount(i) * 2 ** (N - bitcount(dp[i]) - 1)
    print(ans)


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

x=input().split()
h=int(x[0])
n=int(x[1])
a=[]
b=[]
for k in range(n):
  x=input().split()
  a.append(int(x[0]))
  b.append(int(x[1]))  
m=max(a)  
import numpy as np 
dp=np.zeros(h+m)+10**8
dp[0]=0
for k in range(h+m):
  for i in range(n):
    if k-a[i]<0:
      continue
    new=dp[k-a[i]]+b[i]
    if new < dp[k]:
      dp[k]=new
print(int(np.min(dp[h:h+m])))
      
      
  

  
      
      
      

### FIXED CODE ###

x=input().split()
h=int(x[0])
n=int(x[1])
import numpy as np
a=np.full(n,0,int)
b=np.full(n,0,int)
for k in range(n):
  x=input().split()
  a[k]=int(x[0])
  b[k]=int(x[1])
m=max(a)  
inf=10**8
dp=np.full(h+m,inf,int)
dp[0]=0
for k in range(1,h+m):
  dp[k]=(dp[k-a]+b).min()
print(dp[h:h+m].min())
### BUGGY CODE ###

def lcs(s1, s2):
    n, m = len(s1), len(s2)
    dp = [[0] * (m+1) for _ in range(n+1)]

    for i in range(1, n+1):
        for j in range(1, m+1):
            if s1[i-1] == s2[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])

    return dp[n][m]

def solve():
    N = int(input())
    for _ in range(N):
        a = input()
        b = input()
        print(lcs(a, b))

if __name__ == '__main__':
    solve()

### FIXED CODE ###

def lcs(s1, s2):
    dp = []
    for s2_k in s2:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if not chr_idx:
                break
            dp[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if chr_idx:
                dp.append(chr_idx)
    return len(dp)

def solve():
    N = int(input())
    for _ in range(N):
        x = input()
        y = input()
        print(lcs(x, y))

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

H,N = map(int,input().split())

#dpテーブルの設定と初期化
dp = [0] + [10 ** 9] * H

#各魔法について
for i in range(N):
  #d,cはそれぞれ魔法ダメージと魔法のコスト
  d,c = map(int,input().split())
  #dpテーブルの各HPについて
  for j in range(H + 1):
    k = max(j - d,0)
    #ダメージjを与える時のコストについて、
    #魔法iを新たに使った場合と、既存の最小コストを比較し更新する
    l = dp[k] + c
    dp[j] = min(dp[j],l)

print(dp[-1])



### FIXED CODE ###

def main():
    h,n,*t=map(int,open(0).read().split())
    d=[0]+[10**18]*h
    for a,b in zip(*[iter(t)]*2):
        for j in range(h+1):
            k=j-a
            if k<0:k=0
            c=d[k]+b
            if c<d[j]:d[j]=c
    print(d[h])
main()
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
g = [ list(map(lambda x: int(x)-1, input().split())) for _ in range(M) ]

from collections import Counter, defaultdict
childs  = Counter( x[1] for x in g)
childs_list  = defaultdict(list)

for x,y in g:
    childs_list[x].append(y)
roots = []
for i in range(N):
    if childs[i] == 0:
        roots.append(i)

# l = [(i,childs_list[i],0)]
l = [(i,childs_list[i],0) for i in roots]
costs = [ 0 for _ in range(N)]

while l: 
    v_idx, chlist, cnt = l.pop()
    costs[v_idx] = max(costs[v_idx], cnt)

    for c in chlist:
        if cnt+1 > costs[c]:
            l.append(  (c, childs_list[c], cnt+1) ) 
print(max(costs))
        
        



### FIXED CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
g = [ list(map(lambda x: int(x)-1, input().split())) for _ in range(M) ]

from collections import Counter, defaultdict
childs  = Counter( x[1] for x in g)
childs_list  = defaultdict(list)

for x,y in g:
    childs_list[x].append(y)
roots = []
for i in range(N):
    if childs[i] == 0:
        roots.append(i)

l = [ i for i in roots]
costs = [ 0 for _ in range(N)]

while l: 

    nex_stack = []
    # p = l.pop()
    for p in l:
        # cnt = costs[p]
        for c in childs_list[p]:
            costs[c] = max(costs[p]+1, costs[c])
            childs[c] -= 1
            if childs[c] == 0:
                nex_stack.append(c)
    
    l = nex_stack


print(max(costs))
### BUGGY CODE ###

# coding: utf-8

import sys
input=sys.stdin.readline

n=int(input())
p=list(map(int,input().split()))
P=[]
cnt=0

for i in p:
    P.append(i)
    if i==min(P):
        cnt+=1

print(cnt)

### FIXED CODE ###

# coding: utf-8

import sys
input=sys.stdin.readline

n=int(input())
p=list(map(int,input().split()))
P=[]
cnt=0
lowest=float("inf")

for i in p:
    if i<=lowest:
        lowest=i
        cnt+=1

print(cnt)
### BUGGY CODE ###


import sys
import copy
input = sys.stdin.readline

h, w = [ int(v) for v in input().split() ]

field = [ list(map(int,input().replace("#","0").replace(".","1").replace("\n",""))) for i in range(h)]

yoko = [ copy.deepcopy(field[i]) for i in range(h)]


for i in range(h):
	for j in range(1,w):
		if yoko[i][j] == 0:
			yoko[i][j] = 0
		else:
			yoko[i][j] += yoko[i][j-1]
	for j in range(w-1,0,-1):
		if yoko[i][j-1] != 0:
			yoko[i][j-1] = max(yoko[i][j-1],yoko[i][j])

tate = [ [ field[i][j] for i in range(h)] for j in range(w) ]

for i in range(w):
	for j in range(1,h):
		if tate[i][j] == 0:
			tate[i][j] = 0
		else:
			tate[i][j] += tate[i][j-1]
	for j in range(h-1,0,-1):
		if tate[i][j-1] != 0:
			tate[i][j-1] = max(tate[i][j-1],tate[i][j])


ans = 0
for i in range(h):
	for j in range(w):
		ans = max((yoko[i][j] + tate[j][i]),ans)

print(ans-1)


### FIXED CODE ###

import sys
import copy
input = sys.stdin.readline

h, w = [ int(v) for v in input().split() ]

field = [ list(map(int,input().replace("#","0").replace(".","1").replace("\n",""))) for i in range(h)]

yoko = [ copy.deepcopy(field[i]) for i in range(h)]


for i in range(h):
	for j in range(1,w):
		if yoko[i][j] == 0:
			yoko[i][j] = 0
		else:
			yoko[i][j] += yoko[i][j-1]
	for j in range(w-1,0,-1):
		if yoko[i][j-1] != 0:
			yoko[i][j-1] = max(yoko[i][j-1],yoko[i][j])

tate = [ [ field[i][j] for i in range(h)] for j in range(w) ]

for i in range(w):
	for j in range(1,h):
		if tate[i][j] == 0:
			tate[i][j] = 0
		else:
			tate[i][j] += tate[i][j-1]
	for j in range(h-1,0,-1):
		if tate[i][j-1] != 0:
			tate[i][j-1] = max(tate[i][j-1],tate[i][j])


ans = 0
for i in range(h):
	for j in range(w):
		ans = max((yoko[i][j] + tate[j][i]),ans)

print(ans-1)
### BUGGY CODE ###

def tasu(x):
    ans = 0
    for i in range(1 , x + 1):
        ans += i
    return ans

def kitaiti(n , k , p):

    ans = 0
    kitai = [0]*n
    #tf = [False]*N

    for i in range(n):
        kitai[i] = tasu(p[i]) / p[i]

    for i in range(n - k + 1):
        count = 0
        for w in range(i , i + k):
            count += kitai[w]

        ans = max(ans , count)

    return ans

def main():
    n , k = map(int , input().split())
    p = list(map(int,input().split()))
    print(kitaiti(n , k , p))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def tasu(x):
    return x / 2 * (x + 1)

def kitaiti(n , k , p):

    ans = 0
    count = 0
    kitai = [0]*n
    kitaisum = [0]*n
    mod = 10**9+7

    for i in range(n):
        kitai[i] = tasu(p[i]) / p[i]

    for i in range(n):
        if i == 0:
            kitaisum[i] += kitai[i]
        else:
            kitaisum[i] += kitai[i] + kitaisum[i-1]

    for i in range(n - k + 1):

        ans = max(ans , (kitaisum[i + k - 1] - kitaisum[i-1]) if i != 0 else kitaisum[i + k - 1])

    return ans

def main():
    n , k = map(int , input().split())
    p = list(map(int,input().split()))
    print(kitaiti(n , k , p))

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

n, k = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())

s = list()
for i in range(n):
    for j in range(b[i]):
        s.append(a[i])

s.sort()
print(s[k-1])

### FIXED CODE ###

n, k = map(int, input().split())
l = [0]*(10**5+10)

for i in range(n):
    a, b = map(int, input().split())
    l[a] += b

sum = 0
for i in range(len(l)):
    sum += l[i]
    if sum >= k:
        print(i)
        break
### BUGGY CODE ###

from queue import deque
H, W = map(int, input().split())

matrix = []

visited = set()

for i in range(H):
    matrix.append(list(input()))

que = deque([])

for i in range(H):
    for j in range(W):
        if matrix[i][j] == '#' and (i, j) not in visited:
            visited.add((i, j))
            for ud, lr in ((-1, 0), (1, 0), (0, -1), (0, 1)):
                if not(0 <= i+ud < H and 0 <= j+lr < W)  or matrix[i+ud][j+lr] == '#' or (i+ud, j+lr) in visited:
                    continue
                que.append((i+ud, j+lr))

res = 0

while que:
    res += 1
    for k in range(len(que)):
        i, j = que.popleft()
        visited.add((i, j))
        for ud, lr in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            if not(0 <= i+ud < H and 0 <= j+lr < W)  or matrix[i+ud][j+lr] == '#' or (i+ud, j+lr) in visited:
                continue
            que.append((i+ud, j+lr))
print(res)



### FIXED CODE ###

H, W = map(int, input().split())

matrix = []

visited = set()

for i in range(H):
    matrix.append(list(input()))

visited = set()

for i in range(H):
    for j in range(W):
        if matrix[i][j] == '#' and (i, j) not in visited:
            for ud, lr in ((-1, 0), (1, 0), (0, -1), (0, 1)):
                if not(0 <= i+ud < H and 0 <= j+lr < W)  or matrix[i+ud][j+lr] == '#':
                    continue
                visited.add((i+ud, j+lr))
                matrix[i+ud][j+lr] = '#'

res = 0

while visited:
    res += 1
    buf = set()
    for i, j in visited:
        if matrix[i][j] == '#' and (i, j) not in buf:
            for ud, lr in ((-1, 0), (1, 0), (0, -1), (0, 1)):
                if not(0 <= i+ud < H and 0 <= j+lr < W)  or matrix[i+ud][j+lr] == '#':
                    continue
                buf.add((i+ud, j+lr))
                matrix[i+ud][j+lr] = '#'
    if not buf:
        break
    visited = buf

print(res)
### BUGGY CODE ###

N=int(input())
p=input()
p=p.split()
A=[]
for i in range(len(p)):
  A.append(int(p[i]))

X=[]
for i in range(N):
  for j in range(i+1,N):
    X.append(A[i]*A[j])
x=sum(X)

MOD=1000000007
print(x%MOD)



### FIXED CODE ###

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

S=sum(A)
a=0
for x in A:
  S-=x
  a+=S*x
    
MOD=10**9+7
print(int(a%MOD))
### BUGGY CODE ###

n=int(input())
l=[]
s=[]
for i in range(1,n//2+1):
    if n%i==0:
        l.append(i)
for e in l:
    s.append(n//e+e-2)
print(min(s))


### FIXED CODE ###

n=int(input())
mx=10**15
for i in range(1,int(n**.5+1)):
    if n%i==0 and n//i+i-2<mx:
        mx=n//i+i-2
print(mx)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
def main():
	n = int(input())
	a = []
	for _ in range(n):
		a.append(tuple(map(int,input().split())))
	a = tuple(a)

	play = [0 for _ in range(n)]
	flag = [True for _ in range(n)]
	count = 0
	ans = 0
	while True:
		break_flag = True
		for i in range(n):
			if flag[i]:
				num = a[i][play[i]]-1
				if flag[num] and a[num][play[num]]-1 == i:
					play[num] += 1
					play[i] += 1
					flag[num] = False
					flag[i] = False
					break_flag = False
					count += 1
		if break_flag:
			print(-1)
			sys.exit()
		ans += 1

		if count == n*(n-1)//2:
			break
		if ans > 10**6:
			print(-1)
			sys.exit()
		for i in range(n):
			if play[i] < n-1:
				flag[i] = True
			else:
				flag[i] = False

	if ans == 0:
		print(-1)
	else:
		print(ans)
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
readline = sys.stdin.readline
def main():
	limit = 10 ** 4
	n = int(input())
	a = []
	for _ in range(n):
		a.append(tuple(map(int,input().split())))
	a = tuple(a)

	play = [0 for _ in range(n)]
	flag = [True for _ in range(n)]
	count = 0
	ans = 0
	while True:
		break_flag = True
		for i in range(n):
			if flag[i]:
				num = a[i][play[i]]-1
				if flag[num] and a[num][play[num]]-1 == i:
					play[num] += 1
					play[i] += 1
					flag[num] = False
					flag[i] = False
					break_flag = False
					count += 1
		if break_flag:
			print(-1)
			sys.exit()
		ans += 1

		if count == n*(n-1)//2:
			break
		if ans > limit:
			print(n*(n-1)//2)
			sys.exit()
		for i in range(n):
			if play[i] < n-1:
				flag[i] = True
			else:
				flag[i] = False

	if ans == 0:
		print(-1)
	else:
		print(ans)
if __name__ == '__main__':
	main()
### BUGGY CODE ###

import bisect

N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.insert((bisect.bisect(B,b)),a)
    bisect.insort(B,b)

if all(sum(A[0:i+1]) <= B[i] for i in range(N)):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import bisect

N = int(input())

L = []
for i in range(N):
    a,b = map(int, input().split())
    L.append([b,a])
L.sort()

Sum = 0

for i in range(N):
    Sum = Sum + L[i][1]
    if Sum <= L[i][0]:
        continue
    else:
        print("No")
        quit()
print("Yes")
### BUGGY CODE ###

import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def bfs():
    d = [[[float("inf")] * w for _ in range(h)] for _ in range(len(kabe))]
    ans = float("inf")
    for i in range(len(kabe)):
        que = deque([])
        que.append((kabe[i][0], kabe[i][1]))
        d[i][kabe[i][0]][kabe[i][1]] = 0
        while que:
            x, y = que.popleft()
            for dx, dy in ([1, 0], [0, 1], [0, -1], [-1, 0]):
                nx = x + dx
                ny = y + dy
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[i][nx][ny] == float("inf"):
                    que.append((nx, ny))
                    d[i][nx][ny] = d[i][x][y] + 1
    li = []
    for i in range(h):
        for j in range(w):
            tmp = [d[k][i][j] for k in range(len(kabe))]
            li.append(min(tmp))
    return max(li)

h, w = na()
maze = [list(input()) for _ in range(h)]
kabe = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            kabe.append((i, j))
print(bfs())



### FIXED CODE ###

import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)
### BUGGY CODE ###

S = input()
K = int(input())

a = []
for l in range(1, len(S) + 1):
	for i in range(len(S) - l + 1):
		a += [S[i:i + l]]

print(sorted(set(a))[K - 1])


### FIXED CODE ###

S = input()
K = int(input())

a = []
for i in range(len(S)):
	for l in range(1, len(S) - i + 1):
		s = S[i:i + l]
		#print(s, a)
		if s in a:
			continue
		if len(a) < 5:
			a += [s]
			a = sorted(a)
		else:
			if a[-1] < s:
				break
			else:
				a[-1] = s
				a = sorted(a)
print(a[K - 1])
### BUGGY CODE ###

N = int(input())
S = list(input())
count = 3 * 10 ** 5
for i in range(N):
    count_tmp = 0
    count_tmp += S[:i].count("W")
    count_tmp += S[i+1:].count("E")
    count = min(count, count_tmp)
print(count)


### FIXED CODE ###

N = int(input())
S = input()
ans = cnt = S[1:].count("E")
for i in range(1, N):
    if S[i] == "E":
        cnt -= 1
    if S[i - 1] == "W":
        cnt += 1
    ans = min(ans, cnt)
print(ans)
### BUGGY CODE ###

import queue
import copy
q = queue.Queue()
h, w = map(int, input().split())
a = [list('#'+input()+'#') for _ in range(h)]
a = [['#']*(w+2)]+a+[['#']*(w+2)]
a1 = copy.deepcopy(a)
ans = []
        
for i in range(1, h+1):
    for j in range(1, w+1):
        a = copy.deepcopy(a1)
        if a[i][j] == '#':
            continue        
        q.put([i, j, 0])
        while not q.empty():
            now = q.get()
            if a[now[0]][now[1]] == '.':
                ans.append(now[2])
                a[now[0]][now[1]] = '#'
            if a[now[0]+1][now[1]] != '#':
                q.put([now[0]+1, now[1], now[2]+1])
            if a[now[0]-1][now[1]] != '#':
                q.put([now[0]-1, now[1], now[2]+1])
            if a[now[0]][now[1]+1] != '#':
                q.put([now[0], now[1]+1, now[2]+1])
            if a[now[0]][now[1]-1] != '#':
                q.put([now[0], now[1]-1, now[2]+1])
print(max(ans))


### FIXED CODE ###

import queue
import copy
q = queue.Queue()
h, w = map(int, input().split())
a = [list('#'+input()+'#') for _ in range(h)]
a = [['#']*(w+2)]+a+[['#']*(w+2)]
a1 = copy.deepcopy(a)
ans = []
        
for i in range(1, h+1):
    for j in range(1, w+1):
        a = copy.deepcopy(a1)
        if a[i][j] == '#':
            continue        
        q.put([i, j, 0])
        while not q.empty():
            now = q.get()
            
            if a[now[0]][now[1]] == '.':
                ans.append(now[2])
                a[now[0]][now[1]] = '#'
            else:
                continue
                
            if a[now[0]+1][now[1]] != '#':
                q.put([now[0]+1, now[1], now[2]+1])
            if a[now[0]-1][now[1]] != '#':
                q.put([now[0]-1, now[1], now[2]+1])
            if a[now[0]][now[1]+1] != '#':
                q.put([now[0], now[1]+1, now[2]+1])
            if a[now[0]][now[1]-1] != '#':
                q.put([now[0], now[1]-1, now[2]+1])
        a1[i][j] == '#'
print(max(ans))
### BUGGY CODE ###

n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        # r = bisect.bisect_left(tris, a+b)
        # cnt += r - j - 1

        ok = j
        ng = n
        while abs(ok-ng) > 1:
            mid = (ok+ng) // 2
            if tris[mid] < a + b:
                ok = mid
            else:
                ng = mid
        cnt += ok - j
print(cnt)


### FIXED CODE ###

import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)
### BUGGY CODE ###

N = int(input())
a = [int(x) for x in input().split(" ")]
sum = 0
pow = 0
while any(a):
    zero = 0; one = 0
    for i in range(N):
        if a[i] % 2 == 0:
            zero += 1
        else:
            one += 1
        a[i] //= 2
    sum += zero * one * 2 ** pow
    pow += 1
print(sum % (10 ** 9 + 7))

### FIXED CODE ###

import numpy as np

N = int(input())
a = np.array([int(x) for x in input().split(" ")], np.int64)
sum = 0
pow = 0
while any(a):
    one = np.count_nonzero(a & 1)
    sum += one * (N - one) * 2 ** pow
    sum %= (10 ** 9 + 7)
    pow += 1
    a >>= 1
print(sum)