#include <bits/stdc++.h>
using namespace std;
const long long int md = 998244353;
const long long MAX = LONG_MAX;
const long long lrg = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string st;
  cin >> st;
  long long sz = st.length();
  vector<long long> v;
  char s = st[0];
  long long c = 1;
  for (long long i = 1; i < sz; i++) {
    if (s == st[i]) {
      c++;
    } else {
      v.push_back(c);
      c = 1;
      s = st[i];
    }
    if (i == sz - 1) v.push_back(c);
  }
  auto ii = v.begin();
  long long p = *ii, co = 1;
  ii++;
  long long sm = (long long)(p / 3) * 2 + ((p % 3 == 0) ? 0 : 1);
  while (ii != v.end()) {
    if (p % 3 == (*ii) % 3) {
      co++;
      sm += (long long)((*ii) / 3) * 2 + (((*ii) % 3 == 0) ? 0 : 1);
    } else {
      sm += ((p % 3 == 2) ? ((long long)(co / 2)) : 0);
      sm += (long long)((*ii) / 3) * 2 + (((*ii) % 3 == 0) ? 0 : 1);
      p = *ii;
      co = 1;
    }
    ii++;
    if (ii == v.end()) {
      sm += ((p % 3 == 2) ? ((long long)(co / 2)) : 0);
    }
  }
  cout << sm;
  return 0;
}
