# your code goes here import sys sys.setrecursionlimit(10**6) def read_data(): a3, a2, a1 = map(int, input().split()) db = int(input()) b3, b2, b1 = map(int, input().split()) dc = int(input()) c3, c2, c1 = map(int, input().split()) return a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc def solve(a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc): memo = dict() def dfs(a3, a2, a1, depth): nonlocal memo if (a3, a2, a1) in memo: return memo[a3, a2, a1] d3, d2, d1 = generate_payment_patterns(a3, a2, a1, db) if d3 or d2 or d1: t1 = dfs(a3-d3+b3, a2-d2+b2, a1-d1+b1, depth+1) + 1 else: t1 = 0 d3, d2, d1 = generate_payment_patterns(a3, a2, a1, dc) if d3 or d2 or d1: t2 = dfs(a3-d3+c3, a2-d2+c2, a1-d1+c1, depth+1) + 1 else: t2 = 0 t = max(t1, t2) memo[a3, a2, a1] = t return t return dfs(a3, a2, a1, 0) def generate_payment_patterns(a3, a2, a1, d): for d3 in range(min(d//1000, a3), -1, -1): for d2 in range(min((d - d3*1000)//100,a2), -1, -1): d1 = d - d3*1000 - d2*100 if d1 > a1: continue return d3, d2, d1 return 0, 0, 0 if __name__ == '__main__': a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc = read_data() print(solve(a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc))