import java.util.Arrays; import java.util.Scanner; public class Main_yukicoder27_1 { 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(); } int max = 30; 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) { final int INF = Integer.MAX_VALUE / 2; int[] dp = new int[v + 1]; Arrays.fill(dp, INF); dp[0] = 0; for (int i = 0; i < v; i++) { if (dp[i] == INF) { continue; } if (i + a <= v) { dp[i + a] = Math.min(dp[i + a], dp[i] + 1); } if (i + b <= v) { dp[i + b] = Math.min(dp[i + b], dp[i] + 1); } if (i + c <= v) { dp[i + c] = Math.min(dp[i + c], dp[i] + 1); } } if (dp[v] == INF) { return 0; } else { return dp[v]; } } }