import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static boolean is_valid(final long h1, final long h2, final long h3){ return (h1 < h2 && h2 > h3) || (h1 > h2 && h2 < h3); } public static long d(final long h, final long d){ return Math.max(0, h - d); } public static long d(final long h_max, final long h_min, final long d){ return h_max < h_min ? 0 : (h_max - h_min) / d + 1; } public static long all_same(final long h, final long d){ return h > d ? 3 : -1; } public static long two_same(final long h1, final long h2, final long h3, final long d){ if(h1 == h2 && h2 < h3){ return is_valid(h1, d(h2, d), h3) ? 1 : -1; } if(h1 > h2 && h2 == h3){ return is_valid(h1, d(h2, d), h3) ? 1 : -1; } if(h1 == h2 && h2 > h3){ if(is_valid(d(h1, d), h2, h3)){ // d(h1) < h2 && h2 > h3 return 1; } final long h2_count = d(h2, h3, d); final long d_h2 = h2 - d * h2_count; if(is_valid(h1, d_h2, h3)){ return h2_count; } // h1 > d(h2) && d(h2) < h3 else{ return -1; } } if(h1 < h2 && h2 == h3){ if(is_valid(h1, h2, d(h3, d))){ return 1; } final long h2_count = d(h2, h1, d); final long d_h2 = h2 - d * h2_count; if(is_valid(h1, d_h2, h3)){ return h2_count; } else { return -1; } } if(h1 == h3 && h1 < h2){ return is_valid(d(h1, d), h2, h3) ? 1 : -1; } if(h1 == h3 && h1 > h2){ final long h1_count = d(h1, h2, d); final long d_h1 = h1 - d * h1_count; if(d_h1 == 0){ return -1; } return h1_count * 2 + 1; } return -1; } public static long all_diff(final long h1, final long h2, final long h3, final long d){ if(h1 > h2 && h2 > h3){ final long h1_count = d(h1, h2, d); final long d_h1 = h1 - d * h1_count; if(is_valid(d_h1, h2, h3)){ return h1_count; }else{ return two_same(h1, h2, h3, d); } } if(h1 < h2 && h2 < h3){ final long h3_count = d(h3, h2, d); final long d_h3 = h3 - d * h3_count; //System.out.println(d_h3); if(is_valid(h1, h2, d_h3)){ return h3_count; }else{ return two_same(h1, h2, h3, d); } } return -1; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final long d = sc.nextLong(); long h1 = sc.nextLong(); long h2 = sc.nextLong(); long h3 = sc.nextLong(); if(is_valid(h1, h2, h3)){ System.out.println(0); return; }else if(d == 0){ System.out.println(-1); return; } final long max = Math.max(h1, Math.max(h2, h3)); final long min = Math.min(h1, Math.min(h2, h3)); final long med = (h1 + h2 + h3) - (max + min); //System.out.println(max + " " + min + " " + med); if(max == min){ System.out.println(all_same(max, d)); }else if(max == med || min == med){ System.out.println(two_same(h1, h2, h3, d)); }else{ System.out.println(all_diff(h1, h2, h3, d)); } } }