Language: C++

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e12)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  string s;
  cin>>s;
  long long k;
  cin>>k;
  int n = s.size();
  long long dp[n][2][2] = {};
  fill(dp,dp+4*n,INF);
  bool f[n] = {};
  REP(i,n){
    REP(j,2){
      REP(k,2){
        if(i==0){
          if(j==0){
            if(k==0){
              dp[i][j][k] = 0;
            }
          }else{
            if(k==1){
              dp[i][j][k] = 1;
            }
          }
          continue;
        }
        if(j==0){
          if(s[i-1] == s[i]){
            dp[i][j][k] = dp[i-1][1][k];
          }else{
            dp[i][j][k] = min(dp[i-1][0][k], dp[i-1][1][k]);
          }
        }else{
          dp[i][j][k] = 1 + min(dp[i-1][0][k], dp[i-1][1][k]);
        }
      }
    }
  }
  
  long long ans = INF;
  REP(j,2){
    REP(k,2){
      if(j || k){
        ans = min(ans, dp[n-1][j][k]*k);
      }else if(s[n-1] != s[0]){
        ans = min(ans, dp[n-1][j][k]*k);
      }else{
        ;
      }
    }
  }
  //long long ans = min(cand[0],cand[1]);
  cout<<ans<<endl;
  return 0;
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int (*)[2][2]; _Tp = double; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = long long int (*)[2][2]; _Tp = double]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int (*)[2][2]; _Tp = double]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:58:7:   required from here
   58 |   fill(dp,dp+4*n,INF);
      |   ~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const double' to 'long long int [2][2]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~