using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int ans = int.MaxValue; int[] ita = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int i = 1; i <= 30 - 2; i++) { for(int j=i+1; j<=30-1; j++) { for (int k = j + 1; k <= 30; k++) { int cnt = 0; bool cannot = false; foreach (int num in ita) { int key = (1 << i) + (i << j) + (i << k); int ret = this.GetAns(key, i, j, k, num); if (ret == 0) { cannot = true; break; } else { cnt += ret; } } if (!cannot) { ans = Math.Min(cnt, ans); } } } } Console.WriteLine(ans); } private Dictionary> dic = new Dictionary>(); private int GetAns(int key, int a, int b, int c, int target) { if (!dic.ContainsKey(key)) { dic.Add(key, new Dictionary()); } if (dic[key].ContainsKey(target)) { return dic[key][target]; } int ans = int.MaxValue; if (c == target) { ans = 1; } else if (target > c) { int ret = this.GetAns(key, a, b, c, target - c); if (ret > 0) { ret++; ans = Math.Min(ans, ret); } } if (b == target) { ans = 1; } else if (target > b) { int ret = this.GetAns(key, a, b, c, target - b); if (ret > 0) { ret++; ans = Math.Min(ans, ret); } } if (a == target) { ans = 1; } else if (target > a) { int ret = this.GetAns(key, a, b, c, target - a); if (ret > 0) { ret++; ans = Math.Min(ans, ret); } } if (ans == int.MaxValue) { ans = 0; } dic[key].Add(target, ans); return ans; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 3 7 15 "; 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(); } }