import sequtils,strutils,math var A = stdin.readline.split.map(parseInt) B = stdin.readline.parseInt C = stdin.readline.split.map(parseInt) D = stdin.readline.parseInt E = stdin.readline.split.map(parseInt) dp : array[10010, array[11, array[101, int]]] As = A[0] * 1000 + A[1] * 100 + A[2] for i in 1..As: for j in 0..10: var b1000 = B div 1000 d1000 = D div 1000 b1000 = min(b1000, j) d1000 = min(d1000, j) for k in 0..100: var m = i - j * 1000 - k * 100 if i >= B: var b100 = min((B - b1000 * 1000) div 100, k) b = B - b100 * 100 - b1000 * 1000 if b <= m: dp[i][j][k] = max(dp[i][j][k], dp[i - B + C[0] * 1000 + C[1] * 100 + C[2]][j + C[0] - b1000][k + C[1] - b100] + 1) if i >= D: var d100 = min((D - d1000 * 1000) div 100, k) d = D - d100 * 100 - d1000 * 1000 if d <= m: dp[i][j][k] = max(dp[i][j][k], dp[i - D + E[0] * 1000 + E[1] * 100 + E[2]][j + E[0] - d1000][k + E[1] - d100] + 1) echo dp[As][A[0]][A[1]]