#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= int(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 3e5 + 2333;
const int mo = 1e9 + 7;
inline void U(int &x, int y) { x += y; if (x >= mo) x -= mo; }

char str[N];
int n, sum[N], la[3], nxt[N][3], same[N], dp[N];

int main(void) {
	scanf("%s", str + 1); 
	n = strlen(str + 1);
	rep (i, n) {
		str[i] = str[i] == 'b' ? 2 : 1;
		sum[i] = (sum[i - 1] + str[i]) % 3;
	}
	la[0] = la[1] = la[2] = n + 1; same[n + 1] = n + 1;
	for (int i = n; i >= 1; i--) {
		for (int k = 0; k < 3; k++) nxt[i][k] = la[k];
		la[sum[i]] = i;
		if (str[i] == str[i + 1]) same[i] = i + 1;
		else same[i] = same[i + 1];
	}
	if (same[1] > n) return puts("1"), 0;
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		U(dp[i + 1], dp[i]);
		int v = 3 - str[i + 1];
		int val = (v + sum[i]) % 3;
		int nxtpos = nxt[i][val];
		int lb = same[i + 1];
		if (nxtpos <= n) {
			if (nxtpos < lb) nxtpos = nxt[lb - 1][val];
			if (nxtpos <= n) U(dp[nxtpos], dp[i]);
		}
	}
	int ans = 0;
	rep (i, n) if (sum[i] == sum[n]) U(ans, dp[i]);
	cout << ans << "\n";
}
