time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
Input
6
URLLDR
Output
2
Input
4
DLUU
Output
0
Input
7
RLRLRLR
Output
12
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.

题意就是让你找有多少个子串可以使行走者返回起点。

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
char a[];
int t,m,n,h,l,ans;
while(~scanf("%d",&t)){
scanf("%s",&a);
ans=;
for(int i=;i<t;i++){
m=;n=;h=;l=;
for(int j=i;j<t;j++){
if(a[j]=='U') m++;
if(a[j]=='D') n++;
if(a[j]=='L') h++;
if(a[j]=='R') l++;
if(m==n&&h==l) ans++;
}
}
printf("%d\n",ans);
}
return ;
}

Codeforces-8VC Venture Cup 2016-Elimination Round-626A.暴力 626B.水题 626C.二分的更多相关文章

  1. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  2. Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****

    F. Group Projects   There are n students in a class working on group projects. The students will div ...

  3. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  4. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  5. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  6. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  7. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  8. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

  9. 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞

    B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...

  10. 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力

    A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...

随机推荐

  1. ionic环境配置及问题

    ionic是什么? 其实就是一款用于开发web app的开源免费框架,和国产的MUI差不多. 官网:https://ionicframework.com/ 必备条件: 安装Node.js 安装Java ...

  2. Eclipse多行同时进行编辑,可编辑或修改相同内容

    使用Shift+Alt+A可以进入Eclipse多行编辑的功能,选中的一部分区域从光标开始处同时进行修改或者插入功能. 再次按下Shift+Alt+A可已退出该编辑模式.

  3. 数据库SQL优化

    1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  4. c#的关键字

    abstract as base bool break byte case catch char checked decimal default delegate continue double do ...

  5. windows64 系统下安装Nodejs

    1.nodejs安装: 版本号: node-v8.9.3-x64 检测安装成功:(这个版本已经集成了npm) 2.npm作为一个NodeJS的模块管理,先配置npm的全局模块的存放路径以及cache的 ...

  6. Nginx 学习笔记(七)如何解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

    出现:nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 错误,有以下两种情况 1.80端口被占用 2.ipv4端 ...

  7. Ant Design Pro 学习二 新建菜单-布局

    新建布局,注意格式: src/common/nav.js 中增加 { component: dynamicWrapper(app, [], () => import('/path/to/NewL ...

  8. Nginx集群之基于Redis的WebApi身份验证

    目录 1       大概思路... 1 2       Nginx集群之基于Redis的WebApi身份验证... 1 3       Redis数据库... 2 4       Visualbox ...

  9. amaze UI 笔记 - CSS

    导航添加依据 http://amazeui.org/css/  下面内容属学习笔记,如有理解偏差和错误请留言相告,感谢!* =(官网这块写的很详细) 一.基本样式 1.统一样式 说明了为什么使用Nor ...

  10. centos6环境下使用yum安装Ambari

    前言: Ambari是apache下面的开源项目,主要通过web UI方式对Hadoop集群进行统一创建和管理,以节省Hadoop集群的运维成本.本文通过安装过程中的截图简要介绍一下相关步骤供需要的朋 ...