atcoder#ARC132E. [ARC132E] Paw

[ARC132E] Paw

Score : 800800 points

Problem Statement

There are nn 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 ss consisting of ., <, >. If the ii-th character of ss is ., the ii-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 11: Choose one square with a hole randomly with equal probability.
  • Step 22: Fill the hole in the chosen square, stand there, and face to the left or right randomly with equal probability.
  • Step 33: 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 66-th square from the left and faces to the left, the 66-th, 55-th, 44-th, 33-rd squares get left-pointing footprints: >.<<<<><.

Find the expected value of the number of left-pointing footprints when Snuke finishes the procedures, modulo 998244353998244353.

Notes

When the sought expected value is represented as an irreducible fraction p/qp/q, there uniquely exists an integer rr such that rqp(mod 998244353)rq\equiv p \sim (\text{mod } 998244353) and 0r<9982443530 \leq r \lt 998244353 under the Constraints of this problem. This rr is the value to be found.

Constraints

  • 1n1051 \leq n \leq 10^5
  • ss is a string of length nn consisting of ., <, >.
  • ss contains at least one ..

Input

Input is given from Standard Input in the following format:

nn

ss

Output

Print the expected value of the number of left-pointing footprints, modulo 998244353998244353.

5
><.<<
3

In Step 11, Snuke always chooses the only square with a hole.

If Snuke faces to the left in Step 22, the squares become <<<<<, where 55 squares have left-pointing footprints.

If Snuke faces to the right in Step 22, the squares become ><>>>, where 11 square has a left-pointing footprint.

Therefore, the answer is 5+12=3\frac{5+1}{2}=3.

20
>.>.<>.<<.<>.<..<>><
848117770