using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.GetInt(); string str = Reader.ReadLine(); int ans = this.GetAns(0, str, inpt[0], inpt[1], inpt[2]); Console.WriteLine(ans); } private Dictionary>> dic = new Dictionary>>(); private int GetAns(int idx, string str, int g, int c, int p) { if(!dic.ContainsKey(g)) { dic.Add(g, new Dictionary>()); } if(!dic[g].ContainsKey(c)) { dic[g].Add(c, new Dictionary()); } if(dic[g][c].ContainsKey(p)) { return dic[g][c][p]; } int ans = 0; if(idx == str.Length - 1) { Te t = Te.G; if(c > 0) { t = Te.C; } else if(p > 0) { t = Te.P; } ans = this.GetPoint(t, str[idx]); } else { char aite = str[idx]; if(g > 0) { ans = Math.Max(ans, this.GetAns(idx + 1, str, g-1, c, p) + this.GetPoint(Te.G, aite)); } if(c > 0) { ans = Math.Max(ans, this.GetAns(idx+1, str, g, c-1, p) + this.GetPoint(Te.C, aite)); } if(p > 0) { ans = Math.Max(ans, this.GetAns(idx+1, str, g, c, p-1) + this.GetPoint(Te.P, aite)); } } this.dic[g][c].Add(p, ans); return ans; } private int GetPoint(Te te, char aite) { if(aite == 'G') { if(te == Te.G) { return 1; } else if(te == Te.P) { return 3; } } else if(aite == 'C') { if(te == Te.C) { return 1; } else if(te == Te.G) { return 3; } } else { if(te ==Te.P ) { return 1; } else if(te == Te.C) { return 3; } } return 0; } public enum Te { G, C, P } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 100 100 100 GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG "; 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(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }