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 = b, sk + 1 = e, sk + 2 = a, sk + 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.

Examples
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) {char s[5100];scanf("%s",&s);int i,j;int len=strlen(s);if(len<4)printf("0");else{int count=0;for(i=0;i<len-3;i++){for(j=i;j<len-3;j++){if(s[j]=='b'&&s[j+1]=='e'&&s[j+2]=='a'&&s[j+3]=='r'){ count+=(len-3-j);break;}}}printf("%d\n",count);}return 0;
}

Bear and Strings相关推荐

  1. CodeForces - 336D Vasily the Bear and Beautiful Strings(dp+组合数学)

    题目链接:点击查看 题目大意:给出一个 01 字符串,规定求值的过程如下: 每次选择末尾的两个数字: 如果为 0 0 ,那么替换成一个 1 否则替换成一个 0 循环往复,直至只剩一个数字位置,剩下的数 ...

  2. Android TextView 在strings 里面 实现换行

    在TextView 把text 使用快捷键放到strings 里面 \n是无法被放到里面的 如果想实现换行 可以手动在里面添加 \n 例如写了一个小例子, 如果你写了多语言适配 ,那么在你的其他的st ...

  3. Go 学习笔记(51)— Go 标准库之 strings(字符串比较、字符串前后缀、字符串统计、字符串索引、字符串包含、字符串转换、字符串复制、字符串替换、字符串去除、字符串分割和连接)

    1. 概述说明 import "strings" strings 包实现了用于操作字符的简单函数. strings 包与 bytes 包中的函数用法基本一样. 2. 主要函数 2. ...

  4. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

  5. Simple Dynamic Strings(SDS)源码解析和使用说明二

    在<Simple Dynamic Strings(SDS)源码解析和使用说明一>文中,我们分析了SDS库中数据的基本结构和创建.释放等方法.本文将介绍其一些其他方法及实现.(转载请指明出于 ...

  6. Simple Dynamic Strings(SDS)源码解析和使用说明一

    SDS是Redis源码中一个独立的字符串管理库.它是由Redis作者Antirez设计和维护的.一开始,SDS只是Antirez为日常开发而实现的一套字符串库,它被使用在Redis.Disque和Hi ...

  7. golang strings.Fields 使用

    2019独角兽企业重金招聘Python工程师标准>>> s := "Hello 世\n界!\tHe\vl\flo!" ss := strings.Fields(s ...

  8. pandas使用to_datetime函数把dataframe的字符串日期数据列转化为日期格式日期数据列( strings to datetime in dataframe column)

    pandas使用to_datetime函数把dataframe的字符串日期数据列转化为日期格式日期数据列( strings to datetime in dataframe column) 目录

  9. R字符串(Strings)转为日期类型(Dates)

    R字符串(Strings)转为日期类型(Dates) 目录 R字符串(Strings)转为日期类型(Dates) as.Date函数

最新文章

  1. iOS 解决app退出后台应用重新启动的问题
  2. Android Studio配置GreenDAO 3.2.0和使用方法
  3. python怎么计算积分_Python 计算积分实例
  4. Open XML操作Excel导入数据
  5. hive和hadoop关系
  6. cocos2dx 3.16 VS+BabeLua lua环境配置与代码调试
  7. 2022年山东省安全员C证特种作业证考试题库及答案
  8. /etc/shadow可以破解吗?
  9. linux team 模式,linux 聚合口 team libteam 简介
  10. 由随机数生成器到宿命论
  11. 【人月神话】浅谈人月神话0.1焦油坑
  12. 刷题day_12:快乐数
  13. Linux 网络状态工具 ss 详解,比netstat更强大
  14. ios全网通插电信卡显示无服务器,iPhone6/6 Plus全网通无法使用电信4G 苹果称将很快解决...
  15. 银河麒麟系统设置变更
  16. 用图带你了解大数据框架架构之DophinScheduler
  17. OpenShift全力拥抱Operator:Kubernetes运维自动化背后的战争
  18. 数据库与MPP数仓(十三):数据仓库的模型构建
  19. Educational Codeforces Round 100 (Rated for Div. 2)补题记录
  20. linux如何按行拆分与合并

热门文章

  1. buck dcm占空比计算_电源老兵,多年技术笔记曝光!BUCK,BOOST,FLYBACK,LLC都过一篇
  2. mysql 时间周期_数据库三大周期阶段
  3. 预处理_气体在线分析仪预处理系统的工作内容
  4. 戴尔服务器装新硬盘模式,DELL服务器配置RAID及安装ESXI
  5. 分布式内存数据库---Redis的持久化
  6. textrank4zh来处理句子的重要度
  7. 全网首个OpenPrompt尝鲜报告:Prompt研究者必备实验利器
  8. FPGA加速BCNN,模型20倍剪枝率、边缘设备超5000帧/秒推理吞吐量
  9. ​让人惊叹的Johnson-Lindenstrauss引理:应用篇
  10. 直播 | WWW 2021论文解读:强化学习与互信息驱动的子图神经网络