AtCoder Grand Contest 029
A
Irreversible operation
AtCoder
⌀ 423
原题
←B →
翻译中…

Problem Statement

翻译中…

There are $N$ Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string $S$ of length $N$. If $S_i=$B, the $i$-th piece from the left is showing black; If $S_i=$W, the $i$-th piece from the left is showing white.

翻译中…

Consider performing the following operation:

翻译中…
  • Choose $i$ ($1 \leq i < N$) such that the $i$-th piece from the left is showing black and the $(i+1)$-th piece from the left is showing white, then flip both of those pieces. That is, the $i$-th piece from the left is now showing white and the $(i+1)$-th piece from the left is now showing black.
翻译中…

Find the maximum possible number of times this operation can be performed.

翻译中…

Constraints

翻译中…
  • $1 \leq |S| \leq 2\times 10^5$
  • $S_i=$B or W
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

S

翻译中…

Output

翻译中…

Print the maximum possible number of times the operation can be performed.

翻译中…

样例

Input #1
BBW
Output #1
2
The operation can be performed twice, as follows: - Flip the second and third pieces from the left. - Flip the first and second pieces from the left.
Input #2
BWBWBW
Output #2
6
题目信息
题号
agc029_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。