Admissible Map

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

A map is a matrix consisting of symbols from the set of 'U', 'L', 'D', and 'R'.

A map graph of a map matrix aa is a directed graph with nmn \cdot m vertices numbered as (i,j)(i, j) (1in;1jm1 \le i \le n; 1 \le j \le m), where nn is the number of rows in the matrix, mm is the number of columns in the matrix. The graph has nmn \cdot m directed edges (i,j)(i+di_a_i,j,j+dj_a_i,j)(i, j) \to (i + di\_{a\_{i, j}}, j + dj\_{a\_{i, j}}), where (di_U,dj_U)=(1,0)(di\_U, dj\_U) = (-1, 0); (di_L,dj_L)=(0,1)(di\_L, dj\_L) = (0, -1); (di_D,dj_D)=(1,0)(di\_D, dj\_D) = (1, 0); (di_R,dj_R)=(0,1)(di\_R, dj\_R) = (0, 1). A map graph is valid when all edges point to valid vertices in the graph.

An admissible map is a map such that its map graph is valid and consists of a set of cycles.

A description of a map aa is a concatenation of all rows of the map --- a string a_1,1a_1,2a_1,ma_2,1a_n,ma\_{1,1} a\_{1,2} \ldots a\_{1, m} a\_{2, 1} \ldots a\_{n, m}.

You are given a string ss. Your task is to find how many substrings of this string can constitute a description of some admissible map.

A substring of a string s_1s_2s_ls\_1s\_2 \ldots s\_l of length ll is defined by a pair of indices pp and qq (1pql1 \le p \le q \le l) and is equal to s_ps_p+1s_qs\_ps\_{p+1} \ldots s\_q. Two substrings of ss are considered different when the pair of their indices (p,q)(p, q) differs, even if they represent the same resulting string.

입력

In the only input line, there is a string ss, consisting of at least one and at most 20,00020\\,000 symbols 'U', 'L', 'D', or 'R'.

출력

Output one integer --- the number of substrings of ss that constitute a description of some admissible map.

힌트

In the first example, there are two substrings that can constitute a description of an admissible map --- "RDUL" as a matrix of size 2×22 \times 2 (pic. 1) and "DU" as a matrix of size 2×12 \times 1 (pic. 2).

In the second example, no substring can constitute a description of an admissible map. E. g. if we try to look at the string "RDRU" as a matrix of size 2×22 \times 2, we can find out that the resulting graph is not a set of cycles (pic. 3).

In the third example, three substrings "RL", two substrings "RLRL" and one substring "RLRLRL" can constitute an admissible map, some of them in multiple ways. E. g. here are two illustrations of substring "RLRLRL" as matrices of size 3×23 \times 2 (pic. 4) and 1×61 \times 6 (pic. 5).