Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    max_num = 0
    g0,s0,b0 = gsb0
    g1,s1,b1 = gsb1
    g_max = num//g0 if (g0 < g1) else 0
    for i in range(g_max + 1):
        remain = num - i*g0
        d_g = i*g1
        s_max = remain//s0 if (s0 < s1) else 0
        for j in range( s_max + 1 ):
            remain2 = remain - j*s0
            k = remain2//b0 if (b0 < b1) else 0
            tmp = (remain2 - k*b0) + d_g + j*s1 + k*b1
            max_num = max(max_num, tmp)

    return(max_num)

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Fixed submission:
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [num] * (num+1) for _ in range(3+1)]
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v-w)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    max_num = 0
    g0,s0,b0 = gsb0
    g1,s1,b1 = gsb1
    g_max = num//g0 if (g0 < g1) else 0
    for i in range(g_max + 1):
        remain = num - i*g0
        d_g = i*g1
        s_max = remain//s0 if (s0 < s1) else 0
        for j in range( s_max + 1 ):
            remain2 = remain - j*s0
            k = remain2//b0 if (b0 < b1) else 0
            tmp = (remain2 - k*b0) + d_g + j*s1 + k*b1
            max_num = max(max_num, tmp)

    return(max_num)

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Fixed submission:
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [num] * (num+1) for _ in range(3+1)]
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v-w)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    max_num = 0
    g_max = num//gsb0[0] if (gsb0[0] < gsb1[0]) else 0
    for i in range(g_max + 1):
        remain = num - i*gsb0[0]
        s_max = remain//gsb0[1] if (gsb0[1] < gsb1[1]) else 0
        for j in range( s_max + 1 ):
            remain2 = remain - j*gsb0[1]
            k = remain2//gsb0[2] if (gsb0[2] < gsb1[2]) else 0
            tmp = (remain2 - k*gsb0[2]) + i*gsb1[0] + j*gsb1[1] + k*gsb1[2]
            max_num = max(max_num, tmp)

    return(max_num)

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Fixed submission:
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [num] * (num+1) for _ in range(3+1)]
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v-w)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    max_num = 0
    g_max = num//gsb0[0] if (gsb0[0] < gsb1[0]) else 0
    for i in range(g_max + 1):
        remain = num - i*gsb0[0]
        s_max = remain//gsb0[1] if (gsb0[1] < gsb1[1]) else 0
        for j in range( s_max + 1 ):
            k = (remain - j*gsb0[1])//gsb0[2] if (gsb0[2] < gsb1[2]) else 0

            tmp = (num - i*gsb0[0] - j*gsb0[1] - k*gsb0[2]) + i*gsb1[0] + j*gsb1[1] + k*gsb1[2]
            max_num = max(max_num, tmp)

    return(max_num)

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Fixed submission:
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [num] * (num+1) for _ in range(3+1)]
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v-w)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
gsb = [list(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    max_num = 0
    g_max = num//gsb0[0] if (gsb0[0] < gsb1[0]) else 0
    for i in range(g_max + 1):
        remain = num - i*gsb0[0]
        s_max = remain//gsb0[1] if (gsb0[1] < gsb1[1]) else 0
        for j in range( s_max + 1 ):
            k = (remain - j*gsb0[1])//gsb0[2] if (gsb0[2] < gsb1[2]) else 0

            tmp = (num - i*gsb0[0] - j*gsb0[1] - k*gsb0[2]) + i*gsb1[0] + j*gsb1[1] + k*gsb1[2]
            max_num = max(max_num, tmp)

    return(max_num)

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Fixed submission:
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [num] * (num+1) for _ in range(3+1)]
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v-w)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)