Problem:


Score : 600 points

Problem Statement

The squirrel Chokudai has N acorns.
One day, he decides to do some trades in multiple precious metal exchanges to make more acorns.

His plan is as follows:

Get out of the nest with N acorns in his hands.

Go to Exchange A and do some trades.

Go to Exchange B and do some trades.

Go to Exchange A and do some trades.

Go back to the nest.

In Exchange X (X = A, B), he can perform the following operations any integer number of times (possibly zero) in any order:

Lose g_{X} acorns and gain 1 gram of gold.

Gain g_{X} acorns and lose 1 gram of gold.

Lose s_{X} acorns and gain 1 gram of silver.

Gain s_{X} acorns and lose 1 gram of silver.

Lose b_{X} acorns and gain 1 gram of bronze.

Gain b_{X} acorns and lose 1 gram of bronze.

Naturally, he cannot perform an operation that would leave him with a negative amount of acorns, gold, silver, or bronze.

What is the maximum number of acorns that he can bring to the nest?
Note that gold, silver, or bronze brought to the nest would be worthless because he is just a squirrel.

Constraints

1 \leq N \leq 5000

1 \leq g_{X} \leq 5000

1 \leq s_{X} \leq 5000

1 \leq b_{X} \leq 5000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
g_A s_A b_A
g_B s_B b_B

Output

Print the maximum number of acorns that Chokudai can bring to the nest.

Sample Input 1

23
1 1 1
2 1 1

Sample Output 1

46

He can bring 46 acorns to the nest, as follows:

In Exchange A, trade 23 acorns for 23 grams of gold. {acorns, gold, silver, bronze}={ 0,23,0,0 }

In Exchange B, trade 23 grams of gold for 46 acorns. {acorns, gold, silver, bronze}={ 46,0,0,0 }

In Exchange A, trade nothing. {acorns, gold, silver, bronze}={ 46,0,0,0 }

He cannot have 47 or more acorns, so the answer is 46.



Sample input:
23
1 1 1
2 1 1


Sample output:
46

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,k = LI()
    print(n%k)
    return

#B
def B():
    n = I()
    po = LIR(n)
    if n == 1:
        print(1)
        quit()
    ans = float("inf")
    for i in range(n):
        for j in range(n):
            if i == j:continue
            x,y = po[i]
            s,t = po[j]
            p,q = s-x,t-y
            m = n
            for k in range(n):
                for l in range(n):
                    if (po[k][0]-po[l][0],po[k][1]-po[l][1]) == (p,q):m -= 1
            if m < ans:
                ans = m
    print(ans)
    return

#C
def C():
    n = I()
    a = LI()
    a.sort()
    if a[0] >= 0:
        print(sum(a)-2*a[0])
        for i in range(1,n-1):
            print(a[0],a[i])
            a[0] -= a[i]
        print(a[n-1],a[0])
    else:
        if a[-1] < 0:
            print(2*a[-1]-sum(a))
            for i in range(n-1):
                print(a[-1],a[i])
                a[-1] -= a[i]
        else:
            m = bisect.bisect_left(a,0)
            p = n-m
            ans = -sum(a[:m])+sum(a[m:])
            print(ans)
            if p > m:
                l = a[-1]
                a = a[:-1]
                a = a[::-1]
                p -= 1
                p,m = m,p
                k = a[m]-a[m-1]
                print(a[m],a[m-1])
                for i in range(p-1):
                    print(a[m-i-2],k)
                    k = a[m-i-2]-k
                    print(a[m+i+1],k)
                    k = a[m+i+1]-k
                for i in range(m-p):
                    print(k,a[i])
                    k -= a[i]
                print(l,k)
            else:
                k = a[m]-a[m-1]
                print(a[m],a[m-1])
                for i in range(p-1):
                    print(a[m-i-2],k)
                    k = a[m-i-2]-k
                    print(a[m+i+1],k)
                    k = a[m+i+1]-k
                for i in range(m-p):
                    print(k,a[i])
                    k -= a[i]
    return

#D
def D():
    def dfs(d,k):
        if d == 3:
            l.append(k)
        else:
            dfs(d+1,k+[0])
            dfs(d+1,k+[1])
    n = I()
    a = LI()
    b = LI()
    ans = 0
    l = []
    dfs(0,[])
    p = [[]]
    for k in l:
        m = []
        for i in range(3):
            if k[i]:
                m.append(i)
        if len(m) == 1:
            p.append(m)
        elif len(m) == 2:
            p.append(m)
            p.append(m[::-1])
        elif len(m) == 3:
            p.append(m)
            p.append([m[0]]+[m[2]]+[m[1]])
            p.append([m[1]]+[m[0]]+[m[2]])
            p.append([m[1]]+[m[2]]+[m[0]])
            p.append([m[2]]+[m[0]]+[m[1]])
            p.append([m[2]]+[m[1]]+[m[0]])
    p.sort()
    for ka in p:
        for kb in p:
            m = n
            mon = [0,0,0]
            for i in ka:
                mon[i] = m//a[i]
                m %= a[i]
            for i in ka:
                m += mon[i]*b[i]
                mon[i] = 0
            for i in kb:
                mon[i] = m//b[i]
                m %= b[i]
            for i in kb:
                m += mon[i]*a[i]
                mon[i] = 0
            if m > ans:
                ans = m
    print(ans)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
ga, sa, ba = li()
gb, sb, bb = li()

n = max(n*gb//ga, n*sb//sa, n*bb//ba)
n = max(n*ga//gb, n*sa//sb, n*ba//bb)

print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
List_atob = sorted([gb/ga,  sb/sa, bb/ba])
List_btoa =sorted([ga/gb,sa/sb,ba/bb])
res = N
for i in range(5001):
    for j in range(5001-i):
        if ga*i+sa*j<=N:
            k = (N-ga*i-sa*j)//ba
            res = max(res, gb*i+sb*j+bb*k)
N=res  
#%%
for i in range(5001):
    for j in range(5001-i):
        if gb*i+sb*j<=N:
            k = (N-gb*i-sb*j)//bb
            res = max(res, ga*i+sa*j+ba*k)
print(res)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
gsb_A = LIST()
gsb_B = LIST()
gsb_delta = {}
for i in range(3):
	if min(gsb_A[i], gsb_B[i]) in gsb_delta:
		gsb_delta[min(gsb_A[i], gsb_B[i])] = max(max(gsb_A[i], gsb_B[i]), gsb_delta[min(gsb_A[i], gsb_B[i])])
	else:
		gsb_delta[min(gsb_A[i], gsb_B[i])] = max(gsb_A[i], gsb_B[i])
# print(gsb_delta)

dp = [0] * (N+1)
for i in range(N+1):
	for j in gsb_delta:
		if i-j >= 0:
			dp[i] = max(dp[i], dp[i-j] + gsb_delta[j])
# print(dp)
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
Ga, Sa, Ba = map(int, input().split())
Gb, Sb, Bb = map(int, input().split())

dp = [0]
for i in range(1, N+1):
  tmp = dp[-1] + 1
  if Ga <= i:
    t2 = dp[-Ga] + Gb
    tmp = tmp if tmp > t2 else t2
  if Sa <= i:
    t2 = dp[-Sa] + Sb
    tmp = tmp if tmp > t2 else t2
  if Ba <= i:
    t2 = dp[-Ba] + Bb
    tmp = tmp if tmp > t2 else t2
  dp.append(tmp)
N2 = dp[-1]
print(N2)

dp = [0]
for i in range(1, N2+1):
  tmp = dp[-1] + 1
  if Gb <= i:
    t2 = dp[-Gb] + Ga
    tmp = tmp if tmp > t2 else t2
  if Sb <= i:
    t2 = dp[-Sb] + Sa
    tmp = tmp if tmp > t2 else t2
  if Bb <= i:
    t2 = dp[-Bb] + Ba
    tmp = tmp if tmp > t2 else t2
  dp.append(tmp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
# Aのほうが小さくする
ga, gb = min(ga, gb), max(ga, gb)
sa, sb = min(sa, sb), max(sa, sb)
ba, bb = min(ba, bb), max(ba, bb)
hoge = [(ga, gb),(sa, sb),(ba, bb)]
hoge.sort(key=lambda x:(-x[0],-x[1]))


# Aが大きいものから
# もしAが全部1のとき、N^2となるので別計算
if hoge[0][0] == 1:
    print(n*hoge[0][1])
    exit()

ans = 0
for i in range(0, n+1, hoge[0][0]):
    for j in range(n-i+1):
        k = n - i - j
        ans_ = i//hoge[0][0]*hoge[0][1] + j//hoge[1][0]*hoge[1][1] + j%hoge[1][0] + k//hoge[2][0]*hoge[2][1] + k%hoge[2][0]
        if ans < ans_:
            ans = ans_
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
o = [0,0,0]
count = 0
b = list(map(int,input().split()))
c = list(map(int,input().split()))
o[0],o[1],o[2] = c[0]-b[0],c[1]-b[1],c[2]-b[2]
k = b[o.index(max(o))]
l = c[o.index(max(o))]
count += n//k*l
n = n%k
b.remove(b[o.index(max(o))])
c.remove(c[o.index(max(o))])
o.remove(max(o))
k = b[o.index(max(o))]
l = c[o.index(max(o))]
count += n//k*l
n = n%k
b.remove(b[o.index(max(o))])
c.remove(c[o.index(max(o))])
o.remove(max(o))
k = b[0]
l = c[0]
count += n//k*l
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def get(n, rates):
    rates.sort()
    if rates[0][0] >= 1:
        return n
    if rates[1][0] >= 1:
        r, a, b = rates[0]
        return (n % a) + (n // a) * b
    if rates[2][0] >= 1:
        ret = n
        r0, a0, b0 = rates[0]
        r1, a1, b1 = rates[1]
        for n0 in range(0, n, a0):
            n1 = (n - n0)
            d = (n - n0) % a1
            tmp = d + (n0 // a0) * b0 + (n1 // a1) * b1
            ret = max(ret, tmp)
        return ret
    r0, a0, b0 = rates[0]
    r1, a1, b1 = rates[1]
    r2, a2, b2 = rates[2]
    ret = n
    for n0 in range(0, n, a0):
        d0 = (n0 // a0) * b0
        rem = n - n0
        for n1 in range(0, rem, a1):
            n2 = (rem - n1)
            d = (rem - n1) % a2
            tmp = d + d0 + (n1 // a1) * b1 + (n2 // a2) * b2
            ret = max(ret, tmp)
    return ret

def main():
    N = II()
    ga, sa, ba = LI()
    gb, sb, bb = LI()
    rates = [[ga / gb, ga, gb], [sa / sb, sa, sb], [ba / bb, ba, bb]]
    rates2 = [[gb / ga, gb, ga], [sb / sa, sb, sa], [bb / ba, bb, ba]]
    ans = N
    ans = get(ans, rates)
    ans = get(ans, rates2)
    return ans

print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())

torihikiA = list(map(int, input().split()))
torihikiB = list(map(int, input().split()))

rate = 1
for i in range(len(torihikiA)):
    stuff = 0
    if torihikiA[i] > torihikiB[i]:
        stuff = n // torihikiB[i]
        n -= stuff * torihikiB[i]
        n += stuff * torihikiA[i]
    elif torihikiA[i] < torihikiB[i]:
        stuff = n // torihikiA[i]
        n -= stuff * torihikiA[i]
        n += stuff * torihikiB[i]

print(n)

Submission status: Wrong Answer

Solution code:
#D問題
N = int(input())
GSB1 = list(map(int,input().split()))
GSB2 = list(map(int,input().split()))
gper = float(GSB2[0]/GSB1[0])
sper = float(GSB2[1]/GSB1[1])
bper = float(GSB2[2]/GSB1[2])
if gper >= sper and gper >= bper:
    n1 = N//GSB1[0]
    N-=n1
    if sper >= bper:
        n2 = N//GSB1[1]
        n3 = N//GSB1[2]
        N+=n3*GSB2[2]
        N+=n2*GSB2[1]
    else:
        n2 = N//GSB1[2]
        n3 = N//GSB1[1]
        N+=n3*GSB2[1]
        N+=n2*GSB2[2]
    N+=n1*GSB2[0]
    
elif sper >= gper and sper >= bper:
    n1 = N//GSB1[1]
    N-=n1
    if gper >= bper:
        n2 = N//GSB1[0]
        n3 = N//GSB1[2]
        N+=n3*GSB2[2]
        N+=n2*GSB2[0]
    else:
        n2 = N//GSB1[2]
        n3 = N//GSB1[0]
        N+=n3*GSB2[0]
        N+=n2*GSB2[2]
    N+=n1*GSB2[1]
    
elif bper >= sper and bper >= gper:
    n1 = N//GSB1[2]
    N-=n1
    if gper >= sper:
        n2 = N//GSB1[0]
        n3 = N//GSB1[1]
        N+=n3*GSB2[1]
        N+=n2*GSB2[0]
    else:
        n2 = N//GSB1[1]
        n3 = N//GSB1[0]
        N+=n3*GSB2[0]
        N+=n2*GSB2[1]
    N+=n1*GSB2[2]
    
gper = float(GSB1[0]/GSB2[0])
sper = float(GSB1[1]/GSB2[1])
bper = float(GSB1[2]/GSB2[2])
if gper >= sper and gper >= bper:
    n1 = N//GSB2[0]
    N-=n1
    if sper >= bper:
        n2 = N//GSB2[1]
        n3 = N//GSB2[2]
        N+=n3*GSB1[2]
        N+=n2*GSB1[1]
    else:
        n2 = N//GSB2[2]
        n3 = N//GSB2[1]
        N+=n3*GSB1[1]
        N+=n2*GSB1[2]
    N+=n1*GSB1[0]
    
elif sper >= gper and sper >= bper:
    n1 = N//GSB2[1]
    N-=n1
    if gper >= bper:
        n2 = N//GSB2[0]
        n3 = N//GSB2[2]
        N+=n3*GSB1[2]
        N+=n2*GSB1[0]
    else:
        n2 = N//GSB2[2]
        n3 = N//GSB2[0]
        N+=n3*GSB1[0]
        N+=n2*GSB1[2]
    N+=n1*GSB1[1]
    
elif bper >= sper and bper >= gper:
    n1 = N//GSB2[2]
    N-=n1
    if gper >= sper:
        n2 = N//GSB2[0]
        n3 = N//GSB2[1]
        N+=n3*GSB1[1]
        N+=n2*GSB1[0]
    else:
        n2 = N//GSB2[1]
        n3 = N//GSB2[0]
        N+=n3*GSB1[0]
        N+=n2*GSB1[1]
    N+=n1*GSB1[2]
    
print(N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

f = [0, 0, 0]
for i in range(3):
  if A[i] < B[i]:
    f[i] = 1
  elif A[i] > B[i]:
    f[i] = -1

ma = N
for i in range(3):
  if f[i] < 0: continue
  Di = (N // A[i]) * B[i]
  Ni = N - (N // A[i]) * A[i]
  for j in range(3):
    if i == j: continue
    if f[j] < 0:
      ma = max(ma, Ni + Di)
      continue
    Dj = Di + (Ni // A[j]) * B[j]
    Nj = Ni - (Ni // A[j]) * A[j]
    for k in range(3):
      if i == k or j == k: continue
      if f[k]< 0:
        ma = max(ma, Nj + Dj)
        continue
      Dk = Dj + (Nj // A[k]) * B[k]
      Nk = Nj - (Nj // A[k]) * A[k]
      ma = max(ma, Nk + Dk)

N = ma
for i in range(3):
  if f[i] > 0: continue
  Di = (N // B[i]) * A[i]
  Ni = N - (N // B[i]) * B[i]
  for j in range(3):
    if i == j: continue
    if f[j] > 0:
      ma = max(ma, Ni + Di)
      continue
    Dj = Di + (Ni // B[j]) * A[j]
    Nj = Ni - (Ni // B[j]) * B[j]
    for k in range(3):
      if i == k or j == k: continue
      if f[k] > 0:
        ma = max(ma, Nj + Dj)
        continue
      Dk = Dj + (Nj // B[k]) * A[k]
      Nk = Nj - (Nj // B[k]) * B[k]
      ma = max(ma, Nk + Dk)

print(ma)

Submission status: Wrong Answer

Solution code:
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
# Aのほうが小さくする
ga, gb = min(ga, gb), max(ga, gb)
sa, sb = min(sa, sb), max(sa, sb)
ba, bb = min(ba, bb), max(ba, bb)
hoge = [(ga, gb),(sa, sb),(ba, bb)]
hoge.sort(key=lambda x:(-x[0],-x[1]))
# Aが大きいものから
# もしAが全部1のとき、N^2となるので別計算
if hoge[0][0] == 1:
    print(n*hoge[0][1])
    exit()

ans = 0
for i in range(0, n+1, hoge[0][0]):
    for j in range(n-i+1):
        k = n - i - j
        ans_ = i//hoge[0][0]*hoge[0][1] + j//hoge[1][0]*hoge[1][1] + k//hoge[2][0]*hoge[2][1] + k%hoge[2][0]
        if ans < ans_:
            ans = ans_
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ra = [ int(v) for v in input().split() ]
rb = [ int(v) for v in input().split() ]
ab_rate = sorted([ (rb[i] / ra[i],i,ra[i],rb[i]) for i in range(3)],reverse = True)
ba_rate = sorted([ (ra[i] / rb[i],i,rb[i],ra[i]) for i in range(3)],reverse = True)




def excange(r,x):

    if r[0] <= 1:
        return x, 0
    else:
        y = (x // r[2]) * r[3]
        x = x % r[2]
        return x, y

     
prof,amari = 0, n

for i in range(3):
    res = excange(ab_rate[i],amari)
    amari = res[0]
    prof += res[1]

prof,amari = 0, prof+amari

for i in range(3):
    res = excange(ba_rate[i],amari)
    amari = res[0]
    prof += res[1]
    

print(prof+amari)

Submission status: Wrong Answer

Solution code:
n = int(input())
metal_a = [int(x) for x in input().split()]
metal_b = [int(x) for x in input().split()]

sup_a = []
sup_b = []
for i in range(3):
    a_i = metal_a[i]
    b_i = metal_b[i]
    if a_i > b_i:
        sup_a.append((a_i, b_i))
    elif a_i < b_i:
        sup_b.append((a_i, b_i))

len_a = len(sup_a)
len_b = len(sup_b)

if len_a + len_b == 0:
    pass
elif len_a + len_b == 1:
    if len_a == 1:
        a, b = sup_a[0]
        n = int(n / b) * a + n % b
    else:
        a, b = sup_b[0]
        n = int(n / a) * b + n % a
elif len_a + len_b == 2:
    if len_a == 1 and len_b == 1:
        a, b = sup_b[0]
        amount = int(n / a)
        n = amount * b + n % a
        a, b = sup_a[0]
        n = amount * a + n % b
    elif len_a == 2:
        a, b = sup_a[0]
        n1 = int(n / b) * a + n % b
        a, b = sup_a[1]
        n2 = int(n / b) * a + n % b
        n = max(n1, n2)
    else:
        a, b = sup_b[0]
        n1 = int(n / a) * b + n % a
        a, b = sup_b[1]
        n2 = int(n / a) * b + n % a
        n = max(n1, n2)
else:
    if len_a == 0:
        a, b = sup_b[0]
        n1 = int(n / a) * b + n % a
        a, b = sup_b[1]
        n2 = int(n / a) * b + n % a
        a, b = sup_b[2]
        n3 = int(n / a) * b + n % a
        n = max(n1, n2, n3)
    elif len_a == 1:
        a, b = sup_b[0]
        amount = int(n / a)
        n1 = amount * b + n % a
        a, b = sup_a[0]
        n1 = int(n1 / b) * a + n1 % b

        a, b = sup_b[1]
        amount = int(n / a)
        n2 = amount * b + n % a
        a, b = sup_a[0]
        n2 = int(n2 / b) * a + n2 % b

        n = max(n1, n2)
    elif len_a == 2:
        a, b = sup_b[0]
        n = int(n / a) * b + n % a
        a, b = sup_a[0]
        n1 = int(n / b) * a + n % b
        a, b = sup_a[1]
        n2 = int(n / b) * a + n % b
        n = max(n1, n2)
    else:
        a, b = sup_a[0]
        n1 = int(n / b) * a + n % b
        a, b = sup_a[1]
        n2 = int(n / b) * a + n % b
        a, b = sup_a[2]
        n3 = int(n / b) * a + n % b
        n = max(n1, n2, n3)

print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
kane = [0,0,0]
l = [list(map(int, input().split())) for i in range(2)]
u = []
for i in range(3):
    u.append(l[1][i] / l[0][i])
l.append(u)
uu = sorted(u, reverse=True)
if max(u) <= 1:
    print(n)
else :
    kane[u.index(max(u))] += n // l[0][u.index(max(u))]
    n = n % l[0][u.index(max(u))]
    if uu[1] > 1:
        kane[u.index(uu[1])] += n // l[0][u.index(uu[1])]
        n = n % l[0][u.index(uu[1])]
        if uu[2] > 1:
            kane[u.index(uu[2])] += n // l[0][u.index(uu[2])]
            n = n % l[0][u.index(uu[2])]
    n += kane[u.index(max(u))] * l[1][u.index(max(u))]
    n += kane[u.index(uu[1])] * l[1][u.index(uu[1])]
    n += kane[u.index(uu[2])] * l[1][u.index(uu[2])]
    #print(kane)
    #print(l)
    print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
List_atob = sorted([gb/ga,  sb/sa, bb/ba])
List_btoa =sorted([ga/gb,sa/sb,ba/bb])
res = N
for i in range(5000):
    for j in range(5000-i):
        if ga*i+sa*j<=N:
            k = (N-ga*i-sa*j)//ba
            res = max(res, gb*i+sb*j+bb*k)
N=res  
for i in range(5000):
    for j in range(5000-i):
        if gb*i+sb*j<=N:
            k = (N-gb*i-sb*j)//bb
            res = max(res, ga*i+sa*j+ba*k)
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())

def arbitrage(g1, s1, b1, g2, s2, b2, n):
    if g2 / g1 <= 1:
        flag_g = False
    else:
        flag_g = True
    if s2 / s1 <= 1:
        flag_s = False
    else:
        flag_s = True
    if b2 / b1 <= 1:
        flag_b = False
    else:
        flag_b = True
    before = [g1, s1, b1]
    after = [g2, s2, b2]
    flag = [flag_g, flag_s, flag_b]
    dp = []
    for i in range(4):
        dp_plus = [0] * (n + 1)
        dp.append(dp_plus)
    for i in range(3):
        if flag[i] == False:
            continue
        for j in range(n + 1):
            if j < before[i]:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - before[i]] + after[i])
    return max(max(dp[i][n] for i in range(4)), n)

trade1 = arbitrage(ga, sa, ba, gb, sb, bb, n)
trade2 = arbitrage(gb, sb, bb, ga, sa, ba, trade1)
print(trade2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = [b[0]/a[0], b[1]/a[1], b[2]/a[2]]
mv = max(x)
mi = x.index(max(x))

import numpy as np
smv = sorted(x)[-2]
smi = np.array(x).argsort()[-2]

tmv = sorted(x)[0]
tmi = np.array(x).argsort()[0]

p = (N // a[mi]) * b[mi]
q = ((N % a[mi]) // a[smi]) * b[smi]
r = (((N % a[mi]) % a[smi]) // a[tmi]) * b[tmi]
print(p+q+r)

Submission status: Wrong Answer

Solution code:
N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())

ans = 0
for G in range(5001):
    for S in range(5001):
        if ga * G + sa * S > N:
            continue
        if ba <= bb:
            B = (N - (ga * G + sa * S)) // ba
        else:
            B = 0

        tmp_ans = N - (ga * G + sa * S + sb * B)
        tmp_ans += (G * gb) + (S * sb) + (B * bb)
        ans = max(ans, tmp_ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
a_list = np.array(list(map(int, input().split())))
b_list = np.array(list(map(int, input().split())))

a_div_b_list = a_list / b_list
a_div_b_dict = {}
for idx, ite in enumerate(a_div_b_list):
    a_div_b_dict[ite] = (a_list[idx], b_list[idx])

for adb, ab_tap in sorted(a_div_b_dict.items()):
    a = ab_tap[0]
    b = ab_tap[1]
    if adb < 1:
        q, mod = divmod(N, a)
        N = N - (q / a) + (q * b / a)
        if mod == 0:
            break
    else:
        break

for adb, ab_tap in sorted(a_div_b_dict.items(), key=lambda x: -x[0]):
    a = ab_tap[0]
    b = ab_tap[1]
    if adb > 1:
        q, mod = divmod(N, b)
        N = N - (q / b) + (q * a / b)
        if mod == 0:
            break
    else:
        break
print(int(N))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aHIKUb=[[i,(a[i]-b[i])/a[i],(a[i]-b[i])/b[i]] for i in range(3)]
aHIKUb.sort(key=lambda x:x[1])
changeCnt=[0,0,0]
changeCnt[aHIKUb[0][0]]=n//a[aHIKUb[0][0]]
for i,aibiai,aibibi in aHIKUb[1:]:
    remain=n
    for j in range(3):
        remain-=a[j]*changeCnt[j]
    if aibiai<0 and remain>a[i]:
        changeCnt[i]=remain//a[i]
for i in range(3):
    n+=(-a[i]+b[i])*changeCnt[i]

aHIKUb.sort(key=lambda x:x[2])
changeCnt=[0,0,0]
changeCnt[aHIKUb[2][0]]=n//b[aHIKUb[2][0]]
for i,aibiai,aibibi in aHIKUb[:2]:
    remain=n
    for j in range(3):
        remain-=a[j]*changeCnt[j]
    if aibibi>0 and remain>a[i]:
        changeCnt[i]=remain//a[i]
for i in range(3):
    n+=(a[i]-b[i])*changeCnt[i]
print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
ca = list(map(int,input().split()))
cb = list(map(int,input().split()))
ans = N
ab = [a-b for a,b in zip(ca,cb)] + [0]
ba = [b-a for a,b in zip(ca,cb)] + [0]

ans += max(ab) * N
ans += max(ba) * N
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
para = [gb//ga, ga//sb, bb//ba]
pab = max(para)
if pab > 1:
    N *= pab
para = [ga//gb, sa//sb, ba//bb]
pba = max(para)
if pba > 1:
    N *= pba
print(N)

Submission status: Wrong Answer

Solution code:
n = int(input())
ra = [ int(v) for v in input().split() ]
rb = [ int(v) for v in input().split() ]
ab_rate = sorted([ (rb[i] - ra[i],i,ra[i],rb[i]) for i in range(3)],reverse = True)
ba_rate = sorted([ (ra[i] - rb[i],i,rb[i],ra[i]) for i in range(3)],reverse = True)




def excange(r,x):

    if r[0] <= 0:
        return x, 0
    else:
        y = (x // r[2]) * r[3]
        x = x % r[2]
        return x, y

     
prof,amari = 0, n

for i in range(3):
    res = excange(ab_rate[i],amari)
    amari = res[0]
    prof += res[1]

prof,amari = 0, prof+amari

for i in range(3):
    res = excange(ba_rate[i],amari)
    amari = res[0]
    prof += res[1]
    

print(prof+amari)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = list(map(int, input().split()))
*B, = list(map(int, input().split()))

D = []

def swap(a,b):
  tmp = a
  a = b
  b = tmp
  return a,b

for (a,b) in zip(A,B):
  if (b > a):
    a, b = swap(a, b)

  D.append((N // b) * a)

print(max(D))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
for i in range(2):
    x.append(list(map(int, input().split())))
if x[0][0] > x[1][0]:
    gold = x[0][0]
else:
    gold = x[1][0]
if x[0][1] > x[1][1]:
    silver = x[0][1]
else:
    silver = x[1][1]
if x[0][2] > x[1][2]:
    bronze = x[0][2]
else:
    bronze = x[1][2]

print(n * gold * silver * bronze)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_rate = list(map(int, input().split()))
B_rate = list(map(int, input().split()))

g = (N//A_rate[0])*B_rate[0] + N%A_rate[0]
s = (N//A_rate[1])*B_rate[1] + N%A_rate[1]
b = (N//A_rate[2])*B_rate[2] + N%A_rate[2]

N = max(N,g,s,b)

g = (N//B_rate[0])*A_rate[0] + N%B_rate[0]
s = (N//B_rate[1])*A_rate[1] + N%B_rate[1]
b = (N//B_rate[2])*A_rate[2] + N%B_rate[2]

N = max(N,g,s,b)

print(N)

Submission status: Wrong Answer

Solution code:
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
ga, gb = min(ga, gb), max(ga, gb)
sa, sb = min(sa, sb), max(sa, sb)
ba, bb = min(ba, bb), max(ba, bb)
hoge = [(ga, gb),(sa, sb),(ba, bb)]
hoge.sort(key=lambda x:(-x[0],-x[1]))

if hoge[0][0] == 1:
    print(n*hoge[0][1])
    exit()

ans = 0
for i in range(0, n+1, hoge[0][0]):
    for j in range(i, n+1):
        if not(j == i or j % hoge[1][0] == 0):
            continue
        k = n - i - j
        ans_ = i//hoge[0][0]*hoge[0][1] + j//hoge[1][0]*hoge[1][1] + k//hoge[2][0]*hoge[2][1] + k%hoge[2][0]
        if ans < ans_:
            ans = ans_
print(ans)