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

import sys
# sys.setrecursionlimit(10**10)
N = int(sys.stdin.readline().rstrip())
# S = sys.stdin.readline().rstrip()
# N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

ans = 1
for a in A:
    ans *= a
if ans > 10 **18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys
# sys.setrecursionlimit(10**10)
N = int(sys.stdin.readline().rstrip())
# S = sys.stdin.readline().rstrip()
# N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

if 0 in A:
    print(0)
    exit()

ans = 1
for a in A:
    ans *= a
    if ans > 10 **18:
        print(-1)
        exit()
else:
    print(ans)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
lr_list = []

for _ in range(m):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

card2canopen_dict = {i: True for i in range(1, n+1)}

for n_card in range(1, n+1):
    for i, lr in enumerate(lr_list):
        target_l = lr[0]
        target_r = lr[1]
        if card2canopen_dict[n_card] and target_l <= n_card <= target_r:
            pass
        else:
            card2canopen_dict[n_card] = False
            break

card_list = [key for key, value in card2canopen_dict.items() if value]

ans = len(card_list)
print(ans)


### FIXED CODE ###

n, m = list(map(int, input().split()))
lr_list = []

for _ in range(m):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

card2canopen_dict = {i: True for i in range(1, n+1)}

# 重ね合わせの区間を調べれば良い気がする
kukan_min, kukan_max = 1, n

for i, lr in enumerate(lr_list):
    l, r = lr[0], lr[1]
    if l >= kukan_min:
        kukan_min = l
    if r <= kukan_max:
        kukan_max = r

if kukan_max < kukan_min:
    ans = 0
else:
    ans = len(range(kukan_min, kukan_max+1))

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

n,m,q=map(int,input().split())
s=[[0 for i in range(n+1)] for j in range(n+1)]
a=list()

for i in range(m):
  l,r=map(int,input().split())
  s[l][r] += 1

for i in range(n+1):
  for j in range(n):
    s[i][j+1] += s[i][j]

for i in range(q):
  l,r=map(int,input().split())
  t = 0
  for j in range(l,r+1):
    t += s[j][r]-s[j][l-1]
  a.append(t)

for i in range(q):
  print(a[i])


### FIXED CODE ###

n,m,q=map(int,input().split())
s=[[0 for i in range(n+1)] for j in range(n+1)]

a=list()

for i in range(m):
  l,r=map(int,input().split())
  s[l][r] += 1

for i in range(1,n+1):
  for j in range(1,n+1):
    s[i][j] += s[i][j-1] 

for i in range(1,n+1):
  for j in range(1,n+1):
    s[j][i] += s[j-1][i]

for i in range(q):
  l,r=map(int,input().split())
  t = s[r][r] - s[l-1][r] - s[r][l-1] + s[l-1][l-1]
  a.append(t)

for i in range(q):
  print(a[i])
### BUGGY CODE ###

from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
li.sort()

lin = []

for i in li:
    if i[1] == n:
        lin.append(i[0])
for j in li:
    for k in lin:
        if j == [1,k]:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

### FIXED CODE ###

from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [0]*n

for i in li:
    if i[0] == 1:
        lin[i[1]-1] += 1
    if i[1] == n:
        lin[i[0]-1] += 1

for i in lin:
    if i == 2:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
### BUGGY CODE ###

INF = 10**12

class Rmin():
	def __init__(self, size):
		#the number of nodes is 2n-1
		self.n = 1 << (size.bit_length())
		self.node = [INF] * (2*self.n-1)

	def Access(self, x):
		return self.node[x+self.n-1]

	def Update(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)>>1
			self.node[x] = min(self.node[(x<<1)+1], self.node[(x<<1)+2])
		return

	#[l, r)
	def Get(self, l, r):
		L, R = l+self.n, r+self.n
		s = INF
		while L<R:
			if R & 1:
				R -= 1
				s = min(s, self.node[R-1])
			if L & 1:
				s = min(s, self.node[L-1])
				L += 1
			L >>= 1
			R >>= 1
		return s

n, q, a, b = map(int, input().split())
qs = [a] + list(map(int, input().split()))
dp_l, dp_r = Rmin(n+1), Rmin(n+1)
dp_l.Update(b, -b)
dp_r.Update(b, b)

total_diff = 0
for i in range(q):
	x, y = qs[i], qs[i+1]
	diff = abs(y - x)
	l_min = dp_l.Get(1, y)
	r_min = dp_r.Get(y, n+1)
	res = min(l_min + y, r_min - y)
	#print(res)
	dp_l.Update(x, res - diff - x)
	dp_r.Update(x, res - diff + x)
	total_diff += diff

N = dp_l.n
print(total_diff + min(dp_l.node[i+N-1] + i for i in range(1, n+1)))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
INF = 10**12

class Rmin():
	def __init__(self, size):
		#the number of nodes is 2n-1
		self.n = 1 << (size.bit_length())
		self.node = [INF] * (2*self.n-1)

	def Access(self, x):
		return self.node[x+self.n-1]

	def Update(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)>>1
			self.node[x] = min(self.node[(x<<1)+1], self.node[(x<<1)+2])
		return

	#[l, r)
	def Get(self, l, r):
		L, R = l+self.n, r+self.n
		s = INF
		while L<R:
			if R & 1:
				R -= 1
				s = min(s, self.node[R-1])
			if L & 1:
				s = min(s, self.node[L-1])
				L += 1
			L >>= 1
			R >>= 1
		return s

n, q, a, b, *qs = map(int, read().split())
dp_l, dp_r = Rmin(n+1), Rmin(n+1)
dp_l.Update(b, -b)
dp_r.Update(b, b)

total_diff = 0
x = a
for y in qs:
	diff = abs(y - x)
	l_min = dp_l.Get(1, y)
	r_min = dp_r.Get(y, n+1)
	res = min(l_min + y, r_min - y)
	dp_l.Update(x, res - diff - x)
	dp_r.Update(x, res - diff + x)
	total_diff += diff
	x = y

N = dp_l.n
print(total_diff + min((l+r)>>1 for l, r in zip(dp_l.node[N:], dp_r.node[N:])))
### BUGGY CODE ###

s = list(input())

MOD = pow(10, 9) + 7

n = len(s)
s.reverse()

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

#r = list(range(10))

#init
if s[0] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    q = int(s[0])
    dp[0][q] = 1

for i in range(1, n):
    r = pow(10, i, 13) % 13
    # for l in range(10):
    #     r[l] = r[l] * 10 % 13

    #print(r)

    if s[i] == "?":
        for j in range(10):
            q = j * r % 13
            for k in range(13):
                dp[i][k] += dp[i-1][k-q]
    
    else:
        q = int(s[i]) * r % 13
        #print(q)
        for k in range(13):
            dp[i][k] += dp[i-1][k-q]
    #print(dp[i])

print(dp[n-1][5] % MOD)

### FIXED CODE ###

s = list(input())

MOD = pow(10, 9) + 7

n = len(s)

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

#r = list(range(10))

#init
if s[-1] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    q = int(s[-1])
    dp[0][q] = 1

r = 1

for i in range(1, n):
    r = r * 10 % 13
    # for l in range(10):
    #     r[l] = r[l] * 10 % 13

    #print(r)

    if s[n-i-1] == "?":
        for j in range(10):
            q = j * r % 13
            for k in range(13):
                dp[i][k] += dp[i-1][k-q] % MOD
    
    else:
        q = int(s[n-i-1]) * r % 13
        #print(q)
        for k in range(13):
            dp[i][k] += dp[i-1][k-q] % MOD
    #print(dp[i])

print(dp[n-1][5] % MOD)
### BUGGY CODE ###

import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  while x%i != 0:
    x+=(10**9 +7)
  sum+= x//i
  sum= sum%(10**9 +7)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(10**9 +7)
print(ans)

### FIXED CODE ###

import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%(p)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(p)
print(ans)
### BUGGY CODE ###

import sys 
sys.setrecursionlimit(10**9)
N = int(input())
G = [[] for _ in range(N)]
mod = 10**9+7
for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
cnt = [[] for _ in range(N)]
def dfs(p, v, n):
    s = 0
    for nv in G[v]:
        if nv == p:
            continue
        res = dfs(v, nv, n+1)
        cnt[v].append(res)
        s+=res
    cnt[v].append(N-s-1)
    return s+1
dfs(-1, 0, 0) 

ans = 0
for v in range(N):
    if len(cnt[v])<=1:
        continue    
    res = pow(2, N-1, mod)-1
    for a in cnt[v]:
        res-=pow(2, a, mod)-1
    ans+=res
    ans%=mod
inv = pow(2, (mod-2)*N, mod)
print(ans*inv%mod)







### FIXED CODE ###

import sys 
sys.setrecursionlimit(10**9)
N = int(input())
G = [[] for _ in range(N)]
mod = 10**9+7
for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
cnt = [[] for _ in range(N)]
que = [0]
depth = [-1]*N
depth[0] = 0
while que:
    v = que.pop()
    d = depth[v]
    for nv in G[v]:
        if depth[nv]>=0:
            continue
        depth[nv] = d+1
        que.append(nv)
d_to_i = [[] for _ in range(N)]
for i in range(N):
    d_to_i[depth[i]].append(i)
for d in range(N)[::-1]:
    for v in d_to_i[d]:
        for nv in G[v]:
            if depth[nv]<depth[v]:
                continue
            if cnt[nv]:
                cnt[v].append(sum(cnt[nv])+1)
            else:
                cnt[v].append(1)
for i in range(N):
    res = N-1
    for j in cnt[i]:
        res-=j
    cnt[i].append(res)
ans = 0
p = [1]*N
for i in range(1, N):
    p[i] = p[i-1]*2%mod
for v in range(N):
    if len(cnt[v])<=1:
        continue    
    res = p[N-1]-1
    for a in cnt[v]:
        res-=p[a]-1
    ans+=res
    ans%=mod
inv = pow(2, (mod-2)*N, mod)
print(ans*inv%mod)
### BUGGY CODE ###


N = int(input())

arr = []
for i in range(N):
    arr.append(str(input()))

count = 0

def sort_str(s):
    return "".join(sorted(list(s)))


sorted_str_arr = []

for item in arr:
    sorted_str_arr.append(sort_str(item))

for i in range(N):
    for j in range(i+1, N):
        if sorted_str_arr[i] == sorted_str_arr[j]:
            count += 1

print(count)

### FIXED CODE ###

N = int(input())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
    if c > 1:
        count += cmb(c, 2)

print(count)
### BUGGY CODE ###

import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b <= K and max < i + j:
            max = i + j
        j += 1

print(max)

### FIXED CODE ###

import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j
        j += 1

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

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

count = 1; Pj = [P[0]]
for i in range(1, N):
    if min(Pj) > P[i]:
        count += 1
    Pj.append(P[i])

print(count)

### FIXED CODE ###

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

count = 0; min = N
for i in range(N):
    if min >= P[i]:
        count += 1
        min = P[i]

print(count)
### BUGGY CODE ###

H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)
### BUGGY CODE ###

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

if n==1:
  print(0)
  exit()

distance = 1
pl = 0
pr = pl + distance

while (pr<=n-1):
  if s[pl:pr+1]==sorted(s[pl:pr+1])[::-1]:
    pr += 1
    distance += 1
  else:
    pl += 1
    pr += 1

print(distance-1)

### FIXED CODE ###

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

distance = 0
ans = 0
for i in range(1,n):
  if s[i]<=s[i-1]:
    distance += 1
    ans = max(ans,distance)
  else:
    distance = 0
print(ans)
### BUGGY CODE ###

def solve(items, W):
    dp = [[0]*(W+1) for _ in range(len(items)+1)]

    for i, g in enumerate(items, 1):
        for w in range(W+1):
            if w >= g[0]:
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-g[0]]+g[1])
            else:
                dp[i][w] = dp[i-1][w]

    return dp[len(items)][W]


if __name__ == "__main__":
    N, W = map(int, input().split())
    items = [list(map(int, input().split())) for _ in range(N)]
    print(solve(items, W))


### FIXED CODE ###

def solve(items, W):
    dp = [[0]*(W+1) for _ in range(len(items)+1)]

    for i, g in enumerate(items, 1):
        for w in range(W+1):
            if w >= g[0]:
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-g[0]]+g[1])
            else:
                dp[i][w] = dp[i-1][w]

    return dp[len(items)][W]


if __name__ == "__main__":
    N, W = map(int, input().split())
    items = [list(map(int, input().split())) for _ in range(N)]
    print(solve(items, W))
### BUGGY CODE ###

# import sys
# input = sys.stdin.readline

#A1 ~ Aiまでの和 O(logN)
#A1 ~ Aiまでの和 O(logN)
def BIT_query(BIT,idx):
    res_sum = 0
    if idx == 0:
        return 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(BIT,idx,x,n):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

def main():
    N, Q = map( int, input().split())
    C = list( map( int, input().split()))
    LRI = []
    for i in range(Q):
        l, r = map( int, input().split())
        LRI.append((r,l,i))
    LRI.sort()
    lastAppend = [-1]*(N+1)
    BIT = [0]*(N+1)
    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        if idx == 0:
            return 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= N:
            BIT[idx] += x
            idx += idx&(-idx)
        return

    ANS = [0]*Q
    now = 1
    for r, l, i in LRI:
        while now <= r:
            c = C[now-1]
            if lastAppend[c] == -1:
                BIT_update(now, 1)
            else:
                BIT_update( now, 1)
                BIT_update(lastAppend[c],-1)
            lastAppend[c] = now                
            now += 1
        ANS[i] = BIT_query(r) - BIT_query(l-1)
    print( "\n".join( map( str, ANS)))
    
    

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, Q = map( int, input().split())
    C = list( map( int, input().split()))
    LRI = []
    for i in range(Q):
        l, r = map( int, input().split())
        LRI.append((r,l,i))
    LRI.sort(key=lambda x:x[0])
    lastAppend = [-1]*(N+1)
    BIT = [0]*(N+1)
    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        if idx == 0:
            return 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= N:
            BIT[idx] += x
            idx += idx&(-idx)
        return

    ANS = [0]*Q
    now = 1
    for r, l, i in LRI:
        while now <= r:
            c = C[now-1]
            if lastAppend[c] == -1:
                BIT_update(now, 1)
            else:
                BIT_update( now, 1)
                BIT_update(lastAppend[c],-1)
            lastAppend[c] = now                
            now += 1
        ANS[i] = BIT_query(r) - BIT_query(l-1)
    print( "\n".join( map( str, ANS)))
    
    

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

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

A = [LIST() for _ in range(N)]
graph = csr_matrix(A)
dist_matrix = floyd_warshall(graph, directed=False)

ans = 0 
for i, j in combinations(range(N), 2):
    if A[i][j] != dist_matrix[i][j]:
        print(-1)
        break
    for k in range(N):
        if i == k or j == k:
            continue
        if A[i][k] + A[k][j] == A[i][j]:
            break
    else:
        ans += A[i][j]
else:
    print(ans)


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

def warshall_floyd(v_count: int, matrix: list) -> list:
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix

A = [LIST() for _ in range(N)]
dist_matrix = warshall_floyd(N, deepcopy(A))

ans = 0
for i, j in combinations(range(N), 2):
    if A[i][j] != dist_matrix[i][j]:
        print(-1)
        break
    for k in range(N):
        if i == k or j == k:
            continue
        if A[i][k] + A[k][j] == A[i][j]:
            break
    else:
        ans += A[i][j]
else:
    print(ans)
### BUGGY CODE ###

S = input()
a = [0]*len(S)
for i in range(len(S)):
    if S[i] == 'B':
        a[i] = 1

r = 0
chk = True
while chk:
    chk = False
    flg = False
    for i in range(len(a)-1):
        if flg:
            flg = False
            continue
        if a[i] == 1 and a[i+1] == 0:
            chk = True
            flg = True
            a[i] = 0
            a[i+1] = 1
            r += 1
print(r)

### FIXED CODE ###

S = input()
a = [0]*len(S)
for i in range(len(S)):
    if S[i] == 'B':
        a[i] = 1
r = 0
b = 0
for i in a:
    if i == 1:
        b += 1
    else:
        r += b
print(r)
### BUGGY CODE ###

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

def binary_search(list,target,b):
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:
            return center+B.count(target) if b else center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1

    if list[center]<target:
        center+=1
    return center

A.sort()
C.sort()
ans=0
for b in B:
    ans+=binary_search(A,b,0)*(len(C)-binary_search(C,b,1))
print(ans)


### FIXED CODE ###

import bisect
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

A.sort()
C.sort()
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(len(C)-bisect.bisect_right(C,b))
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

r = []
for i in range(N):
    flag = True
    tmp = 0
    for j in range(N):
        if flag: tmp += A[(i+j)%N]
        else: tmp -= A[(i+j)%N]
        flag = not flag
    r.append(tmp)

r = map(str, r)
print(" ".join(r))

### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
s = sum(A)
r = [s - 2 * sum(A[1::2])]

for i in range(N-1):
    r.append(2 * A[i] - r[i])

r = map(str, r)
print(" ".join(r))
### BUGGY CODE ###

import math
from itertools import combinations
def comb(a,b):
    a2 = math.factorial(a)
    b2 = math.factorial(b)
    ab = math.factorial(a-b)
    return a2//(b2*ab)
N = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
ans = []
array = []
for x,y in combinations(a,2):
    ans.append(comb(x,y))
    array.append([x,y])
print(*array[ans.index(max(ans))])


### FIXED CODE ###

import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
ans = []
for i in range(1,N):
    candind = bisect.bisect_left(a,a[i]/2)
    if candind == i:
        candind -= 1
        cand = a[candind]
    elif candind == 0:
        cand = a[candind]
    else:
        if a[candind]-a[i]/2 <= a[i]/2-a[candind-1]:
            cand = a[candind]
        else:
            cand = a[candind-1]
    ans.append([a[i],cand])
ans.sort(reverse=True)
x1 = ans[0][1]
ans2 = [ans[0]]
for i in range(1,len(ans)):
    if x1 >= ans[i][1]:
        break
    ans2.append(ans[i])
    x1 = ans[i][1]
print(*ans2[-1])