#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, j, k, t, p, q, x = 0, y = 0, z = 0;
  string s;
  cin >> s;
  m = s.length();
  for (i = 0; i < m;) {
    k = 0;
    if (s[i] == 'C') {
      for (j = i; j < m; j++) {
        if (s[j] == 'C')
          k++;
        else
          break;
      }
      p = k % 5;
      q = k / 5;
      if (p == 0)
        x += q;
      else
        x += (q + 1);
      i = j;
    } else if (s[i] == 'P') {
      for (j = i; j < m; j++) {
        if (s[j] == 'P')
          k++;
        else
          break;
      }
      p = k % 5;
      q = k / 5;
      if (p == 0)
        x += q;
      else
        x += (q + 1);
      i = j;
    }
  }
  cout << x << endl;
}
