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. Rhel6-cacti+nagios+ganglia(nginx)配置文档

    (lnmp平台) 系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.185 server85.example.com 1 ...

  2. js动画之简单运动一

    虽然现在css3已经有了很多动画效果希望后面有时间也写一些博客,但是先开始我们的基础动画的学习. 1.制作动画常用的属性就是left,right,height,width,opacity等属性 2.因 ...

  3. 在服务器端将XML转换成HTML

    以下是在服务器上转换XML文件所需要的简单源代码: <% 'Load the XML set xml = Server.CreateObject("Microsoft.XMLDOM&q ...

  4. JavaScript基础--小案例:在网页指定位置弹出错误信息(十二)

    案例分析:点击按钮后,在网页上指定区域,提示错误信息!5秒后,错误信息提示自动消失! <script languag="javascript" type="text ...

  5. JSP应用程序(自定义错误页面)

    一.编写 1.index.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> &l ...

  6. POJ 2155 2维线段树 || 2维BIT

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  7. WCF终结点配置

    错误信息:已有针对 IP 终结点 127.0.0.1:8235 的侦听器.如果有其他应用程序已在侦听此终结点,或者,如果在服务主机中具有多个服务终结点,这些终结点具有相同的 IP 终结点但绑定配置不兼 ...

  8. CSS3实现轮播切换效果

    实现轮播的一般思路为在一个大盒子中对无限个元素进行切换操作,大盒子固定大小,超出盒子范围进行隐藏,而里面无限个元素可以任何堆叠,按照一定的步骤进行位置变换,已达到在可视区域呈现我们想要的效果.   看 ...

  9. 第三个Sprint冲刺第一天

    讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 讨论问题:再度强化四则运算app的功能.

  10. 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿

    腾讯优测是专业的android自动化测试平台,拥有上千款真机,彻底解决android碎片化问题! 这里我要说的不是闪光灯的硬件特征,也不是说底层驱动的原理,我只是跟大家聊一聊在项目中遇到的一些关于闪光 ...