import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int[] aArr = new int[4]; int[] bArr = new int[4]; for (int i = 0; i < 4; i++) { aArr[i] = sc.nextInt(); } for (int i = 0; i < 4; i++) { bArr[i] = sc.nextInt(); } HashMap dp = new HashMap<>(); dp.put(a * 1000 + b, c); int count = -1; while (dp.size() > 0) { HashMap next = new HashMap<>(); for (Map.Entry entry : dp.entrySet()) { int x = entry.getKey() / 1000; int y = entry.getKey() % 1000; int z = entry.getValue(); setDP(x, y, z, aArr, next); setDP(x, y, z, bArr, next); } dp = next; count++; } System.out.println(count); } static boolean setDP(int a, int b, int c, int[] arr, HashMap dp) { if (a * 1000 + b * 100 + c < arr[0]) { return false; } int x = arr[0]; while (x >= 1000 && a > 0) { x -= 1000; a--; } while (x >= 100 && b > 0) { x -= 100; b--; } c -= x; if (c < 0) { return false; } a += arr[1]; b += arr[2]; c += arr[3]; int key = a * 1000 + b; if (!dp.containsKey(key) || dp.get(key) < c) { dp.put(key, c); } return true; } }