#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1001000,P=1e9+7;
int n,x,a[N],s[N],t[N],f[3][N],g[N],q[3][N],L[3],R[3];
char S[N];
bool ok0(int l,int r){return (s[r]-s[l-1])%3==0;}
bool ok1(int l,int r){return t[r]>t[l];}
void chk(int&x){x-=P;x+=(x>>31)&P;}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%s",S+1);
	n=strlen(S+1);
	FOR(i,1,n) a[i]=S[i]=='a'?1:2;
	FOR(i,1,n) s[i]=a[i]+s[i-1],t[i]=(a[i]==a[i-1])+t[i-1];
	if(!t[n]) return puts("1"),0;
	ROF(i,n,0){
		FOR(j,1,2){
			x=(s[i]+j)%3;f[j][i]=n+1;
			if(L[x]==R[x]) continue;
			while(L[x]+1<R[x] && ok1(i+1,q[x][L[x]+1])) L[x]++;
			if(ok1(i+1,q[x][L[x]])) f[j][i]=q[x][L[x]];
			if(a[i+1]==j) f[j][i]=i+1;
			chk(g[i]+=g[f[j][i]]);
			if(f[j][i]<=n && ok0(f[j][i]+1,n)) chk(++g[i]);
		}
		q[s[i]%3][R[s[i]%3]++]=i;
		//cout<<i<<':'<<f[1][i]<<' '<<f[2][i]<<' '<<g[i]<<'\n';
	}
	cout<<g[0]<<'\n';
}