import collections S = input() lst = ['KUROI?'.index(c) for c in S if c in 'KUROI?'] m = len(lst) // 5 dp = collections.defaultdict(int) dp[0,0,0,0] = 0 for c in lst: dp_c = dp.copy() for (k0, k1, k2, k3), val in dp_c.items(): if (c == 4 or c == 5) and k3 > val and dp[k0, k1, k2, k3] <= val: dp[k0, k1, k2, k3] = val + 1 if (c == 3 or c == 5) and k2 > k3: new_key = (k0, k1, k2, k3 + 1) if (new_key not in dp) or dp[new_key] < val: dp[new_key] = val if (c == 2 or c == 5) and k1 > k2: new_key = (k0, k1, k2 + 1, k3) if (new_key not in dp) or dp[new_key] < val: dp[new_key] = val if (c == 1 or c == 5) and k0 > k1: new_key = (k0, k1 + 1, k2, k3) if (new_key not in dp) or dp[new_key] < val: dp[new_key] = val if (c == 0 or c == 5) and m > k0: new_key = (k0 + 1, k1, k2, k3) if (new_key not in dp) or dp[new_key] < val: dp[new_key] = val print(max(dp.values()))