S = input().strip() n = len(S) max_count = 20 # since maximum possible sequences is 20 (100/5) # Initialize DP: dp[pos] is a dictionary mapping (a, b, c, d) to the maximum total up to pos dp = [{} for _ in range(n + 1)] dp[0][(0, 0, 0, 0)] = 0 for pos in range(n): current_char = S[pos] possible_choices = [] if current_char == 'K': possible_choices = ['K', 'ignore'] elif current_char == 'U': possible_choices = ['U', 'ignore'] elif current_char == 'R': possible_choices = ['R', 'ignore'] elif current_char == 'O': possible_choices = ['O', 'ignore'] elif current_char == 'I': possible_choices = ['I', 'ignore'] elif current_char == '?': possible_choices = ['K', 'U', 'R', 'O', 'I'] else: possible_choices = ['ignore'] current_states = dp[pos] for (a, b, c, d), total in current_states.items(): for choice in possible_choices: if choice == 'ignore': new_a, new_b, new_c, new_d = a, b, c, d new_total = total key = (new_a, new_b, new_c, new_d) if key in dp[pos + 1]: if new_total > dp[pos + 1][key]: dp[pos + 1][key] = new_total else: dp[pos + 1][key] = new_total else: if choice == 'K': new_a = min(a + 1, max_count) new_b = b new_c = c new_d = d new_total = total elif choice == 'U': if a == 0: continue new_a = a - 1 new_b = min(b + 1, max_count) new_c = c new_d = d new_total = total elif choice == 'R': if b == 0: continue new_a = a new_b = b - 1 new_c = min(c + 1, max_count) new_d = d new_total = total elif choice == 'O': if c == 0: continue new_a = a new_b = b new_c = c - 1 new_d = min(d + 1, max_count) new_total = total elif choice == 'I': if d == 0: continue new_a = a new_b = b new_c = c new_d = d - 1 new_total = total + 1 else: continue # shouldn't happen key = (new_a, new_b, new_c, new_d) if key in dp[pos + 1]: if new_total > dp[pos + 1][key]: dp[pos + 1][key] = new_total else: dp[pos + 1][key] = new_total # The answer is the maximum total in the final position if dp[n]: print(max(dp[n].values())) else: print(0)