#include <bits/stdc++.h>
using namespace std;
int p = 3;
long long kai_size = 1000001;
vector<long long> kai(kai_size, 1);
vector<long long> ink(kai_size, 1);
vector<long long> dist;
long long RE() {
  vector<long long> v(3, 2);
  return v.at(4);
}
long long ru(long long a, long long r) {
  if (r == 0) {
    return 1;
  }
  long long ans = ru(a, r / 2);
  ans *= ans;
  ans %= p;
  if (r % 2 == 1) {
    ans *= a;
  }
  return ans % p;
}
long long inv(long long a) { return ru(a, p - 2); }
void make_kai() {
  for (long long i = 0; i < kai_size - 1; i++) {
    kai[i + 1] = (kai[i] * (i + 1)) % p;
  }
  for (long long i = 0; i < kai_size; i++) {
    ink[i] = inv(kai[i]);
  }
}
long long com(long long n, long long r) {
  if (r < 0 || n < r) {
    return 0;
  }
  long long ans = kai[n] * ink[r];
  ans %= p;
  ans *= ink[n - r];
  ans %= p;
  return ans;
}
vector<long long> dis(long long mid1, vector<vector<long long> > &way) {
  long long n = way.size();
  vector<long long> dist(n, -1);
  dist[mid1] = 0;
  queue<long long> q;
  q.push(mid1);
  while (!q.empty()) {
    long long st = q.front();
    q.pop();
    for (long long i = 0; i < way[st].size(); i++) {
      long long to = way[st][i];
      if (dist[to] == -1) {
        dist[to] = dist[st] + 1;
        q.push(to);
      }
    }
  }
  return dist;
}
pair<long long, long long> most_far(long long now, long long n,
                                    vector<vector<long long> > &way) {
  vector<long long> dist1 = dis(now, way);
  pair<long long, long long> ans = make_pair(-1, 0);
  for (long long i = 0; i < n; i++) {
    if (dist1[i] > ans.first) {
      ans = make_pair(dist1[i], i);
    }
  }
  return ans;
}
long long per(long long a, long long b) {
  long long ans = a % b;
  if (ans < 0) {
    ans += b;
  }
  return ans;
}
vector<long long> uni(vector<long long> &v) {
  sort(v.begin(), v.end());
  vector<long long> ans(1, v[0]);
  for (long long i = 1; i < v.size(); i++) {
    if (v[i] != v[i - 1]) {
      ans.push_back(v[i]);
    }
  }
  v = ans;
  return v;
}
long long s_gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return s_gcd(b, a % b);
}
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  return s_gcd(a, b);
}
bool is_prime(long long i) {
  for (long long j = 2; j * j <= i; j++) {
    if (i % j == 0) {
      return false;
    }
  }
  return true;
}
long long get(long long i, long long j, vector<vector<long long> > &ans) {
  long long n = ans.size();
  if (i < 0 || n <= i || j < 0 || n <= j) {
    return 1;
  }
  return ans[i][j];
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
signed main() {
  string s;
  cin >> s;
  long long n = s.size();
  vector<vector<long long> > lis(3);
  vector<long long> sum(n + 1);
  bool fl = true;
  for (long long i = 0; i < n; i++) {
    lis[sum[i]].push_back(i);
    sum[i + 1] = sum[i] + (s[i] - 'a') + 1;
    sum[i + 1] %= 3;
    if (i % 2 == 0 xor s[i] == s[0]) {
      fl = false;
    }
  }
  if (fl) {
    cout << 1 << endl;
    return 0;
  }
  vector<long long> dp(n);
  dp[0] = 1;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (sum[i] != sum[n]) {
      ans += dp[i];
    }
    long long pla = (sum[i] + 1) % 3;
    auto itr = lower_bound(lis[pla].begin(), lis[pla].end(), i);
    if (itr != lis[pla].end()) {
      dp[*itr] += dp[i];
    }
    pla++;
    pla %= 3;
    itr = lower_bound(lis[pla].begin(), lis[pla].end(), i);
    if (itr != lis[pla].end()) {
      dp[*itr] += dp[i];
    }
  }
  cout << ans << endl;
  return 0;
}
