#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





string S; int N;
mint dp[101010];
int sm[101010], nxt[101010][3];
int ok[101010], oksm[101010];
vector<int> idx[3];
//---------------------------------------------------------------------------------------------------
int getok(int l, int r) { // [l,r)
    if (l >= r) return 0;

    int res = oksm[r - 1];
    if (l) res -= oksm[l - 1];
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    N = S.length();
    rep(i, 0, N) {
        if (S[i] == 'a') sm[i] = 1;
        else sm[i] = 2;
    }
    rep(i, 1, N) sm[i] = (sm[i] + sm[i - 1]) % 3;
    rep(i, 0, N) idx[sm[i]].push_back(i);
    rep(i, 0, 3) idx[i].push_back(N);

    rep(i, 0, N - 1) if (S[i] == S[i + 1]) ok[i] = 1;
    oksm[0] = ok[0];
    rep(i, 1, N) oksm[i] = oksm[i - 1] + ok[i];

    rep(i, 0, N) {
        rep(c, 0, 3) {
            int ng = i, ok = N;
            while (ng + 1 != ok) {
                int md = (ng + ok) / 2;
                int j = *lower_bound(all(idx[c]), md);

                if (getok(i, j)) ok = md;
                else ng = md;
            }

            nxt[i][c] = *lower_bound(all(idx[c]), ok);
        }
    }

    dp[0] = 1;
    rep(i, 0, N) {
        int pre = 0;
        if (i) pre = sm[i - 1];

        // make 'a'
        // sm[j] - pre = 1
        // sm[j] = pre + 1
        if (S[i] == 'a') dp[i + 1] += dp[i];
        else {
            int ai = nxt[i][(pre + 1) % 3];
            if (ai < N) dp[ai + 1] += dp[i];
        }
        
        // make 'b'
        // sm[j] - pre = 2
        // sm[j] = pre + 2
        if (S[i] == 'b') dp[i + 1] += dp[i];
        else {
            int bi = nxt[i][(pre + 2) % 3];
            if (bi < N) dp[bi + 1] += dp[i];
        }
    }

    mint ans = 0;
    if (oksm[N - 1]) {
        rep(i, 1, N + 1) if ((sm[N - 1] - sm[i - 1] + 3) % 3 == 0) ans += dp[i];
    }
    else ans = 1;
    
    cout << ans << endl;
}

Measured memory_bytes: 3784