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, sys.stdin.readline().split())
E = 100 * E / (100 + E)

def main():
    w = set()
    for w1 in range(0, F+1, 100*A):
        for w2 in range(0, F-w1+1, 100*B):
            w.add(w1 + w2)

    s = set()
    for s1 in range(0, F+1, C):
        for s2 in range(0, F-s1+1, D):
            s.add(s1 + s2)
            
    w = sorted(w)
    s = sorted(s)

    res = set()
    for i in w[1:]:
        for j in s:
            if i + j > F:
                break
            sol = 100 * j / (i + j)
            if sol <= E:
                res.add((sol, i+j, j))

    res = sorted(res, reverse=True)
    return res[0][1], res[0][2]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

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

max_concentration = 0
res = (0, 0)
for i in range(0, f//(100*a)+1):
    for j in range(0, (f-100*a*i)//(100*b)+1):
        water = 100 * (a*i + b*j)
        if water == 0:
            continue
        for k in range(0, f-i-j+1):
            for l in range(0, f-i-j-k+1):
                sugar = c*k + d*l
                if water + sugar > f:
                    break
                if sugar > water//100 * e:
                    break
                if water + sugar == 0:
                    continue
                concentration = sugar / (water+sugar)
                if concentration >= max_concentration:
                    max_concentration = concentration
                    res = (water+sugar, sugar)

print(*res)

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

tmp = np.arange(f+1, dtype=int)
water = np.zeros(f+1, dtype=int)
water[0] = 1
for i in range(f):
    if water[i]:
        if i+100*a < f+1:
            water[i + 100 * a] = 1
        if i+100*b < f+1:
            water[i + 100 * b] = 1
water = tmp[water == 1]
capacity = water//100*e
capacity = np.minimum(capacity, f-water)

sugar = np.zeros(f + 1, dtype=int)
sugar[0] = 1
for i in range(f):
    if sugar[i]:
        if i+c < f+1:
            sugar[i + c] = 1
        if i+d < f+1:
            sugar[i + d] = 1
sugar = tmp[sugar == 1]

max_d = 0
pair = 100 * a, 0
s = np.searchsorted(sugar, capacity, side="right")
s = sugar[s-1]
s = s[1:]
water = water[1:]
i = np.argmax(s / (water + s))
print(water[i]+s[i], s[i])

Solution (Python):
abcdef = list(map(int, input().split()))
a, b, c, d, e, f = abcdef[0] * 100, abcdef[1] * 100, abcdef[2], abcdef[3], abcdef[4], abcdef[5]

fa = int(f / a)
fb = int(f / b)
maxc = int(int(f / 100) * e / c)
maxd = int(int(f / 100) * e / d)

res = -1
suger_max = -1
nowden = -1





for i in range(fa + 1):
    for j in range(fb + 1):
        for k in range(maxc + 1):
            for l in range(maxd + 1):
                if i == 0 and j == 0:
                    continue
                wat = a * i + b * j
                sug = c * k + d * l
                if wat + sug > f or sug / wat > e / 100:
                    continue
                else:
                    den = sug / (wat + sug)
                    if (nowden < den):
                        nowden = den
                        res = wat + sug
                        suger_max = sug

print(str(res) + " " + str(suger_max))

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

water=[]
for i in range(31):
    for j in range(30):
        if (A*i+B*j)*100<=F:
            water.append((A*i+B*j)*100)
sugar=[]
for i in range(501):
    for j in range(500):
        if C*i+D*j<=F//2:
            sugar.append(C*i+D*j)

ans_sum=A*100
ans_sugar=0
ans_rate=0
for i in water:
    for j in sugar:
        if i==0:
            continue
        if i+j<=F and ans_rate<j/i<=E/100:
            ans_sum=i+j
            ans_sugar=j
            ans_rate=j/i

print(ans_sum,ans_sugar)

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









xs = set()
ys = set()

a_limit = f // (100 * a)
for i in range(a_limit + 1):
    b_limit = (f - (100 * a * i)) // (100 * b)
    for j in range(b_limit + 1):
        if i == 0 and j == 0:
            continue
        x = 100 * a * i + 100 * b * j
        xs.add(x)

c_limit = f // c
for i in range(c_limit + 1):
    d_limit = (f - c * i) // d
    for j in range(d_limit + 1):
        y = c * i + d * j
        ys.add(y)

density_limit = e / (100 + e)
max_density = 0.0
w = 0
s = 0
for x in xs:
    for y in ys:
        density = y / (x + y)
        if f >= x + y and density_limit >= density and density >= max_density:
            max_density = density
            w = x + y
            s = y

print(w, s)

Solution (Python):
from bisect import bisect_left
a, b, c, d, e, f = map(int, input().split())
mw = []
for i in range(31):
    for j in range(31):
        mw.append(a * i + b * j)
mw.sort()

ms = []
for i in range(3001):
    for j in range(3001):
        ms.append(- (c * i + d * j))

ms.sort()

ans = 0
ans_mw = mw[1]
ans_ms = 0

for mwi in mw[1:]:
    if mwi * 100 > f:
        break
    target = min(f - mwi * 100, mwi * e)
    msi = -ms[bisect_left(ms, - target)]
    cand = msi / mwi
    if mwi * 100 + msi <= f and cand > ans:
        ans = cand
        ans_mw = mwi
        ans_ms = msi

print(ans_mw * 100 + ans_ms, ans_ms)

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

Water = []
Sugar = []

for i in range(0,31):
    for j in range(0,16):
        w = 100*a*i + 100* b*j
        if w <= f:
            Water.append(w)

Water = set(Water)
Water.remove(0)

for k in range(0,3001):
    for l in range(0,1501):
        s = c*k + d*l
        if s <= f:
            Sugar.append(s)

Sugar = set(Sugar)

ans_conc = 0
ans_water = 0
ans_sugar = 0
max_conc = (100*e)/(100+e)

for w in Water:
    for s in Sugar:
        conc = (100 * s) /(w + s)
        if (conc <= max_conc) and (w+s <= f) and (ans_conc <= conc):
            ans_conc = conc
            ans_water = w
            ans_sugar = s 
            
print(str(ans_water+ans_sugar) + ' ' + str(ans_sugar))

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

water = []
for i in range(F//(A*100) + 1):
    for j in range(F//(B*100) + 1):
        n = (i*A + j*B)*100
        if n <= F:
            water.append(n)
water = sorted(list(set(water)))

density_d = {}
density = []

for i in water:
    suger_limit = E*(i//100)

    suger = []

    for j in range(suger_limit//C + 1):
        for k in range(suger_limit//D + 1):
            n = j*C + k*D
            if n <= suger_limit and n + i <= F:
                suger.append(n)
    suger = max(suger)
    if i+suger == 0:
        continue
    else:
        density.append(100*suger/(i+suger))
        density_d[100*suger/(i+suger)] = [i + suger, suger]
density = list(set(density))
a, b = map(int, density_d[max(density)])
print(a,b)

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

water = []
for i in range(31):
    for j in range(31):
        tmp = 100*i*A + 100*j*B
        if tmp <= F:
            water.append(tmp)
            
water = list(set(water))
water.remove(0)

sugar = []
for i in range(101):
    for j in range(101):
        tmp = i*C + j*D
        if tmp <= F:
            sugar.append(tmp)
            
sugar = list(set(sugar))
sugar.remove(0)

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

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

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

W = set()
for a in range(0, F+1, A*100):
  for b in range(0, F+1, B*100):
    w = a+b
    if w==0 or w>F: continue
    W.add(w)

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

d_max = -1
ans = None
for w in W:
  for s in S:
    if w*E//100<s or w+s>F: continue
    d = 100*s/(w+s)
    if d>d_max:
      d_max = d
      ans = (w+s, s)

print(*ans)

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

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  


A, B, C, D, E, F = rl()
water = [False for x in range(F//100 + 1)]
answer = (-1, 0, 0)
for i in range(F//(100*B) + 1):
    for j in range(F//(100*A) + 1):
        k = i * B + j * A
        if k > len(water) - 1:
            continue
        water[k] = True
for i in range(len(water)):
    if water[i] == True:
        water[i] = i
for x in water:
    if not x or x == 0:
        continue
    max = x * E
    for i in range(max//D+1):
        for j in range(max//C+1):
            y = D * i + C * j
            solution = x*100 + y
            if solution > F:
                break
            if y > max:
                break
            elif solution > 0:
                result = y / solution
                if result > answer[0]:
                    answer = (result, solution, y)

print(answer[1], answer[2])

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

water = [0] * (F//100 + 1)
water[0] = 1
for i in range(F//100 + 1):
  if water[i]:
    if i + A < F//100 + 1: water[i+A] = 1
    if i + B < F//100 + 1: water[i+B] = 1
water[0] = 0


suger = [0] * (F + 1)
suger[0] = 1
for i in range(F + 1):
  if suger[i]:
    if i + C < F + 1: suger[i+C] = 1
    if i + D < F + 1: suger[i+D] = 1


max_sol = -1
answer = [0, 0]
for i in range(len(water)):
  if water[i] == 0:
    continue
  
  for j in range(len(suger)):
    if suger[j] and i*100 + j <= F and j / (i*100 + j) <= E / (100 + E):
        if max_sol < 100 * j / (i*100 + j):
          max_sol = 100 * j / (i*100 + j)
          answer = [i*100 + j, j]
print(*answer)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
max_sugar = E / (100 + E)
res = 0 
ans = [0, 0]
for a in range(F // 100*A + 1): 
        for b in range(F // 100*B + 1): 
                for c in range(int(F * max_sugar) // C + 1):
                        for d in range(int(F * max_sugar) // D + 1): 
                                mass = 100*A*a + 100*B*b + C*c + D*d 
                                sugar = C*c + D*d 
                                if 0 < mass <= F and sugar / mass <= max_sugar:
                                        if res <= sugar / mass:
                                                res = sugar / mass 
                                                ans = [mass, sugar]
                                else:
                                        break
print(str(ans[0]) + " " + str(ans[1]))

Solution (Python):
import math
a,b,c,d,e,f = map(int,input().split())
max_nodo = e/(e+100)
answer = {}
for i in range(31):
  for j in range(31):
    water = 100*a*i + 100*b*j
    max_sugar = water*e/100
    sugar_range = int(math.ceil(max_sugar/c))
    if water >= f:
      break
    for k in range(sugar_range):
      for l in range(sugar_range):
        sugar = c*k + d*l
        total = water + sugar
        nodo = sugar / total
        if total > f:
          break
        if sugar > max_sugar:
          break
        answer[nodo] = [total,sugar]
ans = max(answer.items(),key = lambda x:x[0])[1]


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

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time

def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase


input=lambda: sys.stdin.readline().rstrip()

show_flg=False


A,B,C,D,E,F=LI()

m=0
ans=(A*100,0)
for a in range(31):
    for b in range(16):
        for c in range(101):
            for d in range(101):
                if a*A*100+b*B*100+c*C+d*D<=F and (a*A+b*B)*E>=c*C+d*D and a+b>0:
                    if m<(c*C+d*D)/(a*A+b*B):
                        m=(c*C+d*D)/(a*A+b*B)
                        ans=(100*(a*A+b*B)+c*C+d*D,c*C+d*D)

print(*ans)

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
d=0
ans=(100*A,0)
for x in range(F//(100*A)+1):
    for y in range((F-x*100*A)//(100*B)+1):
        if x+y==0:
            continue
        for z in range((F-x*100*A-y*100*B)//C+1):
            for w in range((F-x*100*A-y*100*B-z*C)//D+1):                
                if (x*A+y*B)*E>=(z*C+w*D) and d<100*(z*C+w*D)/(100*(x*A+y*B)+(z*C+w*D)):                    
                    d=100*(z*C+w*D)/(100*(x*A+y*B)+(z*C+w*D))
                    
                    
                    ans=(100*(x*A+y*B)+(z*C+w*D),(z*C+w*D))

print(*ans)

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

def func(ans1,sugar):
    if sugar == 0:
        return 0
    else:
        ans = sugar * 100 / ans1
        return ans

sugar = 0
ans1 = 100 * a
max_a = f // (a * 100)


for i in range(1, max_a + 1):
    max_b = (f - 100 * i * a) // (100 * b)
    
    for j in range(max_b +1):
        water = 100 * a * i + 100 * b * j
        
        max_sugar = (a * i + b * j) * e
        
        if water + max_sugar <= f:
            max_c = max_sugar // c
            for k in range(max_c + 1):
                max_d = (max_sugar - k * c) // d
                if func(ans1, sugar) < func(water + (k * c + max_d * d) , (k * c + max_d * d)):
                    sugar = (k * c + max_d * d)
                    ans1 = water + sugar
        
        else:
            max_sugar = f - water
            min_sugar = c
            if min_sugar <= e:
                for k in range(e // min_sugar + 1):
                    max_d = (max_sugar - k * c) // d
                    if func(ans1, sugar) < func(water + (k * c + max_d * d), (k * c + max_d * d)):
                        sugar = (k * c + max_d * d)
                        ans1 = water + sugar

print(ans1,sugar)

Solution (Python):
from bisect import bisect_right
a, b, c, d, e, f = map(int, input().split())
suger = [0] * ((f // c + 1) * (f // d + 1))
idx = 0
for i in range(f // c + 1):
    for j in range(f // d + 1):
        suger[idx] = c * i + d * j
        idx += 1
suger.sort()
ans1, ans2 = 0, 0
ma = -1
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        w = a * i + b * j
        if f < 100 * w:
            continue
        s = suger[bisect_right(suger, min(w * e, f - 100 * w)) - 1]
        if w != 0 and ma < s / (100 * w + s):
            ma = s / (100 * w + s)
            ans1 = w
            ans2 = s
print(ans1 * 100 + ans2, ans2)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def solve():
    a, b, c, d, e, f = LI()
    lis = []
    for i in range(f //c + 1):
        for k in range(f // d + 1):
            lis.append(c * i + d * k)
    lis = list(set(lis))
    lis.sort()
    ans = [100 * a, 0]
    for i in range(f // 100 + 1):
        for k in range(f // 100 + 1):
            if i == k == 0:
                continue
            water = a * i + b * k
            if water * 100 > f:
                continue
            E = min(f - water * 100, water * e)
            if E <= 0:
                continue
            aa = bisect_right(lis, E) - 1
            if aa == -1:
                continue
            aa = lis[aa]
            if ans[1] / ans[0] < aa / (water * 100 + aa):
                ans = [water * 100 + aa, aa]
    print(*ans)

    return



if __name__ == '__main__':
    solve()

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

mxdensity=e/(100+e)
mxinput=f
templ=[]


newdensity=0
newl=[100*a,0]
for i in range(31):
  for j in range(31):
    for k in range(101):
      for l in range(101):
        water=100*a*i+100*b*j
        sugar=c*k+d*l
        total=water+sugar
        if water==0 or (water+sugar)==0:
          break
        if total>mxinput:
          break
        if (sugar/total)<=mxdensity:
          
          tempdensity=sugar/total
          if tempdensity>newdensity:
            newdensity=tempdensity
            newl=[water,sugar]

print("{0} {1}".format(sum(newl),newl[1]))

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b,c,d,e,f = nm()
L =[]
for aa in range(0,31):
    for bb in range(0,31):
        for cc in range(0,101):
            for dd in range(0,101):
                if 100*a<=100*a*aa+100*b*bb+c*cc+d*dd<=f:
                    L.append((aa,bb,cc,dd))

max_w = 0.0
idx = 10*7
for i,l in enumerate(L):
    
    water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    sugar = c*l[2]+d*l[3]
    if (100+e)*100*sugar<=(100*e)*water:
        
        if l[0]>0 or l[1]>0:
            t = (sugar/water)*100
            if t>=max_w:
                max_w=t
                idx = i

for i,l in enumerate(L):
    if i==idx:
        water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
        sugar = c*l[2]+d*l[3]
        print(water,sugar)
        exit()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, D, E, F):
    ans = 0
    w = set()
    for i in range(F//A + 1):
        for j in range(F//B + 1):
            m = 100*(i*A + j*B)
            if m < F:
                w.add(m)
    mw = max(w)


    ms = (mw // 100) * E
    s = set()
    for i in range(ms+1):
        for j in range(ms+1):
            s.add(i*C + j*D)
    W = sorted(w)
    S = sorted(s)

    ans = (0, A*100, 0)
    for w in W:
        if w == 0:
            continue
        ts = w // 100 * E
        if F < ts + w:
            ts = F - w
        si = bisect.bisect_left(S, ts)
        if S[si] == ts:
            s = ts
        else:
            if si == 0:
                continue
            s = S[si-1]
        if s + w <= F and  s / w > ans[0]:
            ans = (s/w, w + s, s)
    return ' '.join(map(str, ans[1:]))


def main():
    A, B, C, D, E, F = read_int_n()
    print(slv(A, B, C, D, E, F))


if __name__ == '__main__':
    main()

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
water = []
suger = []
import math
for p in range(0, math.floor(f / (100 * a)) + 1) :
    for q in range(0, math.floor(f / (b * 100)) + 1) :
        if p * 100 * a + q * 100 * b <= f:
            water += [p * 100 * a + q * 100 * b]
for p in range(0, math.floor(f / c) + 1) :
    for q in range(0, math.floor(f / d) + 1) :
        if  p * c + q * d <= f :
            suger += [p * c + q * d]
water = sorted(list(set(water)))[1:]
suger = sorted(list(set(suger)))
c = []
for w in water :
    for s in suger :
        if w + s <= f:    
            if s / w <= e /100 :
                c += [[w, s, w + s]]
c = sorted(c, key = lambda x : x[1] / x[2],reverse=True)
print(c[0][2], c[0][1])

Solution (Python):
A, B, C, D, E, F = [int(i) for i in input().split()]

max_sugar = 0
max_water = 100 * A
max_conc = 0.0
A_limit = F // (100 * A)
for i in range(A_limit + 1):
    B_limit = (F - 100 * A * i) // (100 * B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        water_rate = A * i + B * j
        sugar_limit = min(E * water_rate, F - 100 * water_rate)

        sugar = 0
        for c in range(sugar_limit // C + 1):
            d = (sugar_limit - c * C) // D
            temp_sugar = c * C + d * D
            sugar = max(sugar, temp_sugar)
        temp_cons = sugar / (sugar + 100 * water_rate)
        if temp_cons > max_conc:
            max_conc = temp_cons
            max_water = 100 * water_rate
            max_sugar = sugar
print("{} {}".format(max_water + max_sugar, max_sugar))

Solution (Python):
A, B, C, D, E, F = [int(i) for i in input().split()]

max_sugar = 0
max_water = 100 * A
max_conc = 0.0
A_limit = F // (100 * A)
for i in range(A_limit + 1):
    B_limit = (F - 100 * A * i) // (100 * B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A * i + B * j), F - 100 * (A * i + B * j))

        sugar = 0
        for c in range(sugar_limit // C + 1):
            d = (sugar_limit - c * C) // D
            temp_sugar = c * C + d * D
            sugar = max(sugar, temp_sugar)
        temp_cons = sugar / (sugar + 100 * (A * i + B * j))
        if temp_cons > max_conc:
            max_conc = temp_cons
            max_water = 100 * (A * i + B * j)
            max_sugar = sugar
print("{} {}".format(max_water + max_sugar, max_sugar))

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

ans = [0, 0]
max_conc = -1
for a in range(F // 100 + 1):
    left = F - 100 * a * A
    for b in range(left // 100 + 1):
        w = 100 * a * A + 100 * b * B

        s_max = min(F - w, w * E // 100)
        if s_max >= 0:
            for c in range(s_max // C + 1):
                d = (s_max - c * C) // D

                if d >= 0:
                    
                    s = c * C + d * D
                    if s + w > 0:
                        conc = s / (s + w)
                        if conc > max_conc:
                            ans = [s, w]
                            max_conc = conc


print(str(ans[0] + ans[1]) + ' ' + str(ans[0]))

Solution (Python):

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    a, b, c, d, e, f = MI()
    max_sw = a*100
    max_s = 0
    for an in range(f // (100 * a) + 1):
        for bn in range((f - 100 * a * an) // (100 * b) + 1):
            w = a * an + b * bn
            if w == 0: continue
            if 100 * w > f: break
            for cn in range(f):
                dn = (min(w * e, f - 100 * w) - c * cn) // d
                if dn < 0: break
                
                s = c * cn + d * dn
                if s * max_sw > max_s * (s + w * 100):
                    max_sw = s + 100 * w
                    max_s = s
    print(max_sw, max_s)

main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

def main():
    ans_sw=100*a
    ans_s=0
    for an in range(f+1):
        if a*an*100>f:break
        for bn in range(f+1):
            w=an*a+bn*b
            if w*100>f:break
            lim=min(w*e,f-w*100)
            for cn in range(f+1):
                dn=(lim-c*cn)//d
                if dn<0:break
                s=c*cn+d*dn
                if s*ans_sw>ans_s*(s+100*w):
                    ans_sw=s+100*w
                    ans_s=s
    print(ans_sw,ans_s)

main()

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

Water = []
for i in range(0, f // (a * 100) + 1):
  for j in range(0, f // (b * 100) + 1):
    if (i * a + j * b) * 100 <= f:
      Water.append((i * a + j * b) * 100)


import math
Solt = []
for i in range(0, math.ceil((f * e / 100) / c) + 1):
  for j in range(0, math.ceil((f * e / 100) / d) + 1):
    if i * c + j * d <= (f * e / 100):
      Solt.append(i * c + j * d)


max_cnc = 0
champ_w = 0
champ_s = 0
from itertools import product 
for pair in product(list(set(Water[1:])), list(set(Solt))):

  vol = pair[0] + pair[1]
  if vol > f:
    continue
  if pair[1] * 100 / pair[0] > e:
    continue
  cnc = pair[1] * 100 / (pair[0] + pair[1])

  max_cnc = max(cnc, max_cnc)
  if cnc == max_cnc:
    champ_w = pair[0]
    champ_s = pair[1]
print(champ_w + champ_s, champ_s)

Solution (Python):
import sys
import math
a, b, c, d, e, f = [int(i) for i in sys.stdin.readline().split()]
max_sugar = 0
max_sum = min(a, b) * 100
max_noudo = 0
for _a in range(f // a):
    max_b = math.floor((f - _a * a * 100) / b) + 1
    for _b in range(max_b):
        water = (_a * a + _b * b) * 100
        max_c = math.floor(min(f - water, (_a * a + b * _b) * e) / c) + 1
        for _c in range(max_c):
            _d = max(0, min((f - water - _c * c) // d, ((_a * a + _b * b) * e - _c * c) // d))
            if _c + _d == 0:
                continue
            if (_a * a + _b * b) * 100 + _c * c + _d * d > f:
                continue
            noudo = (c * _c + d * _d) / ((_a*a + _b*b) * 100)
            if noudo > e / 100:
                continue
            elif noudo > max_noudo:
                max_sugar = _c * c + _d * d
                max_sum = (_a*a + _b*b) * 100 + max_sugar
                max_noudo = noudo
print(max_sum, max_sugar)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,c,d,e,f=map(int,input().split())
    Water=set()
    Sugar=set()
    for i in range(30):
        for j in range(30):
            w=100*i*a+100*j*b
            if(w>f): break
            Water.add(w)
    Water.remove(0)

    for i in range(b):
        for j in range(1500):
            s=i*c+j*d
            if(s*(100+e)>f*e): break
            Sugar.add(s)

    from itertools import product
    SW=list(product(Water,Sugar))
    SW.sort(lambda x:x[1]/(x[0]+x[1]), reverse=1)
    for w,s in SW:
        if(s+w<=f and s*(100+e)<=e*(s+w)):
            print(s+w,s)
            return
resolve()

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

CONCENT_LIMIT = E/(100+E)
max_concent = 0
water_at_max = 0
sugar_at_max = 0
for num_b in range(F//(100*B)+1):
    
    rest_cap = F - num_b*B*100
    if rest_cap < 0:
        break
        
    for num_a in range(rest_cap//(100*A)+1):
        
        rest_cap_ = rest_cap - num_a*A*100
        water = num_b*B*100+num_a*A*100
        if rest_cap_ <= 0:
            break
        if water == 0:
            continue
            
        for num_d in range(rest_cap_//D+1):
            
            rest_cap__ = rest_cap_ - num_d*D
            if rest_cap__ < 0:
                break
                
            for num_c in range(rest_cap__//C+1):
                
                sugar = num_d*D+num_c*C
                if water+sugar > F:
                    break
                concent = sugar / (water+sugar)

                if (concent <= CONCENT_LIMIT) & (concent >= max_concent):
                    max_concent = concent
                    sugar_at_max = sugar
                    water_at_max = water
                
print(water_at_max+sugar_at_max, end=" ")
print(sugar_at_max)