B. Bear and Strings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring.

String x(i, j) contains string "bear", if there is such index k (i ≤ k ≤ j - 3), that sk = bsk + 1 = esk + 2 = ask + 3 = r.

Help the bear cope with the given problem.

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters.

Output

Print a single number — the answer to the problem.

Sample test(s)
input
bearbtear
output
6
input
bearaabearc
output
20
Note

In the first sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).

In the second sample, the following pairs (i, j) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).

 
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std; int gao(string s){
vector< pair<int,int> >seg ;
vector< pair<int,int> >::iterator it ;
seg.clear() ;
int i ,Len = s.length() ,L ,R ,ans = ,reL ;
for(i = ; i <= Len - ; i++){
if(s[i]=='b'&&s[i+]=='e'&&s[i+]=='a'&&s[i+]=='r')
seg.push_back(make_pair(i+,i++)) ;
}
if(seg.size() == )
return ;
it = seg.begin() ;
reL = L = it->first ;
R = it->second ;
ans += L * (Len - R +) ;
for(it++; it != seg.end() ; it++){
L = it->first ;
R = it->second ;
ans += (L - reL) * (Len - R + ) ;
reL = L ;
}
return ans ;
} int main(){
string s ;
while(cin>>s){
cout<<gao(s)<<endl ;
}
return ;
}

Codeforces Round #226 (Div. 2) B的更多相关文章

  1. Codeforces Round #226 (Div. 2 )

    这次精神状态不怎么好,第一题的描述看得我就蛋疼...看完就速度写了~~~最终fst了%>_<%,第二题写复杂了,一直WA pretest 3,然后就紧张,导致精神更不好了,一直纠结在第二题 ...

  2. Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers

    /* 可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数, 然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数. */ #include <stdio.h ...

  3. Codeforces Round #226 (Div. 2)A. Bear and Raspberry

    /* 贪心的找到相邻两项差的最大值,再减去c,结果若是负数答案为0. */ 1 #include <stdio.h> #define maxn 105 int num[maxn]; int ...

  4. Codeforces Round #226 (Div. 2)B. Bear and Strings

    /* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...

  5. 【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight

    读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm& ...

  6. Codeforces Round #226 (Div. 2) C题

    数论好题 题目要求:求给定序列的素因子如果在给定区间内该数字个数加1; 思路:打表时求出包含给素数因子的数的个数,详见代码 1 #include<cstring> +;      scan ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. mybatis sql in 查询

    mybatis官方学习文档:http://www.mybatis.org/core/getting-started.html 本文转自:http://www.blogjava.net/xmatthew ...

  2. 作业七:团队项目——Alpha版本冲刺阶段 001

    今天进展:准备开发环境,安装软件. 今天安排:因为软件过于庞大,所以我们第一天都在按软件,原本计划第一天要设计框架,但因为软件问题.所以我们决定留到第二天.

  3. 再议C++的性能

    最近在公司里的项目做的是性能优化,相关性能调优的经验总结也在前一篇文章里说了.这里再说一说和性能相关的东西.主要针对的是C++类库中常用的一些数据结构,比方说std::string.顺序容器(vect ...

  4. C# base64图片数据传送加号(+)变空格问题

    今天遇到一个问题,将图片的base64数据转发,客户收到base64数据后生成图片失真. 通过日志监控,对比客户收到的数据和我发出的数据,最终发现客户base64数据中原本应该显示为加号(" ...

  5. Jmeter—5 关联 响应数据传递-正则表达式提取器

    在测试过程中,遇到一个问题:用户登录成功后服务器会返回一个登录凭证,之后所有的操作都需要带上此凭证.我们怎么获取登录凭证并传递给后续的操作? Jmeter提供了正则表达式提取器,用变量提取参数,后续通 ...

  6. DOM扩展之Selectors API

    jQuery的核心就是通过CSS选择符查询DOM文档取得元素的引用,从而抛开了getElementById()和getElementsByTagName(). Selectors API致力于让浏览器 ...

  7. 隐藏ArcGIS server设置的用户名

    打开注册表编辑器,定位到“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\ SpecialAccoun ...

  8. 自己动手编译apache-tomcat-6.0.41-src源码

    第一步:下载apache-tomcat-6.0.41-src 第二步:阅读BUILDING.txt.了解所需要的步骤. In order to build a binary distribution ...

  9. windows在当前位置打开终端

    1) 在此文件夹窗口内空白区域右键单击(需要同时按住Shift),从菜单中选择"在此处打开命令行窗口"的项:2) 在此窗口地址栏里直接输入cmd,回车即可.

  10. 细说Javascript之null、undefined和NaN

    首先简单介绍一下Javascript中的数据类型,Javascript中的数据类型有undefined,boolen,number,string和object等5种,前4种是原始类型,第5种是引用类型 ...