0
点赞
收藏
分享

微信扫一扫

【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)

题干:

The Fair Nut found a string ss. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p1,p2,…,pkp1,p2,…,pk, such that:

  1. For each ii (1≤i≤k1≤i≤k), spi=spi= 'a'.
  2. For each ii (1≤i<k1≤i<k), there is such jj that pi<j<pi+1pi<j<pi+1 and sj=sj= 'b'.

The Nut is upset because he doesn't know how to find the number. Help him.

This number should be calculated modulo 109+7109+7.

Input

The first line contains the string ss (1≤|s|≤1051≤|s|≤105) consisting of lowercase Latin letters.

Output

In a single line print the answer to the problem — the number of such sequences p1,p2,…,pkp1,p2,…,pk modulo 109+7109+7.

Examples

Input

abbaa

Output

5

Input

baaaa

Output

4

Input

agaa

Output

3

Note

In the first example, there are 55 possible sequences. [1][1], [4][4], [5][5], [1,4][1,4], [1,5][1,5].

In the second example, there are 44 possible sequences. [2][2], [3][3], [4][4], [5][5].

In the third example, there are 33 possible sequences. [1][1], [3][3], [4][4].

题目大意:

   让你构造一个序列,有两个要求:1.全为‘a’字符。2.每两个a字符之间一定夹着至少一个b字符,求能构造出多少个这样的序列

解题报告:

   扫一遍遇到a就记录,遇到b就终止并开始计数 最后输出答案,就行了

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
const ll mod = 1e9+7;
char s[MAX];
int main()
{
scanf("%s", s + 1);
int len = strlen(s + 1);
ll ans = 1;
for(int i = 1; i<=len; i++){
ll cnt = 0;
int cur = i;
while(cur <= len){
if(s[cur] == 'a') cnt++,cur++;
else if(s[cur] == 'b') break;
else cur++;
}
i = cur;
ans = ans*(cnt+1) % mod;
}
ans--;
printf("%lld\n", ans);
return 0;
}

 


举报

相关推荐

0 条评论