#ARC132E. [ARC132E] Paw
[ARC132E] Paw
Score : points
Problem Statement
There are squares arranged in a row. Each square has a left- or right-pointing footprint or a hole.
The initial state of each square is described by a string consisting of ., <, >. If the -th character of is ., the -th square from the left has a hole; if that character is <, that square has a left-pointing footprint; if that character is >, that square has a right-pointing footprint.
Snuke, the cat, will repeat the following procedure until there is no more square with a hole.
- Step : Choose one square with a hole randomly with equal probability.
- Step : Fill the hole in the chosen square, stand there, and face to the left or right randomly with equal probability.
- Step : Keep walking in the direction Snuke is facing until he steps on a square with a hole or exits the row of squares.
Here, the choices of squares and directions are independent of each other.
When Snuke walks on a square (without a hole), that square gets a footprint in the direction he walks in.
If the square already has a footprint, it gets erased and replaced by a new one.
For example, in the situation >.<><.><, if Snuke chooses the -th square from the left and faces to the left, the -th, -th, -th, -rd squares get left-pointing footprints: >.<<<<><.
Find the expected value of the number of left-pointing footprints when Snuke finishes the procedures, modulo .
Notes
When the sought expected value is represented as an irreducible fraction , there uniquely exists an integer such that and under the Constraints of this problem. This is the value to be found.
Constraints
- is a string of length consisting of
.,<,>. - contains at least one
..
Input
Input is given from Standard Input in the following format:
Output
Print the expected value of the number of left-pointing footprints, modulo .
5
><.<<
3
In Step , Snuke always chooses the only square with a hole.
If Snuke faces to the left in Step , the squares become <<<<<, where squares have left-pointing footprints.
If Snuke faces to the right in Step , the squares become ><>>>, where square has a left-pointing footprint.
Therefore, the answer is .
20
>.>.<>.<<.<>.<..<>><
848117770