#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 100;
const int inf = 0x3f3f3f3f;
const int iinf = 1 << 30;
const long long linf = 2e18;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
template <class T = int>
T read() {
  T f = 1, a = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    a = (a << 3) + (a << 1) + ch - '0';
    ch = getchar();
  }
  return a * f;
}
long long n, ans;
char s[maxn];
long long f[maxn] = {1}, sum, last = n + 1, nex[maxn][2], flag;
set<long long> pos[3];
signed main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  flag = 1;
  for (register long long i = (2); i <= (n); ++i) flag &= s[i] != s[i - 1];
  if (flag) return puts("1"), 0;
  pos[0].insert(n);
  for (register long long i = (n - 1); i >= (0); --i) {
    (sum += s[i + 1] == 'a' ? 1 : 2) %= 3;
    if (s[i + 1] == s[i + 2]) last = i + 2;
    pos[sum].insert(i);
    if (s[i + 1] == 'a')
      nex[i][0] = i + 1;
    else
      nex[i][1] = i + 1;
    if (s[i + 1] == 'b') {
      auto pre = pos[(sum + 2) % 3].lower_bound(last);
      if (pre == pos[(sum + 2) % 3].end())
        nex[i][0] = n + 1;
      else
        nex[i][0] = *pre;
    } else {
      auto pre = pos[(sum + 1) % 3].lower_bound(last);
      if (pre == pos[(sum + 1) % 3].end())
        nex[i][1] = n + 1;
      else
        nex[i][1] = *pre;
    }
  }
  for (register long long i = (0); i <= (n - 1); ++i) {
    if (nex[i][0] != n + 1) (f[nex[i][0]] += f[i]) %= mod;
    if (nex[i][1] != n + 1) (f[nex[i][1]] += f[i]) %= mod;
  }
  sum = 0, ans = f[n];
  for (register long long i = (n - 1); i >= (0); --i) {
    (sum += s[i + 1] == 'a' ? 1 : 2) %= 3;
    if (!sum) (ans += f[i]) %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
