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

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

ans = 1e19

"""
abcdef
f +4(f-e) + 9+(e-d) + 16(d-c) + ...
= 5f + 5e + 7d + 9c + 11b + 13a
"""
mul = [5] + [5 + 2*i for i in range(N)]
#print(mul)

CX = [0] * (N+1)

#cum_sum
for i in range(N):
  CX[i+1] = CX[i] + A[i]
  
for k in range(1,N+1): # Number of robots (this loop will be ended early)
  cost = N*X + k*X # pickup and throw costs(fixed with k)
  
  # partial point answer (not using cumulative sum)
  for i in range(1,N+1):
    cost += A[N-i] * mul[(i-1)//k]
  #ix = N
  #loopc = 0
  #while ix > 0:
  #  if ix-k > 0:
  #    cost += (CX[ix] - CX[ix-k]) * mul[loopc]
  #  else:
  #    cost += (CX[ix]) * mul[loopc]
  #  loopc += 1
  #  ix -= k
  
  #print(k,cost)
  ans = min(ans,cost)
  if N//k <= 1: # early stopping (after mul is 5 for all A's, cost is monotonicaly increasing)
    print(ans)
    exit(0)
    
#print(ans)
  
  

### FIXED CODE ###

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

ans = 1e19

"""
abcdef
f +4(f-e) + 9+(e-d) + 16(d-c) + ...
= 5f + 5e + 7d + 9c + 11b + 13a
"""
mul = [5] + [5 + 2*i for i in range(N)]
#print(mul)

CX = [0] * (N+1)

#cum_sum
for i in range(N):
  CX[i+1] = CX[i] + A[i]
  
for k in range(1,N+1): # Number of robots (this loop will be ended early)
  cost = N*X + k*X # pickup and throw costs(fixed with k)
  
  # partial point answer (not using cumulative sum)
  # for i in range(1,N+1):
  #  cost += A[N-i] * mul[(i-1)//k]
  ix = N
  loopc = 0
  while ix > 0:
    if ix-k > 0:
      cost += (CX[ix] - CX[ix-k]) * mul[loopc]
    else:
      cost += (CX[ix]) * mul[loopc]
    loopc += 1
    ix -= k
  
  #print(k,cost)
  ans = min(ans,cost)
  if N//k <= 1: # early stopping (after mul is 5 for all A's, cost is monotonicaly increasing)
    print(ans)
    exit(0)
    
#print(ans)
### BUGGY CODE ###

N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
hoge[0] = 1
for i in range(N):
    if i == 0 and (i+1) not in a:
        hoge[i] = 1
    elif i == 1 and (i+1) not in a:
        hoge[i] = hoge[i-1] + 1
    elif i + 1 in a:
        hoge[i] = 0
    elif i in a and (i-1) in a:
        hoge[i] = 0
    elif i in a:
        hoge[i] = hoge[i - 2]
    elif (i-1) in a:
        hoge[i] = hoge[i - 1]
    else:
        hoge[i] = hoge[i-1] + hoge[i-2]
        hoge[i] = hoge[i] % (10**9 + 7)
print(hoge[N-1] % (10**9 + 7))




### FIXED CODE ###

N, M = map(int, input().split())
A = set(int(input()) for _ in range(M))
mod = 10 ** 9 + 7

dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if i in A:
        continue
    if i == 1:
        dp[i] = 1
        continue
    dp[i] = dp[i-1] + dp[i-2]

print(dp[N] % mod)
### BUGGY CODE ###

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

import fractions
from functools import reduce

ans = 0
for i in range(n):
  x = a[:i] + a[i+1:]
  ans = max(ans, reduce(fractions.gcd, x))
  
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
end = sorted(a)[1]

for i in range(end+1, 0, -1):
  x = 0
  for j in a:
    if j % i != 0:
      x += 1
    if x >= 2:
      break
  if x <= 1:
    print(i)
    break
### BUGGY CODE ###

s = input()
q = int(input())
query = []
 
def func(string, t, f, c):
    if int(t) == 1:
        new_str = ''.join(list(reversed(string)))
        return new_str
    else:
        if int(f) == 1:
            return c + string
        else:
            return string + c
 
for i in range(0,q):
    query.append(input().split())
for i in query:
    if int(i[0]) == 1:
        s = func(s,i[0],'','')
    else:
        s = func(s,i[0],i[1],i[2])
print(s)

### FIXED CODE ###

s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)
### BUGGY CODE ###

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

sa=[0]*a
ma=max(k)

for i in range(a-1):
    if k[i]==ma:
        ma=max(k[i+1:a])
    sa[i]=ma-k[i]

sa.sort()
sa.reverse()

ans=1
now=1

while sa[now]==sa[0]:
    ans+=1
    now+=1
    

print(ans)

### FIXED CODE ###

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

sa=0
ans=1

n=k[a-1]

for i in range(a-2,-1,-1):
    if k[i]>n:
        n=k[i]
    tmp=n-k[i]
    if tmp>sa:
        sa=tmp
        ans=1
    elif tmp==sa:
        ans+=1

    

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

N=int(input())
S=input()

ans=10**6
for i in range(N):
    ans=min(ans,(S[:i].count('W') + S[i+1:].count('E')))

print(ans)

### FIXED CODE ###

N=int(input())
S=input()

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

# ABC140E
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

n,m=map(int, input().split())
xs = []
for _ in range(m):
    L, R, C = map(int, input().split())
    xs.append((L-1, R-1, C))
xs.sort()

mx = 10**15
ss = SegTree([0] + [mx] * n, n+1, mx, min)
for l, r, c in xs:
    mm = ss.query(l, n+1)
    nx = min(mm + c, ss.query(r, r+1))
    ss.update(r, nx)
r = ss.query(n-1,n)
print(r if r != mx else -1)


### FIXED CODE ###

# ABC140E
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

n,m=map(int, input().split())
xs = []
for _ in range(m):
    L, R, C = map(int, input().split())
    xs.append((L-1, R-1, C))
xs.sort()

mx = 10**15
ss = SegTree([0] + [mx] * n, n+1, mx, min)
for l, r, c in xs:
    mm = ss.query(l, n+1)
    nx = min(mm + c, ss.query(r, r+1))
    ss.update(r, nx)
r = ss.query(n-1,n)
print(r if r != mx else -1)
### BUGGY CODE ###

import copy
import bisect

def main(N, L):
    L.sort(reverse=True)

    triangles = 0

    for i, P in enumerate(L):
        Q_list = copy.copy(L)
        del Q_list[:i + 1]
        for j, Q in enumerate(Q_list):
            if Q < P / 2:
                break
            minR = P - Q + 1
            R_list = copy.copy(Q_list)
            del R_list[:j + 1]
            R_list.reverse()
            triangles += len(R_list) - bisect.bisect_left(R_list, minR)

    print(triangles)

if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    main(N, L)


### FIXED CODE ###

import copy
import bisect

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

triangles = 0

for i in range(N - 2):
    P = L[i]
    for j in range(i + 1, N - 1):
        Q = L[j]
        if P + Q <= L[j + 1]:
            continue
        maxR = P + Q - 1
        triangles += bisect.bisect_right(L, maxR) - (j + 1)

print(triangles)
### BUGGY CODE ###

from functools import reduce

if __name__ == "__main__":
    input()
    aList = list(map(int, input().split()))
    if not 0 in aList:
        result = reduce(lambda x, y: x*y, aList)
        print(result if result <= 10**18 else -1)
    else:
        print(0)

### FIXED CODE ###

from functools import reduce

def m(l):
    result = 1
    for num in l:
        result *= num
        if result == 0:
            return 0
        elif result > 10**18:
            return -1
    return result

if __name__ == "__main__":
    input()
    aList = list(map(int, input().split()))
    aList.sort()
    print(m(aList))
### BUGGY CODE ###

a, b = map(int, input().split())
ans = 0

for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i ==0:
        for s in range(2, i-1):
            if i % s == 0:
                break
        else:
            ans += 1

print(ans)

### FIXED CODE ###

import math
from fractions import gcd

a, b = map(int, input().split())
cd = set()
ans = set()

'''
g = gcd(a, b)

for i in range(1, g+1):
    if a % i == 0 and b % i == 0:
        cd.add(i)
        '''

i =  1
a_set = set()

for i in range(1, int(math.sqrt(a)) + 1):
    if a % i == 0:
        a_set.add(i)
        a_set.add(a // i)
    i += 1

i = 1
b_set = set()

for i in range(1, int(math.sqrt(b)) + 1):
    if b % i == 0:
        b_set.add(i)
        b_set.add(b // i)
    i += 1

cd = set(a_set) & set(b_set)

for s in sorted(list(cd)):
    if s == 1:
        ans.add(s)
    else:
        for t in sorted(list(ans)):
            if t == 1:
                continue
            elif s % t == 0:
                break
        else:
            ans.add(s)

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

n, m = map(int, input().split(' '))

h = int(m/n)
x = 0
result = [x for x in range(h, 0, -1) if m%x==0]
print(max(result))

### FIXED CODE ###

import sys

def make_divisors(num):
    divisors = []
    for i in range(1, int(num**0.5)+1):
        if num%i == 0:
            divisors.append(i)
            if num//i != i:
                divisors.append(num//i)
    divisors.sort()
    return divisors

n, m = map(int, input().split(' '))

divisors = make_divisors(m)

for i in range(1, len(divisors)+1):
    if divisors[i*-1] * n <= m:
        print(divisors[i*-1])
        sys.exit()
### BUGGY CODE ###

#coding: utf-8
times= int(input())
a= 1
for i in list(map(int, input().split())):
  a*= i

if a > 10**18:
  print('-1')
else:
  print(a)

### FIXED CODE ###

#coding: utf-8
times= int(input())
nums= list(map(int, input().split()))
a= 1
if 0 in nums:
  print(0)
  exit()
for i in nums:
  a*= i
  if a > 10**18:
    print('-1')
    exit()
else:
  print(a)
### BUGGY CODE ###

N, M = map(int, input().split())
G = [[] for _ in range(3 * N)]
L = [0 for _ in range(3 * N)]
for _ in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[3*u+0].append(3*v+1)
    G[3*u+1].append(3*v+2)
    G[3*u+2].append(3*v+0)
s, t = map(int, input().split())
S = 3 * (s-1)
T = 3 * (t-1)

Frontier = [S]
Explored = []
while Frontier:
    v = Frontier.pop(0)
    l = L[v]
    Explored.append(v)
    for i in G[v]:
        if i == T:
            print((L[v] + 1) // 3)
            exit();
        if i not in Explored:
            Frontier.append(i)
            L[i] = l + 1

print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
G = [[] for _ in range(3 * N)]
L = [-3 for _ in range(3 * N)]
for _ in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[3*u+0].append(3*v+1)
    G[3*u+1].append(3*v+2)
    G[3*u+2].append(3*v+0)
s, t = map(int, input().split())
S = 3 * (s-1)
T = 3 * (t-1)

L[S] = 0
Frontier = [S]
while Frontier:
    v = Frontier.pop(0)
    for i in G[v]:
        if L[i] < 0:
            Frontier.append(i)
            L[i] = L[v] + 1

print(L[T]//3)
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
    r1, c1, r2, c2 = map(int, read().split())
    mod = 10 ** 9 + 7

    def generate_inv(n, mod):
        """
        逆元行列
        n >= 2
        Note: mod must bwe a prime number
        """
        ret = [0, 1]
        for i in range(2, n + 1):
            next = -ret[mod % i] * (mod // i)
            next %= mod
            ret.append(next)
        return ret

    inv = generate_inv(2 * 10 ** 6, mod)

    def comb_mod2(n, a, mod):
        """
        return: [n, a] % mod
        Note: mod must be a prime number
        """
        if a == 0 or n == 0:
            return 1
        ret = 1
        for i in range(1, a + 1):
            ret *= n - i + 1
            ret %= mod
            ret *= inv[i]
            ret %= mod
        return ret


    def calc(i,j):
        ret = 0
        agg = comb_mod2(j, 0, mod)
        for k in range(1, i+2):
            agg *= (j+k)%mod
            agg *= inv[k]
            agg %= mod
            ret += agg
        return ret


    ret = 0
    ret += calc(r2, c2)
    ret -= calc(r2, c1-1)
    ret -= calc(r1-1, c2)
    ret += calc(r1-1, c1-1)
    ret %= mod
    print(ret)

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
    r1, c1, r2, c2 = map(int, read().split())
    mod = 10 ** 9 + 7

    def generate_inv(n, mod):
        """
        逆元行列
        n >= 2
        Note: mod must bwe a prime number
        """
        ret = [0, 1]
        for i in range(2, n + 1):
            next = -ret[mod % i] * (mod // i)
            next %= mod
            ret.append(next)
        return ret

    inv = generate_inv(10 ** 6 + 1, mod)



    def calc(i,j):
        ret = 0
        agg = 1
        for k in range(1, i+2):
            agg *= (j+k)%mod
            agg *= inv[k]
            agg %= mod
            ret += agg
        return ret


    ret = 0
    ret += calc(r2, c2)
    ret -= calc(r2, c1-1)
    ret -= calc(r1-1, c2)
    ret += calc(r1-1, c1-1)
    ret %= mod
    print(ret)

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

H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]
nA = [["_" for _ in range(W)] for _ in range(H)]
for i in range(H):
    nA[i] = A[i][:]

result = 0
while True:
    count = 0
    for i in range(H):
        count += A[i].count("#")

    if count == H * W:
        break

    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                    if 0 <= i + di < H and 0 <= j + dj < W:
                        nA[i + di][j + dj] = "#"

    for i in range(H):
        A[i] = nA[i][:]

    result += 1


print(result)

### FIXED CODE ###

from collections import deque
H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]

Q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            Q.append((i, j, 0))

ans = 0
while Q:
    i, j, dist = Q.popleft()
    ans = max(ans, dist)
    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "#"
            Q.append((ni, nj, dist + 1))

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

n,q=map(int,input().split())
s=input()
ans=[0]*n
for i in range(len(s)-1):
    if s[i:i+2]=='AC':ans[i]=1
for _ in range(q):
    l,r=map(int,input().split())
    print(ans[l-1:r-1].count(1))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
ans=[0]*n
cnt=0
for i in range(len(s)-1):
    if s[i:i+2]=='AC': cnt+=1
    ans[i]=cnt
for _ in range(q):
    l,r=map(int,input().split())
    print(ans[r-2]-ans[l-2])
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.zeros((N,2,N), dtype=bool) # A = {([false],[true]),,}

for i in range(N):
  for j in range(int(input())):
  	x, y = map(int,input().split())
  	A[i][y][x-1] = True

upper = 0

def hantei(mask,s):
  m2 = np.repeat([mask], s, axis=0).reshape(-1)
  aa = A[mask]
  a0 = aa[:,0].reshape(-1)
  if np.any(m2[a0]!=0): return False
  a1 = aa[:,1].reshape(-1)
  if np.any(m2[a1]!=1): return False
  return True

seed = 1 << np.arange(N)

for i in range(2**N):
  mask = (seed & i).astype(bool)
  s = np.sum(mask)
  if s <= upper: continue
  if hantei(mask,s): upper = s

print(upper)

### FIXED CODE ###

import numpy as np

N = int(input())
A = np.zeros((N,2,N), dtype=bool) # A = {([false],[true]),,}

for i in range(N):
  for j in range(int(input())):
  	x, y = map(int,input().split())
  	A[i][y][x-1] = True

upper = 0

def hantei(mask):
  for a in A[mask]:
    if np.any(mask[a[0]]): return False
    if not(np.all(mask[a[1]])): return False
  return True

seed = 1 << np.arange(N)

for i in range(2**N):
  mask = (seed & i).astype(bool)
  s = np.sum(mask)
  if s <= upper: continue
  if hantei(mask): upper = s

print(upper)
### BUGGY CODE ###

h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
b = [list(map(int,input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        a[i][j] = abs(a[i][j] - b[i][j])

dp = [[0] * 9600 for _ in range(w)]
for i in range(h):
    for j in range(w):
        min_ = max(0, 3200 - min(i+j, 160-i-j)*80)
        max_ = min(9599, 3200 + min(i+j, 160-i-j)*80)
        a_tmp = a[i][j]
        if(i==0)&(j==0):
            dp[j][3200+a_tmp] += 1
            dp[j][3200-a_tmp] += 1
        elif(i==0):
            for k in range(min_, max_+1):
                if(k+a_tmp < 9600):
                    dp[j][k+a_tmp] += dp[j-1][k]
                if(k-a_tmp >= 0):
                    dp[j][k-a_tmp] += dp[j-1][k]
        elif(j==0):
            tmp = [0] * 9600
            for k in range(min_, max_+1):
                if(k+a_tmp < 9600):
                    tmp[k+a_tmp] += dp[j][k]
                if(k+a_tmp >= 0):
                    tmp[k-a_tmp] += dp[j][k]
            dp[j] = tmp[::]
        else:
            tmp = [0] * 9600
            for k in range(min_, max_+1):
                if(k+a_tmp < 9600):
                    tmp[k+a_tmp] += dp[j-1][k]
                    tmp[k+a_tmp] += dp[j][k]
                if(k+a_tmp >= 0):
                    tmp[k-a_tmp] += dp[j-1][k]
                    tmp[k-a_tmp] += dp[j][k]
            dp[j] = tmp[::]

ans = 3200
for i in range(3100, 3300):
    if(dp[-1][i] > 0):
        ans = min(ans, abs(i-3200))

print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
b = [list(map(int,input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        a[i][j] = abs(a[i][j] - b[i][j])

base = 2**12800 - 1
dp = [[0] * (w+1) for _ in range(h+1)]
dp[1][1] = (2**6400 >> a[0][0])|(2**6400 << a[0][0])&base
for i in range(1,h+1):
    for j in range(1,w+1):
        if(i==1)&(j==1):
            dp[1][1] = (2**6400 >> a[0][0])|(2**6400 << a[0][0])&base
            continue

        dp[i][j] = ((dp[i-1][j] >> a[i-1][j-1])|(dp[i-1][j] << a[i-1][j-1])|
                    (dp[i][j-1] >> a[i-1][j-1])|(dp[i][j-1] << a[i-1][j-1]))&base

ans = 6400
ans_bit = dp[-1][-1]
for i in range(6300,6500):
    if((ans_bit >> i)&1 == 1):
        ans = min(ans, abs(6400-i))

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

H, W, M = map(int, input().split())
row=[0]*H
col=[0]*W

mat=[[0 for i in range(W)] for j in range(H)]

for i in range(M):
  h, w = map(int, input().split())
  h-=1
  w-=1
  row[h]+=1
  col[w]+=1
  mat[h][w]+=1

r=max(row)
c=max(col)

rr=[i for i in range(H) if row[i]==r]
cc=[i for i in range(W) if col[i]==c]

for i in rr:
  for j in cc:
    if mat[i][j]==0:
      print(r+c)
      exit()

print(r+c-1)

### FIXED CODE ###

H, W, M = map(int, input().split())
row=[0]*H
col=[0]*W

mat=[]

for i in range(M):
  h, w = map(int, input().split())
  row[h-1]+=1
  col[w-1]+=1
  mat.append((h-1,w-1))
  
r=max(row)
c=max(col)

rr=[1 if row[i]==r else 0 for i in range(H)]
cc=[1 if col[i]==c else 0 for i in range(W)]

x=0
for k in mat:
  if rr[k[0]]==1 and cc[k[1]]==1:
    x+=1

if sum(rr)*sum(cc)==x:
  print(r+c-1)
else:
  print(r+c)
### BUGGY CODE ###

from collections import Counter

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

A_sort = sorted(A)
A_counter = Counter(A)

res = 0
# res_list = []
for i in range(len(A_sort)):
    count = 0
    A_sort_tmp = A_sort[:i]

    if A_counter[A_sort[i]] >= 2:
        continue

    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] != 0:
            count += 1

    if count == len(A_sort_tmp):
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)


### FIXED CODE ###

from collections import defaultdict

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

bool_list = [True] * (10 ** 6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2*a, 10 ** 6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))
### BUGGY CODE ###

import sys

Num = int(sys.stdin.readline().rstrip())
list_stu_Num = list(sys.stdin.readline().rstrip().split())
list_attend_stu = []
for i in range(1, Num + 1):
    for l in range(0, Num):
        if list_stu_Num[l] == str(i):
            list_attend_stu.append(l + 1)
print(*list_attend_stu)

### FIXED CODE ###

import sys
import numpy as np

Num = int(sys.stdin.readline().rstrip())
list_stu_Num = list(sys.stdin.readline().rstrip().split())
list_stu_Num_int = [int(s) for s in list_stu_Num]
print(*np.argsort(list_stu_Num_int) + 1)
### BUGGY CODE ###

N = int(input())
S = input()

res = 1e+9
for i in range(N):
    l = S[:i]
    r = S[i+1:]
    cnt = 0
    cnt += l.count('W')
    cnt += r.count('E')
    res = min(res,cnt)
print(res)

### FIXED CODE ###

N = int(input())
S = input()

def f(S):
    cnt = S.count('E')
    for s in S:
        if s == 'E':
            cnt -= 1
        yield cnt
        if s == 'W':
            cnt += 1

print(min(list(f(S))))