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

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

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

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

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

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

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

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

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

def res(water, sugar, memo):
    if water + sugar > F:
        return None
    if (water, sugar) in memo:
        return None
    if water + sugar == 0:
        memo[(water, sugar)] = -1        
    elif E*(water+sugar) >= sugar*(100+E):
        memo[(water, sugar)] = sugar/(water+sugar)
    else:
        memo[(water, sugar)] = -1

    res(water+100*A, sugar, memo)
    res(water+100*B, sugar, memo)
    res(water, sugar+C, memo)
    res(water, sugar+D, memo)
    return memo

memo = res(0, 0, {})
k, v = max(memo.items(), key=lambda x:x[1])
print(k[0]+k[1], k[1])

Solution (Python):




def solveProblem(WaterOne100,WaterTwo100,SugarOne,SugarTwo,meltMax,maxSugarWater):
	maxBreakDown = meltMax / (meltMax + 100)
	WaterOneCup = WaterOne100 * 100
	WaterTwoCup = WaterTwo100 * 100
	WaterPossibleList=[]
	for oneCup in range(0,maxSugarWater+1,+WaterOneCup):
		for twoCup in range(0,maxSugarWater-oneCup+1,+WaterTwoCup):
				WaterPossibleList.append(oneCup+twoCup)

	SugarPossibleList = []
	for oneSugarCup in range(0,maxSugarWater+1,+SugarOne):
		for twoSugarCup in range(0,maxSugarWater+1-oneSugarCup,+SugarTwo):
				SugarPossibleList.append(oneSugarCup+twoSugarCup)

	returnSugarWater = -1
	returnSugar = -1
	limitedMaxDensity = -1
	for water in WaterPossibleList:
		for sugar in SugarPossibleList:
			if (0 < water+sugar) and (water+sugar<=maxSugarWater) and ((sugar/(sugar+water)) <= maxBreakDown):
				if limitedMaxDensity <= sugar/(sugar+water):
					limitedMaxDensity = sugar/(sugar+water)
					returnSugarWater = water+sugar
					returnSugar = sugar

	answer = returnSugarWater,returnSugar
	return answer

if __name__ == '__main__':
	A,B,C,D,E,F = map(int,input().strip().split(' '))
	solWater,solSuger = solveProblem(A,B,C,D,E,F)
	print("{} {}".format(solWater,solSuger))

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

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

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

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

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
dp = [[False]*(F+1) for _ in range(F//100+1)]
dp[0][0] = True
for i in range(F//100+1):
    for j in range(F+1):
        if j > i*E:
            break
        if 100*i + j > F:
            break
        if j >= C:
            dp[i][j] = dp[i][j] or dp[i][j-C]
        if j >= D:
            dp[i][j] = dp[i][j] or dp[i][j-D]
        if i >= A:
            dp[i][j] = dp[i][j] or dp[i-A][j]
        if i >= B:
            dp[i][j] = dp[i][j] or dp[i-B][j]

dense = -1
argi, argj = 0, 0
for i in range(F//100+1):
    for j in range(F+1):
        if i == j == 0:
            continue
        if dp[i][j]:
            if j/(100*i+j) >= dense:
                dense = j/(100*i+j)
                argi, argj = i, j
print(100*argi+argj, argj)

Solution (Python):


def calcCons(nA, nB, nC, nD):
    W = nA*a*100 + nB*b*100
    S = nC*c + nD*d
    if W+S == 0:
        return -1
    return 100*S/(W+S)


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


maxCons = 0
answer_W, answer_S = 0, 0

nA, nB, nC, nD = 0, 0, 0, 0
while nA*a*100 + nB*b*100 + nC*c + nD*d <= f:
    
    while nA*a*100 + nB*b*100 + nC*c + nD*d <= f:
        
        while nA*a*100 + nB*b*100 + nC*c + nD*d <= f:
            
            while nA*a*100 + nB*b*100 + nC*c + nD*d <= f:
                
                cons = calcCons(nA, nB, nC, nD)
                
                if cons > maxCons and cons <= 100*e/(100+e):
                    maxCons = cons
                    answer_W, answer_S = nA*a*100 + nB*b*100, nC*c + nD*d
                nD += 1
            nD = 0
            nC += 1
        nC = 0
        nB += 1
    nB = 0
    nA += 1

if maxCons == 0:
    answer_W = a*100
print("{} {}".format(int(answer_W+answer_S), int(answer_S)))

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
w = set()
for x in range(0,f+1,100*a):
    for y in range(0,f+1-x,100*b):
        w.add(x+y)
s = set()
for x in range(0,f+1,c):
    for y in range(0,f+1-x,d):
        s.add(x+y)
ans = -1
sugerwater = 0
suger = 0
for x in w:
    for y in s:
        if  0<x+y<=f and y <= x*e/100:
            if ans < y/(x+y):
                ans = y/(x+y)
                sugerwater = x+y
                suger = y
print(sugerwater,suger)

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
W=set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1-a,100*B):
        W.add(a+b)
S=set()
for c in range(0,F+1,C):
    for d in range(0,F+1-c,D):
        S.add(c+d)
mx=-1
for w in W:
    for s in S:
        if 0<w+s<=F and s<=w*E//100:
            if mx<s/(w+s):
                ans=w+s,s
                mx=s/(w+s)
print(ans[0],ans[1])

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def dense(a, b):
    try:
        return 100 * b / (a + b)
    except ZeroDivisionError:
        return 0


A, B, C, D, E, F = il()
A *= 100
B *= 100
max_dense = 0
max_water = 0
max_sugar = 0
for a in range(31):
    for b in range(31):
        water = a * A + b * B
        if water == 0:
            break
        for c in range((F - water) // C + 1):
            for d in range((F - water) // D + 1):
                sugar = c * C + d * D
                if water + sugar > F or water / 100 * E < sugar:
                    break
                if max_dense <= dense(water, sugar):
                    max_dense = dense(water, sugar)
                    max_water = water
                    max_sugar = sugar
print(max_water + max_sugar, max_sugar)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
limwater = F // 100
waterdp = [False] * (limwater + 1)
waterdp[0] = True
for i in range(1, limwater + 1):
	if i >= A and waterdp[i - A]:
		waterdp[i] = True
	if i >= B and waterdp[i - B]:
		waterdp[i] = True
sugardp = [False] * (F + 1)
sugardp[0] = True
for i in range(1, F + 1):
	if i >= C and sugardp[i - C]:
		sugardp[i] = True
	if i >= D and sugardp[i - D]:
		sugardp[i] = True
waterans = 0
sugarans = 0
maxdensity = -1.0
for i in range(1, limwater + 1):
	for j in range(0, F + 1):
		if waterdp[i] and sugardp[j] and i * 100 + j <= F:
			density = j / (i * 100 + j)
			if density <= E / (100 + E) and density > maxdensity:
				maxdensity = density
				waterans = i
				sugarans = j
print(waterans * 100 + sugarans, sugarans)

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

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

sugar = []

for c in range(3001):
    for d in range(3001):
        if c * C + d * D <= F:
            sugar.append(c * C + d * D)
sugar = list(set(sugar))
sugar.remove(0)

memo = []
for w in water:
    for s in sugar:
        if w + s <= F and s/(w+s) <= E/(100+E):
            memo.append([s/(s+w),w+s, s])
memo.sort(reverse=True)
if len(memo) == 0:
    print(100 * A, 0)
else:
    print(memo[0][1], memo[0][2])

Solution (Python):
a,b,c,d,e,f=map(int, input().split())
 
W=[100*a*x + 100*b*y for x in range(0,31) for y in range(0,31) if 0<(100*a*x+100*b*y)<=f]
S=[c*x+d*y for x in range(0,3001) for y in range(0,3001) if 0<(c*x+d*y)<=f]
 
dense = 0
sugar = 0
mass = 100*a
for w in W:
    for s in S:
        if (w+s<=f and s<=(w*e/100) and dense*(s+w)<s):
            dense=s/(s+w)
            sugar=s
            mass=s+w
print(mass,sugar)

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

ans=0
Wit=A*100
Cnc=0

for a in range(30):
    if a*A>30:
        break
    for b in range(31):
        if b*B>30:
            break
        for c in range(3000):
            if a*A*100+b*B*100+c*C>F:
                break
            for d in range(3000):
                if 0<a*A*100+b*B*100+c*C+d*D>F:
                    break
                else:
                    if a==0 and b==0:
                        pass
                    else:
                        if (c*C*100+d*D*100)<=E*(a*A*100+b*B*100):
                            if ans<((c*C*100+d*D*100)/(a*A*100+b*B*100)):
                                ans=((c*C*100+d*D*100)/(a*A*100+b*B*100))
                                Wit=(a*A*100+b*B*100+c*C+d*D)
                                Cnc=(c*C+d*D)
                  
print(Wit,Cnc)

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 100*a*i + 100*b*j <= f and 100*a*i + 100*b*j not in water:
            water.append(100*a*i+100*b*j)

for i in range(f//c+1):
    for j in range(f//d+1):
        if c*i+d*j not in suger:
            suger.append(c*i+d*j)
max = 0
maxs = [100*a,0]
for w in water:
    for s in suger:
        if w+s > 0 and w//100*e >= s and w + s <= f and max < s/(w+s):
            max = s/(w+s)
            maxs = [w,s]

print(sum(maxs),maxs[1])

Solution (Python):
def abc074_c():
    from math import ceil
    a, b, c, d, e, f = map(int, input().split())
    ans_wat = 100 * a
    ans_sug = 0

    for i in range(ceil(f / (100 * a))):
        for j in range(ceil((f - 100 * a * i) / (100 * b))):
            for k in range((f - 100 * (a * i + b * j)) // c + 1):
                for l in range((f - 100 * (a * i + b * j) - c * k) // d + 1):
                    tmp_sug = c * k + d * l
                    tmp_wat = 100 * (a * i + b * j)
                    if tmp_wat and tmp_sug / tmp_wat <= e / 100 and \
                            tmp_sug / (tmp_wat + tmp_sug) > ans_sug / (ans_wat + ans_sug):
                        ans_sug = c * k + d * l
                        ans_wat = 100 * (a * i + b * j)
    print(ans_wat + ans_sug, ans_sug)


abc074_c()

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

waterlist=[]
for i in range(0,int(f/100/a)+1):
  for j in range(0,int(f/100/b)+1):
    if 100*a*i+100*b*j <=f:
      waterlist+=[100*a*i+100*b*j]
waterlist=list(set(waterlist))


sugarlist=[]
for i in range(int(f/c)+1):
  for j in range(int(f/d)+1):
    if c*i+d*j <=f:
      sugarlist+=[c*i+d*j]
sugarlist=list(set(sugarlist))


density=0

for i in range(len(waterlist)):
  for j in range(len(sugarlist)):
    if 0 < waterlist[i]+sugarlist[j] <= f and sugarlist[j]<=waterlist[i]/100*e:
      tmp=sugarlist[j]/(waterlist[i]+sugarlist[j])
      if density <= tmp:
        density = tmp
        ans1=waterlist[i]+sugarlist[j]
        ans2=sugarlist[j]
        
print(ans1,ans2)

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

waterlist=[]
for i in range(0,f+100*a,100*a):
  for j in range(0,f+100*b,100*b):
    if i+j <=f:
      waterlist+=[i+j]
waterlist=list(set(waterlist))


sugarlist=[]
for i in range(int(f/c)+1):
  for j in range(int(f/d)+1):
    if c*i+d*j <=f:
      sugarlist+=[c*i+d*j]
sugarlist=list(set(sugarlist))


density=0

for i in range(len(waterlist)):
  for j in range(len(sugarlist)):
    if 0 < waterlist[i]+sugarlist[j] <= f and sugarlist[j]<=waterlist[i]/100*e:
      tmp=sugarlist[j]/(waterlist[i]+sugarlist[j])
      if density <= tmp:
        density = tmp
        ans1=waterlist[i]+sugarlist[j]
        ans2=sugarlist[j]
        
print(ans1,ans2)

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

sugerWater = 0
suger = 0
maxConcentration = 0.0
for a in range(31):
    for b in range(16):
        for c in range(3001):
            for d in range(1501):
                x = a * 100 * A + b * 100 * B
                y = c * C + d * D
                if 0 < x + y <= F and 100 * y <= E * x:
                    concentration = 100 * y / (x + y)
                    if maxConcentration <= concentration:
                        maxConcentration = concentration
                        sugerWater = x + y
                        suger = y
                else:
                    break

print('{} {}'.format(sugerWater, suger))

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

    ws = set()
    for w_a in range(0, f + 1, 100 * a):
        for w_b in range(0, f + 1 - w_a, 100 * b):
            ws.add(w_a + w_b)
    ws.remove(0)

    ss = set()
    for s_c in range(0, f + 1, c):
        for s_d in range(0, f + 1 - s_c, d):
            ss.add(s_c + s_d)
    ss.remove(0)

    ws = sorted(iter(ws))
    ss = sorted(iter(ss))

    res = (100 * a, 0)
    density_max = 0

    for w in ws:
        for s in ss:
            if w + s > f:
                break
            if w * e < s * 100:
                break
            density = s / (w + s)
            if density > density_max:
                density_max = density
                res = (w + s, s)

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


if __name__ == '__main__':
    main()

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

water_cand = []
for i in range(F):
    for j in range(F):
        tmp = 100 * A * i + 100 * B * j
        if tmp > F:
            break
        water_cand.append(tmp)

ws_cand = []
for x in water_cand:
    for i in range(F-x+1):
        for j in range(F-x+1):
            tmp = C * i + D * j
            if x + tmp > F:
                break
            if x + tmp == 0:
                ws_cand.append((x, tmp))
                continue
            if (tmp / (x+tmp)) <= (E / (100+E)):
                ws_cand.append((x, tmp))
if len(ws_cand) == 1 and ws_cand[0] == (0, 0):
    print(0, 0)
    exit()
ws_cand.remove((0, 0))
ans = max(ws_cand, key=lambda x: x[1] / (x[0]+x[1]))
print(ans[0]+ans[1], ans[1])

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

water_cand = []
for i in range(F):
    for j in range(F):
        tmp = 100 * A * i + 100 * B * j
        if tmp > F:
            break
        water_cand.append(tmp)

ws_cand = []
for x in water_cand:
    for i in range(F-x+1):
        for j in range(F-x+1):
            tmp = C * i + D * j
            if x + tmp == 0:
                ws_cand.append((x, tmp))
                continue
            if x + tmp <= F and (tmp / (x+tmp)) <= (E / (100+E)):
                ws_cand.append((x, tmp))
            elif x + tmp > F:
                break
if len(ws_cand) == 1 and ws_cand[0] == (0, 0):
    print(0, 0)
    exit()
ws_cand.remove((0, 0))
ans = max(ws_cand, key=lambda x: x[1] / (x[0]+x[1]))
print(ans[0]+ans[1], ans[1])

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

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

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

ans_water = -1
ans_sugar = -1
ans_sugar_water = -1
ans_density = -1

W = sorted(list(W))
S = sorted(list(S))

for i in W :
    for j in S :
        if (i+j) > F :
            break
        if i*E < j*100 :
            break
        density = (j/(i+j))
        if density > ans_density :
            ans_density = density
            ans_water = i
            ans_sugar = j
            ans_sugar_water = ans_water + ans_sugar
print(ans_sugar_water, ans_sugar)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
maxcon = 0
wans = 0
sans = 0
for i in range(f//(a*100) + 1):
    for j in range((f-i*100*a)//(b*100) + 1):
        for k in range((f-i*100*a-j*100*b)//c + 1):
            for l in range((f-i*100*a-j*100*b-k*c)//d + 1):
                if i+j+k+l != 0 and (k*c+l*d)*(100+e) <= e*(100*(i*a+j*b)+k*c+l*d):
                    con = 100*(k*c+l*d) / (100*(i*a+j*b)+k*c+l*d)
                    maxcon = max(maxcon, con)
                    if con == maxcon:
                        wans = 100*(i*a+j*b)
                        sans = k*c+l*d
print(wans+sans, sans)

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


water = set()
for a in range(F//(100*A)+1):
	for b in range(F//(100*B)+1):
		w = A*a + B*b
		if w > F//100:
			break
		water.add(w)
water.remove(0)

suger = set()
for c in range(F//C+1):
	for d in range(F//D+1):
		s = C*c + D*d
		if s > F:
			break
		suger.add(s)



max_num = 0
max_w, max_s = A, 0
for w in water:
	for s in suger:
		if 100*w+s > F or s > E*w:
			continue
		
		if max_num < s/w:
			max_num = s/w
			max_w, max_s = w, s

print(100*max_w+max_s, max_s)

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

n = f//(100*a)
m = f//(100*b)
p = f//c
q = f//d

mx = 0
for i in range(n+1):
    for j in range(m+1):
        for k in range(p+1):
            for l in range(q+1):
                if i == 0 and j == 0:
                    continue
                s = 100*a*i+100*b*j
                t = c*k+d*l
                u = 100*t/s
                if s + t> f:
                    continue
                if u > e:
                    continue
                if mx <= u:
                    mx = u
                    ans1, ans2 = s+t, t
                    if mx == e:
                        print(ans1, ans2)
                        exit()
print(ans1, ans2)

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

n = f//(100*a)
m = f//(100*b)
p = f//c
q = f//d

mx = 0
for k in range(p+1):
    for l in range(q+1):
        for i in range(n+1):
            for j in range(m+1):
                if i == 0 and j == 0:
                    continue
                s = 100*a*i+100*b*j
                t = c*k+d*l
                u = 100*t/s
                if s + t> f:
                    continue
                if u > e:
                    continue
                if mx <= u:
                    mx = u
                    ans1, ans2 = s+t, t
                    if mx == e:
                        print(ans1, ans2)
                        exit()
print(ans1, ans2)

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

n = f//(100*a)
m = f//(100*b)
p = f//c
q = f//d

mx = 0
state = True
for k in range(p+1):
    for l in range(q+1):
        for i in range(n+1):
            for j in range(m+1):
                if i == 0 and j == 0:
                    continue
                s = 100*a*i+100*b*j
                t = c*k+d*l
                u = 100*t/s
                if s + t> f:
                    continue
                if u > e:
                    continue
                if mx < u:
                    state = False
                    mx = u
                    ans1, ans2 = s+t, t
                    if mx == e:
                        print(ans1, ans2)
                        exit()
if state:
    print(100*a, 0)
else:
    print(ans1, ans2)

Solution (Python):
import itertools
A, B, C, D, E, F = [int(_) for _ in input().split()]
W = [0] * (F+1)
S = [0] * (F+1)
for a, b in itertools.product(range(F // (100*A) + 1), range(F//(100*B) + 1)):
    if 100*A*a+100*B*b <= F:
        W[100*A*a+100*B*b] = min(E*(A*a+B*b), F-100*A*a-100*B*b)

for c, d in itertools.product(range(F // C + 1), range(F // D + 1)):
    if C*c+D*d <= F:
        S[C*c+D*d] = C*c+D*d
for i in range(F):
    if S[i+1] == 0:
        S[i+1] = S[i]
water = 100*A
sugar = 0
for i in range(1, F+1):
    if W[i] and S[W[i]]/i > sugar/water:
        sugar, water = S[W[i]], i
print(sugar+water, sugar)

Solution (Python):
a, b, c, d, e, f = [int(i) for i in input().split()]
waterA = [a * 100 * i for i in range(int(f / (100 * a)) + 1)]
waterB = [b * 100 * i for i in range(int(f / (100 * b)) + 1)]
sugarC = [c * i for i in range(int(f / c) + 1)]
sugarD = [d * i for i in range(int(f / d) + 1)]


_water = []
for i in range(len(waterA)):
    for j in range(len(waterB)):
        if 100 * a * i + 100 * b * j <= f:
            _water.append(100 * a * i + 100 * b * j)
_water = sorted(_water)[1:]
water = [_water[0]]
for i in range(1, len(_water)):
    if _water[i] != _water[i - 1]:
        water.append(_water[i])

_sugar = []
for i in range(len(sugarC)):
    for j in range(len(sugarD)):
        if c * i + d * j <= f:
            _sugar.append(c * i + d * j)
_sugar = sorted(_sugar)
sugar = [_sugar[0]]
for i in range(1, len(_sugar)):
    if _sugar[i] != _sugar[i - 1]:
        sugar.append(_sugar[i])



maxSugar = [-1, -1, -1]  
for i in range(len(sugar)):
    for j in range(len(water)):
        if sugar[i] + water[j] > f:
            continue
        elif maxSugar[0] < sugar[i]/(sugar[i]+water[j]) <= e/(100+e):
            maxSugar[0] = sugar[i]/(sugar[i]+water[j])
            maxSugar[1] = sugar[i]
            maxSugar[2] = sugar[i] + water[j]
        

if maxSugar[0] == -1:
    print("1 0")
else:
    print("{} {}".format(maxSugar[2], maxSugar[1]))

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

sug = 0
sugwat = 100 * a
for h in range(0,f + 1,100 * a):
    if h > f:
        break
    for i in range(0, f + 1, 100 * b):
        if h + i > f:
            break
        for j in range(0, f + 1, c):
            if h + i + j <= f:
                if h + i + j > 0:
                    if 100 * (j / (h + i + j)) > 100 * (e / (100 + e)):
                        break
            else:
                break
            for k in range(0, f + 1, d):
                if h + i + j + k <= f:
                    if h + i + j + k > 0:
                        if 100 * ((j + k) / (h + i + j + k)) <= 100 * (e / (100 + e)):
                            if 100 * (sug / sugwat) <= 100 * ((j + k) / (h + i + j + k)):
                                sugwat = h + i + j + k
                                sug = j + k
                else:
                    break

print(sugwat, sug)

Solution (Python):

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

max_rate = 0
ans = (1, 0, 0, 0)
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        
        if water == 0: continue 
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for k in list(range(salt_upper // C + 1))[::-1]:
            for l in list(range(salt_upper // D + 1))[::-1]:
                salt = k * C + D * l
                
                if salt == 0: continue
                elif salt / water > E: continue
                elif salt + 100 * water > F: continue
                
                if salt / water > max_rate_tmp:
                    ans_tmp = (i, j, k, l)
                    max_rate_tmp = salt / water
                break
        
        if max_rate_tmp == 0: continue
        elif max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
ans = []
water = []
for i in range(31):
    for j in range(31):
        tmp = 100*i*A + 100*j*B
        if tmp <= F:
            water.append(tmp)
water = list(set(water))
water.remove(0)

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

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

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
a*=100
b*=100
res=chk=0
ans=[]

for i in range(16):
    for j in range(16):
        for k in range(1501):
            w=(i*a)+(j*b)
            s=(k*c)
            o=(w//100)*e
            if w==0:
                pass
            elif w+s>f or s>o:
                break
            else:
                s+=(min(f-w-s,o-s)//d)*d
                if len(ans)==0:
                    ans=[s/(w+s),w+s,s]
                elif s/(w+s)>ans[0]:
                    ans=[s/(w+s),w+s,s]
print(ans[1],ans[2])

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
x = []
y = []
t = 100 * e / (100 + e)
for i in range(f // (100 * a) + 1):
    bb = f - 100 * a * i
    for j in range(bb // (100 * b) + 1):
        if 100 * (a * i + b * j) in x:
            continue
        else:
            x.append(100 * (a * i + b * j))
for i in range(f // c + 1):
    dd = f - c * i
    for j in range(dd // d + 1):
        if c * i + d * j in y:
            continue
        else:
            y.append(c * i + d * j)
y.sort()
rr = 0
ans = []
for i, xi in enumerate(x):
    for j, yi in enumerate(y):
        if xi + yi == 0:
            continue
        r = 100 * yi / (xi + yi)
        if r > t:
            break
        elif xi + yi <= f and rr <= r:
            ans = [xi + yi, yi]
            rr = r
print(ans[0], ans[1])

Solution (Python):
A = list(map(int, input().split()))
sugar = []
water = []
if A[2] == 1:
    sugar = [i for i in range(A[5]+1)]
else:
    for i in range(10 + (1 + A[5])//A[2]):
        for j in range(10 + (A[5]-A[2]*i+1)//A[3]):
            if A[2] * i + A[3] * j not in sugar and A[2] * i + A[3] * j <= 3000:
                sugar.append(A[2] * i + A[3] * j)
for i in range(2 + 31//A[0]):
    for j in range(2 + (31 - i)//A[1]):
        if A[0] * i + A[1] * j <= 30 and A[0] * i + A[1] * j not in water:
            water.append(A[0] * i + A[1] * j)
ans = 0
anssugar = 0
answater = min(A[0], A[1]) * 100
for i in sugar:
    for j in water:
        if i + j != 0:
            if ans < 100.0 * i / (i + j) and (i + 100 * j) <= A[5] and i  <= j * A[4]:
                ans = 100.0 * i / (i + j)
                anssugar = i
                answater = 100 * j

print(str(anssugar + answater)+" "+str(anssugar))

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
waters,sugars = [],[]
ans_w = 0
ans_s = 0
ans_d = 0

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

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

for w in waters:
    for s in sugars:
        if (w+s) <= f:
            s_e = w/100 * e
            if s_e < s or w+s == 0:
                continue
            if (100*s/(w+s)) > ans_d:
                ans_w = w
                ans_s = s
                ans_d = 100*s/(w+s)

if ans_w == ans_s == ans_d == 0:
    print('%d 0' % (a*100))
else:
    print('%d %d' % (ans_w+ans_s,ans_s))

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
a_num = int(F/(100*A))
b_num = int(F/(100*B))
c_num = int(F/C)
concentration = 0
ans1 = 100*A
ans2 = 0
for i in range(a_num+1):
    a = i*100*A
    for j in range(b_num+1):
        b = j*100*B
        if a+b > F:
            break
        for k in range(c_num+1):
            c = k*C
            if a+b+c > F:
                break
            if ((a+b)/100)*E < c:
                break
            limit_e = ((a+b)/100)*E - c
            limit_f = F - (a+b+c)

            d = min(int(limit_e/D)*D, int(limit_f/D)*D)
            if d < 0:
                break
            if a+b+c+d == 0:
                break
            _concentration = (100*(c+d))/(a+b+c+d)
            if _concentration > concentration:
                concentration = _concentration
                ans1 = a+b+c+d
                ans2 = c+d
print(ans1, ans2)