#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >>s;
  int r=0;
  int c1=0;
  char top=s.at(0);
  for (int i=0;i<s.size();i++){
    if (s.at(i)==top)r++;
    else if (r>0)c1++;
  }
  
  reverse(s.begin(),s.end())
  r=0;
  int c2=0;
  top=s.at(0);
  for (int i=0;i<s.size();i++){
    if (s.at(i)==top)r++;
    else if (r>0)c2++;
  }
  
  
  cout <<max(c1*2,c2*2)<<endl;
}