using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; string inpt = Reader.ReadLine(); int ans = this.GetAns(inpt, 0, new List()); Console.WriteLine(ans); } private int GetAns(string inpt, int idx, List items) { if (inpt.Count(a => a == '?') == 0) { return Count(inpt); } if (inpt.Count(a => a != '?') == 0) { return inpt.Length / this.target.Length; } for (int i = idx; i < inpt.Length; i++) { if (inpt[i] == '?') { string[] splt = inpt.Split('?'); string prt1 = splt[0]; string prt2 = string.Join("?", splt.Skip(1).ToArray()); List subItems = new List(items); int ans = 0; if (items.Count < inpt.Length / target.Length) { subItems.Add("K"); ans = this.GetAns(prt1 + "K" + prt2, idx + 1, subItems); } for (int j = 1; j < target.Length; j++) { string str = items.FirstOrDefault(a => a.Length == j); if (str != null) { subItems = new List(items); int ind = items.IndexOf(str); subItems[ind] += target[j]; ans = Math.Max(ans, this.GetAns(prt1 + target[j] + prt2, idx + 1, subItems)); } } return ans; } else { for (int j = 0; j < target.Length; j++) { if (inpt[i] == target[j]) { if (j == 0) { items.Add(target[0].ToString()); } else { string str = items.FirstOrDefault(a => a.Length == j); if (str != null) { int ind = items.IndexOf(str); items[ind] += target[j]; } } break; } } } } return 0; } private char[] target = new char[] { 'K', 'U', 'R', 'O', 'I' }; private int Count(string inpt) { List tmp = new List(); for (int i = 0; i < inpt.Length; i++) { for (int j = 0; j < target.Length; j++) { if (inpt[i] == target[j]) { if (j == 0) { tmp.Add(target[0].ToString()); } else { string key = tmp.FirstOrDefault(a => a.Length == j); if (key != null) { int idx = tmp.IndexOf(key); tmp[idx] += target[j]; } } break; } } } return tmp.Count(a => a.Length == target.Length); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" ???K??O??U????R???I?R??? "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }