import heapq A=list(map(int,input().split())) DB=int(input()) B=list(map(int,input().split())) DC=int(input()) C=list(map(int,input().split())) DP=dict() DP[tuple(A)]=0 def SUM(x,y,z): return x*1000+y*100+z Q=[] Q.append((-SUM(A[0],A[1],A[2]),A[0],A[1],A[2])) def calc_b(x,y,z): money=DB k=money//1000 MIN=min(k,x) x-=MIN money-=MIN*1000 k=money//100 MIN=min(k,y) y-=MIN money-=MIN*100 z-=money if x>=0 and y>=0 and z>=0: return x+B[0],y+B[1],z+B[2] return -1,-1,-1 def calc_c(x,y,z): money=DC k=money//1000 MIN=min(k,x) x-=MIN money-=MIN*1000 k=money//100 MIN=min(k,y) y-=MIN money-=MIN*100 z-=money if x>=0 and y>=0 and z>=0: return x+C[0],y+C[1],z+C[2] return -1,-1,-1 while Q: S,a,b,c=heapq.heappop(Q) time=DP[a,b,c] a2,b2,c2=calc_b(a,b,c) if a2>=0 and b2>=0 and c2>=0: if (a2,b2,c2) in DP: if DP[(a2,b2,c2)]=0 and b2>=0 and c2>=0: if (a2,b2,c2) in DP: if DP[(a2,b2,c2)]