from sys import setrecursionlimit setrecursionlimit(10**6) def check(x1000, x100, x1, d, d1000, d100, d1): m = d // 1000 if m <= x1000: d %= 1000 x1000 -= m else: d -= x1000 * 1000 x1000 = 0 m = d // 100 if m <= x100: d %= 100 x100 -= m else: d -= x100 * 100 x100 = 0 if d <= x1: x1 -= d x1000 += d1000 x100 += d100 x1 += d1 return True, x1000, x100, x1 else: return False, -1, -1, -1 def dfs(x1000, x100, x1): ret = 0 flg,b1000,b100,b1 = check(x1000, x100, x1, Db, B1000, B100, B1) if flg: ret = max(ret, dfs(b1000, b100, b1) + 1) flg,c1000,c100,c1 = check(x1000, x100, x1, Dc, C1000, C100, C1) if flg: ret = max(ret, dfs(c1000, c100, c1) + 1) memo[x1000, x100, x1] = ret return ret A1000,A100,A1 = map(int,input().split()) Db = int(input()) B1000,B100,B1 = map(int,input().split()) Dc = int(input()) C1000,C100,C1 = map(int,input().split()) memo = {} print(dfs(A1000, A100, A1))