#include <bits/stdc++.h>
using namespace std;
int N;
char str[1000010];
bool f[1000010];
int pre(int i) { return ((i - 1 + N) % N); }
int nex(int i) { return ((i + 1 + N) % N); }
int main() {
  while (scanf("%s", str) != EOF) {
    N = strlen(str);
    int cnt = 1;
    for (int i = 1; i < N; i++)
      if (str[i] != str[i - 1]) cnt++;
    if (str[0] == str[N - 1] && cnt > 1) cnt--;
    for (int i = 1; i < N - 1; i++)
      if (str[i] != str[i - 1] && str[i] != str[i + 1]) cnt--;
    if (str[0] != str[1] && str[0] != str[N - 1]) cnt--;
    if (str[N - 1] != str[N - 2] && str[N - 1] != str[0]) cnt--;
    memset(f, false, sizeof(f));
    for (int i = 0; i < N; i++)
      if (str[pre(i)] != str[i] && str[pre(pre(i))] != str[pre(i)] &&
          str[nex(i)] != str[i])
        f[i] = true;
    if (f[0] && f[N - 1]) {
      int l = 0, r = N - 1;
      f[l] = f[r] = false;
      while (f[l + 1]) {
        l++;
        f[l] = false;
      }
      while (f[r - 1]) {
        r--;
        f[r] = false;
      }
      int tmp = (l + 1) + (N - r);
      cnt += (tmp + 1) / 2;
    }
    int l = 0;
    while (l < N) {
      if (!f[l])
        l++;
      else {
        int r = l;
        while (f[r + 1]) r++;
        cnt += (r - l + 2) / 2;
        l = r + 1;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
