#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
string s;
vi a,S,b[3],g[2];

int main(){
	cin>>s;
	n=s.size();
	a=vi(n);S=vi(n+1);
	b[0]=b[1]=b[2]=g[0]=g[1]=vi(n+1,-1);
	for(int i=0;i<n;i++){
		if(s[i]=='a') a[i]=2;
		else a[i]=1;
	}
	for(int i=1;i<=n;i++) S[i]=S[i-1]+a[i-1];
	for(int i=n-1;i>=0;i--){
		b[a[i]][i]=i+1;
		for(int j=0;j<3;j++) if(j!=a[i]){
			b[j][i]=b[(j-a[j]+3)%3][i+1];
		}
	}
	int I=-1;
	for(int i=n-1;i>=0;i--){
		if(i!=n-1&&s[i]==s[i+1]) I=i+2;
//		cout<<I<<endl;
		if(s[i]=='a'){
			g[0][i]=i+1;
			if(I==-1) continue;
			int t=(4-S[I]+S[i])%3;
			if(!t) g[1][i]=I;
			else g[1][i]=b[(4-S[I]+S[i])%3][I];
		}
		else{
			g[1][i]=i+1;
			if(I==-1) continue;
			int t=(5-S[I]+S[i])%3;
			if(!t) g[0][i]=I;
			else g[0][i]=b[(5-S[I]+S[i])%3][I];
		}
	}
	int J=-1;
	for(int i=n-2;i>=0;i--) if(s[i]==s[i+1]){
		J=i+2;
		break;
	}
	if(J==-1){
		cout<<1<<endl;
		return 0;
	}
	vi dp(n+1);
	dp[0]++;
	int res=0;
	for(int i=0;i<n;i++) for(int j=0;j<2;j++) if(g[j][i]!=-1){
		I=g[j][i];
		(dp[I]+=dp[i])%=mod;
		if((S[n]-S[I]+3)%3==0&&(I!=i+1||i+1>=I))(res+=dp[i])%=mod;
	}
	cout<<res<<endl;
}