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

N=int(input())
A=[int(x) for x in input().split()]
A=sorted(A)
maxA=max(A)
ans=0
so_list=[1]*(maxA+1)
index=0
for i in range(N):
    now=A[i]
    if so_list[now]==1:
        index=0
        while(index+now<=maxA):
            so_list[index+now]=0
            index+=now
        if A.count(now)==1:
            ans+=1
            #print(now)

print(ans)

### FIXED CODE ###

import bisect
N=int(input())
A=[int(x) for x in input().split()]
A=sorted(A)
maxA=max(A)
ans=0
so_list=[1]*(maxA+1)
index=0
i=0

while(i<N):
    flag=0
    now=A[i]
    if so_list[now]==1:
        index=0
        flag=1
        while(index+now<=maxA):
            so_list[index+now]=0
            index+=now
    right=bisect.bisect_right(A,now)#同じ数字はいくつある？
    if right-i==1:
        if flag==1:
            ans+=1
            #print(now)
        i=right
    else:
        i+=1

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

n = int(input())
l = list(map(int, input().split()))
a = 10000000000
for i in range(1,n):
    a = min(a,abs(sum(l[:i])-sum(l[i:])))
print(a)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
a = 10000000000
A = 0
B = sum(l)
for i in range(n-1):
    A += l[i]
    B -= l[i]
    a = min(a,abs(A-B))
print(a)
### BUGGY CODE ###

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

for i in range(N):
    route = copy.deepcopy(A)
    route.pop(i)
    route.insert(0,0)
    route.append(0)
    #print(route)
    dist = 0
    for j in range(N):
        dist += abs(route[j]-route[j+1])
    print(dist)


### FIXED CODE ###

import copy
N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0,0)
dist = 0
for j in range(N+1):
    dist += abs(A[j]-A[j+1])
for j in range(N):
    res = dist + abs(A[j+2]-A[j]) - abs(A[j+1]-A[j]) - abs(A[j+2]-A[j+1])
    print(res)
### BUGGY CODE ###

from collections import deque
n = int(input())
a_list = [None for _ in range(n)]
num = 0
day = 0
for i in range(n):
    a_list[i] = deque([int(i) - 1 for i in input().split()])

while (num < n * (n - 1) // 2):
    visit = set([])
    day += 1
    for j in range(n):
        if j not in visit:
            if len(a_list[j]) > 0:
                k = a_list[j][0]
                if k not in visit:
                    if a_list[k][0] == j:
                        num += 1
                        visit = visit.union({k, j})
                        a_list[k].popleft()
                        a_list[j].popleft()
    if (len(visit) == 0):
        day = -1
        break
print(day)

### FIXED CODE ###

from collections import deque
n = int(input())
a_list = []
for i in range(n):
    a_list.append(deque([int(aa) - 1 for aa in input().split()]))
day = 0
battle = 0
for _ in range(n * (n - 1) // 2):
    if battle == n * (n - 1) // 2:
        break
    day += 1
    battle_today = 0
    tomorrow = set([])
    if (day == 1):
        player = set([i for i in range(n)])
    for i in player:
        if len(a_list[i]) == 0:
            continue
        j = a_list[i][0]
        if (i == a_list[j][0]) & (j not in tomorrow) & (len(a_list[j]) > 0) & (i not in tomorrow):
            tomorrow.add(i)
            tomorrow.add(a_list[i][0])
            battle += 1
            battle_today += 1
            a_list[i].popleft()
            a_list[j].popleft()
    player = tomorrow
    if battle_today == 0:
        day = -1
        break
print(day)
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
s = input()
for i in range(q):
    l, r = na()
    ct = 0
    frg = s[l-1:r]
    for j in range(len(frg)-1):
        if frg[j:j+2] == "AC":
            ct += 1
    print(ct)

### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
s = input()
ct = [0] * n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        ct[i+1] = 1
for i in range(n-1):
    ct[i+1] += ct[i]
for i in range(q):
    l, r = na()
    l -= 1
    r -= 1
    print(ct[r] - ct[l])
### BUGGY CODE ###

#!/usr/bin/env python3

N = int(input())
P = list(map(int, input().split()))
cnt = 0

for i in range(0, N):
    P_i = P[i]
    P_j = P[0:i+1]
    if P_i == min(P_j):
        cnt += 1

print(cnt)

### FIXED CODE ###

#!/usr/bin/env python3

N = int(input())
P = list(map(int, input().split()))
cnt = 0
tmp = 10 ** 10

for i in range(N):
    if tmp >= P[i]:
        cnt += 1
    tmp = min(tmp, P[i])

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

MOD=10**9+7
N,M=map(int,input().split())
A=[0]*M

for i in range(M):
    A[i]=(int(input())+1)

S=[0]*(N+2)
S[1]=1
for i in range(2,N+2):
    if(i not in A):
        S[i]=(S[i-1]+S[i-2])%MOD
    else:
        S[i]=0
print(S[N+1])

### FIXED CODE ###

MOD=10**9+7
N,M=map(int,input().split())
A=[True]*(N+2)

for i in range(M):
    a=(int(input())+1)
    A[a]=False

S=[0]*(N+2)
S[1]=1
for i in range(2,N+2):
    if(A[i]):
        S[i]=(S[i-1]+S[i-2])%MOD
    else:
        S[i]=0
print(S[N+1])
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = list(map(int,input().split()))
uf = UnionFind(N)
p = list(map(int,input().split()))
L = []
for i in range(M):
    x,y = map(int,input().split())
    uf.union(x - 1,y - 1)
cnt = 0

for i in range(N):
    if i in uf.members( p[i] - 1 ):
        cnt+=1
print(cnt)


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return {i for i in range(self.n) if self.find(i) == root}

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = list(map(int,input().split()))
uf = UnionFind(N)
p = list(map(int,input().split()))
L = []
for i in range(M):
    x,y = map(int,input().split())
    uf.union(x - 1,y - 1)
cnt = 0
for i in range(N):
    if uf.same(i,p[i]-1):
        cnt+=1
print(cnt)
### BUGGY CODE ###

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

while i < q:
  l, r = map(int, input().split())
  print(s[l - 1: r].count("AC"))
  i += 1

### FIXED CODE ###

n, q = (int(i) for i in input().split())  
s = input()

count_list = []
bef_str = ''
bef_count = 0

for x in s:
  if bef_str == 'A' and x == 'C':
    bef_count += 1
    
  count_list.append(bef_count)
  bef_str = x
    
for i in range(q):
  l, r = (int(i) for i in input().split())
  print(count_list[r-1] - count_list[l-1])
### BUGGY CODE ###

# +2019までを調べれば十分

l, r = map(int, input().split())
ans = 10**9

for li in range(l, l+2020):
  for ri in range(li, r+1):
    if li < ri:
      ans = min(ans, (li*ri)%2019)

print(ans)

### FIXED CODE ###

# +2019までを調べれば十分

l, r = map(int, input().split())
ans = 10**9

for i in range(l, min(r+1, l+2020)):
  for j in range(i,  min(r+1, l+2020)):
    if i < j:
      ans = min(ans, (i * j)%2019)

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

# D - AtCoder Express 2

import bisect, copy

N, M, Q = map(int, input().split())
LRidx = [list(map(int, input().split())) + [i] for i in range(M)]
p, q = [], []
for _ in range(Q):
    tmp_p, tmp_q = map(int, input().split())
    p.append(tmp_p)
    q.append(tmp_q)

# l,rはそれぞれ高々500通りなので、l,rの値に対して探索結果をメモしておく
LRidx = sorted(LRidx, key = lambda x: x[0])
tmp_L = [LRidx[idx][0] for idx in range(M)]
l_memo = [[-1] for _ in range(N+1)]
l_ok_idx = [[] for _ in range(Q)]
for i in range(Q):
    if l_memo[p[i]] and l_memo[p[i]][0] == -1:
        b_idx = bisect.bisect_left(tmp_L, p[i])
        tmp = [LRidx[j][2] for j in range(b_idx, M)]
        l_ok_idx[i] = copy.deepcopy(tmp)
        l_memo[p[i]] = copy.deepcopy(tmp)
    else:
        l_ok_idx[i] = copy.deepcopy(l_memo[p[i]])
    
LRidx = sorted(LRidx, key = lambda x: x[1])
tmp_R = [LRidx[idx][1] for idx in range(M)]
r_memo = [[-1] for _ in range(N+1)]
r_ok_idx = [[] for _ in range(Q)]
for i in range(Q):
    if l_ok_idx[i] and r_memo[q[i]] and r_memo[q[i]][0] == -1:
        b_idx = bisect.bisect_right(tmp_R, q[i])
        tmp = [LRidx[j][2] for j in range(b_idx)]
        r_ok_idx[i] = copy.deepcopy(tmp)
        r_memo[q[i]] = copy.deepcopy(tmp)
    else:
        r_ok_idx[i] = copy.deepcopy(r_memo[q[i]])
    
for i in range(Q):
    print(len(set(l_ok_idx[i]) & set(r_ok_idx[i])))

### FIXED CODE ###

# D - AtCoder Express 2

import numpy as np

N, M, Q = map(int, input().split())
LR = np.zeros((N+1, N+1))

for _ in range(M):
    l, r = map(int, input().split())
    LR[l,r] += 1

np.cumsum(LR, axis = 0, out = LR)
np.cumsum(LR, axis = 1, out = LR)
    
for _ in range(Q):
    p, q = map(int, input().split())
    print(int(LR[q,q] - LR[p-1,q] - LR[q,p-1] + LR[p-1,p-1]))
### BUGGY CODE ###

a=input()
num=len(a)
mod_map={0:1}
moji_int=0
Sn=0
tens=1
for i in a[::-1]:
    tmp=int(i)*(tens%2019)
    Sn=(Sn+tmp%2019)%2019
    mod=Sn
    tens*=10
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1


res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)


### FIXED CODE ###

a=reversed(input())
#num=len(a)
mod_list=[1]+[0]*2019
moji_int=0
Sn=0
tens=1
for i in a:
    tmp=int(i)*(tens)
    Sn=(Sn+tmp)%2019
    mod=Sn
    tens=tens*10%2019
    mod_list[mod]+=1
res=0
for i in mod_list:
    res+=int(i*(i-1)/2)
print(res)
### BUGGY CODE ###

N = int(input())
alist = list(map(int, input().split()))
Sum_a = 0
for i in range(N):
  Sum_j = 0
  for j in range(i+1, N):
    Sum_j += alist[j]
  Sum_a += alist[i]*Sum_j
print(int(Sum_a%(1e9+7)))

### FIXED CODE ###

N = int(input())
alist = list(map(int, input().split()))
import numpy as np
Sum_a = 0
Sum_j_list = np.cumsum(alist)
for i in range(N-1):
  Sum_j = int((Sum_j_list[N-1] - Sum_j_list[i]) % int(1e9+7))
  Sum_a += (alist[i] * Sum_j) % int(1e9+7)
print(int(Sum_a % int(1e9+7)))
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
odd = 0
even = 0
temp = 0
for i in range(N):
    temp += a[i]
    if i % 2 == 0:
        # 奇数番目が正
        while temp < 1:
            temp += 1
            odd += 1
    else:
        while temp > -1:
            temp -= 1
            odd += 1       
temp = 0
for i in range(N):
    temp += a[i]
    if i % 2 == 0:
        # 奇数番目が負
        while temp > -1:
            temp -= 1
            even += 1
    else:
        while temp < 1:
            temp += 1
            even += 1
print(min(odd,even))

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
odd = 0
even = 0
temp = 0
for i in range(N):
    temp += a[i]
    if i % 2 == 0:
        # 奇数番目が正
        if temp < 1:
            odd += 1-temp
            temp = 1
    else:
        if temp > -1:
            odd += 1 + temp
            temp = -1
                   
temp = 0
for i in range(N):
    temp += a[i]
    if i % 2 == 0:
        # 奇数番目が負
        if temp > -1:
            even += 1 + temp
            temp = -1     
    else:
        if temp < 1:
            even += 1-temp
            temp = 1
print(min(odd,even))
### BUGGY CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
a.sort()
res = 0
for i in range(n-k+1):
    if i == 0:
        c = 1
    else:
        c *= i+k-1
        c //= i
    cc = c%mod
    # print(c)
    res += cc*(a[i+k-1]-a[n-k-i])
    res %= mod
print(res)

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
comb = Combination(100010)
n,k = inpl()
a = inpl()
a.sort()
res = 0
for i in range(n-k+1):
    cc = comb(n-i-1,k-1)
    res += cc*(-a[i]+a[n-i-1])
    res %= mod
print(res)
### BUGGY CODE ###

a, b, c, n = map(int, input().split())
aa =[a,b,c]
aa.sort()
r = aa[0]
g = aa[1]
b = aa[2]
 
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int((n-r*i_r)/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count = count + 1
 
print(count)

### FIXED CODE ###

a, b, c, n = map(int, input().split())
aa =[a,b,c]
aa.sort()
r = aa[2]
g = aa[1]
b = aa[0]
 
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int((n-r*i_r)/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count = count + 1
 
print(count)
### BUGGY CODE ###

N=int(input())
A=[int(x) for x in input().split()]
l=[0]
c=0

if 1 not in A:
    print(-1)
    exit()


for i in range(N-1):
    if A[i] in l:
        continue
    if l[c]+1 != A[i]:
        continue
    for j in range(i+1,N):
        if A[i]>A[j]:
            if A[j] not in l:
                continue
        else:
            if A[i] in l:
                continue
            else:
                l.append(A[i])
                c+=1
if l[-1]+1 == A[-1]:
    l.append(A[-1])

print(N+1-len(l))


### FIXED CODE ###

N=int(input())
A=[int(x) for x in input().split()]
ne=1
c=0

if 1 not in A:
    print(-1)
    exit()


for i in range(N-1):
    if A[i]==ne:
        c+=1
        ne+=1
if A[-1]==ne:
    c+=1
print(N-c)
### BUGGY CODE ###

import fractions
from functools import reduce

k = int(input())

result = 0

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b == c:
                result += a
            elif a == b and a!= c:
                result += gcd(a, c)*3
            elif a == c and a != b:
                result += gcd(a, b)*3
            elif b == c and a != b:
                result += gcd(a, b)*3
            else:
                result += gcd(a, b, c)*6
print(result)

### FIXED CODE ###

import math
from functools import reduce

k = int(input())

result = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b == c:
                result += a
            elif a == b and a!= c:
                result += gcd(a, c)*3
            elif a == c and a != b:
                result += gcd(a, b)*3
            elif b == c and a != b:
                result += gcd(a, b)*3
            else:
                result += gcd(a, b, c)*6
print(result)
### BUGGY CODE ###

# 嘘解法なおそうとおもったけどなおらん。
N, K = map(int, input().split())
A = list(map(int, input().split()))

binary = [bin(a) for a in A]
bin_K = bin(K)
ma_len = max([len(e) for e in binary] + [len(bin_K)]) - 2
B = [e[2:].zfill(ma_len) for e in binary]
bin_K = bin_K[2:].zfill(ma_len)
ans = 0
X = []


def latter(div, ma_len, B, bin_K):
    X = []
    for i in range(div, ma_len):
        num_0 = 0
        num_1 = 0
        for j in range(len(B)):
            if B[j][i] == "0":
                num_0 += 1
            else:
                num_1 += 1
        if num_1 >= num_0:
            X.append("0")
        else:
            X.append("1")
    return X


former = []
cand = [bin_K]
for i in range(ma_len):
    if bin_K[i] == "1":
        cand.append("".join(former + ["0"] + latter(i + 1, ma_len, B, bin_K)))
    former.append(bin_K[i])

# print(B)
# print(bin_K)
# print(cand)

print(max([sum([int(e, 2) ^ int(b, 2) for b in B]) for e in cand]))


### FIXED CODE ###

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

binary = [bin(a) for a in A]
bin_K = bin(K)
ma_len = max([len(e) for e in binary] + [len(bin_K)]) - 2
B = [e[2:].zfill(ma_len) for e in binary]
bin_K = bin_K[2:].zfill(ma_len)
ans = 0
X = []

flag = False
for i in range(ma_len):
    num_1 = 0
    num_0 = 0
    for j in range(N):
        if B[j][i] == "0":
            num_0 += 1
        else:
            num_1 += 1
    if num_1 >= num_0:
        added = "0"
        if bin_K[i] == "1":
            flag = True
    else:
        if flag:
            added = "1"
        else:
            if bin_K[i] == "1":
                added = "1"
            else:
                added = "0"
    if added == "1":
        ans += 2**(ma_len - i - 1) * num_0
    else:
        ans += 2**(ma_len - i - 1) * num_1
    # X.append(added)

print(ans)
# print("".join(X))
### BUGGY CODE ###

s=input()
n=len(s)

dp=[[0]*13 for i in range(n)]

for i in range(n):
    if s[i]!='?':
        a=int(s[i])*10**(n-i-1)%13
        if i==0:
            dp[i][a]=1
        else:
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-a)%13]
    else:
        for k in range(10):
            a=k*10**(n-i-1)%13
            if i==0:
                dp[i][a]=1
            else:
                for j in range(13):
                    dp[i][j]+=dp[i-1][(j-a)%13]
print(dp[n-1][5]%(10**9+7))

### FIXED CODE ###

s=input()
n=len(s)
p=10**9+7
 
dp=[[0]*13 for i in range(n)]
m=[0]*(n-1)+[1]
for i in range(n-1):
    m[-i-2]=m[-i-1]*10%13
 
if s[0]!='?':
    a=int(s[0])*m[0]%13
    dp[0][a]=1
else:
    for k in range(10):
        a=k*m[0]%13
        dp[0][a]=1
 
for i in range(1,n):
    if s[i]!='?':
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(s[i])*m[i])%13]%p
    else:
        for k in range(10):
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-k*m[i])%13]%p
print(dp[n-1][5]%p)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

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

from collections import Counter

cA = Counter(A)
cB = Counter(B)

# 同じ文字が両方に存在していて、その個数の和がNを越えていたらNG
for key,value in cA.items():
  if key in cB:
    if value + cB[key] > N:
      print("No")
      exit(0)
print("Yes")

from collections import deque
q = deque(B)

ans = []

a_ind = 0
while a_ind < N:
  while True:
    b = q.popleft()
    if b != A[a_ind]:
      ans.append(b)
      break
    else:
      q.append(b)
  a_ind += 1
  
print(*ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline

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

from collections import Counter

cA = Counter(A)
cB = Counter(B)

# 両チームに入っている文字の合計数が多い順に処理していく
# heapqで、(両方に入っている個数, Bにいる個数, その数)
# 使うごとに、1つ目、2つ目の要素を-1してもう一度heappush

import heapq as hq
q = []
hq.heapify(q)
for key,value in cB.items():
  if key in cA:
    hq.heappush(q, (-(value + cA[key]), value, key))
    if value + cA[key] > N:
      print("No")
      exit(0)
  else:
    hq.heappush(q, (-value, value, key))
print("Yes")
a_ind = 0
ans = []

while a_ind < N:
  keep = []
  while True:
    allcnt, bcnt, key = hq.heappop(q)
    allcnt *= (-1)
    if A[a_ind] == key:
      keep.append((allcnt, bcnt, key))
    else:
      ans.append(key)
      if bcnt - 1 > 0:
        hq.heappush(q, (-(allcnt - 1), bcnt - 1, key))
      break
  for k in keep:
    hq.heappush(q, k)
  a_ind += 1
    
print(*ans)
### BUGGY CODE ###

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

### FIXED CODE ###

n=int(input()) 
alist=list(map(int,input().split()))
a=1
if 0 in alist:
    print("0")
else:
    for i in alist:
        if a<=10**18:
            a=a*i
        else:
            break
    if a>10**18:
        print('-1')
    else:
        print(a)
### BUGGY CODE ###

def resolve():
    s = input()
    ans = 0
    for i in range(len(s)):
        if s[i] == "W":
            ans += s[:i].count("B")
    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    s = input()
    ans = 0
    b = 0
    for i in range(len(s)):
        if s[i] == "W":
            ans += b
        else:
            b += 1
    print(ans)


if __name__ == "__main__":
    resolve()