#include #include #include #include #include #include using namespace std; int*pv,*nt; int dp1[21][21][21][21]; int dp2[21][21][21][21]; const int INF = 1e6; #define id(a,b,c,d) (a)*21*21*21+(b)*21*21+(c)*21+(d) int main() { string str; cin>>str; int n=str.size(); pv=(int*)dp1; nt=(int*)dp2; for(int i = 0; i < 21; i++) for(int j = 0; j < 21; j++) for(int k = 0; k < 21; k++) for(int l = 0; l < 21; l++) pv[id(i,j,k,l)]=-INF; pv[id(0,0,0,0)]=0; int res=0; for(int m = 0; m < n; m++){ for(int i = 0; i <21 ; i++) for(int j = 0; j < 21; j++) for(int k = 0; k < 21; k++) for(int l = 0; l < 21; l++){ nt[id(i,j,k,l)]=pv[id(i,j,k,l)]; if(str[m]=='K'||str[m]=='?') nt[id(i,j,k,l)]=max((i>0)?pv[id(i-1,j,k,l)]:-INF,nt[id(i,j,k,l)]); if(str[m]=='U'||str[m]=='?') nt[id(i,j,k,l)]=max((j>0&&i<20)?pv[id(i+1,j-1,k,l)]:-INF,nt[id(i,j,k,l)]); if(str[m]=='R'||str[m]=='?') nt[id(i,j,k,l)]=max((k>0&&j<20)?pv[id(i,j+1,k-1,l)]:-INF,nt[id(i,j,k,l)]); if(str[m]=='O'||str[m]=='?') nt[id(i,j,k,l)]=max((l>0&&k<20)?pv[id(i,j,k+1,l-1)]:-INF,nt[id(i,j,k,l)]); if(str[m]=='I'||str[m]=='?') nt[id(i,j,k,l)]=max((l<20)?(pv[id(i,j,k,l+1)]+1):-INF,nt[id(i,j,k,l)]); res=max(res,nt[id(i,j,k,l)]); // printf("%d:dp[%d][%d][%d][%d]=%d\n",m,i,j,k,l,nt[id(i,j,k,l)]); } swap(pv,nt); } cout<