#include using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; string S; void init(){ cin >> S; } int dp[ 2 ][ 20 + 1 ][ 20 + 1 ][ 20 + 1 ][ 20 + 1 ]; void preprocess(){ memset( dp, -1, sizeof( dp ) ); dp[ 0 ][ 0 ][ 0 ][ 0 ][ 0 ] = 0; for( int i = 0; i < S.size(); ++i ){ for( int j = 0; j <= 20; ++j ){ for( int k = 0; k <= 20; ++k ){ for( int l = 0; l <= 20; ++l ){ for( int m = 0; m <= 20; ++m ){ int v = dp[ i & 1 ][ j ][ k ][ l ][ m ]; if( v == -1 ) continue; if( ( S[ i ] == 'K' or S[ i ] == '?' ) and j + 1 <= 20 ){ upmax( dp[ ~i & 1 ][ j + 1 ][ k ][ l ][ m ], v ); } if( ( S[ i ] == 'U' or S[ i ] == '?' ) and j - 1 >= 0 and k + 1 <= 20 ){ upmax( dp[ ~i & 1 ][ j - 1 ][ k + 1 ][ l ][ m ], v ); } if( ( S[ i ] == 'R' or S[ i ] == '?' ) and k - 1 >= 0 and l + 1 <= 20 ){ upmax( dp[ ~i & 1 ][ j ][ k - 1 ][ l + 1 ][ m ], v ); } if( ( S[ i ] == 'O' or S[ i ] == '?' ) and l - 1 >= 0 and m + 1 <= 20 ){ upmax( dp[ ~i & 1 ][ j ][ k ][ l - 1 ][ m + 1 ], v ); } if( ( S[ i ] == 'I' or S[ i ] == '?' ) and m - 1 >= 0 ){ upmax( dp[ ~i & 1 ][ j ][ k ][ l ][ m - 1 ], v + 1 ); } upmax( dp[ ~i & 1 ][ j ][ k ][ l ][ m ], v ); } } } } memset( dp[ i & 1 ], -1, sizeof( dp[ i & 1 ] ) ); } } void solve(){ int ans = 0; for( int i = 0; i <= 20; ++i ){ for( int j = 0; j <= 20; ++j ){ for( int k = 0; k <= 20; ++k ){ for( int l = 0; l <= 20; ++l ){ upmax( ans, dp[ ( int ) S.size() & 1 ][ i ][ j ][ k ][ l ] ); } } } } cout << ans << endl; } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }