#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; (i) < (int) (n); (i) ++)
using namespace std;

const int inf = 1e7;
const long long mod = 1e9 + 7;
int main() {
        string s;
        cin >> s;
        int n = (int) s.size();
        bool unko = true;
        rep(i, n - 1) unko = unko && s[i] != s[i + 1];
        if (unko) {
                cout << 1 << endl;
                return 0;
        }
        vector<int> acc(n + 1);
        rep(i, n) {
                int a = (s[i] == 'a' ? 1 : 2);
                acc[i + 1] = (acc[i] + a) % 3;
        }
        vector<vector<int>> app(n + 2, vector<int> (3));
        rep(i, 3) app[n + 1][i] = inf;
        for (int i = n; i >= 0; i --) {
                rep(j, 3) {
                        app[i][j] = (acc[i] == j ? i : app[i + 1][j]);
                }
        }
        long long ans = 0;
        vector<int> add(n + 1);
        add[0] = 1;
        rep(i, n + 1) {
                if (acc[n] == acc[i]) (ans += add[i]) %= mod; // cut last part (sum == 0 (mod 3))
                for (int put = 1; put <= 2; put ++) {
                        int pos = app[i + 1][(put + acc[i]) % 3];
                        if (pos != inf) (add[pos] += add[i]) %= mod;
                }
        }
        if (acc[0] == acc[n]) (ans += mod - 1) %= mod; // no operation
        cout << ans << endl;
        return 0;
}
