import java.util.Arrays; import java.util.Scanner; public class Main_yukicoder291 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] s = sc.next().toCharArray(); int n = s.length; int[][][][][] dp = new int[2][20 + 1][20 + 1][20 + 1][20 + 1]; for (int i = 0; i < 2; i++) { for (int jk = 0; jk <= 20; jk++) { for (int ju = 0; ju <= 20; ju++) { for (int jr = 0; jr <= 20; jr++) { // for (int jo = 0; jo <= 20; jo++) { Arrays.fill(dp[i][jk][ju][jr], -1); // } } } } } dp[0][0][0][0][0] = 0; int ret = 0; for (int i = 0; i < n; i++) { int now = i % 2; int next = (i + 1) % 2; for (int jk = 0; jk <= 20; jk++) { for (int ju = 0; ju <= 20; ju++) { for (int jr = 0; jr <= 20; jr++) { for (int jo = 0; jo <= 20; jo++) { int d = dp[now][jk][ju][jr][jo]; if (d < 0) { continue; } dp[next][jk][ju][jr][jo] = Math.max(dp[next][jk][ju][jr][jo], d); if ((s[i] == 'K' || s[i] == '?') && jk < 20) { dp[next][jk + 1][ju][jr][jo] = Math.max(dp[next][jk + 1][ju][jr][jo], d); } if ((s[i] == 'U' || s[i] == '?') && ju < 20 && jk > 0) { dp[next][jk - 1][ju + 1][jr][jo] = Math.max(dp[next][jk - 1][ju + 1][jr][jo], d); } if ((s[i] == 'R' || s[i] == '?') && jr < 20 && ju > 0) { dp[next][jk][ju - 1][jr + 1][jo] = Math.max(dp[next][jk][ju - 1][jr + 1][jo], d); } if ((s[i] == 'O' || s[i] == '?') && jo < 20 && jr > 0) { dp[next][jk][ju][jr - 1][jo + 1] = Math.max(dp[next][jk][ju][jr - 1][jo + 1], d); } if ((s[i] == 'I' || s[i] == '?') && jo > 0) { dp[next][jk][ju][jr][jo - 1] = Math.max(dp[next][jk][ju][jr][jo - 1], d + 1); ret = Math.max(ret, dp[next][jk][ju][jr][jo - 1]); } } } } } } System.out.println(ret); sc.close(); } }