#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll moda=1000000007;
typedef vector<ll> vl1;
typedef vector<vl1> vl2;
typedef vector<string> vst1;

struct struka
{ll val; ll ind;};
typedef vector<struka> vs1;

bool compa(struka& a, struka& b)
{ if(a.val==b.val) return a.ind<b.ind;
  return a.val<b.val;
}

ll lova(vl1&  veka, ll dole, ll gore, ll val)
{ ll sred;
  while(dole<=gore)
  {sred=(gore+dole)/2;
   if(veka[sred]>=val) gore=sred-1;// real condition !
   else dole=sred+1;
  }
 return dole;
}

ll gcd(ll a,ll b)
{ll t;
  while (b)
  { t= b;
    b = a % b;
    a = t;
  }
return a;
}

ll fast_pow(ll a, ll p)
{ ll res = 1;
  while (p)
   { if ( (p &1) == 0) { a = (a * a); p >>=1; }
     else {  res *=  a;   p--; }
   }
  return res;
}

void radi(ll& q)
{ ll i, j, k, kn, m, n, p, t, l, r, x, y, z, a, b, c, d, depa;
  ll val, pos, tmp, suma, maxa, mina, naso, num, pola, duz, broj;
  string str1;
  char ch1;
  cin>> str1;
  n=str1.size();
  //cout<<'\n'<<n<<'\n';
  vl2 kata(n+1, vl1(n+1));
  vl1 duga(n+1);
  for(i=1;i<n;i++)
   { a=n-i;
     if(a>i) duz=i; else duz=a;
     duga[i]=duz;
     mina=i-duz+1;
     for(k=i;k>=mina;k--)
      { j=i-k;
        if(str1[k-1]==str1[i+j]) kata[i][j+1]=kata[i][j]+1;
        else kata[i][j+1]=kata[i][j];
        // cout<<i<<' '<<j+1<<' '<<kata[i][j+1]<<'\n';
      }

   }
  vl2 dp(n+2, vl1(n+2));
  maxa=0;
  /*Postoje 3 preloma:j, k, i. Nas interesuje srednji(k) prelom
  Za dato i,k gledamo sve predhodne prelome j. Ako ga nema j=0.
  dp[k][num] zavisi samo od j
  kata[k][broj] zavisi od kraceg preloma u odnosu na k i max k preloma !!!
  */
  for(i=2;i<=n;i++)
   { if(i==n-1) continue;
     //duz=duga[i];
     for(k=2;k<=i-2;k++)//predhodni prelom
      { depa=0;
        val=i-k;
        //if(val>duz) val=duz;
        for(j=0;j<=k-2;j++)
          { if(j==1) continue;
            num=k-j;
            //if(num>duga[k]) num=duga[k];
            broj=i-k;
            if(broj>k-j) broj=k-j;//prelom (k-i) veci od (k-j)
            if(broj>duga[k]) broj=duga[k];//max prelom za k
            suma=dp[k][num]+kata[k][broj];
            //if(i==10 && k==8) cout<<"\nProv - "<<num<<' '<<broj<<endl;
            if(suma>depa) depa=suma;
          }

        dp[i][val]=depa;
        if(depa>maxa) maxa=depa;
        //cout<<'\n'<<i<<' '<<k<<' '<<depa;
      }
   }
  //cout<<'\n';
  cout<<maxa<<'\n';

}

int main()
{ /*
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(nullptr);
  cout<<fixed<<setprecision(15);
  */

  ll t, q;
  //cin>>t;
  t=1;
  for(q=1;q<=t;q++)
   { // cout<<"Case #"<<q<<": ";
     radi(q);
   }
  return 0;
}
/*
hastalavista
anavolimilovana
anavolimmilovana
anavolimpericamilovana
anavolimmilovanaanavoli
anavolimmilovanaanavoliilov
anavolimabcdmilovanacdqweerranavolijkilov
xnavolimabcdmilovanacdqweerranavolijkixov
abccbbcaac
*/