#include<bits/stdc++.h>
#define N 1000005
#define Mod 1000000007
using namespace std;
char s[N];int sum[N],last[N],dp[N],nxt[N][3];
inline int gt(char ch){if(ch=='a')return 1;return 2;}
int main(){
	scanf("%s",s+1);int n=strlen(s+1);
	bool flag=1;
	for (int i=1;i<=n;i++){
		if (s[i]==s[i-1]) flag=0;
		sum[i]=sum[i-1]+gt(s[i]);
		sum[i]%=3;
	}
	if (flag) return puts("1"),0;
	for (int i=0;i<3;i++) last[i]=n+1;
	for (int i=n;~i;i--){
		for (int j=0;j<3;j++) nxt[i][j]=last[j];
		last[sum[i]]=i;
	}
	int ans=0;dp[0]=1;
	for (int i=0;i<=n;i++){
		for (int j=1;j<=2;j++)
			if (nxt[i][(sum[i]+j)%3]<=n) dp[nxt[i][(sum[i]+j)%3]]=1ll*(dp[nxt[i][(sum[i]+j)%3]]+dp[i])%Mod;
		if (i&&sum[i]==sum[n]) ans=1ll*(ans+dp[i])%Mod;
	}
	printf("%d\n",ans);
	return 0;
}