import java.util.Arrays; import java.util.Scanner; public class Main_yukicoder27 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] v = new int[4]; for (int i = 0; i < 4; i++) { v[i] = sc.nextInt(); } Arrays.sort(v); int max = v[3]; int min = Integer.MAX_VALUE; for (int i = 1; i <= max; i++) { for (int j = i + 1; j <= max + 1; j++) { next: for (int k = j + 1; k <= max + 2; k++) { int sum = 0; for (int e : v) { int tmp = isOK(e, i, j, k, max); if (tmp == 0) { continue next; } sum += tmp; } min = Math.min(min, sum); } } } System.out.println(min); sc.close(); } private static int isOK(int v, int a, int b, int c, int max) { int min = Integer.MAX_VALUE; for (int i = v / c; i >= 0; i--) { for (int j = (v - c * i) / b; j >= 0; j--) { if ((v - c * i - b * j) % a == 0) { int k = (v - c * i - b * j) / a; if ((j != 0 && b > max) || (i != 0 && c > max)) { continue; } min = Math.min(min, i + j + k); } } } if (min == Integer.MAX_VALUE) { return 0; } else { return min; } } }