#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
void solve() {
  string s;
  cin >> s;
  vector<int> A;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i + 1 == s.size() || s[i] != s[i + 1]) {
      cnt++;
      A.push_back(cnt);
      cnt = 0;
    } else {
      cnt++;
    }
  }
  int ans = 0;
  for (int i = 0; i < A.size(); i++) {
    ans += A[i] / 3 * 2;
    A[i] %= 3;
  }
  for (int i = 0; i + 1 < A.size(); i++) {
    if (!A[i]) continue;
    if (A[i] == 1 && A[i + 1] == 1) ans += 2;
    if (A[i] == 1 && A[i + 1] == 2) ans += 2;
    if (A[i] == 2 && A[i + 1] == 1) ans += 2;
    if (A[i] == 2 && A[i + 1] == 2) ans += 3;
    A[i] = 0;
    A[i + 1] = 0;
  }
  if (A.back()) ans++;
  cout << ans << "\n";
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
}
