using System; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { Reader.IsDebug = false; long ans = GetAns(long.Parse(Reader.ReadLine()), new int[]{}); Console.WriteLine(ans); } private Dictionary dic = new Dictionary(); private long GetAns(long num, int[] idx) { if(idx.Length == 0 && dic.ContainsKey(num)) { return dic[num]; } long ans = 0; string numstr = num.ToString(); if(numstr.Length + idx.Length < 3) { return 0; } int start = 0; if(idx.Length > 0) { start = idx.Last() + 1; } for(int i=start; i tmp = numstr.ToList(); tmp.RemoveAt(i); tmp.RemoveAt(idx[1]); tmp.RemoveAt(idx[0]); long ret = 0; if(tmp.Count > 0) { ret = this.GetAns(int.Parse(string.Join(string.Empty, tmp)), new int[] {}); } ans = Math.Max(ans, ret + addNum); } } if(idx.Length == 0) { dic.Add(num, ans); } return ans; } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 133144 "; public static string ReadLine() { if(IsDebug) { if(SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }