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; j++) { next: for (int k = j + 1; k <= max; k++) { int sum = 0; for (int e : v) { int tmp = isOK(e, i, j, k); 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 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) { min = Math.min(min, i + j + (v - c * i - b * j) / a); } } } if (min == Integer.MAX_VALUE) { return 0; } else { return min; } } }