from collections import defaultdict def solve(): SS = input() S = [c for c in SS if c in 'KUROI?'] dp2 = defaultdict(lambda: -1) # dp[x, k, u, r, o] = 次に見るのが x 文字目で、 kまで: k個、uまで: u個、rまで: r個、oまで: o個 のとき、i までできた数 dp2[0, 0, 0, 0] = 0 ma = 0 for x, c in enumerate(S): dp1 = dp2 dp2 = defaultdict(lambda: -1, dp1) for kuro in dp1: now = dp1[kuro] k, u, r, o = kuro if c == 'K': nt = k + 1, u, r, o dp2[nt] = max(dp2[nt], now) elif c == 'U': if k: nt = k - 1, u + 1, r, o dp2[nt] = max(dp2[nt], now) elif c == 'R': if u: nt = k, u - 1, r + 1, o dp2[nt] = max(dp2[nt], now) elif c == 'O': if r: nt = k, u, r - 1, o + 1 dp2[nt] = max(dp2[nt], now) elif c == 'I': if o: nt = k, u, r, o - 1 dp2[nt] = max(dp2[nt], now) ma = max(ma, now + 1) elif c == '?': nt = k + 1, u, r, o dp2[nt] = max(dp2[nt], now) if k: nt = k - 1, u + 1, r, o dp2[nt] = max(dp2[nt], now) if u: nt = k, u - 1, r + 1, o dp2[nt] = max(dp2[nt], now) if r: nt = k, u, r - 1, o + 1 dp2[nt] = max(dp2[nt], now) if o: nt = k, u, r, o - 1 dp2[nt] = max(dp2[nt], now) ma = max(ma, now + 1) print(ma) if __name__ == '__main__': solve()