from collections import * A = list(map(int, input().split())) Db = int(input()) B = list(map(int, input().split())) Dc = int(input()) C = list(map(int, input().split())) num = [1000, 100, 1] Sb, Sc = 0, 0 N = 0 for i in range(3): N += num[i] * A[i] Sb += num[i] * B[i] Sc += num[i] * C[i] Edge1 = [] for a in range(11): now = num[0] * a if now > Db: break for b in range(101): now = num[0] * a + num[1] * b if now > Db: break for c in range(10001): now = num[0] * a + num[1] * b + num[2] * c if now > Db: break if now == Db: Edge1.append((a, b, c)) Edge2 = [] for a in range(11): now = num[0] * a if now > Dc: break for b in range(101): now = num[0] * a + num[1] * b if now > Dc: break for c in range(10001): now = num[0] * a + num[1] * b + num[2] * c if now > Dc: break if now == Dc: Edge2.append((a, b, c)) L = [[] for i in range(N + 1)] L[N].append(tuple(A)) inf = 10 ** 18 D = defaultdict(lambda: -inf) D[tuple(A)] = 0 ans = 0 for i in range(N, -1, -1): for a1, b1, c1 in L[i]: for a2, b2, c2 in Edge1: if a1 < a2 or b1 < b2 or c1 < c2: continue temp = max(D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])], D[(a1, b1, c1)] + 1) ans = max(ans, temp) D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])] = temp L[i - Db + Sb].append((a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])) for a2, b2, c2 in Edge2: if a1 < a2 or b1 < b2 or c1 < c2: continue temp = max(D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])], D[(a1, b1, c1)] + 1) ans = max(ans, temp) D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])] = temp L[i - Dc + Sc].append((a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])) print(ans)