atcoder#AGC015B. [AGC015B] Evilator
[AGC015B] Evilator
Score : points
Problem Statement
Skenu constructed a building that has 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 is U
, only "up" button is installed on the -th floor and one can only go up; if is D
, only "down" button is installed on the -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 : the minimum number of times one needs to take the elevator to get to the -th floor from the -th floor.
Constraints
- is either
U
orD
. - is
U
. - is
D
.
Input
The input is given from Standard Input in the following format:
Output
Print the sum of the following numbers over all ordered pairs of two floors : the minimum number of times one needs to take the elevator to get to the -th floor from the -th floor.
UUD
7
From the -st floor, one can get to the -nd floor by taking the elevator once.
From the -st floor, one can get to the -rd floor by taking the elevator once.
From the -nd floor, one can get to the -st floor by taking the elevator twice.
From the -nd floor, one can get to the -rd floor by taking the elevator once.
From the -rd floor, one can get to the -st floor by taking the elevator once.
From the -rd floor, one can get to the -nd floor by taking the elevator once.
The sum of these numbers of times, , should be printed.
UUDUUDUD
77