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


sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush


sys.setrecursionlimit(10 ** 7)
import math








INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())


def run():
    A, B, C, D, E, F = mapline()
    aa = 100 * A
    bb = 100 * B
    max_con = 0
    ans = (100 * A, 0)
    for x in range(0, F // aa + 1):
        ylim = (F - aa * x) // bb
        for y in range(0, ylim + 1):
            tot = aa * x + bb * y
            if not tot:continue
            slim = E * (x * A + y * B)
            
            for w in range(0, slim // C + 1):
                vlim = (slim - w * C) // D
                for v in range(0, vlim + 1):
                    sug = C * w + D * v
                    
                    if tot + sug <= F:
                        _con = sug / (tot + sug)
                        if max_con < _con:
                            max_con = _con
                            ans = (tot + sug, sug)
    print(f'{ans[0]} {ans[1]}')


if __name__ == "__main__":
    run()

Solution (Python):

import sys


sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush


sys.setrecursionlimit(10 ** 7)
import math








INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())


def run():
    A, B, C, D, E, F = mapline()
    aa = 100 * A
    bb = 100 * B
    max_con = 0
    ans = (100 * A, 0)
    for x in range(0, F // aa + 1):
        ylim = (F - aa * x) // bb
        for y in range(0, ylim + 1):
            tot = aa * x + bb * y
            if not tot:continue
            slim = E * (x * A + y * B)
            
            for w in range(0, slim // C + 1):
                vlim = (slim - w * C) // D
                for v in range(0, vlim + 1):
                    sug = C * w + D * v
                    
                    if tot + sug <= F:
                        _con = sug / (tot + sug)
                        if max_con < _con:
                            max_con = _con
                            ans = (tot + sug, sug)
    print(f'{ans[0]} {ans[1]}')


if __name__ == "__main__":
    run()

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

ans = [0, 0]
maxno = 0

a = 0
while True:
    aaa = 100*A*a
    if aaa > F:
        break

    b = 0
    while True:
        bbb = aaa+100*B*b
        if bbb > F:
            break
        
        c = 0
        while True:
            if not bbb:
                break
            ccc = C*c
            if ccc > F:
                break

            d = 0
            while True:
                ddd = ccc+D*d
                if bbb+ddd > F:
                    break

                if ddd/bbb > E/100:
                    break

                no = ddd / (bbb+ddd)

                if no >= maxno:
                    ans = [bbb+ddd, ddd]
                    maxno = no
                
                d += 1
            c += 1
        b += 1
    a += 1

print(*ans)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
w=set()
for i in range(0,f,100*a):
    for j in range(0,f,100*b):
        if i+j<=f:
            w.add(i+j)
        else:
            break
s=set()
for i in range(0,f,c):
    for j in range(0,f,d):
        if i+j<=f:
            s.add(i+j)
        else:
            break
n=100*a
m=0
l=0
for x in w:
    for t in s:
        if x+t!=0 and x+t<=f and 100*t<=e*x and t/(x+t)>l:
            n=x+t
            m=t
            l=t/(x+t)
print(n,m)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
water = [False for _ in range(31)]
water[0] = True
for g in [a, b]:
    for i in range(31):
        if i - g < 0:
            continue
        elif water[i - g]:
            water[i] = True
            
salt = [False for _ in range(3001)]
salt[0] = True
for g in [c, d]:
    for i in range(3001):
        if i - g < 0:
            continue
        elif salt[i - g]:
            salt[i] = True

water_cand = []
for i, tf in enumerate(water):
    if tf:
        water_cand.append(i * 100)
salt_cand = []
for i, tf in enumerate(salt):
    if tf:
        salt_cand.append(i)
        
ans = [0, 0]
max_ratio = -1
for w in water_cand:
    if w == 0:
        continue
    for s in salt_cand:
        if w + s > f:
            break
        if w // 100 * e < s:
            break
        ratio = 100 * s / (w + s)
        if max_ratio < ratio:
            max_ratio = ratio
            ans = [w + s, s]
print(*ans)

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

per = 0.0
ans = salt = w = s = 0
for i in range(0, f + 1, 100 * a):
    for j in range(0, f + 1, 100 * b):
        w = i + j
        if w > f: break
        for k in range(0, f + 1, c):
            if w + k > f: break
            for l in range(0, f + 1, d):
                w = i + j
                s = k + l
                if w + s > f: break
                if s <= (w // 100) * e:
                    if 0 < s + w <= f:
                        if per < s / (s + w):
                            per = s / (s + w)
                            ans = w + s
                            salt = s
if ans == 0:
    print(100*a,0)
else:
    print(ans,salt)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b,c,d,e,f = i_map()
    W = set()
    for i in range(0,f+1,a*100):
        for j in range(0,f+1, b*100):
            W.add(i+j)

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

    rate = -1

    for w in W:
        for s in S:
            if 0 < w+s <= f and s <= w*e//100:
                if s/(w+s) > rate:
                    rate = s/(w+s)
                    ans = (w+s,s)
    print(ans[0], ans[1])





if __name__=="__main__":
    main()

Solution (Python):
def main():
    a,b,c,d,e,f = map(int,input().split())
    ans = []
    for i in range(f//a//100+1):
        for j in range((f-100*a*i)//b//100+1):
            if a*i*100+b*j*100 < f:
                ans.append([i,j])
    ans = ans[1:]
    D = 0
    A = [0,0]
    for an in ans:
        m = a*100*an[0] + b*100*an[1]
        slv = e*m//100
        M = 0
        for i in range(min(f-m,slv)//c+1):
            for j in range((min(f-m,slv)-c*i)//d+1):
                if i*c+d*j <= min(slv,f-m):
                    if M < i*c+d*j:
                        M = i*c+d*j
        den = M/(m+M)
        if den>=D:
            D = den
            A = [m+M,M]
    print(' '.join([str(a) for a in A]))

if __name__ == "__main__":
    main()

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

water = []
for i in range(30):
    for j in range(30):
        x = 100*a*i + 100*b*j
        if x <= f:
            water.append(x)

sugar = []
for i in range(3001):
    for j in range(3001):
        y = c*i + d*j
        if y <= f:
            sugar.append(y)


ans = []
for x in water:
    if x == 0:
        continue
    for y in sugar:
        if x + y > f:
            continue
        if (x//100)*e < y:
            continue
        noudo = 100*y / (x+y)
        all_weight = x + y
        sugar_weight = y
        ans.append([noudo, all_weight, sugar_weight])

ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])

Solution (Python):
from itertools import product
from collections import namedtuple
A, B, C, D, E, F = map(int, input().split())

r100 = lambda x: range(F//(100*x)+1)
cct = 0
sw = namedtuple('sw', ['suger', 'water']) 
ans = sw(0, A*100)
for a, b in product(r100(A), r100(B)):
    water = (a * A + b * B) * 100
    if water > F or water == 0:
        continue
    r = lambda x: range((F-water)//x+1)
    for c, d in product(r(C), r(D)):
        suger = c * C + d * D
        if  water + suger > F:
            continue

        if suger * 100 > water * E:
            continue
        
        if water+suger == 0:
            continue

        if cct < 100 * suger/(suger+water):
            cct = 100 * suger/(suger+water)
            ans = sw(suger, water)

print(ans.suger+ans.water, ans.suger)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
w = []
s = []
i = 0
while 100*a*i <= f:
  j = 0
  while 100*a*i + 100*b*j <= f:
    w.append(100*a*i+100*b*j)
    j += 1
  i += 1
i = 0
while c*i <= f:
  j = 0
  while c*i + d*j <= f:
    s.append(c*i+d*j)
    j += 1
  i += 1
mx = -1
mxw = 0
mxs = 0
for wi in w:
  for si in s:
    if wi + si <= f and 100*si <= wi*e:
      if si > mx*wi:
        mx = si/wi
        mxw = wi
        mxs = si
print(mxs+mxw,mxs)

Solution (Python):
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        
        maxsugar = water * e // 100
        for ct in range(0, maxsugar//c + 1):
            for dt in range(0, (maxsugar-ct*c)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Solution (Python):
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar)//c + 1):
            for dt in range(0, (maxsugar-ct*c)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Solution (Python):
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Solution (Python):
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar+1)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Solution (Python):
from decimal import Decimal
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar+1)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    
                    n = Decimal(100 * sugar / water)
                    if n == Decimal(e):
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
perc = 0.0
ans = [0, 0]
op = [0, 0, 0, 0]
a = 0
while 100 * a <= F:
  b = 0
  while 100 * (a + b) <= F:
    c = 0
    while 100 * (a + b) + c <= F:
      if c > (a + b) * E:
        break
      d = 0
      while 100 * (a + b) + c + d <= F:
        if c + d > (a + b) * E:
          break
        if a == b == c == d == 0:
          break
        p = (c + d) * 1.0 / (100 * (a + b) + c + d)
        if p >= perc:
          perc = p
          ans = [100 * (a + b) + c + d, c + d]
          op = [a, b, c, d]
        d += D
      c += C
    b += B
  a += A
print(str(ans[0]) + " " + str(ans[1]))

Solution (Python):
def main():
    A, B, C, D, E, F = map(int, input().split())
    ans = -1
    sugar = 0
    sugar_water = 0
    for a in range(F // (A * 100) + 1):
        for b in range((F - 100 * A * a) // (B * 100) + 1):
            for c in range((F - 100 * A * a - 100 * B * b) // C + 1):
                for d in range((F - 100 * A * a - 100 * B * b - C * c) // D + 1):
                    x = a * A + b * B
                    y = c * C + d * D
                    if x == 0:
                        continue
                    if x * E >= y and ans < (100 * y)/(x*100+y):
                        ans = (100 * y)/(x*100+y)
                        sugar = y
                        sugar_water = 100 * x + y
    print(sugar_water,sugar)

if __name__ == "__main__":
    main()

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
noudo=0
water=[]
for i in range(31):
  for j in range(31):
    w=100*A*i+100*B*j
    if w<=F and w!=0:
      water.append(w)
sugar=[]
for i in range(F//C+1):
  for j in range(F//D+1):
    w=C*i+D*j
    if w<=F:
      sugar.append(w)
ans1=0
ans2=0
for i in range(len(water)):
  for j in range(len(sugar)):
    if water[i]+sugar[j]<=F:
      if sugar[j]/water[i]<=E/100:
        if noudo<sugar[j]/water[i]:
          ans1=sugar[j]+water[i]
          ans2=sugar[j]
          noudo=sugar[j]/water[i]
if ans2==0:
  print(water[0],0)
else:
  print(ans1,ans2)

Solution (Python):
from math import gcd
a,b,c,d,e,f=map(int,input().split())
g=gcd(a,b)
a=a//g
b=b//g
G=gcd(c,d)
c=c//G
d=d//G
axby=[0]*1000
czdw=[0]*1000
for x in range(100):
    for y in range(100):
        if a*x+b*y<(a-1)*(b-1):
            axby[a*x+b*y]=1
for z in range(100):
    for w in range(100):
        if c*z+d*w<(c-1)*(d-1):
            czdw[c*z+d*w]=1
A=[]
C=[]
for i in range(1000):
    if axby[i]==1:
        A.append(i)
for i in range(1000):
    if czdw[i]==1:
        C.append(i)
i=(a-1)*(b-1)
while i<=(f//(100*g))+5:
    A.append(i)
    i+=1
j=(c-1)*(d-1)
while j<=(f//G)+5:
    C.append(j)
    j+=1
n=len(A)
m=len(C)
dis=0
ans=[0,0]
for i in range(n):
    for j in range(m):
        if 100*g*A[i]+G*C[j]<=f and G*C[j]<=e*g*A[i] and not(A[i]==C[j]==0):
            if dis<=(100*G*C[j])/(100*g*A[i]+G*C[j]):
                dis=(100*G*C[j])/(100*g*A[i]+G*C[j])
                ans[0],ans[1]=A[i],C[j]
print(100*g*ans[0]+G*ans[1],G*ans[1])

Solution (Python):
"""
a, b, c, d, e, f = map(int, input().split())
ans = [pow(10, 9), 1]
a *= 100
b *= 100
for w1 in range(31):
    for w2 in range(31):
        water = w1 * a + w2 * b
        if water > f or water == 0:
            continue
        for s1 in range(min(water, 3000 - water)):
            for s2 in range(min(water, 3000 - water)):
                sugar = s1 * c + s2 * d
                if water + sugar > f or e / 100 < sugar / water:
                    break
                if ans[1] / ans[0] <= sugar / (water + sugar):
                    ans = [water + sugar, sugar]
print(ans[0], ans[1])
"""


a, b, c, d, e, f = map(int, input().split())
sugar = [0] * (f + 5)
for i in range(f + 1):
    if i * c > f:
        break
    for j in range(f + 1):
        if i * c + j * d > f:
            break
        sugar[i * c + j * d] = 1
water = [0] * (f // 100 + 5)
for i in range(f // 100 + 1):
    if i * a > f // 100:
        break
    for j in range(f // 100 + 1):
        if i * a + j * b > f // 100:
            break
        water[i * a + j * b] = 1
m = 0
ans1, ans2 = a * 100, 0
for i in range(1, f // 100 + 1):
    if water[i] == 0:
        continue
    t = 0
    for j in range(i * e, 0, -1):
        if sugar[j] == 1:
            if 100 * i + j <= f and m <= 100 * j / (i + j):
                ans1, ans2 = 100 * i + j, j
                m = 100 * j / (i + j)
                t = 1
        if t == 1:
            break
print(ans1, ans2)

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

nou = [0,100*A]
for a in range(31):
    for b in range(31):
        for c in range(3001):
            if a==0 and b==0:
                continue
            if F<(100*A*a+100*B*b+C*c):
                continue
            if E*(A*a+B*b)<C*c:
                continue
            
            d = max(0, (F-(100*A*a+100*B*b+C*c))//D)
            d = min(d,(E*(A*a+B*b)-C*c)//D)

            if nou[0]*((100*A*a+100*B*b)+(C*c+D*d)) < (C*c+D*d)*nou[1]:
                nou = [C*c+D*d,((100*A*a+100*B*b)+(C*c+D*d)),a,b,c,d]

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

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

water = [False] * (f//100 + 1)
for i in range(0, len(water), a):
    water[i] = True
for i in range(len(water) - b):
    if water[i]:
        water[i + b] = True

sugar = [False] * ((f//100) * e + 1)
for i in range(0, len(sugar), c):
    sugar[i] = True
for i in range(len(sugar) - d):
    if sugar[i]:
        sugar[i + d] = True


deno = a * 100
nume = 0

for i in range(1, len(water)):
    if water[i]:
        j = min([i*e, f - 100*i])
        while not sugar[j]:
            j -= 1
        i = 100 * i + j

        if nume * i < deno * j:
            deno = i
            nume = j

print(deno, nume)

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

water = [False] * (f//100 + 1)
for i in range(0, len(water), a):
    water[i] = True
for i in range(len(water) - b):
    if water[i]:
        water[i + b] = True

sugar = [False] * ((f//100) * e + 1)
for i in range(0, len(sugar), c):
    sugar[i] = True
for i in range(len(sugar) - d):
    if sugar[i]:
        sugar[i + d] = True


deno = a * 100
nume = 0

for i in range(1, len(water)):
    if water[i]:
        j = min([i*e, f - 100*i])
        while not sugar[j]:
            j -= 1
        i = 100 * i + j

        if nume * i < deno * j:
            deno = i
            nume = j

print(deno, nume)

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

def reduce(x): 
  
  d = math.gcd(x[0], x[1])
  return (x[0] // d, x[1] // d)

def is_valid(s, w): 
  return s <= w * E and s + 100*w <= F

ratios = set()
recipe = {}

Waters = [] 
for a in range(0, w_max+1, A):
  for b in range(0, w_max+1, B):
    if (a == 0 and b == 0) or a + b > F:
      continue
    Waters.append(a+b)
Waters.sort()

s_max = 0
for x in Waters:
  s_max = max(s_max, min(x*E,F-100*x))

Sugars = [] 
for c in range(0, s_max+1, C):
  for d in range(0, s_max+1, D):
    Sugars.append(c+d)
Sugars.sort()

i = 0
ascend = True
for w in Waters:
  while i >= 0 and not is_valid(Sugars[i], w):
    i -= 1
  while 0 <= i < len(Sugars) and is_valid(Sugars[i], w):
    i += 1
  i -= 1
  if i >= 0:
    ratios.add(reduce((Sugars[i], w)))
    recipe[reduce((Sugars[i], w))] = (Sugars[i], w)

ans = recipe[max(ratios, key = lambda x: float(x[0]/x[1]))]
print(ans[1]*100 + ans[0], ans[0])

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

best_dense = -float("inf")
for a in range(31):
    for b in range(31):
        for c in range(1501):
            for d in range(1501):
                w_sum = 100 * A * a + 100 * B * b
                s_sum = C * c + D * d
                sum = w_sum + s_sum
                if sum > F: break
                if w_sum == 0: break
                if E * (w_sum / 100) < s_sum: break
                dense = s_sum / sum
                if dense > best_dense:
                    best_dense = dense
                    ans_sum = sum
                    ans_s_sum = s_sum
print(ans_sum, ans_s_sum)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
max_a = int(3000 / (100 * A))
max_b = int(3000 / (100 * B))
max_c = int(3000 / C)
max_d = int(3000 / D)
max_dens = 0
max_sugar = 0
max_sugar_water = 0
for i in range(max_a + 1):
  water_A = 100 * A * i
  if water_A > F:
    break
  for j in range(max_b + 1):
    water = 100 * B * j + water_A
    if water > F:
      break
    max_solvable_sugar = E * water
    for s in range(max_c + 1):
      sugar_C = C * s
      if sugar_C * 100 > max_solvable_sugar:
        break
      for t in range(max_d + 1):
        sugar = D * t + sugar_C
        if sugar * 100 > max_solvable_sugar:
          break
        sugar_water = water + sugar
        if sugar_water > F or sugar_water == 0:
          break
        dens = 100 * sugar / sugar_water
        if dens >= max_dens:
          max_dens = dens
          max_sugar = sugar
          max_sugar_water = sugar_water
print("{} {}".format(max_sugar_water, max_sugar))

Solution (Python):
from itertools import product
A,B,C,D,E,F=map(int, input().split())
ans = -float("inf")
mass = 0
sugarr = 0
for s, t in product(range(0, 31), repeat=2):
    water = 100*(A*s+B*t)
    if water > F or water == 0:
        continue
    up = min(F-water, E*(A*s+B*t))
    for u in range(0, up+1):
        if C*u > up:
            continue
        v = int((up-C*u)/D)
        if v < 0:
            continue
        sugar = C*u+D*v
        cons = sugar/(water+sugar)
        if cons > ans:
            ans = cons
            mass = water + sugar
            sugarr = sugar
print(mass, sugarr)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
dins = -1
suger = 0
ans = 0

for i in range(f//(a*100)+1):
  for j in range(f//(b*100)+1):
    if 100*(i*a+j*b)>f:
      continue
    else:
      water = 100*(i*a+j*b) 
      maxsuger = e*(i*a+j*b)
      for k in range(maxsuger//c+1):
        for l in range(maxsuger//d+1):
          su = k*c+l*d
          if su>maxsuger or (water+su)>f:
            continue
          else:
            if (water+su) != 0:
                nowd = (su/(water+su))*100
                if nowd>dins:
                  suger = su
                  ans = (water+su)
                  dins = nowd
print(ans,suger)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
dins = -1
suger = 0
ans = 0

for i in range(f//(a*100)+1):
  for j in range(f//(b*100)+1):
    if 100*(i*a+j*b)>f:
      continue
    else:
      water = 100*(i*a+j*b) 
      maxsuger = e*(i*a+j*b)
      for k in range(maxsuger//c+1):
        for l in range(maxsuger//d+1):
          su = k*c+l*d
          if su>maxsuger or (water+su)>f:
            continue
          else:
            if (water+su) != 0:
                nowd = (su/(water+su))*100
                if nowd>dins:
                  suger = su
                  ans = (water+su)
                  dins = nowd
print(ans,suger)

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

wa=[]
su=[]
for i in range(1,31):
  for j in range(0,31):
    x=i-j*a
    if x>=0:
      if x%b==0:
        wa.append(i*100)
        
for p in range(1,3001):
  for q in range(0,3001):
    y=p-q*c
    if y>=0:
      if y%d==0:
        su.append(p)
        
wa1=list(set(wa))
su1=list(set(su))

ans=0
ans1=[]
for r in wa1:
  for t in su1:
    if r+t<=f and t/r <= e/100:
      if t/(r+t)>=ans:
        ans=t/(r+t)
        ans1.append([r,t])
        
if len(ans1)==0:
  print(str(wa[0])+' '+str(0))
else:
  W=ans1[-1][0]
  S=ans1[-1][1]
  print(str(W+S)+' '+str(S))

Solution (Python):
def solve():
    max_density = -1
    ans = [-1, -1]
    A, B, C, D, E, F = map(int, input().split())
    for a in range(0, F + 1, A * 100):
        for b in range(0, F - a + 1, B * 100):
            w = a + b
            if w == 0:
                continue
            max_s = min(F - w, w // 100 * E)
            for c in range(0, max_s + 1, C):
                for d in range(0, max_s - c + 1, D):
                    s = c + d
                    density = 100 * s / (w + s)
                    if density > max_density:
                        ans = [w + s, s]
                        max_density = density
    return ans


print(*solve())

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
s = set()
for i in range(30 // a + 1):
    for j in range(30 // b + 1):
        if 0 < (a * i + b * j) * 100 <= f:
            s = s | {a * i + b * j}
s2 = set()
for i in range(3000 // c + 1):
    for j in range(3000 // d + 1):
        if c * i + d * j <= f:
            s2 = s2 | {c * i + d * j}
ans = []
for i in s:
    for j in s2:
        if i * 100 + j <= f and j <= i * e:
            ans.append([j / i * -1, i * 100 + j, j])
ans.sort()
print(ans[0][1], ans[0][2])

Solution (Python):

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A,B,C,D,E,F = map(int, readline().split())
ans = (100*A,0)
max_con = 0

for a in range(31):
    for b in range(31):
        for c in range(50):
            for d in range(50):
                W = a * 100 * A + b * 100 * B
                S = c*C + d*D
                SW = S + W 
                e = W // 100
                if F < SW or SW == 0:
                    continue
                if e * E < S:
                    continue
                tmp = 100 * S / SW
                if tmp > max_con:
                    max_con = tmp
                    ans = (SW,S)
print(' '.join(str(a) for a in ans))

Solution (Python):
from math import gcd

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

N = 0; max_SW = A*100; max_S = 0
f = F//100; a = f//A; b = f//B
cn = D // gcd(C, D)

for j in range(b+1): 
    for i in range(a+1): 
        if i==0 and j==0:
            continue
        elif A*i + B*j > f:
            continue
        w = (A*i + B*j) * 100 
        e = (A*i + B*j) * E 
        S = min(e, F-w) 
        s = 0
        for ci in range(min(S//C, cn)+1):
            s = max(s, S - (S - C*ci) % D)
        if s/(w+s) > N:
            N = s/(w+s)
            max_SW = s + w
            max_S = s

print(max_SW, max_S)

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

max_a=f//(100*a)
max_b=f//(100*b)
max_c=f//c
max_d=f//d


x_list=[]
for i in range(max_a+1):
   for j in range(max_b+1):
        
       x=100*a*i+100*b*j
       if 0<x<=f and x not in x_list:
           x_list.append(x)

       

y_list=[]
for i in range(max_c+1):
   for j in range(max_d+1):
        
       y=c*i+d*j
       if 0<=y<f and y not in y_list:
           y_list.append(y)


concentration_list=[]
sugar_water_list=[]
sugar_list=[]

for i in x_list:
   for j in y_list:
       if i+j<=f and j/i<=e/100:
           concentration=100*j/(i+j)
           concentration_list.append(concentration)
           sugar_water_list.append(i+j)
           sugar_list.append(j)
                   
sugar_index=concentration_list.index(max(concentration_list))
print(sugar_water_list[sugar_index],sugar_list[sugar_index])

Solution (Python):
import bisect, heapq

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

w = set()
temp = [a * i for i in range((30 - 1) // a + 2)]
for i in temp:
    while i not in w and i <= 30:
        w.add(i)
        i += b
w = list(w)
w.remove(0)
w.sort()

s = set()
temp = [c * i for i in range((3000 - 1) // c + 2)]
for i in temp:
    while i not in s and i <= 3000:
        s.add(i)
        i += d
s = list(s)
s.sort()

queue = []
heapq.heapify(queue)
for i in w:
    if i * 100 > f:
        continue
    num = bisect.bisect(s, i * e)
    for j in range(num - 1, -1, -1):
        if i * 100 + s[j] > f:
            continue
        heapq.heappush(queue, [-s[j] / i, 100 * i + s[j], s[j]])
        break
print(queue[0][1], queue[0][2])