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):
A,B,C,D,E,F = map(int,input().split())
Ans = [0,100*A,0]
def Con(water,sugar):
    return 100*(sugar)/(water+sugar)
def limit(water):
    return water*E//100
for NumA in range(1,F//(100*A)+2):
    for NumB in range(0,F//(100*B)+1):
        water = 100*(A*NumA+B*NumB)
        lim1 = limit(water)
        lim2 = F-water
        lim = min(lim1,lim2)
        for i in range(lim//D+1):
            sugar = D*i
            sugar += ((lim-sugar)//C)*C
            Con1 = Con(water,sugar)
            if Ans[0] < Con1:
                Ans = [Con1,water,sugar]
print(Ans[1]+Ans[2],Ans[2])

Solution (Python):
a,b,c,d,e,mv=map(int,input().split())
e= e/(e+100)

ans=-1
for i in range(31):
    if 100*i*a> mv: continue
    for j in range(31):
        if i+j==0:continue
        if 100*(i*a+j*b)> mv:continue
        for k in range(2801):
            if 100*(i*a+j*b)+k*c> mv:continue
            for l in range(2801):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= sugar/(water+sugar)
                
                if e>= pp and ans<pp:
                    
                    ans=pp
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

Solution (Python):
from math import floor
A, B, C, D, E, F = map(int, input().split())
P = []
for i in range(31):
    for j in range(31):
        W=A*i+B*j
        if 100*W>F: break
        for k in range(3001):
            l = floor(min(F-100*W-C*k,W*E-C*k)/D)
            S = C*k+D*l
            if l<0 or S+W==0: continue
            P.append((100*S/(W*100+S),(W*100+S,S)))
P.sort(key=lambda x:x[0])
print(*P[-1][1])

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

    waters = set()
    for i in range((30 + A - 1) // A + 1):
        for j in range((30 + B - 1) // B + 1):
            a = 100 * (i * A + j * B)
            if a > F or a == 0:
                continue
            waters.add(a)

    sugars = set()
    for k in range((3000 + C - 1) // C + 1):
        for l in range((3000 + D - 1) // D + 1):
            b = k * C + l * D
            if b > F:
                continue
            sugars.add(b)

    max_density = -1
    ans = [-1, -1]
    for w in waters:
        for s in sugars:
            if w + s > F or w // 100 * E < s:
                continue
            density = 100 * s / (w + s)
            if density > max_density:
                ans = [(w + s), s]
                max_density = density
    return ans


print(*solve())

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
a,b,c,d,e,f = ma()
la = f//(100*a)
lb = f//(100*b)
tmp = -1
ws = 0
s = 0
for ia in range(la+1):
    for ib in range(lb+1):
        water = ia*a*100 + ib*b*100
        if water>f or water==0:
            continue
        lc = (ia*a + ib*b)*e //c
        ld =(ia*a + ib*b)*e //d
        
        
        for ic in range(lc+1):
            for id in range(ld+1):


                suger = ic*c + id*d
                if suger >e*(ia*a+ib*b) or suger+water>f:
                    continue
                if tmp <(suger)/(water+suger):
                    tmp = (suger)/(water+suger)
                    ws = water+suger
                    s = suger
print(ws,s)

Solution (Python):
import bisect

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

dp_w = [0] * 31
dp_w[0] = 1
for w in [a,b]:
    for i in range(w,31):
        dp_w[i] |= dp_w[i-w]

water = []
for i in range(1,31):
    if(dp_w[i]==1):
        water.append(i*100)

dp_s = [0] * 1600
dp_s[0] = 1
for w in [c,d]:
    for i in range(w,1600):
        dp_s[i] |= dp_s[i-w]

sugar = []
for i in range(1600):
    if(dp_s[i]==1):
        sugar.append(i)

ans_w =water[0]
ans_s = 0

for wi in water:
    if(f < wi):
        continue
    max_s = min(wi//100 * e, f-wi)
    ind = bisect.bisect_right(sugar,max_s)
    if(ind==0):
        continue
    si = sugar[ind-1]

    if( (ans_w + ans_s) * si > (wi+si) * ans_s):
        ans_w = wi
        ans_s = si

print('{} {}'.format(ans_w+ans_s,ans_s))

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

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


ok = [0]*3001
for i in range(0,3001,c):
    ok[i] = 1

for i in range(3001):
    if ok[i] and i+d <= 3000:
        ok[i+d] = 1



ans = (0.0,100*a,0)

for x in range(31):
    for y in range(31):
        p = x*100*a + y*100*b
        if p==0: continue
        if p > f: break
        for q in range(min(f-p,e*p//100),-1,-1):
            if ok[q]:
                v = q/(p+q)
                if v > ans[0]:
                    ans = (v,p+q,q)
                break
        
print(*ans[1:])

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
dp=[0]*(f+1)
w=[]
s=[]
for i in range(f+1):
  if i%(a*100)==0:dp[i]=i
  if i%(b*100)==0:dp[i]=i
  if i>a*100 and dp[i-a*100]:dp[i]=i
  if i>a*100 and dp[i-b*100]:dp[i]=i
for i in dp:
  if i:w.append(i)
m=w[-1]*e//100+1
dp=[0]*(m)
for i in range(m):
  if i%c==0:dp[i]=i
  if i%d==0:dp[i]=i
  if i>c and dp[i-c]:dp[i]=i
  if i>d and dp[i-d]:dp[i]=i
for i in dp:
  if i: s.append(i)
g=0
ans=(w[0],0)
for i in w:
  for j in s:
    if i+j<=f and g<j/(i+j)<=e/(100+e):
      g=j/(i+j)
      ans=(i+j,j)
print(*ans)

Solution (Python):
from itertools import product
def main():
    a, b, c, d, e, f = list(map(int, input().split()))
    max_con = -1
    ans_w, ans_s = 0, 0
    W, S = [], []
    a *= 100
    b *= 100
    for i, j in product(range(f // a + 1), range(f // b + 1)):
        if (w := a * i + b * j) <= f:
            W.append(w)
    for i, j in product(range(f // c + 1), range(f // d + 1)):
        if (s := c * i + d * j) <= f:
            S.append(s)
    for w, s in product(W, S):
        if w == s == 0:
            continue
        if w * e >= 100 * s and (con := 100 * s / (w + s)) > max_con and w + s <= f:
            max_con = con
            ans_w, ans_s = w, s

    print(' '.join([str(ans_w + ans_s), str(ans_s)]))

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import bisect
    a, b, c, d, e, f = map(int, input().split())
    a = a * 100
    b = b * 100
    g = f * e // 100
    wtr = [0] * f
    sgr = [0] * g
    wtr[0] = 1
    sgr[0] = 1
    wtr_l = []
    sgr_l = []


    def comb(lmt, tgt, lis):
        for i in range(lmt - tgt):
            if lis[i] != 0:
                lis[i + tgt] = 1


    comb(f, a, wtr)
    comb(f, b, wtr)
    comb(g, c, sgr)
    comb(g, d, sgr)

    for i, w in enumerate(wtr):
        if i == 0:
            continue
        elif w == 1:
            wtr_l.append(i)

    for j, s in enumerate(sgr):
        if s == 1:
            sgr_l.append(j)

    res = -1
    ans = []
    for wt in wtr_l:
        pct = min(f - wt, wt * e // 100)
        sid = bisect.bisect_left(sgr_l, pct)
        if pct in sgr_l:
            sgr_max = sgr_l[sid]
        else:
            sgr_max = sgr_l[sid - 1]
        pct_max = 100 * sgr_max / (wt + sgr_max)
        if pct_max > res:
            res = pct_max
            ans.append((wt + sgr_max, sgr_max))
    print(*ans[-1])
if __name__ == '__main__':
    main()

Solution (Python):
import bisect
a, b, c, d, e, f = map(int, input().split())
a = a * 100
b = b * 100
g = f * e // 100
wtr = [0] * f
sgr = [0] * g
wtr[0] = 1
sgr[0] = 1
wtr_l = []
sgr_l = []


def comb(lmt, tgt, lis):
    for i in range(lmt - tgt):
        if lis[i] != 0:
            lis[i + tgt] = 1


comb(f, a, wtr)
comb(f, b, wtr)
comb(g, c, sgr)
comb(g, d, sgr)

for i, w in enumerate(wtr):
    if i == 0:
        continue
    elif w == 1:
        wtr_l.append(i)

for j, s in enumerate(sgr):
    if s == 1:
        sgr_l.append(j)

res = -1
ans = []
for wt in wtr_l:
    pct = min(f - wt, wt * e // 100)
    sid = bisect.bisect_left(sgr_l, pct)
    if pct in sgr_l:
        sgr_max = sgr_l[sid]
    else:
        sgr_max = sgr_l[sid - 1]
    pct_max = 100 * sgr_max / (wt + sgr_max)
    if pct_max > res:
        res = pct_max
        ans.append((wt + sgr_max, sgr_max))
print(*ans[-1])

Solution (Python):
from itertools import product

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

lima = [100 * a * i for i in range(f // (100 * a) + 1)]
limb = [100 * b * i for i in range(f // (100 * b) + 1)]
setw = set([i + j for i, j in product(lima, limb) if 0 < i + j <= f])
limc = [c * i for i in range(f // c + 1)]
limd = [d * i for i in range(f // d + 1)]
sets = set([i + j for i, j in product(limc, limd) if 0 < i + j <= f])

cnt, ans = 0, (max(setw), 0)
for w in setw:
    for s in sets:
        if (cnt <= 100 * s / w <= e) and (s + w <= f):
            cnt = 100 * s / w
            ans = s + w, s
else:
    print(*ans)

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

water = []
sugar = []
for i in range(0,1000):
    for j in range(0,1000):
        if (100*i*a + 100*j*b ) <= f:
            water.append(100*i*a + 100*j*b)
        if c*i + d*j <= f:
            sugar.append(c*i+d*j)
        

water = list(set(water))
water.sort()
water.remove(0)
sugar = list(set(sugar))
sugar.sort()

concentration = 0
sgw = 0
sg = 0

x = e/100

for i in water:
    for j in sugar:
        temp = (100 * j) / (i + j)
        if concentration <= temp and i + j <= f and (i /100)*e  >= j:
            
            sgw = i + j
            sg = j
            concentration = temp
if sgw == 0:
    sgw = water[-1]
print(sgw,sg)

Solution (Python):



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


def main():
    ans = (0, 0, 0)
    for a in range(0, F + 1, 100 * A):
        for b in range(0, F + 1, 100 * B):
            if a == 0 and b == 0:
                continue
            water = a + b
            if water > F:
                break
            s = min(F - water, water // 100 * E)
            sugar = 0
            for c in range(0, s + 1, C):
                t = s - c
                sugar = max(sugar, c + (t // D) * D)
            ans = max(ans, (sugar / water, water + sugar, sugar))
    
    print(ans[1], ans[2])


if __name__ == "__main__":
    main()

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


SD = {}
WD = {}
MS = (E * F) // (100 + E)
for i in range(MS // C + 1):
  for j in range((MS - i * C) // D + 1):
    SD[i*C+j*D] = 1
Sup = F // (100 * A)
wans, sans = 0, 0
for i in range(Sup+1):
  SUp = (F - 100 * A * i) // (100 * B)
  for j in range(SUp+1):
    W = 100 * (A * i + B * j)
    if i != 0 or j != 0:
      for S in SD:
        if W + S <= F and 100 * S <= W * E:
          if wans == 0 and sans == 0:
            wans, sans = W + S, S
          else:
            if sans * (S + W) < S * wans:
              wans, sans = W + S, S
print(wans, sans)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
L = []
for p in range(f//a+1):
    for q in range((f-a*p)//b+1):
        h = 100*(a*p+b*q)
        for r in range((f-h)//c+1):
            for s in range((f-h-c*r)//d+1):
                g = c*r+d*s
                if g+h !=0:
                    bool1 = (g/(g+h) <= e/(100+e))
                    if bool1 and g+h <= f:
                        if h !=0:
                            L.append((100*g/(g+h),g+h,g))
L.sort(reverse = True)  

print(L[0][1],L[0][2])

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
ms = 0
mt = 100
for i in range(f//(100*a) + 1):
    for j in range((f-100*i*a)//(100*b) + 1):
        for k in range((f-i*a*100 - j*b*100)//(c)+1):
            for l in range((f-i*a*100 - j*b*100-k*c)//(d)+1):

                ss, tt = c*k+d*l, i*a*100 + j*b*100+c*k+d*l
                if ss*100 > e*(tt-ss):
                    continue
                if ss*mt >= tt*ms:
                    ms, mt = ss, tt
print(mt, ms)

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

conc = 0
total = 0

ans = [100 * A,0]

for a in range(0,31):
  for b in range(0,31):
    water = (A * a + B * b) * 100
    if water > F:
      break
    else:
      for c in range(3001):
        water = (A * a + B * b) * 100
        if water == 0:
          break
        
        sugar_limit = int(water * E / 100)
        
        sugarC = c * C
        
        if sugarC > sugar_limit:
          break
        
        else:
          rest = F - water - sugarC
          
          sugar_rest = sugar_limit - sugarC
          
          if rest < 0:
            break
          
          else:
            
            sugarD = (min(rest,sugar_rest) // D) * D
            sugar = sugarC + sugarD
            temp = (sugar) / (water + sugar)
            if conc < temp and temp < E:
              conc = temp
              total = water + sugar
              ans = [total,sugar]
        
print(ans[0],ans[1])

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

noudo = 0
ans = (100*A, 0)
for a in range(31):
    for b in range(31):
        water = A * a + B * b
        if water*100 > F:
            break
        for c in range(3001):
            water = A * a + B * b
            if water == 0:
                break
            can_sugar = water * E
            if C * c > can_sugar:
                break
            rest = F - water * 100 - C*c
            if rest < 0:
                break
            rest_sugar = can_sugar - C * c
            sugar = (min(rest_sugar, rest) // D) * D
            tmp = (sugar + C*c) / (water + sugar + C*c)
            if noudo < tmp:
                noudo = tmp
                ans = (water*100 + C*c + sugar, c*C + sugar)

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

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
water=[]
for i in range(F//(100*B)+1):
  for j in range((F-100*B*i)//(100*A)+1):
    water.append(100*A*j+100*B*i)
water=sorted(list(set(water)))
suger=[]
for i in range(F//(C)+1):
  for j in range((F-C*i)//D+1):
    suger.append(C*j+D*i)
suger=sorted(list(set(suger)))
Water=0
Suger=0
ans=0
if (A*100+min(C,D)>F):
  print(A*100,0)
else:
  for i in range(len(water)):
    if i==0:
      continue
    for j in range(len(suger)):
      if water[i]+suger[j]>F:
        break
      c=float(suger[j]*100/water[i])
      if c<=E:
        if c>ans:
          ans=c
          Water=water[i]+suger[j]
          Suger=suger[j]
  if Water==0:
    print(A*100,0)
  else:
    print(Water,Suger)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    A,B,C,D,E,F = Scanner.map_int()
    n,m = 0,0
    M = 0
    for a in range(41):
        for b in range(41):
            w = A * a * 100 + B * b * 100
            for c in range(41):
                for d in range(41):
                    s = c * C + d * D
                    mass = w + s
                    if mass > F:
                        continue
                    if s * 100 > E * w:
                        continue
                    if s * n >= m * mass:
                        n,m = mass,s

    print(n,m)
    return

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,d,e,f = inpl()
water = set()
sugar = set()
for i in range(f//(a*100)+10):
    for j in range(f//(b*100)+10):
        w = a*100*i + b*100*j
        if w > f:
            break
        water.add(w)
for i in range(f//c+10):
    for j in range(f//d+10):
        s = c*i + d*j
        if s > f:
            break
        sugar.add(s)
water = sorted(list(water))
sugar = sorted(list(sugar))



max_cons = 0
res_to = a*100
res_s = 0
for w in water:
    for s in sugar:
        if w+s > f:
            break
        if w == 0 and s == 0:
            continue
        cons = s/(w+s)
        
        if cons > e/(100+e):
            continue
        if cons > max_cons:
            res_to = w+s
            res_s = s
            max_cons = cons
print(res_to,res_s)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,d,e,f = inpl()
water = set()
sugar = set()
for i in range(f//(a*100)+10):
    for j in range(f//(b*100)+10):
        w = a*100*i + b*100*j
        if w > f:
            break
        water.add(w)
for i in range(f//c+10):
    for j in range(f//d+10):
        s = c*i + d*j
        if s > f:
            break
        sugar.add(s)
water = sorted(list(water))
sugar = sorted(list(sugar))



max_cons = 0
res_to = 0
res_s = 0
for w in water:
    for s in sugar:
        if w+s > f:
            break
        if w == 0 and s == 0:
            continue
        cons = s/(w+s)
        
        if cons > e/(100+e):
            continue
        if cons >= max_cons:
            res_to = w+s
            res_s = s
            max_cons = cons
print(res_to,res_s)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
limit = 100 * e / (100 + e)
mx = -1

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

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

for i in waters:
    for j in sugars:
        if i + j <= f and i + j != 0:
            noudo = 100 * j / (i + j)
            if noudo <= limit:
                if noudo > mx:
                    mx = noudo
                    x, y = i + j, j
print(x, y)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
a, b = 100 * a, 100 * b
limit = 100 * e / (100 + e)
mx = -1

for i in range(f // a + 1):
    for j in range((f - i * a) // b + 1):
        for k in range((f - i * a - j * b) // c + 1):
            for l in range((f - i * a - j * b - k * c) // d + 1):
                water = i * a + j * b + k * c + l * d
                sugar = k * c + l * d
                if water > f or water == 0:
                    break
                if (100 * sugar / water) <= limit:
                    if (100 * sugar / water) > mx:
                        mx = (100 * sugar / water)
                        x, y = water, sugar
print(x, y)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()
  ans_n=-inf
  ans_pair=[0,0]

  z=100*e/(100+e)
  
  
  for i in range(31):
    for j in range(31):
      for k in range(3001):
        for l in range(3001):
          _a=a*i*100+b*j*100
          _b=k*c+l*d

          if _a+_b>f:
            break

          if _a+_b==0:
            break

          y=100*_b/(_a+_b)

          if y<=z:
            if ans_n<=y:
              ans_n=y
              ans_pair=[_a+_b,_b]

  return str(ans_pair[0])+' '+str(ans_pair[1])


print(main())

Solution (Python):
import sys
input = sys.stdin.readline
A, B, C, D, E, F = map(int, input().split())
wdp = [0] * (F + 1)
sdp = [0] * (F + 1)
wdp[0] = 1
sdp[0] = 1
resa = 100 * A
resb = 0
for i in range(F + 1):
  if i + A * 100 <= F: wdp[i + A * 100] += wdp[i]
  if i + B * 100 <= F: wdp[i + B * 100] += wdp[i]
for i in range(F + 1):
  if i + C <= F: sdp[i + C] += sdp[i]
  if i + D <= F: sdp[i + D] += sdp[i]
for i in range(1, F + 1):
  if sdp[i] == 0: continue
  w = 0
  for j in range(1, F + 1):
    if i + j > F: break
    if wdp[j] == 0: continue
    if i <= j * E // 100:
      w = j
      break
  if w == 0: continue
  
  
  if resb / resa < float(i) / float(i + w):
    resb = i
    resa = i + w
print(resa, resb)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
wl=set()
i=0
while i*100*a<=f:
    j=0
    while i*100*a+j*100*a<=f:
        wl.add(i*100*a+j*100*a)
        j+=1
    i+=1
sl=set()
i=0
while i*c<=f:
    j=0
    while i*c+j*d<=f:
        sl.add(i*c+j*d)
        j+=1
    i+=1
max=0
x=0
y=0
for w in wl:
    if w==0:
        continue
    for s in sl:
        if w//100*e>=s and w+s<=f:
            if x==0 and y==0:
                x=w
                y=s
            if max<s/(w+s):
                max=s/(w+s)
                x=w+s
                y=s
print(x,y)

Solution (Python):
def main():
    a,b,c,d,e,f = map(int,input().split())
    a*=100
    b*=100
    den=0.0
    x=0
    y=0
    for i in range(f//b+1):
        for j in range((f-(i*b))//a+1):
            for k in range((f-(i*b+j*a))//d+1):
                for l in range((f-(i*b+j*a+k*d))//c+1):
                    if i*b+j*a>0 and f>=i*b+j*a+k*d+l*c and (k*d+l*c)/(i*b+j*a) <= e/100 and den < (k*d+l*c)/(i*b+j*a):
                        den=(k*d+l*c)/(i*b+j*a)
                        x=i*b+j*a+k*d+l*c
                        y=k*d+l*c
    if x==0:
        print(a,0)
    else:
        print(x,y)                  
if __name__ == "__main__":
    main()

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

def main():
    A, B, C, D, E, F = map(int, input().split())
    waters = set()
    sugars = set()
    for a in range(0, F+1, 100 * A):
        for b in range(0, F+1, 100 * B):
            if a + b <= F:
                waters.add(a + b)
            else:
                break
    for c in range(0, F+1, C):
        for d in range(0, F+1, D):
            if c + d <= F:
                sugars.add(c + d)
            else:
                break
    waters = sorted(list(waters))[1:]
    sugars = sorted(list(sugars))
    
    ans = 0
    ans_w = 0
    ans_s = 0
    for w in waters:
        for s in sugars:
            if w + s <= F:
                if s <= (w//100) * E:
                    tmp = (100 * s)/(w + s)
                    
                        
                    if tmp >= ans:
                        ans = tmp
                        ans_w = w
                        ans_s = s
            else:
                break
    print(ans_w + ans_s, ans_s)

if __name__ == "__main__":
    main()

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

x, y, maxe = 0, 0, 0.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+B*b))//C+1):
            for d in range((F-100*(A*a+B*b)-C*c)//D+1):
                if A*a+B*b == 0:
                    continue
                e = (C*c+D*d) / (A*a+B*b)
                if e <= E and maxe <= e:
                    maxe = e
                    y = C*c+D*d
                    x = 100*(A*a+B*b) + y

print(x, y)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d, e, f = list(map(int, input().rstrip('\n').split()))
    mt = a * 100
    ms = 0
    mn = 0
    for i in range(0, f + 1, a * 100):
        for j in range(0, f - i + 1, b * 100):
            for k in range(0, f - i - j + 1, c):
                for l in range(0, f - i - j - k + 1, d):
                    t = i + j
                    s = k + l
                    if 0 < t + s <= f:
                        if s / (t + s) <= e / (100 + e):
                            if s / (t + s) > mn:
                                mn = s / (t + s)
                                mt = t
                                ms = s
    print(mt + ms, ms)


if __name__ == '__main__':
    slove()

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d, e, f = list(map(int, input().rstrip('\n').split()))
    abcd = 0
    cd = 0
    md = 0
    for ai in range(0, f + 1, a * 100):
        for bi in range(0, f + 1, b * 100):
            for ci in range(0, f + 1, c):
                for di in range(0, f + 1, d):
                    if 0 < ai + bi + ci + di <= f:
                        if ai + bi != 0:
                            if md < (ci + di) / (ai + bi + ci + di) <= e / (100 + e):
                                md = (ci + di) / (ai + bi + ci + di)
                                abcd = ai + bi + ci + di
                                cd = ci + di
                    else:
                        break
    print(abcd if abcd != 0 else a * 100, cd)


if __name__ == '__main__':
    slove()

Solution (Python):

from collections import deque, defaultdict
import copy
import bisect

import math
import heapq

import sys
def input():
	return sys.stdin.readline().strip()

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

water = [0]*(F//100 + 1)
water[0] = 1
water_list = [0]
for i in range(1, len(water)):
	if A <= i and water[i - A] == 1:
		water[i] = 1
		water_list.append(i*100)
	elif B <= i and water[i - B] == 1:
		water[i] = 1
		water_list.append(i * 100)

suger = [0]*(E*water_list[-1]//100 + 1)
suger[0] = 1
max_n = 0
ws = [A*100, 0]
for i in range(1, len(suger)):
	if C <= i and suger[i - C] == 1:
		suger[i] = 1
	elif D <= i and suger[i - D] == 1:
		suger[i] = 1
	if suger[i] == 1:
		max_s = i*100/E
		loc = bisect.bisect_left(water_list, max_s)
		if loc <= len(water_list) and  water_list[loc] + i <= F:
			if max_n < 100*i/(water_list[loc] + i):
				ws = [water_list[loc], i]
			max_n = max(max_n, 100*i/(water_list[loc] + i))
print(ws[0] + ws[1], ws[1])

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
ans={'water':A*100,'suger':0}
def density(water,suger):
    return 100*suger/(water+suger)
for a in range(31):
    for b in range(31):
        water=(a*A+b*B)*100
        if water>F:
            continue
        max_suger=min((a*A+b*B)*E,F-water)
        for c in range(max_suger//C+1):
            suger=c*C
            suger+=((max_suger-suger)//D)*D
            if water+suger==0:
                continue
            elif density(water,suger)>density(ans['water'],ans['suger']):
                ans['water']=water
                ans['suger']=suger
print(ans['water']+ans['suger'],ans['suger'])

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

mc, mw, ms = 0, 0, 0
for a in range(F // (A * 100) + 1):
    for b in range((F - a * A * 100) // (B * 100) + 1):
        if a == 0 and b == 0:
            continue
        for c in range((F - (a * A + b * B) * 100) // C + 1):
            for d in range((F - (a * A + b * B) * 100 - c * C) // D + 1):
                w, s = (a * A + b * B) * 100, c * C + d * D
                if w + s <= F and w * E >= s * 100 and mc <= s / (w + s):
                    mc, mw, ms = s / (w + s), w, s
print(mw + ms, ms)