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

x = sorted(set([w for i in range(0,F+1,A*100) for j in range(0,F+1,B*100) if (w := i + j) < F]))[1::]
y = sorted(set([s for i in range(0,F+1,C) for j in range(0,F+1,D) if (s := i + j) < F]))

n = 0
WS = S = 0
for w in x:
    for s in y:
        if w + s > F:
            break
        if w * E//100 >= s:
            m = s / (w + s)
            if m >= n:
                n = m
                WS, S = w + s , s

print(WS,S)

Solution (Python):
import sys
import math
import collections
import bisect
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    a, b, c, d, e, f = ns()
    max_cncnt, ans_sum, ans_sugar = -1, 0, 0

    sugar_cand = []
    sugar_dp = [False for _ in range(f + 1)]
    sugar_dp[0] = True
    for i in range(f + 1):
        if sugar_dp[i]:
            if i + c <= f:
                sugar_dp[i + c] = True
            if i + d <= f:
                sugar_dp[i + d] = True
            sugar_cand.append(i)

    for i in range(f // (100 * a) + 1):
        for j in range(f // (100 * b) + 1):
            water = 100 * (a * i + b * j)
            if water == 0:
                continue
            if water > f:
                break
            sugar_lim = min(water * e // 100, f - water)
            sugar_idx = bisect.bisect_right(sugar_cand, sugar_lim)
            sugar = 0 if sugar_idx == 0 else sugar_cand[sugar_idx - 1]
            if max_cncnt < sugar / (water + sugar):
                ans_sum = water + sugar
                ans_sugar = sugar
                max_cncnt = ans_sugar / ans_sum

    print(ans_sum, ans_sugar)


if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
waters = []
for i in range(31):
    for j in range(31):
        v = 100*a*i + 100*b*j
        if v <= f and v != 0:
            waters.append(v)

waters = list(set(waters))
ans_vol, ans_sug = waters[0], 0
for w in waters:
    rem = f - w
    max_s = e*w//100
    max_s = min(rem, max_s)
    for c_cnt in range(max_s//c+1):
        cs = c_cnt*c
        rem_d = max_s - cs
        d_cnt = rem_d//d
        ds = d_cnt*d
        sug = cs+ds
        vol = sug + w
        if ans_sug*vol < sug*ans_vol:
            ans_vol, ans_sug = vol, sug

print(ans_vol, ans_sug)

Solution (Python):
import bisect
A, B, C, D, E, F = map(int, input().split())
water = []
sugar = []

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

water = list(set(water))

for i in range(F//C+1):
  for j in range(F//D+1):
    if C*i + D*j <= F:
      sugar += [C*i + D*j]

sugar = list(set(sugar))
sugar = sorted(sugar)
ans_sw = 0
ans_s = 0
ans = 0
for w in water:
  s = min((E/100)*w, F-w)
  idx = bisect.bisect_right(sugar, s)
  if w + sugar[idx-1] == 0:
    continue
  conc = (sugar[idx-1]/(w+sugar[idx-1]))*100
  if ans < conc:
    if sugar[idx-1] <= (E/100)*w and sugar[idx-1] + w <= F:
      ans = conc
      ans_sw = w + sugar[idx-1]
      ans_s = sugar[idx-1]
if ans_sw == 0:
  ans_sw = 100*A
print(ans_sw, ans_s)

Solution (Python):
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    
    A, B, C, D, E, F = read_ints()
    dp = [0]*(F+1)
    for i in range(1, F+1):
        dp[i] = dp[i-1]
        if i-C >= 0:
            dp[i] = max(dp[i], dp[i-C]+C)
        if i-D >= 0:
            dp[i] = max(dp[i], dp[i-D]+D)

    highest_ratio = [0, 100*A]

    for a in range(31):
        for b in range(31):
            water = 100*A*a+100*B*b
            if water < F:
                sugar_limit = min(E*water//100, F-water)
                sugar = dp[sugar_limit]
                if sugar*highest_ratio[1] > water*highest_ratio[0]:
                    highest_ratio = [sugar, water]
    return sum(highest_ratio), highest_ratio[0]


if __name__ == '__main__':
    print(*solve())

Solution (Python):
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    
    A, B, C, D, E, F = read_ints()
    dp = [False]*(F+1)
    dp[0] = True
    for i in range(F+1):
        if i+C < F+1:
            dp[i+C] = dp[i+C] or dp[i]
        if i+D < F+1:
            dp[i+D] = dp[i+D] or dp[i]
    
    dp2 = [0]*(F+1)
    highest_sugar = 0
    for i in range(F+1):
        if dp[i]:
            dp2[i] = highest_sugar = i
        else:
            dp2[i] = highest_sugar

    highest_ratio = [0, 100*A]

    for a in range(31):
        for b in range(31):
            water = 100*A*a+100*B*b
            if water < F:
                sugar_limit = min(E*water//100, F-water)
                sugar = dp2[sugar_limit]
                if sugar*highest_ratio[1] > water*highest_ratio[0]:
                    highest_ratio = [sugar, water]
    return sum(highest_ratio), highest_ratio[0]


if __name__ == '__main__':
    print(*solve())

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

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

A = A*100
B = B*100

Alim =F//A
Blim = F//B
water = []
for ai in range(Alim+1):
    for bi in range(Blim+1):
        tmp = ai*A+bi*B
        if tmp <=F:
            water.append(tmp)
water = set(water)

suger_limit = math.ceil(F/100)*E
Clim = suger_limit//C
Dlim = suger_limit//D
suger = []
for ci in range(Clim+1):
    for di in range(Dlim+1):
        tmp = ci*C+di*D
        if tmp <=suger_limit:
            suger.append(tmp)
suger = sorted(list(set(suger)),reverse=1)


candi = [[0,0]]


while water:
    w = water.pop()
    for su in suger:
        
        if w+su > F:
            continue
        else:
            if w*E>=su*100:
                candi.append([w+su,su])
                break
ans = [0,0]
judge = 0
for can in candi:
    ws,s = can
    if ws == 0:
        continue
    else:
        con = s/ws*100
        if con >= judge:
            ans = [ws,s]
            judge=con
  
print(*ans)

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

limit_water = f * 100 / (100 + e)
limit_suger = f * e / (100 + e)


waters = []
sugars = []

for i in range(31):
    for j in range(31):
        water = 100 * a * i + 100 * b * j
        if water != 0 and water <= 3000:
            waters.append(water)

for i in range(1500):
    for j in range(1500):
        sugar = c * i + d * j
        sugars.append(sugar)

ans = []
max_density = 0.0

sugars = list(set(sugars))
sugars.sort()
waters = list(set(waters))
waters.sort()

for water in waters:
    for sugar in sugars:
        if sugar + water <= f and sugar <= (water * e / 100):
            density = sugar / (sugar + water)
            if density >= max_density:
                ans = [water + sugar, sugar]
                max_density = density

print(*ans)

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

concentration = 0
ans = [A*100,0]

water = []
for a in range(F//(A*100) + 1):
  for b in range(((F-a*A*100)//(B*100))+1):
    water.append((a*A+b*B)*100)
    
water = sorted(list(set(water)))

sugar = []
for c in range(F//C + 1):
  for d in range(((F - c*C)//D)+1):
    sugar.append(c*C+d*D)
sugar = sorted(list(set(sugar)))


for wa in water:
  for su in sugar:
    if wa + su <= F:
      if su <= (wa/100)*E:
        if wa != 0:
          if concentration < su/(su+wa):
            concentration = su/(su+wa)
            ans = [su+wa,su]

print(" ".join(map(str,ans)))

Solution (Python):
def solve():


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

    
    list = {}

    
    ope1 = 100 * A
    ope2 = 100 * B
    ope3 = C
    ope4 = D


    for i in range(31):
        for j in range(31):
            for k in range(101):
                for l in range(101):
                    w_sum = i * ope1 + j * ope2
                    s_sum = k * ope3 + l * ope4
                    if w_sum == 0:
                        break
                    if w_sum+s_sum > F:
                        break
                    else:
                        if w_sum/100 * E >= s_sum:
                            p_tmp = (s_sum / (w_sum + s_sum)) * 100
                            list[i, j, k, l] = p_tmp

    max_v = max(list.values())

    for k, v in list.items():
        if v == max_v:
            print(ope1*k[0] + ope2*k[1] + ope3*k[2] + ope4*k[3], ope3*k[2] + ope4*k[3])
            break

if __name__ == "__main__":
    solve()

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                elif targ==0:
                    break
                elif s>e*w/100:
                    break
                elif  mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                elif targ==0:
                    break
                elif s>e*w/100:
                    break
                elif  mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                if targ==0:
                    break
                if  s<=e*w/100  and mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=100*a
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,51):
            for l in range(0,51):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                if w+s<=f and s<=e*w/100 and w!=0 and mx<100*s/(w+s):
                    mx=100*s/(w+s)
                    swmx=w+s
                    smx=s
print(swmx,smx)

Solution (Python):
def main():
    water_a, water_b, sugar_c, sugar_d, max_sugar, max_mass = map(int, input().split())
    op_a = 30 // water_a
    op_b = 30 // water_b
    op_c = 3000 // sugar_c
    max_concentration = [water_a * 100, 0]
    for times_a in range(op_a + 1):
        for times_b in range(op_b + 1):
            for times_c in range(op_c + 1):
                now_water = water_a * times_a + water_b * times_b
                now_sugar_lim = now_water * max_sugar
                now_water *= 100
                now_sugar = sugar_c * times_c
                now_mass = now_water + now_sugar
                if max_mass < now_mass or now_water == 0 or now_sugar_lim < now_sugar:
                    break
                add = (min(max_mass - now_mass, now_sugar_lim - now_sugar) // sugar_d) * sugar_d
                now_mass += add
                now_sugar += add
                if now_mass * max_concentration[1] < sum(max_concentration) * now_sugar and now_sugar <= now_sugar_lim:
                    max_concentration = [now_water, now_sugar]
    print(sum(max_concentration), max_concentration[1])


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

mx_rate = 0
ans_water = 0
ans_sugar = 0
for i in range(31):
    for j in range(31):
        total = (i * A + j * B) * 100
        if total > F:
            continue
        sugar_limit = min(F - total, (total // 100) * E)
        if sugar_limit > 0:
            for k in range(sugar_limit // C + 1):
                sugar_total = k * C
                if sugar_total < sugar_limit:
                    sugar_total += ((sugar_limit - sugar_total) // D) * D
                rate = 100 * sugar_total / (sugar_total + total)
                if rate >= mx_rate:
                    mx_rate = rate
                    ans_water = total + sugar_total
                    ans_sugar = sugar_total
print(ans_water, ans_sugar)

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

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

    for p in range(F // (100 * A) + 1):
        for q in range(0, (F - 100 * A * p) // (100 * B) + 1):
            upper = (A * p + B * q) * E
            water = (A * p + B * q) * 100
            if water == 0: continue
            for r in range(0, upper // C + 1):
                if water + C * r > F: continue
                s = (upper - C * r) // D
                while s >= 0 and water + C * r + D * s > F: s -= 1
                if s < 0: continue
                if sugar * (water + C * r + D * s) < (C * r + D * s) * weight:
                    weight = water + C * r + D * s
                    sugar = C * r + D * s
    if sugar == 0:
        print("{} 0".format(100 * A))
    else:
        print("{} {}".format(weight, sugar))

    


if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100*s/(w+s)
                            memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
    solve()

Solution (Python):
import sys

input = sys.stdin.readline


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

    max_concentration = 0
    ans = (100 * A, 0)
    for a in range(0, F + 1, 100 * A):
        for b in range(0, F - a + 1, 100 * B):
            water = a + b
            if water == 0:
                break
            for c in range(0, F - water + 1, C):
                for d in range(0, F - water - c + 1, D):
                    sugar = c + d
                    if sugar > (water // 100) * E:
                        break
                    concentration = (100 * sugar) / (water + sugar)
                    if concentration > max_concentration:
                        max_concentration = concentration
                        ans = (water + sugar, sugar)

    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

Solution (Python):
import bisect
a,b,c,d,e,f = map(int,input().split())
lw = []
ls = []
for i in range((f//100)//b+1):
    for j in range(100):
        if b*i*100+a*j*100 > f:
            break
        lw.append(b*i*100+a*j*100)
for i in range((f//2)//d+1):
    for j in range(3000):
        if (d*i+c*j) > (f*e)/(100+e):
            break
        ls.append(d*i+c*j)
ls.sort()
lw.sort()
n = len(lw)
ans = 0
ansl = [0,0]

for i in range(n):
    w = lw[i]
    t = min(f-w,w/100*e)
    s = ls[bisect.bisect_right(ls,t)-1]
    if (s+w)==0:
        continue
    if 100*s/(s+w) >= ans:
        ans = 100*s/(s+w)
        ansl = [s+w,s]
print(*ansl)

Solution (Python):
A,B,C,D,E,F = map(int, open(0).read().split())
ans = [0] * 3
for a in range(F//(100*A)+1):
    for b in range((F-(100*A)*a)//(100*B)+1):
        if a == 0 and b == 0:
            continue
        else:
            m = min(((A*a)+(B*b))*E,F-(100*((A*a)+(B*b))))
            sugar = 0
            for c in range(m//C+1):
                sugar = max(sugar,m-(m-C*c)%D)
                if sugar == m:
                    break
            temp = sugar / (100*((A*a)+(B*b))+sugar)
            if temp > ans[0]:
                ans[0] = temp
                ans[1] = 100 * ((A*a)+(B*b)) + sugar
                ans[2] = sugar
if ans[1] == 0:
    ans[1] = 100 * A
print(ans[1],ans[2])

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
water=[]
suger=[]
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        if 0<100*(i*A+j*B)<=F:
            water.append(100*(i*A+j*B))
        if 100*(i*A+j*B)>F:
            break

for i in range((F*E//(100+E))//C+1):
    for j in range((F*E//(100+E))//D+1):
        if 0<=i*C+j*D<=F*E/(100+E):
            suger.append(i*C+j*D)
        if i*C+j*D>F*E/(100+E):
            break


c=0
w=100*A 
s=0
for i in range(len(water)):
    for j in range(len(suger)):
        if water[i]+suger[j]<=F and water[i]*E/100>=suger[j] and suger[j]/(water[i]+suger[j])>c:
            c=suger[j]/(water[i]+suger[j])
            w=water[i]
            s=suger[j]

print(w+s,s)

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
weight=100*A
suger=0
c=0
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        for k in range((i*A+j*B)*E//C+1):
            for l in range((i*A+j*B)*E//D+1):
                if 100*(i*A+j*B)+k*C+l*D<=F and k*C+l*D<=(i*A+j*B)*E and (i*i+j*j+k*k+l*l)!=0 and (k*C+l*D)/(100*(i*A+j*B)+k*C+l*D)>c:
                    c=(k*C+l*D)/(100*(i*A+j*B)+k*C+l*D)
                    weight=100*(i*A+j*B)+k*C+l*D
                    suger=k*C+l*D


print("{} {}".format(weight,suger))

Solution (Python):
import sys
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    sugar = set()
    for i in range(F // C + 1):
        for j in range(F // D + 1):
            s = C * i + D * j
            if s <= F:
                sugar.add(s)
            else:
                break

    sugar = sorted(sugar)

    water = set()
    for i in range(F // (100 * A) + 1):
        for j in range(F // (100 * B) + 1):
            w = 100 * A * i + 100 * B * j
            if w <= F:
                water.add(w)
            else:
                break

    water = sorted(water)

    concentration = 0
    ans_water = ans_sugar = 0
    for w in water[1:]:
        s_max = min(F - w, w // 100 * E)
        s = sugar[bisect_right(sugar, s_max) - 1]
        if concentration < 100 * s / (w + s):
            concentration = 100 * s / (w + s)
            ans_water = w
            ans_sugar = s

    if ans_water == 0:
        ans_water = 100 * A

    print(ans_water + ans_sugar, ans_sugar)
    return


if __name__ == '__main__':
    main()

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

max_s=0
max_w=a
max_conc=0

water_s=set()
sugar_s=set()
for i in range(f//a//100+1):
  aa=a*i
  for j in range(f//b//100+1):
    bb=b*j
    if aa+bb <= f//100:
      water_s.add(aa+bb)
      
for i in range(f//c+1):
  cc=c*i
  for j in range(f//d+1):
    dd=d*j
    if cc+dd <= f:
      sugar_s.add(cc+dd)

for w in water_s:
  for sg in sugar_s:
    if w*100+sg <= f and w*e >= sg and w+sg > 0:
      conc=(100*sg)/(100*w+sg)
      if max_conc < conc:
        max_conc=conc
        max_w=w
        max_s=sg
print(max_w*100+max_s,max_s)

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

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

def searints(m,n,l):
  mask=(1<<l+1)-1
  s=sum([1<<n*i for i in range(1,l//n+1)])&mask
  for i in range(1,l//m+1):
    s=(s+1<<m*i|s) &mask
  return [x for x in range(0,l+1) if ((s+1)>>x)&1==1]

w=searints(100*a,100*b,f)
s=searints(c,d,f)
candidates=[(100*y/(x+y),x+y,y) for x in w for y in s if e*x>=100*y and x*y>0 and x+y<=f]
if candidates:
  print(*max(candidates)[1:])
else:
  print(100*a,0)

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


water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))


sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))


max_conc = -1
max_conc_water = -1
max_conc_sugar = -1
for water in water_list:
    for sugar in sugar_list:
        
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc > max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)

Solution (Python):


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


water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))


sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))

max_conc = 0
max_conc_water = 0
max_conc_sugar = 0
for water in water_list:
    for sugar in sugar_list:
        
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc >= max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)

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


water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))


sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))

max_conc = 0
max_conc_water = 0
max_conc_sugar = 0
for water in water_list:
    for sugar in sugar_list:
        
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc >= max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)

Solution (Python):
from copy import deepcopy
import itertools

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

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
Ms = 0
Mw = A
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)

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

noudo = 0
satou = 0
sato_mizu = 100 * A

for x in range(F//(100*A)+1):
    for y in range(F//(100*B)+1):
        if 100 * (A*x+B*y) > F:
            break

        for z in range(F // C + 1):
            if C * z > (A * x + B * y) * E:
                break

            if 100 * (A * x + B * y) + C * z > F:
                break

            for w in range(F // C + 1):
                if (C*z + D*w + 100 * (A*x+B*y)) == 0:
                    break

                if C*z + D*w > (A * x + B * y)*E:
                    break

                if 100 * (A*x+B*y)+C*z + D*w > F:
                    break

                if noudo < 100* (C*z + D*w)/(C*z + D*w + 100 * (A*x+B*y)):
                    noudo = 100* (C*z + D*w)/(C*z + D*w + 100 * (A*x+B*y))
                    sato_mizu = (C*z + D*w + 100 * (A*x+B*y))
                    satou = C*z + D*w
print(sato_mizu, satou)

Solution (Python):
import sys

A, B, C, D, E, F = map(int, sys.stdin.readline().split())

max_a = (F - 1) // (100 * A) + 1
max_b = (F - 1) // (100 * B) + 1

max_rate = 0
ans_water = 0
ans_sugar = 0
for a in range(max_a + 1):
    for b in range(max_b + 1):
        water = 100 * A * a + 100 * B * b
        if water >= F:
            break

        max_sugar = min(F - water, water // 100 * E)
        
        max_c = (max_sugar - 1) // C + 1
        max_d = (max_sugar - 1) // D + 1
        for c in range(max_c + 1):
            for d in range(max_d + 1):
                sugar = C * c + D * d
                if sugar > max_sugar or sugar + water > F:
                    break

                if sugar * (ans_water + ans_sugar) >= ans_sugar * (water + sugar):
                    ans_water = water
                    ans_sugar = sugar

print(ans_water + ans_sugar, ans_sugar)

Solution (Python):
import numpy as np


def solve(stdin):
    A, B, C, D, E, F = stdin
    conc = -1
    ans = (1, 2)
    for na in range(F // (100 * A) + 1):
        for nb in range(F // (100 * B) + 1):
            if na == nb == 0:
                continue
            G = F - na * 100 * A - nb * 100 * B
            for nc in range(G // C + 1):
                for nd in range(G // D + 1):
                    W = na * 100 * A + nb * 100 * B + nc * C + nd * D
                    if 0 < W <= F and nc * C + nd * D <= E * (na * A + nb * B):
                        conc2 = 100 * (nc * C + nd * D) / W
                        if conc < conc2 <= 100 * E / (100 + E):
                            ans = (W, nc * C + nd * D)
                            conc = conc2
    return ans


def main():
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    print(*solve(stdin))


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

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


def main(A, B, C, D, E, F):
    conc = -1
    ans = (1, 2)
    for na in range(F // (100 * A) + 1):
        for nb in range(F // (100 * B) + 1):
            if na == nb == 0:
                continue
            G = F - na * 100 * A - nb * 100 * B
            for nc in range(G // C + 1):
                for nd in range(G // D + 1):
                    W = na * 100 * A + nb * 100 * B + nc * C + nd * D
                    if 0 < W <= F and nc * C + nd * D <= E * (na * A + nb * B):
                        conc2 = 100 * (nc * C + nd * D) / W
                        if conc < conc2 <= 100 * E / (100 + E):
                            ans = (W, nc * C + nd * D)
                            conc = conc2
    return ans


print(*main(A, B, C, D, E, F))