import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto vi = readln.split.map!(to!int).array; vi.sort(); auto minN = -1; foreach (a; 1..vi.back - 1) foreach (b; a + 1..vi.back) foreach (c; b + 1..vi.back + 1) { auto n = calc(vi, [a, b, c]); if (n >= 0) { if (minN < 0) minN = n; else minN = min(minN, n); } } writeln(minN); } int calc(int[] vi, int[] li) { auto memo = new int[](vi.back + 1); memo[1..$] = -1; foreach (l; li) { foreach (i; l..vi.back + 1) { if (memo[i - l] >= 0) { if (memo[i] < 0) memo[i] = memo[i - l] + 1; else memo[i] = min(memo[i], memo[i - l] + 1); } } } auto ri = vi.map!(v => memo[v]).filter!("a > 0").array; if (ri.length != vi.length) return -1; else return ri.sum; }