S = input().strip() total_q = S.count('?') def is_possible(x): if x == 0: return True n = len(S) # Check for K positions k_pos = [] used_q_k = 0 current = 0 for _ in range(x): found = False while current < n: if S[current] == 'K' or S[current] == '?': k_pos.append(current) if S[current] == '?': used_q_k += 1 current += 1 found = True break current += 1 if not found: return False # Check for U positions u_pos = [] used_q_u = 0 for k in k_pos: current = k + 1 found = False while current < n: if S[current] == 'U' or S[current] == '?': u_pos.append(current) if S[current] == '?': used_q_u += 1 current += 1 found = True break current += 1 if not found: return False # Check for R positions r_pos = [] used_q_r = 0 for u in u_pos: current = u + 1 found = False while current < n: if S[current] == 'R' or S[current] == '?': r_pos.append(current) if S[current] == '?': used_q_r += 1 current += 1 found = True break current += 1 if not found: return False # Check for O positions o_pos = [] used_q_o = 0 for r in r_pos: current = r + 1 found = False while current < n: if S[current] == 'O' or S[current] == '?': o_pos.append(current) if S[current] == '?': used_q_o += 1 current += 1 found = True break current += 1 if not found: return False # Check for I positions i_pos = [] used_q_i = 0 for o in o_pos: current = o + 1 found = False while current < n: if S[current] == 'I' or S[current] == '?': i_pos.append(current) if S[current] == '?': used_q_i += 1 current += 1 found = True break current += 1 if not found: return False total_used = used_q_k + used_q_u + used_q_r + used_q_o + used_q_i return total_used <= total_q low = 0 high = len(S) // 5 ans = 0 while low <= high: mid = (low + high) // 2 if is_possible(mid): ans = mid low = mid + 1 else: high = mid - 1 print(ans)