AtCoder Grand Contest 015
B
Evilator
AtCoder
⌀ 665
原题
← AC →
翻译中…

Problem Statement

翻译中…

Skenu constructed a building that has $N$ floors. The building has an elevator that stops at every floor.

翻译中…

There are buttons to control the elevator, but Skenu thoughtlessly installed only one button on each floor - up or down. This means that, from each floor, one can only go in one direction. If $S_i$ is U, only "up" button is installed on the $i$-th floor and one can only go up; if $S_i$ is D, only "down" button is installed on the $i$-th floor and one can only go down.

翻译中…

The residents have no choice but to go to their destination floors via other floors if necessary. Find the sum of the following numbers over all ordered pairs of two floors $(i,j)$: the minimum number of times one needs to take the elevator to get to the $j$-th floor from the $i$-th floor.

翻译中…

Constraints

翻译中…
  • $2 ≤ |S| ≤ 10^5$
  • $S_i$ is either U or D.
  • $S_1$ is U.
  • $S_{|S|}$ is D.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

S_1S_2...S_{|S|}

翻译中…

Output

翻译中…

Print the sum of the following numbers over all ordered pairs of two floors $(i,j)$: the minimum number of times one needs to take the elevator to get to the $j$-th floor from the $i$-th floor.

翻译中…

样例

Input #1
UUD
Output #1
7
From the $1$-st floor, one can get to the $2$-nd floor by taking the elevator once. From the $1$-st floor, one can get to the $3$-rd floor by taking the elevator once. From the $2$-nd floor, one can get to the $1$-st floor by taking the elevator twice. From the $2$-nd floor, one can get to the $3$-rd floor by taking the elevator once. From the $3$-rd floor, one can get to the $1$-st floor by taking the elevator once. From the $3$-rd floor, one can get to the $2$-nd floor by taking the elevator once. The sum of these numbers of times, $7$, should be printed.
Input #2
UUDUUDUD
Output #2
77
题目信息
题号
agc015_b
时间限制
2 s
内存限制
256 MB

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