#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int MOD = 1000000007;
string s;

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int main() {
    cin >> s;
    int n = (int)s.size();
    
    // 累積和
    vector<int> sum(n+1, 0);
    for (int i = 0; i < n; ++i) {
        int par = (s[i] == 'a' ? 1 : 2);
        sum[i+1] = (sum[i] + par) % 3;
    }
    
    // 次の累積和が「０」「１」「２」になる瞬間の切れ目
    vector<vector<int> > next(n+1, vector<int>(3, n+1));
    for (int i = n-1; i >= 0; --i) {
        next[i][sum[i+1]] = i+1;
        for (int j = 0; j < 3; ++j) next[i][j] = min(next[i][j], next[i+1][j]);
    }
    
    // 次の「同じ文字 2 連続」を含む切れ目
    vector<int> next2(n+1, n);
    for (int i = n-2; i >= 0; --i) {
        if (s[i] == s[i+1]) next2[i] = i+1;
        else next2[i] = min(next2[i], next2[i+1]);
    }
    
    // DP
    vector<long long> dp(n+1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        add(dp[i+1], dp[i]);
        int ne = next[next2[i]][(sum[i]+(s[i]=='a'?2:1))%3];
        if (ne <= n) add(dp[ne], dp[i]);
    }
    
    // res
    long long res = 0;
    if (next2[0] == n) res = 1;
    else {
        for (int i = 1; i <= n; ++i) {
            if (sum[i] == sum[n]) add(res, dp[i]);
        }
    }
    
    cout << res << endl;
}