Harryxun/stf_run huggingface dataset:
from collections import deque

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

if r:
    while min(deque_p[-1], deque_q[-1]) < r[0]:
        if deque_p[-1] <= deque_q[-1]:
            deque_p.pop()
            deque_r.append(r.popleft())
        else:
            deque_q.pop()
            deque_r.append(r.popleft())

        if not r:
            break

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)


### FIXED CODE ###

from collections import deque

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

if r:
    while min(deque_p[-1], deque_q[-1]) < r[0]:
        if deque_p[-1] <= deque_q[-1]:
            deque_p.pop()
            deque_r.append(r.popleft())
        else:
            deque_q.pop()
            deque_r.append(r.popleft())

        if (not r) or (not deque_p) or (not deque_q):
            break

if r and deque_p:
    while deque_p[-1] < r[0]:
        deque_p.pop()
        deque_r.append(r.popleft())

        if (not r) or (not deque_p):
            break

if r and deque_q:
    while deque_q[-1] < r[0]:
        deque_q.pop()
        deque_r.append(r.popleft())

        if (not r) or (not deque_q):
            break
    

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)
abc=lint(map(int,input().split()))
print(sum(sorted(abc)[:2]))

### FIXED CODE ###

a,b,c = sorted(map(int,input().split()))
print(a+b)
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
mod = (10**9)+7
ans = [1,0] if 1 in a else [1,1]
for i in range(2,n+1):
  if i in a:
    ans.append(0)
  else:
    k = (ans[-1]+ans[-2])%mod
    ans.append(k)
print(ans[-1])
    

### FIXED CODE ###

pqr = list(map(int,input().split()))
print(sum(pqr)-max(pqr))
s=input()
l=[SUN,MON,TUE,WED,THU,FRI,SAT]
print(7-l.index(s))

### FIXED CODE ###

s=input()
if s=='SUN':
  print('7')
elif s=='MON':
  print('6')
elif s=='TUE':
  print('5')
elif s=='WED':
  print('4')
elif s=='THU':
  print('3')
elif s=='FRI':
  print('2')
else:
  print('1')
print('Odd' if eval(input().replace(' ','*')%2!=0 else 'Even')

### FIXED CODE ###

print('Odd' if eval(input().replace(' ','*'))%2!=0 else 'Even')
s = input()
if length(s) == 6:
  if s[2] == s[3]:
  	if s[4] == s[5]:
      print("Yes")
	else:
  	print("No")


### FIXED CODE ###

s = input()
 
if s[2] == s[3]:
  if s[4] == s[5]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
a = int(input())
b = int(input())
if 1<=a<=100 and 1<=b<=100:
  print(a*b)


### FIXED CODE ###

a,b = map(int,input().split())
print(a*b)
n.x.t = map(int, input().split())
w = n//x
if (n % x) == 0:
    print(w * t)
else:
    w += 1
    print(w * t)



### FIXED CODE ###

n,x,t = map(int, input().split())
w = n//x
if (n % x) == 0:
    print(w * t)
else:
    w += 1
    print(w * t)
n,k＝ map(int,input().split())
if k=1:
    print(0)
else:
    print(n-k)

### FIXED CODE ###

n,k= map(int,input().split())
if k==1:
    ans=0
else:
    ans=n-k
print(ans)
class UnionFind:
    def __init__(self, n):
        self.table = [-1 for _ in range(n)]

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

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1<=d2:
            self.table[r2] = r1
            if d1==d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(n):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.union(x, y)

ans = 0
for v in uf.table:
    if v<0:
        ans += 1
print(ans)

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.table = [-1 for _ in range(n)]

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

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1<=d2:
            self.table[r2] = r1
            if d1==d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.union(x, y)

ans = 0
for v in uf.table:
    if v<0:
        ans += 1
print(ans)
def getItems(layerCount):
	if layerCount == 0:
		return 1
	return 2*getItems(layerCount-1) + 3

def getPats(layerCount):
	return 2**(layerCount + 1) - 1

def patEaten(layer, toEat):
	pattyCount = 0

	if layer == 1:
		burger = "BPPPB"

		for x in range(toEat):
			if burger[x] == "P":
				pattyCount += 1
		return pattyCount
		
	elif layer == 0:
		if toEat == 1:
			return 1
		else:
			return 0
	
	else:
		items = getItems(layer)
		if toEat == items:
			pattyCount += patEaten(layer, toEat)
      toEat = 0
			return pattyCount
		elif toEat < 2+getItems(layer-1):
			if items + 1 == 2* toEat:
				toEat-=2
				return 1 + patEaten(layer - 1, toEat)
			toEat -= 1
			return patEaten(layer - 1, toEat)
		else:
			toEat -= (1+1+getItems(layer-1))
			pattyCount += 1 + getPats(layer-1)
			
			return pattyCount + patEaten(layer-1, toEat)

#i, j = [int(x) for x in input().split()]
print(patEaten(2,13))
#print(getItems(2))

### FIXED CODE ###

def getItems(layerCount):
	if layerCount == 0:
		return 1
	return 2*getItems(layerCount-1) + 3

def getPats(layerCount):
	return 2**(layerCount + 1) - 1

def patEaten(layer, toEat):
	pattyCount = 0

	if layer == 1:
		burger = "BPPPB"

		for x in range(toEat):
			if burger[x] == "P":
				pattyCount += 1
		return pattyCount
		
	elif layer == 0:
		if toEat == 1:
			return 1
		else:
			return 0
	
	else:
		items = getItems(layer)
		if toEat == items:
			pattyCount += getPats(layer)
			return pattyCount
		elif toEat < 2+getItems(layer-1):
			if items + 1 == 2* toEat:
				toEat-=2
				return 1 + patEaten(layer - 1, toEat)
			toEat -= 1
			return patEaten(layer - 1, toEat)
		else:
			toEat -= (1+1+getItems(layer-1))
			pattyCount += 1 + getPats(layer-1)
			
			return pattyCount + patEaten(layer-1, toEat)

i, j = [int(x) for x in input().split()]
#print(patEaten(2,13))
print(patEaten(i,j))
num = int(input())
seven = 7
col = -1
cnt = 1

for i in range(0, 1000):
  if seven % num == 0:
    col = 1
    break
  else:
    seven = (seven*10) + 7
    cnt+=1

if col == 1:
  print(cnt)
else:
  print(col)

### FIXED CODE ###

import numpy as np

N, D = list(map(int, input().split())) 
cnt = 0
for n in range(0, N):
  x, y = list(map(int, input().split())) 
  if  (x*x + y*y) <= D*D:
    cnt += 1

print(cnt)
N = int(input())
a = list(map(int,input().split()))
b=[]
for i in range(N+1):
  b.append(1.0/i)
  B = sum(b)
print(1/B)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
b=[]
for i in range(N):
  b.append(1.0/a[i])
  B = sum(b)
print(1.0/B)
N = int(input())
x,y,h=[],[],[]
for i in range(N):
    tmpx, tmpy, tmph = (int(i) for i in input().split())
    x.append(tmpx)
    y.append(tmpy)
    h.append(tmph)

def solve(N,x,y,h):
    for cx in range(101):
        for cy in range(101):
            H = [h[i]+abs(x[i]-cx)+abs(y[i]-cy) for i in range(N)]
            if all([i==H[0] for i in H]):
                return [cx,cy,H[0]]
ans = solve(N,x,y,h)
print(ans[0],ans[1],ans[2])

### FIXED CODE ###

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

tmpx,tmpy,tmph=0,0,0
for x,y,h in xyh:
    if h>0:
        tmpx,tmpy,tmph=x,y,h
        break

truecx,truecy,trueh=0,0,0
for cx in range(101):
    for cy in range(101):
        largeh=tmph+abs(tmpx-cx)+abs(tmpy-cy)
        flag=True
        for x,y,h in xyh:
            if h != max(largeh-abs(x-cx)-abs(y-cy),0):
                flag = False
                break
        if flag:
            truecx,truecy,trueh=cx,cy,largeh
            break
print(truecx,truecy,trueh)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a,b=[0],[0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans,j=0,M
for i in range(N + 1): 
	if a[i]>K:
    	break
while b[j] > K - a[i]:
    j -= 1
ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a,b=[0],[0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans,j=0,M
for i in range(N + 1): 
	if a[i]>K:
    		break
	while b[j] > K - a[i]:
    		j -= 1
	ans = max(ans, i + j)
print(ans)
n, m = map(int, input().split(' '))
for i in range(m):
    l, r = map(int, input().split(' '))
    if i == 0:
        s = [l, r]
        continue
    else:
        result = []
        for j in range(s[0], s[1]+1):
            if l <= j <= r:
                result += [j]
        s[0] = min(result)
        s[1] = max(result)
print(s[1] - s[0] + 1)

### FIXED CODE ###

n, m = map(int, input().split(' '))
l_ = []
r_ = []
for i in range(m):
    l,r = map(int, input().split(' '))
    l_ += [l]
    r_ += [r]
l = max(l_)
r = min(r_)
if n < l:
    print(0)
elif n < r:
    r = n
    print(r - l + 1)
elif l > r:
    print(0)
elif l == r:
    print(1)
else:
    print(r - l + 1)
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())

sa = B - A + 1

C2 = (B // C) - ((A - 1) // C)
D2 = (B // D) - ((A - 1) // D)

CD = lcm(C, D)

CD2 = (B // CD) - ((A - 1) // CD)

print(sa - (C2 + D2 - CD2))

### FIXED CODE ###

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

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B, C, D = map(int, input().split())

sa = B - A + 1

C2 = (B // C) - ((A - 1) // C)
D2 = (B // D) - ((A - 1) // D)

CD = lcm(C, D)

CD2 = (B // CD) - ((A - 1) // CD)

print(sa - (C2 + D2 - CD2))
import numpy as np
import sys

n,k,*a=map(int,sys.stdin.readlines().split())
a=np.array(a,dtype=np.int64)

print(n,k,a)

a.sort()
neg=a[a<0]
zero=a[a==0]
pos=a[a>0]

print(np.searchsorted(a,0//pos,side='right').sum())

def count(x):
    cnt=0
    if x>=0:
        cnt+=len(zero)
    cnt+=np.searchsorted(a,x//pos,side='right').sum()
    cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()
    cnt-=np.count_nonzero(a*a<=x)
    return cnt//2


left=-10**18
right=10**18

while left+1<right:
    x=(left+right)//2
    cnt=count(x)
    if cnt>=k:
        right=x
    if cnt<k:
        left=x

print(right)


### FIXED CODE ###

import numpy as np
import sys

n,k=map(int,sys.stdin.readline().split())
a=np.array(sys.stdin.readline().split(),dtype=np.int64)

a.sort()
neg=a[a<0]
zero=a[a==0]
pos=a[a>0]

def count(x):
    cnt=0
    if x>=0:
        cnt+=len(zero)*n
    cnt+=np.searchsorted(a,x//pos,side='right').sum()
    cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()
    cnt-=np.count_nonzero(a*a<=x)
    return cnt//2


left=-10**18
right=10**18

while left+1<right:
    x=(left+right)//2
    out=count(x)
    if out>=k:
        right=x
    if out<k:
        left=x

print(right)
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"):

    '''
    Warshall-Floyd
    input:  c[|V|][|V|]
            input example to from cost
            (c[i][i] == 0)
    Output: Minimun cost of all paths in the inputed graph 
    '''
    V = N
    INF = 1<<32
    d = [[INF] * (N+1) for i in range(N+1)]
 
    for i in range(M):
        d[A[i]][B[i]] = C[i]
        d[B[i]][A[i]] = C[i]

    for k in range(N+1):
        for i in range(N+1):
            if d[i][k] == INF : continue
            for j in range(N+1):
                if d[k][j] == INF: continue
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])


    ans = INF

    from itertools import product
    for i in product(r,repeat=len(r)):
        # print(i)
        if(len(i) != len(set(i))): continue
        ta = 0
        for j in range(1,len(i)):
            ta += d[i[j-1]][i[j]]
        
        ans = min(ans, ta)
    
    print(ans)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    r = [int(next(tokens)) for _ in range(R)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, R, r, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

n = input()
if(n[0] == '9' or n[1] == '9'):
    print('Yes')
else:
    print('No')
_, *a = map(int, open(0).read().split())
a.sort()
m = -~a[-1]
c = [0] * m
for i in a:
    c[i] += 1
    if c[i] > 1:
        continue
    for j in range(i * 2, m, i):
        c[j] = 2
print(sum(c[i]for i in a))

### FIXED CODE ###

print(input().split().index("0")+1)
import bisect

A,B,Q = map(int, input().split())

S = []
for i in range(A):
    S.append(int(input()))

T = []
for i in range(B):
    T.append(int(input()))

ans = []
for i in range(Q):
    x = int(input())
    s = bisect.bisect_left(S, x)
    s = min([s,len(S)-1])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori1 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    s = max([s-1,0])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori2 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    t = bisect.bisect_left(T, x)
    t = min([t,len(T)-1])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([st2-1,0])
    kyori3 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    t = max([t-1,0])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([st2-1,0])
    kyori4 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    ans.append(min([kyori1,kyori2,kyori3,kyori4]))

for i in ans:
    print(i)

### FIXED CODE ###

import bisect

A,B,Q = map(int, input().split())

S = []
for i in range(A):
    S.append(int(input()))

T = []
for i in range(B):
    T.append(int(input()))

ans = []
for i in range(Q):
    x = int(input())
    s = bisect.bisect_left(S, x)
    s = min([s,len(S)-1])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori1 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    s = max([s-1,0])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori2 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    t = bisect.bisect_left(T, x)
    t = min([t,len(T)-1])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([ts1-1,0])
    kyori3 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    t = max([t-1,0])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([ts1-1,0])
    kyori4 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    ans.append(min([kyori1,kyori2,kyori3,kyori4]))

for i in ans:
    print(i)
c = 0
result = 0
while True:
    st = raw_input()
    if c == 0:
        s_str = st
    elif 'END_OF_TEXT' in st:
        break
    else:
        c = c+1
        if s_str in st:
            result = result + st.count(s_str)
        else:
            pass
print result

### FIXED CODE ###

c = 0
result = 0
while True:
    st = raw_input()
    if c == 0:
        s_str = st
    elif 'END_OF_TEXT' == st:
        break
    elif c > 0:
        if s_str.lower() in st.lower():
            result = result + st.lower().split(' ').count(s_str.lower())
        else:
            pass
    c = c+1
print result
n = int(input())
X = map(int, input().split())
# n = 3
# X = [3, 5, -1]

X.insert(0,0)
X.append(0)
Y = []
for i, x in enumerate(X[1:]):
    Y.append(abs(x-X[i]))
sumY = sum(Y)

for i, x in enumerate(X):
    if i not in [0,len(X)-1]:
        ans = sumY - (Y[i-1] + Y[i]) + abs(X[i+1]-X[i-1])
        print(ans)

### FIXED CODE ###

n = int(input())
X = map(int, input().split())
X = list(X)
# n = 3
# X = [3, 5, -1]

X.insert(0,0)
X.append(0)
Y = []
for i, x in enumerate(X[1:]):
    Y.append(abs(x-X[i]))
sumY = sum(Y)

for i, x in enumerate(X):
    if i not in [0,len(X)-1]:
        ans = sumY - (Y[i-1] + Y[i]) + abs(X[i+1]-X[i-1])
        print(ans)
x=int(input())
if(x==1):
  print(0)
 elif(x==0):
  print(1)

### FIXED CODE ###

x=int(input())
if(x==1):
  print(0)
elif(x==0):
  print(1)
import sys

N, M = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort()

ans = [float('inf')]

if N >= M:
    print(0)
    sys.exit()


def find_max(pivot, places, s):
    if len(places) == N:
        s += abs(nums[places[-1]] - nums[-1])
        if s < ans[0]:
            ans[0] = s
        return

    for i in range(pivot+1, len(nums) - (N - len(places) - 1)):
        tmp = s + abs(nums[pivot] - nums[i-1])
        if tmp > ans[0]: continue
        find_max(i, places + [i], tmp)

find_max(0, [0], 0)

print(ans[0])


### FIXED CODE ###


import sys

N, M = [int(x) for x in input().split()]
nums = list(set([int(x) for x in input().split()]))

if not nums:
    print(0)
    sys.exit()

if N >= M:
    print(0)
    sys.exit()

nums.sort()

rank = [(abs(nums[i] - nums[i-1]), (i-1, i)) for i in range(1, len(nums))]
rank = sorted(rank, reverse=True)[:N-1]

pos = [0] + [pos[1] for dis, pos in rank]
pos.sort()
ans = 0
for i in range(len(pos)):
    if i == len(pos)-1:
        ans += abs(nums[pos[i]] - nums[-1])
    else:
        ans += abs(nums[pos[i]] - nums[pos[i+1]-1])

print(ans)
class UnionFind():
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
        self.size = [1 for _ in range(size)]

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

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] > self.table[s2]:
                self.table[s2] = s1
                self.table[s1] -= 1
                self.size[s1] += self.size[s2]
                self.size[s2] = 0
            else:
                self.table[s1] = s2
                self.table[s2] -= 1
                self.size[s2] += self.size[s1]
                self.size[s1] = 0
        return

n = int(input())

uf = UnionFind(n)

for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    # 同じなら0、違ったら1
    if w % 2 == 0:
        uf.union(u, v)

ans = []
for i in range(n):
    ans.append(uf.find(i))
num = list(set(ans))[0]
out = list(map(lambda x: 0 if x == num else 1, ans))

for color in out:
    print(color)


### FIXED CODE ###

import queue

n = int(input())
links = [set() for _ in [0] * n]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    links[u].add((v, w))
    links[v].add((u, w))
ans = [-1] * n
q = queue.Queue()
q.put((0, 0, -1))
while not q.empty():
    v, d, p = q.get()
    if d % 2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1
    for u, w in links[v]:
        if u == p:
            continue
        q.put((u, d + w, v))
for i in ans:
    print(i)
# your code goes here
import numpy as np

def a(s, w):
	if(s == ""):
		return 0
	elif(s[-1] == 'B'):
		if(w == 0):
			return a(s[:-1], 0)
		else:
			return a(s[:-1], w)+w
	else:
		return a(s[:-1], w+1)

def main():
	s = input()
	print(a(s, 0))
	
	
	
	
	
main()

### FIXED CODE ###

# your code goes here
import numpy as np

def main():
	s = input()
	ans = 0
	w = 0
	for i in range(len(s)):
		c = s[len(s)-1-i]
		if(c == 'B'):
			if(w > 0):
				ans += w
		else:
			w += 1
	
	print(ans)
	
main()
import fractions

N,X = map(int,input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
y = [0]*N
for i in range(N):
    y[i] = x[i+1]-x[i]

answer = fractions.gcd(y[0],y[1])
for i in range(2,N):
    answer = fractions.gcd(answer,y[i])

print(answer)


### FIXED CODE ###

import fractions

N,X = map(int,input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
y = [0]*N
for i in range(N):
    y[i] = x[i+1]-x[i]

if len(y) == 1:
    print(y[0])
else:
    answer = fractions.gcd(y[0],y[1])
    for i in range(2,N):
        answer = fractions.gcd(answer,y[i])
    print(answer)
def main():
    x, y = map(int, input().split())
    print(abs((x // y + x % y) - (x // y)))


if __name__ == "__main__":
    main()
i

### FIXED CODE ###


def main():
    x, y = map(int, input().split())
    if x % y != 0:
        print(abs((x // y + 1) - (x // y)))
    else:
        print(abs((x // y) - (x // y)))


if __name__ == "__main__":
    main()
n,m = map(int,input().split())

c = []
for i in range(m):
    c.append(list(map(int,input().split())))

max = 0
for i in range(m):
    if c[i][0] >= max:
        max = c[i][0]

ans = -1
if n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = c[0][1]
else:            
 for i in range(pow(10,max-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i

print(ans)    

### FIXED CODE ###

n,m = map(int,input().split())
 
c = []
for i in range(m):
    c.append(list(map(int,input().split())))
 

ans = -1
if n == 1 and m == 0:
    ans = 0
elif m == 0 and n != 1:
    ans = pow(10,n-1)
elif n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = c[0][1]
            break
else:            
 for i in range(pow(10,n-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i
         break
print(ans)
a,b,k=list(map(int ,input().split()))
l=[]
count=0
for i in range(1,max(a,b)):
	if(a%i==0 and b%i==0):
		l.append(i)
		
		
	
	else:
		count+=1

l.sort()
l.reverse()
if(len(l)==0):
	
	print(0)
else:
	print(l[k-1])


### FIXED CODE ###

A,B,K=map(int,input().split())
ans=0
n=100
while True:
    if A%n==0 and B%n==0:
        ans+=1
        if ans==K:
            print(n)
            exit()
    n-=1
N,K = input().split()
N = int(N)
K = int(K)
h = [input().split()]
r = 0
for j in range(N):
  if int(h[j]) >= K:
    r += 1
print(r)


### FIXED CODE ###

N,K = list(map(int, input().split()))
h = list(map(int, input().split()))
r = 0
for j in range(N):
  if int(h[j]) >= K:
    r += 1
print(r)
# ABC 130: B – Bounding
n, x = [int(s) for s in input().split()]
l = [int(s) for s in input().split()]

d = 0
times = 0

while d <= x:
    d = d + l[times]
    times += 1

print(times)

### FIXED CODE ###

# ABC 130: B – Bounding
N, X = map(int, input().split())
L = [int(s) for s in input().split()]

D = [0]

for i in range(N):
    D.append(D[i] + L[i])

print(len([d for d in D if d <= X]))