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

n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
sl=[]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        sl.append([i+1,i+2])
    else:
        pass

for i in range(q):
    ctr1=1
    ctr2=0
    for k in range(len(sl)):
        if lr[i][0] > sl[k][0]:
            ctr1+=1
        else:
            break
    for m in range(len(sl)):
        if lr[i][1] >= sl[m][1]:
            ctr2+=1
        else:
            break
    print(ctr2-ctr1+1)


### FIXED CODE ###

n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
ctr1=0
t_list=[0]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        t_list.append(ctr1)
    else:
        t_list.append(ctr1)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(t_list[right-1]-t_list[left-1])
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[]
for i in range(Q):
    b,c=(map(int,input().split()))
    BC.append([b,c])
#最初に全探索で位置をインデックスに登録する
DP=[[] for _ in range(10**5+1)]
for i in range(len(A)):
    DP[A[i]].append(i)#
for i in BC:
    target=i[0]
    nex=i[1]
    for j in DP[target]:
        A[j]=nex
        DP[nex].append(j)
    print(sum(A))
    DP[target]=[]

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[]
for i in range(Q):
    b,c=(map(int,input().split()))
    BC.append([b,c])

#最初に全探索で位置をインデックスに登録する
DP=[0]*(10**5+1)
for i in A:
    DP[i]+=1#
ans=sum(A)
for i in BC:
    target=i[0]
    nex=i[1]
    num=DP[target]
    DP[target]=0
    DP[nex]=DP[nex]+num
    ans=ans+num*nex-num*target
    print(ans)
### BUGGY CODE ###

import numpy as np
from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
S = [stdin.readline().rstrip() for _ in range(H)]

left = [[0]*W for i in range(H)]
right = [[0]*W for i in range(H)]
up = [[0]*W for i in range(H)]
down = [[0]*W for i in range(H)]

for i in range(H):
    p = 0
    for j in range(W):
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        left[i][j] = p
for i in range(H):
    p = 0
    for j in range(W)[::-1]:
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        right[i][j] = p
for j in range(W):
    p = 0
    for i in range(H):
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        up[i][j] = p
for j in range(W):
    p = 0
    for i in range(H)[::-1]:
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        down[i][j] = p

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3) 

print(ans)

### FIXED CODE ###

from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
S = [stdin.readline().rstrip() for _ in range(H)]

left = [[0]*W for i in range(H)]
right = [[0]*W for i in range(H)]
up = [[0]*W for i in range(H)]
down = [[0]*W for i in range(H)]

for i in range(H):
    p = 0
    for j in range(W):
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        left[i][j] = p
for i in range(H):
    p = 0
    for j in range(W)[::-1]:
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        right[i][j] = p
for j in range(W):
    p = 0
    for i in range(H):
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        up[i][j] = p
for j in range(W):
    p = 0
    for i in range(H)[::-1]:
        if S[i][j] == '#':
            p = 0
        else:
            p += 1
        down[i][j] = p

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3) 

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

N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i] =map(int,input().split())

ans_list=[]  
from copy import deepcopy
def dfs(x,M,N,ans):
  if len(ans)<=N:
    ans.append(x)
    if len(ans)==N:
      if ans not in ans_list:
        ans_list.append(ans)
    else:
      for i in range(x,M+1):
        tmp=deepcopy(ans)
        dfs(i,M,N,tmp)   
      
q=dfs(1,M,N,[])

f=0
for A in ans_list:
  cnt=0
  for i in range(Q):
    if A[b[i]-1]-A[a[i]-1]==c[i]:
      cnt += d[i]
  f=max(f,cnt)
  
print(f)

### FIXED CODE ###

N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i] =map(int,input().split())

ans_list=[]  
from copy import deepcopy
def dfs(x,M,N,ans):
  if len(ans)<=N:
    ans.append(x)
    if len(ans)==N:
      ans_list.append(ans)
    else:
      for i in range(x,M+1):
        tmp=deepcopy(ans)
        dfs(i,M,N,tmp)   
      
q=dfs(1,M,N,[])

f=0
for A in ans_list:
  cnt=0
  for i in range(Q):
    if A[b[i]-1]-A[a[i]-1]==c[i]:
      cnt += d[i]
  f=max(f,cnt)
  
print(f)
### BUGGY CODE ###

N, K = map(int,input().split())
h = sorted(int(input()) for _ in range(N))

ans = 1e9+7
for i in range(N-K+1):
  x = h[i:i+K]
  ans = min(ans, x[-1]-x[0])
print(ans)

### FIXED CODE ###

N, K = map(int,input().split())
h = sorted([int(input()) for i in range(N)])
trees = [h[i+K-1] - h[i] for i in range(N-K+1)]
print(min(trees))
### BUGGY CODE ###

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
def lcma(a,b):
  return a*b//gcd(a,b)
n=int(input())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a[1:]:
  lcm=lcma(lcm,i)
b=[]
for i in a:
  b.append(lcm//i)
ans=sum(b)%(10**9+7)
print(ans)

### FIXED CODE ###

n=int(input())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a:
  lcm = lcm * i // fractions.gcd(lcm, i)
b=[]
for i in a:
  b.append(lcm//i)
ans=sum(b)%(10**9+7)
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import deque


if __name__ == '__main__':

    n, m = [int(s) for s in input().split(" ")]
    M = [set() for j in range(n)]
    for _ in range(m):
        u, v = [int(s) for s in input().split(" ")]
        M[u].add(v)
        M[v].add(u)
        
    color = [0] * n
    def dfs(u, c):  # depth-first search
        color[u] = c
        for v in range(n):
            if v in M[u] and color[v] == 0:
                dfs(v, c)
        color[u] = c
    
    c = 1
    for u in range(n):
        if color[u] == 0:
            dfs(u, c)
            c += 1
    
    l = int(input())
    for _ in range(l):
        p, q = [int(s) for s in input().split(" ")]
        if color[p] == color[q]:
            print("yes")
        else:
            print("no")



### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import deque
import sys
sys.setrecursionlimit(200000)


if __name__ == '__main__':

    n, m = [int(s) for s in input().split(" ")]
    M = [set() for j in range(n)]
    for _ in range(m):
        u, v = [int(s) for s in input().split(" ")]
        M[u].add(v)
        M[v].add(u)
        
    color = [0] * n
    def dfs(u, c):  # depth-first search
        color[u] = c
        for v in M[u]:
            if color[v] == 0:
                dfs(v, c)
    
    c = 1
    for u in range(n):
        if color[u] == 0:
            dfs(u, c)
            c += 1
    
    l = int(input())
    for _ in range(l):
        p, q = [int(s) for s in input().split(" ")]
        if color[p] == color[q]:
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
for i in range(N):
    if A[i] != max(A):
        print(max(A))
    else:
        B = A.copy()
        del B[i]
        print(max(B))

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
for i in range(N):
    if A[i] == B[0]:
        print(B[1])
    else:
        print(B[0])
### BUGGY CODE ###

n, k, l = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        self.tree = [i for i in range(n)]

    def root(self, x):
        if(self.tree[x] == x):
            return x
        self.tree[x] = self.root(self.tree[x])
        return self.tree[x]  # 経路圧縮

    def same(self, x, y):  # xとyが同じ木に属するか
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if(x == y):
            return
        self.tree[x] = y


uf = UnionFind(n)
uf2 = UnionFind(n)

for _ in range(k):
    p, q = map(int, input().split())
    uf.unite(q-1, p-1)
for _ in range(l):
    r, s = map(int, input().split())
    uf2.unite(s-1, r-1)

for i in range(n):
    ans = 0
    for j in range(n):
        if uf.same(i, j) and uf2.same(i, j):
            ans += 1
    print(ans, end=' ')


### FIXED CODE ###

n, k, l = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        self.tree = [i for i in range(n)]

    def root(self, x):
        if(self.tree[x] == x):
            return x
        self.tree[x] = self.root(self.tree[x])
        return self.tree[x]  # 経路圧縮

    def same(self, x, y):  # xとyが同じ木に属するか
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if(x == y):
            return
        self.tree[x] = y


uf = UnionFind(n)
uf2 = UnionFind(n)

for _ in range(k):
    p, q = map(int, input().split())
    uf.unite(q-1, p-1)
for _ in range(l):
    r, s = map(int, input().split())
    uf2.unite(s-1, r-1)

#table = [[0]*n for _ in range(n)]
table = dict()

for i in range(n):
    #table[uf.root(i)][uf2.root(i)] += 1
    table[(uf.root(i), uf2.root(i))] = table.get(
        (uf.root(i), uf2.root(i)), 0)+1
for i in range(n):
    print(table[(uf.root(i), uf2.root(i))], end=' ')

exit(0)
for i, j in [(uf.root(i), uf2.root(i)) for i in range(n)]:
    table[i][j] += 1
for i, j in [(uf.root(i), uf2.root(i)) for i in range(n)]:
    print(table[i][j], end=' ')


exit(0)
for i in range(n):
    ans = 0
    for j in range(n):
        if uf.same(i, j) and uf2.same(i, j):
            ans += 1
    print(ans, end=' ')
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c={}
for i in b:
    c[i]=a.count(i)
al=0
ans=[]
for i in c.values():
    al+=(i*(i-1))//2
for i in range(n):
    print(al - (c[a[i]]-1))

### FIXED CODE ###

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

c=Counter(a)

al=0
for i in c.values():
    al+=(i*(i-1))//2
for i in range(n):
    print(al - (c[a[i]]-1))
### BUGGY CODE ###

N,K=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
ex=[1/2*(i+1) for i in p]

mx=0
ind=0
ans=0
# for i in range(ind,ind+K):
#   ans+=ex[p[i]-1]
s=0
for i in range(N-K+1):
  s=sum(ex[i:i+K])
  mx=max(mx,s)
print(mx)




### FIXED CODE ###

N,K=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
ex=[1/2*(i+1) for i in p]
ruiseki=[0]
ans=0

for i in range(N):
  ruiseki.append(ruiseki[i]+ex[i])


for i in range(N+1-K):
  if ans<ruiseki[i+K]-ruiseki[i]:
    ans=ruiseki[i+K]-ruiseki[i]
print(ans)
### BUGGY CODE ###

H, W = map(int, input().split())
C = list(map(lambda x: int(x) - 1, input().split()))
D = list(map(lambda x: int(x) - 1, input().split()))
S = [input() for _ in range(H)]
toGo = [[False if i != C[0] or j != C[1] else True for j in range(W)] for i in range(H)]
queue = [C]
ans = 0

while True:
    tmp = queue.pop()
    dfs = [tmp]

    while len(dfs):
        a = dfs.pop()
        for move in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            hh, ww = a[0] + move[0], a[1] + move[1]
            if hh >= H or hh < 0 or ww >= W or ww < 0:
                continue

            if not toGo[hh][ww] and S[hh][ww] == '.':
                toGo[hh][ww] = True
                dfs.append([hh, ww])

    if toGo[D[0]][D[1]]:
        break

    flag = True
    if not len(queue):
        ttogo = [[toGo[i][j] for j in range(W)] for i in range(H)]
        ans += 1
        for i in range(H):
            for j in range(W):
                if not toGo[i][j] and S[i][j] == ".":
                    t = False
                    for ii in range(-2, 3):
                        for jj in range(-2, 3):
                            hh, ww = i + ii, j + jj
                            if hh >= H or hh < 0 or ww >= W or ww < 0:
                                continue

                            if toGo[hh][ww]:
                                ttogo[i][j] = True
                                flag, t = False, True
                                queue.append([i, j])
                                break
                        if t:
                            break
        toGo = ttogo
        if flag:
            print(-1)
            exit()

print(ans)


### FIXED CODE ###

H, W = map(int, input().split())
C = list(map(lambda x: int(x) - 1, input().split()))
D = list(map(lambda x: int(x) - 1, input().split()))
S = [input() for _ in range(H)]
toGo = [[False if i != C[0] or j != C[1] else True for j in range(W)] for i in range(H)]
queue, mahou = [C], [C]
ans = 0

while True:
    tmp = queue.pop()
    mahou.append(tmp)
    dfs = [tmp]

    while len(dfs):
        a = dfs.pop()
        for move in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            hh, ww = a[0] + move[0], a[1] + move[1]
            if hh >= H or hh < 0 or ww >= W or ww < 0:
                continue

            if not toGo[hh][ww] and S[hh][ww] == '.':
                toGo[hh][ww] = True
                dfs.append([hh, ww])
                mahou.append([hh, ww])

    if toGo[D[0]][D[1]]:
        break

    flag = True
    if not len(queue):
        ans += 1
        for k in mahou:
            for i in range(-2, 3):
                for j in range(-2, 3):
                    h, w = i + k[0], j + k[1]
                    if h >= H or h < 0 or w >= W or w < 0:
                        continue

                    if not toGo[h][w] and S[h][w] == '.':
                        flag = False
                        toGo[h][w] = True
                        queue.append([h, w])
        mahou = []

        if flag:
            print(-1)
            exit()

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

n = input()
s = raw_input()

result = 300000

for i in range(n):
    cnt = 0
    a = s[:i].replace("E", "")
    b = s[i+1:].replace("W", "")
    result = min(len(a) + len(b), result)

print result

### FIXED CODE ###

n = input()
s = raw_input()

result = 300000

before = 0
after = 0

for i in range(n):
    if s[i] == "E":
        before = before + 1
    if before > after:
        before = after
    if s[i] == "W":
        after = after + 1

print min(before, after)
### BUGGY CODE ###

import itertools
N = int(input())
A = [[int(i) for i in input().split()] for j in range(N)]
for i in range(N):
    A[i][i] = float("inf")
Node = [int(i) for i in range(N)]
Comb = list(itertools.combinations(Node, 2))
 
Total, Possible = 0, True
for c in Comb:
    a = A[c[0]][c[1]]
    for i in range(N):
        if A[c[0]][i] + A[c[1]][i] == a:
            break
        elif A[c[0]][i] + A[c[1]][i] < a:
            Possible = False
            break
    else:
        Total += a
    if not Possible:
        print(-1)
        break
else:
    print(Total)

### FIXED CODE ###

import sys
from itertools import permutations, combinations
  
def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [[int(a) for a in input().split()] for _ in range(N)]

    length = 0
    possible = True
    for a, b in combinations(range(N), 2):
        Lab = A[a][b]
        create_pass = True
        for k in range(N):
            if k != a and k != b:
                if Lab >  A[a][k] + A[k][b]:
                    possible = False
                    break
                elif Lab ==  A[a][k] + A[k][b]:
                    create_pass = False
                    break
        if create_pass: length += Lab
        if not possible:
            print(-1)
            break
    else: print(length)
    
    return 0
  
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

def main():
    import sys
    n = int(input())
    a = list(map(int, input().split()))

    ans = 1
    for i in a:
        if i == 0:
            print(0)
            sys.exit()
        ans *= i

    if ans > 10 ** 18:
        print(-1)
        sys.exit()

    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    n = int(input())
    a = list(map(int, input().split()))

    try:
        if a.index(0):
            print(0)
            sys.exit()
    except ValueError:
        pass

    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            print(-1)
            sys.exit()

    print(ans)


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

import numpy  as np

N = int(input())

# log_6 10^5 < 7
# log_9 10^5 < 6
# 15 = 1 + 6 + 5
memo = np.zeros((15, N + 1))
memo[:, :] = N * 2
memo[0][0] = 0

values = []

i = 1
while i <= N:
    values.append(i)
    i *= 6
i = 9
while i <= N:
    values.append(i)
    i *= 9

for i in range(len(values)):
    v = values[i]
    for w in range(N+1):
        if v > w:
            memo[i + 1][w] = memo[i][w]
        else:
            memo[i + 1][w] = min(memo[i][w], memo[i+1][w - v] + 1)
print(int(memo[len(values)][N]))

### FIXED CODE ###

import numpy  as np

N = int(input())

# log_6 10^5 < 7
# log_9 10^5 < 6
# 15 = 1 + 6 + 5
memo = np.zeros((15, N + 1),int)
memo[:, :] = N * 2
memo = memo.tolist()
memo[0][0] = 0

values = []

i = 1
while i <= N:
    values.append(i)
    i *= 6
i = 9
while i <= N:
    values.append(i)
    i *= 9

for i in range(len(values)):
    v = values[i]
    for w in range(N+1):
        if v > w:
            memo[i + 1][w] = memo[i][w]
        else:
            memo[i + 1][w] = min(memo[i][w], memo[i+1][w - v] + 1)
print(int(memo[len(values)][N]))
### BUGGY CODE ###

from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())

cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            a = math.gcd(i+1, j+1)
            b = math.gcd(a, k+1)
            cnt += b

print(cnt)

### FIXED CODE ###

from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())

cnt = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k) * 6
            if i == j and j == k:
                b = int(b/6)
            elif i == j or j == k or i == k:
                b = int(b/2)
            #print(str(i) + ' ' + str(j) + ' ' + str(k) + ' : ' + str(b))
            cnt += b

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

import math
def q77(N, a):
    i = 0
    while True:
        b = False
        for j in range(N):
            if (a[j]/2).is_integer():
                a[j] = a[j]/2
                i += 1
                b = True
                break
        if not b:
            break
    return i

N = int(input())
a = [int(i) for i in input().split()]

print(q77(N, a))

### FIXED CODE ###

import math
def q77(N, a):
    i = 0
    o = 0
    while True:
        b = False
        for j in range(o, N):
            a[j] = a[j]/2
            if a[j].is_integer():
                i += 1
                b = True
                break
            else:
                o = j
        if not b:
            break
    return i

N = int(input())
a = [int(i) for i in input().split()]

print(q77(N, a))
### BUGGY CODE ###

N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
Bn = Bn + An
Cn = Cn + An
for k in range(N):    
    Bn[k] = Bn[k] + k + 1
    Cn[k] = k + 1 - Cn[k]
Bn_and_Cn = set(Bn) & set(Cn)
for i in Bn_and_Cn:
    c += Bn.count(i) * Cn.count(i)
print(c)

### FIXED CODE ###

from collections import Counter
N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
for k in range(N):    
    Bn.append(An[k]+k)
    Cn.append(k-An[k])
Cj = Counter(Cn)
for i in Bn:
    c+=Cj[i]
print(c)
### BUGGY CODE ###

def main():
    from collections import defaultdict,deque
    from itertools import count
    (n,),*a=[list(map(int,t.split()))for t in open(0)]
    d=defaultdict(count().__next__)
    es=[]
    for i,b in enumerate(a,1):
        for j,k in zip(b,b[1:]):
            x,y=i,j
            if y<x:x,y=y,x
            v,w=i,k
            if w<v:v,w=w,v
            es+=(d[x*n+y],d[v*n+w]),
    s=len(d)
    outs=[[]for _ in range(s)]
    ins=[0]*s
    f=set(range(s))
    for i,j in es:
        outs[i]+=j,
        f-={j}
        ins[j]+=1
    q=deque(f)
    r=[]
    data=[0]*s
    m=0
    while q:
        i=q.popleft()
        r+=i,
        t=data[i]+1
        if t>m:m=t
        for j in outs[i]:
            ins[j]-=1
            if ins[j]<1:q+=j,
            if t>data[j]:data[j]=t
    print(-(len(r)<s)or m)
main()

### FIXED CODE ###

def main():
    from collections import defaultdict,deque
    from itertools import count
    (n,),*a=[list(map(int,t.split()))for t in open(0)]
    d=defaultdict(count().__next__)
    es=[]
    for i,b in enumerate(a,1):
        for j,k in zip(b,b[1:]):
            x,y=i,j
            if y<x:x,y=y,x
            v,w=i,k
            if w<v:v,w=w,v
            es+=(d[x*n+y],d[v*n+w]),
    s=len(d)
    outs=[[]for _ in range(s)]
    ins=[0]*s
    f=set(range(s))
    for i,j in es:
        outs[i]+=j,
        f-={j}
        ins[j]+=1
    q=deque(f)
    r=[]
    data=[0]*s
    m=0
    while q:
        i=q.popleft()
        r+=i,
        t=data[i]+1
        if t>m:m=t
        for j in outs[i]:
            ins[j]-=1
            if ins[j]<1:q+=j,
            if t>data[j]:data[j]=t
    print(-(len(r)<s)or m)
main()
### BUGGY CODE ###

a=input();c=0
for i,j in enumerate(a):
	c+=(j=="B")*a[i:].count("W")
print(c)

### FIXED CODE ###

import bisect
a=input()
bs=[i for i,j in enumerate(a) if j=="B"]
ws=[i for i,j in enumerate(a) if j=="W"]
cnt=0
for w in ws:
	cnt+=bisect.bisect(bs,w)
print(cnt)
### BUGGY CODE ###

import heapq

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()

pq = []
for i in range(n):
    heapq.heappush(pq, (-a[i]*f[i], a[i], f[i]))

for i in range(k):
    score, ai, fi = heapq.heappop(pq)
    if score == 0:
        heapq.heappush(pq, (0, 0, 0))
        break
    heapq.heappush(pq, (-((ai-1) * fi), ai-1, fi))

print(-heapq.heappop(pq)[0])


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()

ori = [0] * n
for i in range(n):
    ori[i] = a[i]*f[i]

ok = max(ori)
ng = -1
mid = (ok+ng) // 2
while ok - ng > 1:
    cnt = 0
    flg = 0
    for i in range(n):
        if ori[i] > mid:
            cnt += (a[i] - mid // f[i])
        if cnt > k:
            flg = 1
            break
    if flg:
        ng = mid
    else:
        ok = mid
    mid = (ok + ng) // 2

print(ok)
### BUGGY CODE ###

import numpy as np
n,k = map(int,input().split())
s = list(input())
 
l0 = []
l1 = []
pred = s[0]
if s[0] == "0":
    l0.append(1)
    l1.append(0)
else:
    l1.append(1)
 
for i in range(1,n):
    if pred == s[i]:
        if s[i] == "0":
            l0[-1] += 1
        else:
            l1[-1] += 1
    else:
        if s[i] == "0":
            l0.append(1)
        else:
            l1.append(1)
    pred = s[i]
if s[-1] == "0":    
    l1.append(0)

ans = 0
if k >= len(l0):
    print(n)
else:
    nl1 = len(l1)
    for i in range(nl1-k):
        ans = max(ans,(sum(l0[i:i+k])+sum(l1[i:i+k+1])))
    print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
s = list(input())
 
l0 = []
l1 = []
pred = s[0]
if s[0] == "0":
    l0.append(1)
    l1.append(0)
else:
    l1.append(1)
 
for i in range(1,n):
    if pred == s[i]:
        if s[i] == "0":
            l0[-1] += 1
        else:
            l1[-1] += 1
    else:
        if s[i] == "0":
            l0.append(1)
        else:
            l1.append(1)
    pred = s[i]
if s[-1] == "0":    
    l1.append(0)
 
ans = sum(l0[:k])+sum(l1[:k+1])
tmp = ans
for i in range(k,min(len(l0),len(l1))):
    tmp -= l0[i-k]
    tmp -= l1[i-k]
    tmp += l0[i]
    tmp += l1[i+1]
    ans = max(ans, tmp)
print(ans)