Problem:
 Score : 300 points    Problem Statement Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.   Operation 1: Pour 100A grams of water into the beaker.  Operation 2: Pour 100B grams of water into the beaker.  Operation 3: Put C grams of sugar into the beaker.  Operation 4: Put D grams of sugar into the beaker.   In our experimental environment, E grams of sugar can dissolve into 100 grams of water.  Snuke will make sugar water with the highest possible density.  The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.  We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.      Constraints  1 \leq A < B \leq 30  1 \leq C < D \leq 30  1 \leq E \leq 100  100A \leq F \leq 3  000  A , B , C , D , E and F are all integers.         Inputs Input is given from Standard Input in the following format:  A  B  C  D  E  F       Outputs Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.        Sample Input 1 1 2 10 20 15 200      Sample Output 1 110 10  In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.  We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:   If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.  If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.        Sample Input 2 1 2 1 2 100 1000      Sample Output 2 200 100  There are other acceptable outputs, such as:  400 200  However, the output below is not acceptable:  300 150  This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.       Sample Input 3 17 19 22 26 55 2802      Sample Output 3 2634 934

Solution (Python):
import sys
a, b, c, d, e, f = map(int, input().split())

m = sys.maxsize
mlist = [1,0,0,0]

for x in range(int(f / (100*a)) + 1):
    for y in range(int((f - 100 * a * x) / 100*b) + 1):
        for z in range(min(int((f - 100* a * x - 100 * b * y) / c), int(((a*x + b*y) * e) / c)) + 1):
            for w in range(min(int((f - 100* a * x - 100 * b * y - c * z) / d), int(((a*x + b*y) * e - c*z) / d)) + 1):
                if (z != 0 or w != 0) and float((a*x + b*y) / (c*z + d*w)) <= m:
                    mlist = [x,y,z,w]
                    m = float((a*x + b*y) / (c*z + d*w))
print(100 * a * mlist[0] + 100 * b * mlist[1] + c * mlist[2] + d * mlist[3], c * mlist[2] + d * mlist[3])

Solution (Python):



def main():
    a, b, c, d, e, f = map(int, input().split())
    concentration = 0
    water_set = set()
    sugar_set = set()

    
    
    for i in range(f + 1):
        for j in range(f + 1):
            y = c * i + d * j

            if y <= f:
                sugar_set.add(y)

    for k in range(0, f + 1, 100):
        for l in range(0, f + 1, 100):
            x = a * k + b * l

            if 0 < x <= f:
                water_set.add(x)

    sugar_water_amount = min(water_set) + min(sugar_set)
    sugar_amount = min(sugar_set)

    for water in water_set:
        for sugar in sugar_set:
            if (water + sugar <= f) and (sugar <= e * (water // 100)):
                candidate = (100 * sugar) / (water + sugar)

                if candidate > concentration:
                    concentration = candidate
                    sugar_water_amount = water + sugar
                    sugar_amount = sugar

    print(sugar_water_amount, sugar_amount)


if __name__ == '__main__':
    main()

Solution (Python):
(a, b, c, d, e, f) = list(map(int, input().split()))
a *= 100
b *= 100

n = [[0, 0] for _ in range(f + 1)]
n[a][0] = a
for i in range(f + 1 - a):
    if n[i][0] != 0:
        n[i + a][0] = n[i][0] + a
if f >= b:
    n[b][0] = b
    for i in range(f + 1 - b):
        if n[i][0] != 0:
            n[i + b][0] = n[i][0] + b
for i in range(f + 1 - c):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (c + n[i][1]) / tmpt <= e and n[i + c][1] / (i + c) < (n[i][1] + c) / (i + c):
            n[i + c][0] = n[i][0]
            n[i + c][1] = n[i][1] + c
for i in range(f + 1 - d):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (d + n[i][1]) / tmpt <= e and n[i + d][1] / (i + d) < (n[i][1] + d) / (i + d):
            n[i + d][0] = n[i][0]
            n[i + d][1] = n[i][1] + d
maxp = [0, a, 0]
for i in range(len(n)):
    if(n[i][1] != 0 and maxp[0] < n[i][1] / i):
        maxp = [n[i][1] / i] + n[i]
print(str(maxp[1] + maxp[2]) + ' ' + str(maxp[2]))

Solution (Python):

def 解():
    iA,iB,iC,iD,iE,iF = [int(_) for _ in input().split()]
    
    d = {}
    def searchAll(d,bF): 
        iMaxA = iF // 100*iA
        for i in range(iMaxA+1):
            iMaxB = (iF - 100*iA*i) // iB
            for j in range(iMaxB + 1):
                if i==0 and j==0:
                    continue
                iAB = 100*iA*i + 100*iB*j
                iUlim = iAB * iE //100
                if bF:
                    iUlim = min(iUlim,iF-iAB)
                else:
                    if iUlim > iF - iAB:
                        continue
                iMaxC = iUlim //iC
                for k in range(iMaxC+1):
                    l = (iUlim - iC*k ) //iD
                    iCD = iC*k +iD*l
                    if iUlim -iCD == 0:
                        print(iAB +iCD,iCD)
                        exit()
                    else:
                        iKey = iUlim-iCD
                        if not iKey in d:
                            d[iKey] = (iAB +iCD,iCD)
        return d
    d = searchAll(d,0)
    if not d:
        d = searchAll(d,1)
    iMin = min(d.keys())
    print(" ".join(map(str,d[iMin])))

解()

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

max_c = 0
ans_sw = A*100
ans_s = 0

water = set()
for a in range(0, F + 1, A * 100):
    for b in range(0, F - a + 1, B * 100):
        water.add(a + b)

suger = set()
for c in range(0, F + 1, C):
    for d in range(0, F - c + 1, D):
        suger.add(c + d)

for w in water:
    for s in suger:
        
        if s <= E * w // 100 and 0 < w + s <= F:
            c = s / (w + s)
            if max_c < c:
                max_c = c
                ans_sw = s + w
                ans_s = s

print(ans_sw, ans_s)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())

w = 0
s = 0
max_s = f * e // (100 + e)
max_a = f // (a * 100)
max_b = f // (b * 100)
max_c = max_s // c
max_d = max_s // d

ans = 0
ans_s = 0
ans_w = 0
for ia in range(max_a + 1):
    for ib in range(max_b + 1):
        temp_w = (ia * a + ib * b) * 100
        if temp_w > f:
            break
        for ic in range(max_c + 1):
            for id in range(max_d + 1):
                temp_s = ic * c + id * d
                if temp_s > min(temp_w * e / 100, f - temp_w):
                    break
                elif temp_s + temp_w > 0:
                    temp = temp_s / (temp_s + temp_w)
                    if temp >= ans:
                        ans = temp
                        ans_s = temp_s
                        ans_w = temp_w

print((ans_w + ans_s), ans_s)

Solution (Python):
a, b, c, d, e, f = [int(v) for v in input().split()]

water = set()
for i in range(0, f + 1, 100 * a):
    for j in range(0, f - a + 1, 100 * b):
        water.add(i + j)

sugar = set()
for i in range(0, f + 1, c):
    for j in range(0, f - c + 1, d):
        sugar.add(i + j)

max_r = -1
max_sw = -1
max_s = -1
for w in water:
    for s in sugar:
        if 0 < w + s <= f and s <= w * e // 100:
            r = s / (w + s)
            if max_r < r:
                max_r = r
                max_sw = s + w
                max_s = s

print(max_sw, max_s)

Solution (Python):

import itertools

A,B,C,D,E,F = map(int, input().split())

ope1 = [x for x in range(F//(100*A)+1)]
ope2 = [x for x in range(F//(100*B)+1)]
ope3 = [x for x in range(F//C+1)]
ope4 = [x for x in range(F//D+1)]

water = []
for a,b in itertools.product(ope1, ope2):
    temp = 100*a*A + 100*b*B
    water.append(temp)
water = sorted(list(set(water)))

sugar = []
for c,d in itertools.product(ope3, ope4):
    temp = c*C + d*D
    sugar.append(temp)
sugar = sorted(list(set(sugar)))

ans_list = []
for w,s in itertools.product(water, sugar):
    if w == 0:
        continue
    if s/(w//100) > E:
        continue
    if w+s > F:
        continue
    ans_list.append([s*100/(s+w),s+w,s])

if len(ans_list) > 0 :
    ans_list.sort(key=lambda x:x[0])
    print(ans_list[-1][1],ans_list[-1][2])
else:
    print(100*A,0)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
Smax = E * F // 100
S, W = [False for i in range(Smax+1)], [False for i in range(F+1)]
S[0], W[0] = True, True
for i in range(1, len(S)):
    if i - C >= 0:
        if S[i-C] == True:
            S[i] = True
    if i - D >= 0:
        if S[i-D] == True:
            S[i] = True
for i in range(1, F+1):
    if i - A >= 0:
        if W[i-A] == True:
            W[i] = True
    if i - B >= 0:
        if W[i-B] == True:
            W[i] = True

conc = 0
ans = [A, 0]
for i in reversed(range(len(S))):
    if S[i] == True:
        for j in range(1, F-i+1):
            if W[j] == True and 100 * i <= j * E:
                if 100 * i / (i+j) > conc:
                    conc = 100 * i / (i+j)
                    ans = [i+j, i]
                    break
print(" ".join(map(str, ans)))

Solution (Python):

A, B, C, D, E, F = map(int, input().split())

i = 0
j = 0
X = []

while A*i <= F:
    j = 0
    while A*i + B*j <= F:
        X.append(A*i + B*j)
        j += 100
    i += 100
X = sorted(list(set(X)))

i = 0
j = 0
Y = []

while C*i <= F:
    j = 0
    while C*i + D*j <= F:
        Y.append(C*i + D*j)
        j += 1
    i += 1
Y = sorted(list(set(Y)))

ans1 = X[1]
ans2 = 0
max_con = 0

for x in X[1:]:
    for y in Y:
        if x + y > F:
            break
        elif x + y != 0:
            con = 100*y / (x + y)
            if con > max_con and y <= E*x/100:
                ans1 = x + y
                ans2 = y
                max_con = con

print(ans1,ans2)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
w = []
for k in range(f//(100*a)+1):
  x = a*k
  while x <= f//100:
    w += [x]
    x += b    
s = []
for k in range(f//c+1):
  x = c*k
  while x <= f:
    s += [x]
    x += d
  
p,q = a,0    
for x in w:
  if x == 0:
    continue
  for y in s:
    if 100*x+y <= f and y/x <= e and y/x > q/p:
      p,q = x,y
print(100*p+q,q)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

W = set()
for a in range(0, F+1, 100 * A):
    for b in range(0, F - a+1, 100 * B):
        W.add(a + b)

S = set()
for c in range(0, F+1, C):
    for d in range(0, F - c+1, D):
        S.add(c + d)

mx = -1
for w in W:
    for s in S:
        if 0 < w + s <= F and s <= w * E // 100:
            if mx < s/(w+s):
                ans = w+s, s
                mx = s/(w+s)
print(ans[0], ans[1])

Solution (Python):

"""
Created on Mon Oct  8 14:30:54 2018
ABC074C
@author: maezawa
"""

a, b, c, d, e, f = list(map(int, input().split()))

pos_water = set([])
pos_sugar = set([])
max_water = f
max_sugar = f*e//100

for i in range(max_water//100//a+1):
    for j in range(max_water//100//b+1):
        if 100*(i*a + j*b) > max_water:
            break
        else:
            pos_water.add(100*(i*a + j*b))

for i in range(max_sugar//c+1):
    for j in range(max_sugar//d):
        if i*c + j*d > max_sugar:
            break
        else:
            pos_sugar.add(i*c + j*d)

water = list(pos_water)
water.sort()
sugars = list(pos_sugar)
sugars.sort()
water.remove(0)




ans_weight = water[0]
ans_sugar = 0
max_conc = 0
for w in water:
    for s in sugars:
        conc = s/(s+w)
        weight = s+w
        
        if weight > f:
            break
        if conc > e/(100+e):
            break
        if conc > max_conc:
            max_conc = conc
            ans_weight = weight
            ans_sugar = s

print(ans_weight, ans_sugar)

Solution (Python):
A,B,C,D,E,F = map(int,input().split())

waters = set()
for b in range(0, F+1, 100*B):
    for a in range(0, F-b+1, 100*A):
        waters.add(a+b)
waters.remove(0)

sugars = set()
for d in range(0, F+1, D):
    for c in range(0, F-d+1, C):
        sugars.add(c+d)

best_w = best_s = best_r = -1
for water in sorted(waters):
    for sugar in sorted(sugars):
        if water + sugar > F: break
        if water*E < sugar*100: break
        rate = sugar / (water + sugar)
        if rate > best_r:
            best_r = rate
            best_w = water
            best_s = sugar
print(best_s+best_w, best_s)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

water_set = set()
sugar_set = set()

for a in range(0, F+1, 100*A):
    for b in range(0, F+1, 100*B):
        if a + b <= F:
            water_set.add(a + b)

for c in range(0, F+1, C):
    for d in range(0, F+1, D):
        if c + d <= F//2 + 1:
            sugar_set.add(c + d)

water_set.remove(0)
water_list = list(water_set)
sugar_list = list(sugar_set)

cons = -1
water_ans = 0
sugar_ans = 0
for water in water_list:
    for sugar in sugar_list:
        if water + sugar <= F and sugar * 100 <= E * water:
            if 100 * sugar / (water + sugar) > cons:
                cons = 100 * sugar / (water + sugar)
                water_ans = water
                sugar_ans = sugar

print(water_ans + sugar_ans, sugar_ans)

Solution (Python):
import sys
stdin = sys.stdin

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())

a,b,c,d,e,f = li()

water_set = set()
sugar_set = set()

MAX = 3000


for ai in range(0,MAX//100+1,a):
    for bi in range(0,MAX//100+1,b):
        if 100 * (ai + bi) <= MAX:
            water_set.add(100 * (ai + bi))

water_list = sorted(list(water_set))
water_list.remove(0)

for ci in range(0,30*e+1,c):
    for di in range(0,30*e+1,d):
        if ci + di <= 30*e:
            sugar_set.add(ci+di)
            
sugar_list = sorted(list(sugar_set))

node_max = -1
sw = 0
sg = 0

for wi in water_list:
    for si in sugar_list:
        if wi+si <= f and si <= e * (wi//100) and wi+si > 0:
            node = (100*si) / (wi+si)
            if node > node_max:
                sw = si + wi
                sg = si
                node_max = node
                
print(sw,sg)

Solution (Python):
import sys
stdin = sys.stdin

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())

a,b,c,d,e,f = li()

water_set = set()
sugar_set = set()

MAX = 3000


for ai in range(0,MAX//100+1,a):
    for bi in range(0,MAX//100+1,b):
        if 100 * (ai + bi) <= MAX:
            water_set.add(100 * (ai + bi))

water_list = sorted(list(water_set))

for ci in range(0,30*e+1,c):
    for di in range(0,30*e+1,d):
        if ci + di <= 30*e:
            sugar_set.add(ci+di)
            
sugar_list = sorted(list(sugar_set))

node_max = -1
sw = 0
sg = 0

for wi in water_list:
    for si in sugar_list:
        if wi+si <= f and si <= e * (wi//100) and wi+si > 0:
            node = (100*si) / (wi+si)
            if node > node_max:
                sw = si + wi
                sg = si
                node_max = node
                
print(sw,sg)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
num = (0, 0)
rec = 0
for a in range(101):
    for b in range(101):
        if a * A * 100 + b * B * 100 > F:
            break
        for c in range(100):
            if a * A * 100 + b * B * 100 + c * C > F:
                break
            for d in range(100):
                q = a * A * 100 + b * B * 100
                p = C * c + D * d
                if p > E * (a * A + b * B):
                    continue
                if p + q == 0:
                    continue
                if p + q <= F:
                    if rec <= 100 * p / (p + q):
                        rec = 100 * p / (p + q)
                        num = (p + q, p)
                else:
                    break

print(num[0], num[1])

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
ans1 = 100 * A
ans2 = 0
n = 0
for x in range(100, F+1, 100):
    for y in range(F+1):
        if x + y == 0:
            continue        
        if x + y > F:
            continue
        if (x / 100) * E < y:
            continue

        s = []
        for i in range((y//C)+1):
            for j in range((y//D)+1):
                if y == i * C + j * D:
                    s.append((i, j))
                    break
            if len(s):
                break
        if len(s) == 0:
            continue

        w = []
        for i in range((x//(100*A))+1):
            for j in range((x//(100*B))+1):
                if x == 100 * A * i + 100 * B * j:
                    w.append((i, j))
                    break
            if len(w):
                break

        if len(w) == 0:
            continue

        if n < (y/(x+y)):
            n = y/(x+y)
            ans1 = x + y
            ans2 = y

print(ans1, ans2)

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
total = 0
sugar = 0
p,q,r,s = 0,0,0,0
p_max,q_max,r_max,s_max = 0,0,0,0
p_max = f // (100*a)
q_max = f // (100*b)
r_max = int((0.01 * f * e) // c)
s_max = int((0.01 * f * e) // d)
set_water = set()
set_sugar = set()

for p in range(0,p_max+1):
    for q in range(0,q_max+1):
        if 100*(a*p + b*q) <= f:
            set_water.add(100*(p*a+q*b))
for r in range(0,r_max+1):
    for s in range(0,s_max+1):
        if c*r + d*s <= 0.01*f*e:
            set_sugar.add(r*c+s*d)
conc_max = 0
max_sugar = 0
max_tot = 0
for water in set_water:
    for sugar in set_sugar:
        if water + sugar > f:
            pass
        elif water == 0 or sugar == 0:
            pass
        elif sugar / water > 0.01*e:
            pass
        else:
            conc = sugar / (water+sugar)
            if conc >= conc_max:
                conc_max = conc
                max_sugar = sugar
                max_tot = water+sugar
            else:
                pass
if max_tot == 0:
    max_tot = 100*a
print(max_tot,max_sugar)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
x=set()
y=set()
m=f//(100*a)
for i in range(m+1):
  for j in range(f//(100*b)+1):
    x1=i*100*a+j*100*b
    if x1<=f:
      x.add(x1)

m=int(f*(e/100))
for i in range(0,m+1,c):
  for j in range(0,m-i+1,d):
     y.add(i+j)
x.remove(0) 
z=[-1]
ans=[]
for i in x:
  for j in y:
    if i+j<=f and j*100/(i+j)<=e*100/(100+e):
      if j*100/(i+j)>max(z):
        z.append(j*100/(i+j))
        ans.append([i+j,j])
        
print(ans[-1][0],ans[-1][1])

Solution (Python):
a, b, c, d, e, f = list(map(int, input().split()))
res = [0, 0]
w = set()
s = set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        total = a*i*100 + b*j*100
        if a*i*100 + b*j*100 <= f:
            w.add(total)
w.remove(0)

s_max = int(f * (e / 100))
for i in range(0, s_max+1, c):
    for j in range(0, s_max-i+1, d):
        s.add(i+j)

max_nodo = -1
for wtr in w:
    for sgr in s:
        nodo = (sgr * 100) / (wtr + sgr)
        if wtr + sgr <= f and nodo <= (e*100) / (e+100):
            if nodo > max_nodo:
                max_nodo = nodo
                res[0] = wtr+sgr
                res[1] = sgr

print(str(res[0]) + " " + str(res[1]))

Solution (Python):
A = list(map(int,input().split()))

water = {}
for i in range(A[5]//(100*A[0])+1):
    for j in range((A[5]-i*A[0]*100)//(100*A[1])+1):
        water[100*(A[0]*i+A[1]*j)]=1
water.pop(0)

ans = [100*A[0], 0]
max_ = -1

for w in water.keys():
    for c in range(min((w//100*A[4])//A[2]+1,(A[5]-w)//A[2]+1)):
        d = min(((w//100*A[4])-c*A[2])//A[3], (A[5]-w-c*A[2])//A[3])
        tmp = (A[2]*c+A[3]*d)/(w+A[2]*c+A[3]*d)
        if max_ < tmp and (w+A[2]*c+A[3]*d) <= A[5]:
            ans=[w+A[2]*c+A[3]*d, A[2]*c+A[3]*d]
            max_=tmp

print(ans[0], ans[1])

Solution (Python):

A, B, C, D, E, F=map(int, input().split())
A=100*A
B=100*B
count_A=F//A
count_B=F//B
count_C=F//C
count_D=F//D
max=-1
ans=[0]*2
total=0
density=0
for i in range(count_A+1):
    for j in range(count_B+1):
        if i*A+j*B<=F and 0<i*A+j*B:
            for k in range(count_C+1):
                if i*A+j*B+k*C<=F:
                    for l in range(count_D+1):
                        total=i*A+j*B+k*C+l*D
                        if total!=0:
                            density=(k*C+l*D)/total
                            if total<=F and density<=E/(100+E) and max<density:
                                max=density
                                ans[0]=total
                                ans[1]=k*C+l*D
                                if density==E/(100+E):
                                    print(' '.join(map(str, ans)))
                                    exit()
print(' '.join(map(str, ans)))

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
rec = (0, 0)
ma = 0
for i in range(31):
    for j in range(31):
        for k in range(100):
            t = i * a * 100 + j * b * 100 + c * k
            if t > f:
                break
            for l in range(100):
                s = i * a * 100 + j * b * 100 + c * k + d * l
                if s > f:
                    break
                if c * k + d * l > (a * i + b * j) * e:
                    break
                if (i * a + j * b + c * k + d * l) == 0:
                    continue
                q = (c * k + d * l) / (100 * i * a + 100 * j * b + c * k + d * l) * 100
                if q >= ma:
                    ma = q
                    rec = (s, c * k + d * l)

print(rec[0], rec[1])

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

max_water = 0
max_sugar = 0
max_con = 0
max_AB = 31
max_CD = 101

for a in range(max_AB):
    for b in range(max_AB):
        water = (100 * A) * a + (100 * B) * b
        if water == 0:
            break

        for c in range(max_CD):
            for d in range(max_CD):
                sugar = C * c + D * d
                if water + sugar > F:
                    break

                con = 100*sugar / (water + sugar)
                if water/100 * E >= sugar and con >= max_con:
                    max_con = con
                    max_water = water
                    max_sugar = sugar
print(str(max_water+max_sugar) + " " + str(max_sugar))

Solution (Python):
a, b, c, d, e, f = list(map(int, input().split()))

water = {}
for i in range(f//(100*a)+1):
    for j in range(f//(100*b)+1):
        wtr = 100*a*i+100*b*j
        if wtr <= f and not wtr in water.keys():
            water[wtr] = 1
water = sorted(water.keys())[1:]

suger = {}
for i in range(f//c+1):
    for j in range(f//d+1):
        sgr = c*i+d*j
        if sgr <= f and not sgr in suger.keys():
            suger[sgr] = 1
suger = sorted(suger.keys())


ans_w = 0
ans_s = 0
concent = 0
for wtr in water:
    for sgr in suger:
        if wtr+sgr > f:
            break
        if sgr > (wtr//100)*e:
            break
        if sgr/(sgr+wtr) >= concent:
            concent = sgr/(sgr+wtr)
            ans_w = wtr+sgr
            ans_s = sgr

print(ans_w, ans_s)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

best = -1.0
ws = sg = 0

for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        w = a + b
        m = min(F - w, w * E // 100)

        if w == 0: continue
        for c in range(0, m + 1, C):
            for d in range(0, m - c + 1, D):
                s = c + d
                if best < s / (w + s):
                    best = s / (w + s)
                    ws = w + s
                    sg = s
print(ws, sg)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

best = -1.0
a = ws = sg = 0

while 100 * a * A <= F:
    b = 0
    while True:
        w = 100 * (a * A + b * B)
        if w > F: break
        c = 0
        while w + c * C <= F and 100 * c * C <= w * E:
            d = 0
            while True:
                s = c * C + d * D
                if w + s > F or 100 * s > w * E:
                    break
                elif w + s != 0 and best < s / (w + s):
                    best = s / (w + s)
                    ws = w + s
                    sg = s
                d += 1
            c += 1
        b += 1
    a += 1
print(ws, sg)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C, D, E, F = map(int, input().split())

    ws, ss = set(), set()
    for a in range(F // A + 1):
        for b in range(F // B + 1):
            w = 100 * (a * A + b * B)
            if w != 0 and w <= F:
                ws.add(w)
    for c in range(F + 1):
        for d in range(F + 1):
            if c * C + d * D <= F:
                ss.add(c * C + d * D)

    best = 0
    ans = (0, 0)
    for w in ws:
        for s in ss:
            if w + s > F or s > w * E // 100:
                continue
            if best <= ((100 * s) / (w + s)):
                best = (100 * s) / (w + s)
                ans = (w + s, s)

    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C, D, E, F = map(int, input().split())

    best = 0
    ans = (0, 0)
    for a in range(F // (100 * A) + 1):
        for b in range(F // (100 * B) + 1):
            if a == 0 and b == 0:
                continue
            for c in range(F // C + 1):
                w = 100 * (a * A + b * B)
                d = min((F - w - c * C), E * w // 100 - c * C) // D
                if d < 0:
                    continue
                s = c * C + d * D
                if best <= ((100 * s) / (w + s)):
                    best = (100 * s) / (w + s)
                    ans = (w + s, s)

    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter

A, B, C, D, E, F = map(int, input().split())


def f(x, y):
    max_i = F // x
    max_j = F // y
    arr = []
    for i in range(max_i + 1):
        for j in range(max_j + 1):
            a = x * i + y * j
            if a <= F:
                arr.append(a)
    return list(set(arr))


water = f(100 * A, 100 * B)
sugar = f(C, D)

ans = []
for w in water:
    if w == 0:
        continue
    for s in sugar:
        if w + s <= F and s / w <= E / 100:
            ans.append((w + s, s, s / (w + s)))
ans = sorted(ans, key=itemgetter(2), reverse=True)
print(ans[0][0], ans[0][1])

Solution (Python):
A, B, C, D, E, F=map(int, input().split())
a=[[str(100*A),'0']]
for i in range(101):
    for j in range(101):
        for k in range(101):
            for l in range(101):
                x=100*A*i+100*B*j
                y=C*k+D*l
                if x+y>F or x==0:
                    break
                if 100*y/(x+y)<=(E*100)/(100+E):
                    a.append([str(x+y),str(y)])
print(' '.join(sorted(a, key=lambda x: (100*int(x[1]))/int(x[0]) if int(x[0])!=0 else 0)[-1]))

Solution (Python):
from math import ceil
A,B,C,D,E,F = map(int,input().split())
am,bm,cm,dm=ceil(31/A),ceil(31/B),ceil(F*E/(100+E)/C)+1,ceil(F*E/(100+E)/D)+1
temp = []
for a in range(am):
    for b in range(bm):
        for c in range(cm):
            for d in range(dm):
                w = 100*a*A+100*b*B
                s = c*C+d*D
                if w + s > F:
                    break
                else:
                    if w / 100 * E >= s:
                        temp.append([w+s,s])
print(*sorted(temp, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])

Solution (Python):
A, B, C, D, E, F = map(int, input().split())

water = A*100
salt = 0
conc = 0


for i in range(1,30):
  Amax = i // A
  notMakeFlag = True
  for k in range(Amax + 1):
    if (i - A * k) % B == 0:
      notMakeFlag = False
      break
  if notMakeFlag:
    continue
  
  
  
  
  Cmax = min(E*i, (F-i*100))//C
  saltmax = 0
  for k in range(Cmax + 1):
    Dcount = (min(E*i, (F-i*100)) - k * C) // D
    saltmax = max(saltmax, k*C + Dcount * D)
  
    if conc < saltmax / (saltmax + i * 100):
      water = i * 100
      salt = saltmax
      conc = saltmax / (saltmax + i * 100)

print(water+salt, salt)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
water=[]
suguar=[]
temp_3=0
temp_2=0
ans=0
temp=0
for i in range((f+1)//100):
    for j in range((f+1)//100):
        x=100*i*a+100*j*b
        if 1<=x<=f:
            water.append(x)
for i in range(f+1):
    for j in range(f+1):
        y=c*i+d*j
        if y<=f:
            suguar.append(y)
for i in water:
    for j in suguar:
        total=i+j
        if total<=f:
            if j<=i//100*e:
                ans=100*j/(i+j)
                if temp<=ans:
                    temp=ans
                    temp_2=total
                    temp_3=j
print(temp_2,temp_3)

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
noudo_max = (100*E)/(100+E)


res = [-float('inf')]*3

i,j = 0,0
while 100*A*i<=F:
    j = 0
    while 100*A*i+100*B*j<=F:
        water = 100*A*i + 100*B*j
        sugar_max = F - water
        
        p = 0
        while C*p<=sugar_max:
            q = 0
            while C*p+D*q<=sugar_max:
                sugar = C*p+D*q
                if water+sugar!=0:
                    noudo = (100*sugar)/(water+sugar)
                    if noudo<=noudo_max and res[0]<noudo:
                        res = noudo,water,sugar
                q += 1
            p += 1
        j += 1
    i += 1

print(res[1]+res[2],res[2])