8VC Venture Cup 2016 - Elimination Round
A
Robot Sequence
Codeforces
1000
原题
←B →
翻译中…

Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of $*n*$ commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.

翻译中…

Input

翻译中…

The first line of the input contains a single positive integer, $*n*$ ($1 ≤ *n* ≤ 200$) — the number of commands.

翻译中…

The next line contains $*n*$ characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.

翻译中…

Output

翻译中…

Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.

翻译中…

Note

翻译中…

In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.

翻译中…

Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.

翻译中…

样例

Input #1
6
URLLDR
Output #1
2
InputCopy OutputCopy
Input #2
4
DLUU
Output #2
0
InputCopy OutputCopy
Input #3
7
RLRLRLR
Output #3
12
InputCopy OutputCopy
题目信息
题号
626A
时间限制
2 s
内存限制
256 MB
标签
暴力
模拟

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