#include <bits/stdc++.h>
#define gc IO::fastgc()
#define pc(c) IO::fastpc(c)
using namespace std;
typedef long long unsigned llu,ull;
namespace IO{
char ibuf[1<<23],obuf[1<<23],*ip1=ibuf,*ip2=ibuf,*o=obuf;
inline char fastgc(){
return ((ip1==ip2)&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++);
}
inline void fastpc(char c){
*(o++)=c;
}
inline int read(){
register int t=0,f=1;
register char c=gc;
while(c!='-'&&(c<'0'||c>'9')) c=gc;
if(c=='-') c=gc,f=-1;
while(c>='0'&&c<='9') t=10*t+(c^48),c=gc;
return f*t;
}
inline void write(int x){
if(!x) return (void)pc('0');
if(x<0) pc('-'),x=-x;
static char c[33]={""};
static int cc=0;
while(x) c[++cc]=x%10,x/=10;
while(cc) pc(c[cc--]|48);
}
inline void writes(const string &__){
for(auto _:__) pc(_);
}
inline string rs(){
static auto isspc=[](char c)->bool{return c==' '||c=='\r'||c=='\n'||c=='\t'||c==EOF||!c;};
string s="";
register char c=gc;
while(isspc(c)) c=gc;
while(!isspc(c)) s+=c,c=gc;
return s;
}
inline void flush(){
fwrite(obuf,o-obuf,1,stdout);
}
struct IO_Flusher{
inline IO_Flusher(){}
inline ~IO_Flusher(){
flush();
}
}__io_flusher_;
}
using IO::read;
using IO::rs;
using IO::write;
using IO::writes;
constexpr int L=57;
constexpr llu B=27;
const string M="M",R="R";
int n;
string s,ans;
string f[L][L];
llu ha[L],bp[L];
int cti(char c){
return c-'a';
}
inline int lrha(int l,int r){
return ha[r]-ha[l-1]*bp[r-l+1];
}
inline bool equ(int l1,int r1,int l2,int r2){
return lrha(l1,r1)==lrha(l2,r2);
}
inline string smin(const string &s1,const string &s2){
if(s1.size()==s2.size()){
if(s1[0]=='M') return s1;
return s2;
}
if(s1.size()<s2.size()){
return s1;
}
return s2;
}
signed main(){
s="!"+IO::rs();
n=s.size()-1;
for(int i=1;i<=n;++i){
for(int j=i;j<=n;++j){
f[i][j]=s.substr(i,j-i+1);
}
}
bp[0]=1;
for(int i=1;i<=n;++i){
ha[i]=ha[i-1]*B+cti(s[i]);
bp[i]=bp[i-1]*B;
}
for(int l=2;l<=n;++l){
for(int i=1;i<=n-l+1;++i){
int j=i+l-1;
if(l%2==0){
int k=(i+j)>>1;
if(equ(i,k,k+1,j)){
if(f[i][k][0]=='M'){
f[i][j]=smin(f[i][j],f[i][k]+R);
}
else{
f[i][j]=smin(f[i][j],M+f[i][k]+R);
}
}
}
for(int k=i;k<j;++k){
f[i][j]=smin(f[i][j],f[i][k]+f[k+1][j]);
}
}
}
ans=f[1][n];
if(ans[0]=='M') ans.erase(ans.begin());
#ifdef RZH
writes(ans),pc('\n');
#endif
write(ans.size()),pc('\n');
return 0;
}