#include <bits/stdc++.h>
int main() {
  int pos, c, p, jum, pjg;
  char kal[105];
  scanf("%s", kal);
  pjg = strlen(kal);
  pos = 0;
  jum = 0;
  while (pos < pjg) {
    c = 0;
    p = 0;
    while (pos < pjg && kal[pos] == 'C') {
      c++;
      pos++;
    }
    jum = jum + c / 5;
    if (c % 5 != 0) jum++;
    while (pos < pjg && kal[pos] == 'P') {
      p++;
      pos++;
    }
    jum = jum + p / 5;
    if (p % 5 != 0) jum++;
  }
  printf("%d\n", jum);
  return 0;
}
