package no291; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); s = sc.next().toCharArray(); n = s.length; System.out.println(dfs(0,0,0,0,0)); } static int n ; static char[] s; static HashMap hm = new HashMap<>(); public static int dfs(int i,int U,int R,int O,int I) { if (i == n) { return 0; } long h = i + U * 101 + R * 101 * 101 + O * 101 * 101 * 101 + (long) I * 101 * 101 * 101 * 101; Integer memo = hm.get(h); if (memo != null) { return memo; } int ret = 0; if (s[i] != '?') { ret = Math.max(ret,dfs(i+1,U,R,O,I)); } if (U + R + O + I < n / 5 && (s[i] == 'K' || s[i] == '?')) { ret = Math.max(ret,dfs(i+1,U+1,R,O,I)); } if ((s[i] == 'U' || s[i] == '?') && U > 0) { ret = Math.max(ret,dfs(i+1,U-1,R+1,O,I)); } if ((s[i] == 'R' || s[i] == '?') && R > 0) { ret = Math.max(ret,dfs(i+1,U,R-1,O+1,I)); } if ((s[i] == 'O' || s[i] == '?') && O > 0) { ret = Math.max(ret,dfs(i+1,U,R,O-1,I+1)); } if ((s[i] == 'I' || s[i] == '?') && I > 0) { ret = Math.max(ret,dfs(i+1,U,R,O,I-1) + 1); } hm.put(h,ret); return ret; } }