#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  int c, p, cnt;
  cin >> str;
  int len = str.size();
  cnt = 0;
  for (int i = 0; i < len;) {
    if (str[i] == 'P') {
      p = 0;
      i++;
      while (str[i] == 'P' && (p < 4)) {
        i++;
        p++;
      }
      cnt++;
    } else {
      c = 0;
      i++;
      while ((str[i] == 'C') && (c < 4)) {
        i++;
        c++;
      }
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
