from collections import defaultdict S = input() dp = defaultdict(int) dp[0, 0, 0, 0] = 0 for c in S: pp = dp.copy() dp, pp = pp, dp for key in pp.keys(): k, u, r, o = key nkey = None match c: case 'K': nkey = (k+1, u, r, o) case 'U': nkey = (k-1, u+1, r, o) case 'R': nkey = (k, u-1, r+1, o) case 'O': nkey = (k, u, r-1, o+1) case 'I': if o > 0: dp[k, u, r, o-1] = max(dp[k, u, r, o-1], pp[k, u, r, o] + 1) if nkey is not None and all(x >= 0 for x in nkey): dp[nkey] = max(dp[nkey], pp[key]) if c == '?': nkeys = [ (k+1, u, r, o), (k-1, u+1, r, o), (k, u-1, r+1, o), (k, u, r-1, o+1), ] for nkey in nkeys: if all(x >= 0 for x in nkey): dp[nkey] = max(dp[nkey], pp[key]) # for 'I' if o > 0: dp[k, u, r, o-1] = max(dp[k, u, r, o-1], pp[k, u, r, o] + 1) ans = max(dp.values()) print(ans)