Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(1, N+1):
        if w-a >= 0:
            dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(1, M+1):
        if w-b >= 0:
            dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(1, N+1):
        if w-a >= 0:
            dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(1, M+1):
        if w-b >= 0:
            dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N]
for w in range(1, N+1):
    dp.append(max([N] + [dp[w-a] + b-a for a, b in zip(A, B) if w-a >= 0]))

M = max(dp)
dp = [M]
for w in range(1, M+1):
    dp.append(max([M] + [dp[w-b] + a-b for a, b in zip(A, B) if w-b >= 0]))

print(max(dp))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N]
for w in range(1, N+1):
    dp.append(max([N] + [dp[w-a] + b-a for a, b in zip(A, B) if w-a >= 0]))

M = max(dp)
dp = [M]
for w in range(1, M+1):
    dp.append(max([M] + [dp[w-b] + a-b for a, b in zip(A, B) if w-b >= 0]))

print(max(dp))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N] * (N+1)
for w in range(N+1):
    dp[w] = max([N] + [dp[w-a] + b-a for a, b in zip(A, B) if w-a >= 0])

M = max(dp)
dp = [M] * (M+1)
for w in range(M+1):
    dp[w] = max([M] + [dp[w-b] + a-b for a, b in zip(A, B) if w-b >= 0])

print(max(dp))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Runtime Error):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N] * (N+1)
for w in range(N+1):
    dp[w] = max(dp[w], max((dp[w-a] + b-a for a, b in zip(A, B) if w-a >= 0), default=0))

M = max(dp)
dp = [M] * (M+1)
for w in range(M+1):
    dp[w] = max(dp[w], max((dp[w-b] + a-b for a, b in zip(A, B) if w-b >= 0), default=0))

print(max(dp))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N] * (N+1)
for w in range(N+1):
    for a, b in zip(A, B):
        if w >= a:
            dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp)
dp = [M] * (M+1)
for w in range(M+1):
    for a, b in zip(A, B):
        if w >= b:
            dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N] * (N+1)
for w in range(N+1):
    for a, b in zip(A, B):
        if w >= a:
            dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp)
dp = [M] * (M+1)
for w in range(M+1):
    for a, b in zip(A, B):
        if w >= b:
            dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AB = [(a, b) for a, b in zip(A, B) if a < b]
dp = [[N] * (N + 1) for _ in range(len(AB)+1)]
for i, (a, b) in enumerate(AB):
    for w in range(N+1):
        if w >= a:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-a] + b-a)
        else:
            dp[i+1][w] = dp[i][w]

M = max(dp[-1])

BA = [(a, b) for a, b in zip(A, B) if a > b]
dp = [[M] * (M + 1) for _ in range(len(BA)+1)]
for i, (a, b) in enumerate(BA):
    for w in range(M+1):
        if w >= b:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-b] + a-b)
        else:
            dp[i+1][w] = dp[i][w]
print(max(dp[-1]))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AB = [(a, b) for a, b in zip(A, B) if a < b]
dp = [[N] * (N + 1) for _ in range(len(AB)+1)]
for i, (a, b) in enumerate(AB):
    for w in range(N+1):
        if w >= a:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-a] + b-a)
        else:
            dp[i+1][w] = dp[i][w]

M = max(dp[-1])

BA = [(a, b) for a, b in zip(A, B) if a > b]
dp = [[M] * (M + 1) for _ in range(len(BA)+1)]
for i, (a, b) in enumerate(BA):
    for w in range(M+1):
        if w >= b:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-b] + a-b)
        else:
            dp[i+1][w] = dp[i][w]
print(max(dp[-1]))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AB = [(a, b) for a, b in zip(A, B) if a < b]
dp = [[N] * (N + 1) for _ in range(len(AB)+1)]
for i, (a, b) in enumerate(AB):
    for w in range(N+1):
        if w >= a:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-a] + b-a)
        else:
            dp[i+1][w] = dp[i][w]

M = max(dp[-1])

BA = [(a, b) for a, b in zip(A, B) if a > b]
dp = [[M] * (M + 1) for _ in range(len(BA)+1)]
for i, (a, b) in enumerate(BA):
    for w in range(M+1):
        if w >= b:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-b] + a-b)
        else:
            dp[i+1][w] = dp[i][w]
print(max(dp[-1]))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [[N] * (N + 1) for _ in range(4)]
for i in range(3):
    for w in range(N+1):
        if w >= A[i]:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-A[i]] + B[i]-A[i])
        else:
            dp[i+1][w] = dp[i][w]

M = max(dp[-1])

dp = [[M] * (M + 1) for _ in range(4)]
for i in range(3):
    for w in range(M+1):
        if w >= B[i]:
            dp[i+1][w] = max(dp[i][w], dp[i+1][w-B[i]] + A[i]-B[i])
        else:
            dp[i+1][w] = dp[i][w]
print(max(dp[-1]))


Fixed submission:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)