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[20 + 1][20 + 1][20 + 1][20 + 1][n + 1]; 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[jk][ju][jr][jo], -1); } } } } dp[0][0][0][0][0] = 0; int ret = 0; for (int i = 0; i < n; 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++) { int d = dp[jk][ju][jr][jo][i]; if (d < 0) { continue; } dp[jk][ju][jr][jo][i + 1] = Math.max(dp[jk][ju][jr][jo][i + 1], d); if ((s[i] == 'K' || s[i] == '?') && jk < 20) { dp[jk + 1][ju][jr][jo][i + 1] = Math.max(dp[jk + 1][ju][jr][jo][i + 1], d); } if ((s[i] == 'U' || s[i] == '?') && ju < 20 && jk > 0) { dp[jk - 1][ju + 1][jr][jo][i + 1] = Math.max(dp[jk - 1][ju + 1][jr][jo][i + 1], d); } if ((s[i] == 'R' || s[i] == '?') && jr < 20 && ju > 0) { dp[jk][ju - 1][jr + 1][jo][i + 1] = Math.max(dp[jk][ju - 1][jr + 1][jo][i + 1], d); } if ((s[i] == 'O' || s[i] == '?') && jo < 20 && jr > 0) { dp[jk][ju][jr - 1][jo + 1][i + 1] = Math.max(dp[jk][ju][jr - 1][jo + 1][i + 1], d); } if ((s[i] == 'I' || s[i] == '?') && jo > 0) { dp[jk][ju][jr][jo - 1][i + 1] = Math.max(dp[jk][ju][jr][jo - 1][i + 1], d + 1); ret = Math.max(ret, dp[jk][ju][jr][jo - 1][i + 1]); } } } } } } System.out.println(ret); sc.close(); } }