import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ int v1 = read.to!int; int v2 = read.to!int; int v3 = read.to!int; int v4 = read.to!int; int ans = 10000; foreach(a; 1 .. 29) foreach(b; a + 1 .. 30) foreach(c; b + 1 .. 31){ int tmp = solve(v1, a, b, c) + solve(v2, a, b, c) + solve(v3, a, b, c) + solve(v4, a, b, c); if(tmp < ans) ans = tmp; } ans.writeln; } int solve(int v, int a, int b, int c){ int res = 10000; foreach(i; 0 .. v + 1) foreach(j; 0 .. v + 1){ if(i * a + j * b > v) break; if((v - i * a - j * b) % c > 0) continue; int tmp = i + j + (v - i * a - j * b) / c; if(tmp < res) res = tmp; } return res; }