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


def FindMaxCon(res, water, C, D, E):
  c = 0
  d = 0
  tmpCon = 0
  dp = list([False] * 3001)
  dp[0] = True
  for i in range(3001):
    if(i - C >= 0 and i - D >= 0):
      dp[i] = dp[i - C] or dp[i - D]
    elif(i - C >= 0):
      dp[i] = dp[i - C]
    elif(i - D >= 0):
      dp[i] = dp[i - D]
  tmpSugar = 0
  for i in range(min(res, int(E * water / 100)) + 1):
    if(dp[i]):
      tmpSugar = i
  ans = tmpSugar
  return ans

A, B, C, D, E, F = (int(_) for _ in input().split())
amax = F / (A * 100)
bmax = F / (B * 100)
amax = int(amax)
bmax = int(bmax)
water = 0
sugar = 0
waterAns = 100 * A
sugarAns = 0
con = 0
conAns = 0
for a in range(1, amax + 1):
  for b in range(bmax + 1):
    water = 100 * (a * A + b * B)
    if(water > F):
      continue
    else:
      res = F - water
      tmp = FindMaxCon(res, water, C, D, E)
      sugar = tmp
      con = sugar / water
      if(con > conAns):
        conAns = con
        waterAns = water
        sugarAns = sugar
answer = str(waterAns + sugarAns) + " " + str(sugarAns)
print(answer)

Solution (Python):
abc = input().split()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])
d = int(abc[3])
e = int(abc[4])
f = int(abc[5])

x = []
y = []
pair = []
con = []


for i in range(int((f/100)+1)):
    for j in range(int((f/100)+1)):
        canx = ((a*i)+(b*j))*100
        if canx<=f:
            x.append(canx)

if x == []:
    print('x is empty')
            
for i in range(f):
    for j in range(f):
        cany = (c*i)+(d*j)
        if cany<=f:
            y.append(cany)
            
if y == []:
    print('y is empty')
            
for i in x:
    for j in y:
        if i+j<=f:
            if i!=0:
                if 100*j/i<=e:
                    pair.append([i, j])

if pair == []:
    print('pair is empty')

for i in pair:
    if sum(i)!=0:
        con.append(i[1]/sum(i))
    
if con == []:
    print('con is empty')
    
ans = pair[con.index(max(con))]
print(sum(ans), ans[1])

Solution (Python):

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


sugar_list=[0]*(F+1)
i=0
while i <= F :
	for j in range(F):
		val=C*i+D*j
		if val > F:
			break
		elif val <= F:
			sugar_list[val]=1
	i+=1





water_list=[0]*(F/100+1)

loop_cnt=F/100+1

i=0
while i <= loop_cnt:
	for j in range(loop_cnt):
		val=A*i+B*j
		if val > F/100:
			break
		else:
			
			water_list[val]=1
	i+=1




max_noudo=float(E)/(100+E)



hwm=0
water_ans=A*100
sugar_ans=0
for i in range(1,len(water_list)):
	for j in range(len(sugar_list)):
		if water_list[i]*sugar_list[j]==1 and i*100+j<=F and j<=i*E:
			if float(j)/(i*100+j)>hwm:
				hwm=float(j)/(i*100+j)
				water_ans=i*100
				sugar_ans=j
				

print water_ans+ sugar_ans, sugar_ans

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
rw = rs = 0
conc = 0.0
s = set()
t = set()
for ai in range(30):
    for bi in range(15):
        wat = 100*(a*ai+b*bi)
        if wat > f: continue
        if wat in s:
            continue
        else:
            s.add(wat)
for ci in range(3000):
    for di in range(1500):
        sug = c*ci+d*di
        if sug > f: continue
        if sug in t:
            continue
        else:
            t.add(sug)
for w in s:
    if w == 0: continue
    for x in t:
        if w+x <= f and x/w <= 0.01*e:
            if conc < (100*x)/(x+w):
                conc = (100*x)/(x+w)
                rw = w; rs = x
if rs == 0 and rw == 0: rw = a*100
print(rw+rs,rs)

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

a = 100 * a
b = 100 * b

max_w = 0
max_sugar_w = 0
max_c = 0
for i in range(31):
    for j in range(31):
        water = a * i + b * j
        if 0 < water <= f:
            for k in range(50):
                for l in range(50):
                    sugar = c * k + d * l
                    if water + sugar <= f:
                        con = 100 * sugar /(sugar+water)
                        if sugar <= water/100*e:
                            if con >= max_c:
                                max_w = water + sugar
                                max_sugar_w = sugar
                                max_c = con
print(str(int(max_w))+" "+str(int(max_sugar_w)))

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

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):
    for j in range(31):
        water = (i * a + j * b) * 100
        if (water <= f and water):
            nsug = min(water * e // 100, f - water)
            for k in range(nsug//c+1):
                l = (nsug - k*c)//d
                suger = k * c + l * d
                rate = 100 * suger / (suger + water)
                if(ans_rate <= rate):
                    ans_rate = rate
                    ans_sug = suger
                    ans_wat = water

print(ans_wat+ans_sug,ans_sug)

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

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):
  for j in range(31):
      wat=(i*a+j*b)*100
      if wat<=f and wat:
          psug = min(f-wat,wat//100*e)
          for k in range(psug//c+1):
              l = (psug-c*k)//d
              sug = k*c+l*d
              rate = 100*sug/(wat+sug)
              if ans_rate<=rate:
                  ans_wat = wat
                  ans_sug = sug
                  ans_rate = rate

print(ans_wat+ans_sug,ans_sug)

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

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):
  for j in range(31):
      wat=(i*a+j*b)*100
      if wat<=f and wat:
          psug = min(f-wat,wat//100*e)
          for k in range(psug//c+1):
              l = (psug-c*k)//d
              sug = k*c+l*d
              rate = 100*sug/(wat+sug)
              if ans_rate<=rate and rate<=e and wat+sug<=f:
                  ans_wat = wat
                  ans_sug = sug
                  ans_rate = rate

print(ans_wat+ans_sug,ans_sug)

Solution (Python):


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

x = set()


y = set()

for i in range(F//C+1):
    for j in range((F-C*i)//D+1):
        
            
        y.add( i * C + j * D)

for i in range(F//(100 * A)+1):
    for j in range((F-100*A*i)//(100*B)+1):
        if i + j == 0:
            continue
        x.add(i * A * 100 + j * B * 100)


ans_sweetwater = 1
ans_sugar = -1



for m in x:
    for n in y:
        
        if m + n <= F and m*E/100 >= n and ans_sugar/ans_sweetwater <= n/(m+n):
            ans_sweetwater =  m + n
            ans_sugar = n
            
print(ans_sweetwater,ans_sugar)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
 
x = set()
y = set()
 
for i in range(F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        if i + j == 0:
            continue
        x.add(A * i * 100 + B * j * 100)
 
for i in range(F // C + 1):
    for j in range((F - C * i) // D + 1):
        y.add(C * i + D * j)
 
ret_w = 1
ret_s = -1
 
for w in x:
    for s in y:
        if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
            ret_s = s
            ret_w = w + s
 
print(ret_w, ret_s)

Solution (Python):
import math

def concentration(water, sugar):
    if water + sugar == 0:
        return -1
    else:
        return 100 * sugar / (water + sugar)


if __name__ == "__main__":
    A, B, C, D, E, F = map(int, input().split(' '))
    res_water = 0
    res_sugar = 0
    for ia in range(math.ceil(F / (100 * A))):
        for ib in range(math.ceil(F / (100 * B))):
            water = 100 * (ia * A + ib * B)
            rest = F - water
            if rest < 0:
                break
            for ic in range(math.ceil(rest / C)):
                for id in range(math.ceil(rest / D)):
                    sugar = ic * C + id * D
                    if rest - sugar < 0:
                        break
                    if (water / 100) * E >= sugar and \
                       concentration(res_water, res_sugar) < concentration(water, sugar):
                        res_water = water
                        res_sugar = sugar
    print(res_water + res_sugar, res_sugar)

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

x = set()
y = set()

for i in range(F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        if i + j == 0:
            continue
        x.add(A * i * 100 + B * j * 100)

for i in range(F // C + 1):
    for j in range((F - C * i) // D + 1):
        y.add(C * i + D * j)

ret_w = 1
ret_s = -1

for w in x:
    for s in y:
        if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
            ret_s = s
            ret_w = w + s

print(ret_w, ret_s)

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

ret_w = 1
ret_s = -1
for a in range(F // (100 * A) + 1):
    w_a = a * A * 100
    for b in range((F - w_a) // (100 * B) + 1):
        if a + b == 0:
            continue
        w_b = b * B * 100

        max_suger = min(F - w_a - w_b, (w_a + w_b) // 100 * E)
        for c in range(max_suger // C + 1):
            s_c = c * C
            for d in range((max_suger - s_c) // D + 1):
                s_d = d * D
                if ret_s / ret_w < (s_c + s_d) / (w_a + w_b + s_c + s_d):
                    ret_s = s_c + s_d
                    ret_w = ret_s + w_a + w_b

print(ret_w, ret_s)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


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

    w_list, s_list = [False] * 3001, [False] * 3001
    for i in range(F // (A * 100) + 1):
        for j in range(F // (B * 100) + 1):
            w = 100 * A * i + 100 * B * j
            if w <= 3000:
                w_list[w] = True
    for i in range(F // C + 1):
        for j in range(F // D + 1):
            s = C * i + D * j
            if s <= 3000:
                s_list[s] = True

    best = -INF
    ans = 0, 0
    for s in range(len(s_list)):
        for w in range(len(w_list)):
            if s + w <= F and s_list[s] and w_list[w]:
                total = s + w
                if total > 0 and s <= w // 100 * E:
                    if s / total > best:
                        best = s / total
                        ans = total, s

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


if __name__ == '__main__':
    main()

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

max_ratio = -1
for cnt_A in [n for n in range(30) if 100*A*n <= F]:
  for cnt_B in [n for n in range(30) if 100*A*cnt_A * 100*B*n <= F]:
    for cnt_C in [n for n in range(1500) if n*C <= E*(A*cnt_A+B*cnt_B) and 100*A*cnt_A + 100*B*cnt_B + n*C <= F]:
      for cnt_D in [n for n in range(1500) if n*D + C*cnt_C <= E*(A*cnt_A + B*cnt_B)and 100*A*cnt_A + 100*B*cnt_B + C*cnt_C + D*n <= F]:
        if (cnt_A!=0 or cnt_B !=0)and max_ratio < (C*cnt_C+D*cnt_D)/(100*A*cnt_A+100*B*cnt_B):
          max_ratio = (C*cnt_C + D*cnt_D)/(100*A*cnt_A+100*B*cnt_B)
          a = 100*A*cnt_A + 100*B*cnt_B
          b = C*cnt_C + D*cnt_D
print(a+b, b)

Solution (Python):
L = list(map(int,input().split()))
A = L[0]
B = L[1]
C = L[2]
D = L[3]
E = L[4]
F = L[5]
dmax = 0
wmax = 0
smax = 0

a = 1
while a*A*100 <= F:
	b = 0
	while (a*A+b*B)*100 <= F:
		water = (a*A+b*B)*100
		c = 0
		while water + c*C <= F and c*C <= water*E/100:
			d = 0
			while water + c*C + d*D <= F and c*C + d*D <= water*E/100:
				dens = (c*C+d*D) / (water + c*C + d*D)
				if dmax <= dens:
					dmax = dens
					wmax = water
					smax = c*C + d*D
				d += 1
			c += 1
		b += 1
	a += 1
a = 0
b = 1
while (a*A+b*B)*100 <= F:
	water = (a*A+b*B)*100
	c = 0
	while water + c*C <= F and c*C <= water*E/100:
		d = 0
		while water + c*C + d*D <= F and c*C + d*D <= water*E/100:
			dens = (c*C+d*D) / (water + c*C + d*D)
			if dmax <= dens:
				dmax = dens
				wmax = water
				smax = c*C + d*D
			d += 1
		c += 1
	b += 1
print(wmax+smax,smax)

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

waters = set()
sugars = set()

for i in range(0, f+1):
    for j in range(0, f+1):
        watersum = 100*a*i + 100*b*j
        if watersum == 0 or watersum > f:
            break
        waters.add(watersum)

for i in range(0, f+1):
    for j in range(0, f+1):
        sugarsum = c*i + d*j
        if sugarsum > f:
            break
        sugars.add(sugarsum)


maxx = 0
answ, anss = 100*a, 0

for water in waters:
    for sugar in sugars:
        if water + sugar > f or sugar*(100+e) > e*(water+sugar):
            continue
        conc = sugar / (water + sugar)
        if maxx < conc:
            maxx = conc
            answ, anss = water, sugar

print(answ+anss, anss)

Solution (Python):

import itertools
A, B, C, D, E, F = map(int, input().split())
waterWeights = []
sugarWeights = []
ansFactor = []
for tmp in range(F//(100*A)+1):
    for tmp2 in range(F//(100*B)+1):
        factor = 100*A*tmp+100*B*tmp2
        if factor <= F:
            waterWeights.append(factor)
        else:
            pass

for tmp in range(F//C+1):
    for tmp2 in range(F//D+1):
        factor = C*tmp + D*tmp2
        if factor <= F:
            sugarWeights.append(factor)
        else:
            pass

for combi in itertools.product(waterWeights, sugarWeights):
    if combi[0]+combi[1] <= F and combi[0]+combi[1] != 0:
        if E*combi[0]/100 >= combi[1]:
            ansFactor.append(combi)
        else:
            pass
    else:
        pass
ans = sorted(ansFactor, key = lambda i: i[1]*100/(i[0]+i[1]), reverse=True)
print(str((ans[0])[0]+(ans[0])[1])+' '+str((ans[0])[1]))

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

maxx = 0
answ, anss = 100*a, 0

for i in range(0, 31):
    for j in range(0, 31):
        water = 100 * a * i + 100 * b * j
        if water == 0:
            continue

        rest = f - water
        if rest < 0:
            break

        ub = water * e // 100
        if ub > rest:
            ub = rest

        for k in range(0, 3001):
            rest2 = ub - c * k
            if rest2 < 0:
                break
            dnum = rest2 // d

            sugar = k * c + dnum * d
            conc = sugar / (water + sugar)
            if maxx < conc:
                maxx = conc
                answ, anss = water+sugar, sugar

print(answ, anss)

Solution (Python):
a,b,c,d,e,f = map(int,raw_input().split())
lim = f
f /= 100
wl = [False for _ in range(f+1)]
sl = [False for _ in range(f*e+1)]
if a <= f:
    wl[a] = True
if b <= f:
    wl[b] = True
if c <= f*e:
    sl[c] = True
if d <= f*e:
    sl[d] = True

for i in range(f):
    if wl[i] and i+a <= f:
        wl[i+a] = True
    if wl[i] and i+b <= f:
        wl[i+b] = True

for i in range(f*e):
    if sl[i] and i+c <= f*e:
        sl[i+c] = True
    if sl[i] and i+d <= f*e:
        sl[i+d] = True

maxd = 0.0
maxw = a*100
maxs = 0
for i,w in enumerate(wl):
    for j,s in enumerate(sl):
        if w and s and i*100+j <= lim:
            if i*e >= j and float(j) / float(100*i+j) > maxd:
                maxd = float(j) / float(100*i + j)
                maxw = i*100
                maxs = j
print maxw+maxs,maxs

Solution (Python):
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))


for i in range(1+n_a):
 for j in range(1+int((f-100*i*a)/(100*b))):
  for k in range(1+int((f-100*i*a-100*j*b)/c)):
   for l in range(1+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Solution (Python):
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))
for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Solution (Python):
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))


for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Solution (Python):
def main():
    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, sugar, mass = 0, 0, 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)

    
if __name__ == "__main__":
    main()

Solution (Python):
A,B,C,D,E,F = list(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):
from itertools import product


def main():
    """
    1 ≦ A < B ≦ 30
    1 ≦ C < D ≦ 30
    1 ≦ E ≦ 100
    100A ≦ F ≦ 3000 より
       A,B: 30回まで
       C,D: 100回まで
    """
    A, B, C, D, E, F = map(int, input().split())

    ans_w = 0
    ans_s = 0
    for a, b, c in product(range(31),
                           range(31),
                           range(101)):
        for d in range(101):
            w = (100 * A * a) + (100 * B * b)
            s = C * c + D * d

            if w == 0 or (w + s) > F:
                break

            
            if s * 100 == w * E:
                print(w + s, s)
                return

            
            
            if s * 100 > E * w:
                break

            
            
            if (ans_w, ans_s) == (0, 0) or \
                    s * ans_w > ans_s * w:
                ans_w, ans_s = w, s

    print(ans_w + ans_s, ans_s)

if __name__ == '__main__':
    main()

Solution (Python):
def Sugar_water():
    key_list = ["wA", "wB", "sC", "sD", "dE", "tF"]
    
    val = "17 19 22 26 55 2802"
    
    if 'LOCAL_FLAG' in globals():
        val_list = list(map(int, val.split()))
    else:
        val_list = list(map(int, input().split()))

    var = dict(zip(key_list, val_list))
    limit = var.copy()

    m_density=0
    m_sugar=0
    m_water=0

    limit_density=var['dE']/(100+var['dE'])
    limit['wA'] = int(var['tF']/100/var['wA'])
    limit['wB'] = int(var['tF']/100/var['wB'])

    for A in range(0, limit['wA']+1):
        for B in range(0, limit['wB']+1):
            water = 100*var['wA']*A + 100*var['wB']*B
            if(water > var['tF']):
                break
            elif((var['tF']-water)*m_density > (var['tF']-water)):
                break
            limit['sC'] = int(water/100*var['dE']/var['sC'])
            limit['sD'] = int(water/100*var['dE']/var['sD'])

            for C in range(0, limit['sC']+1):
                for D in range(0, limit['sD']+1):
                    sugar = var['sC']*C + var['sD']*D

                    total = water + sugar
                    density = sugar / total if total > 0 else 0

                    if(total > var['tF']):
                        break
                    elif(density > limit_density):
                        break
                    elif(density > m_density):
                        
                        m_density=density
                        m_sugar=sugar
                        m_water=water


    if(m_water == 0):
        m_water = 100*var['wA']
    print(m_sugar + m_water, " ", m_sugar)

Sugar_water()

Solution (Python):

import math

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

w_list = []
for i in range(math.ceil(F / (100 * A)) + 1):
    for j in range(math.ceil(F / (100 * B)) + 1):
        if i == 0 and j == 0:
            continue
        water = 100 * A * i + 100 * B * j
        if water <= F:
            w_list.append(water)

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

max_c = 0
max_w = 100 * A
max_s = 0
for w in set(w_list):
    for s in set(s_list):
        if w + s > F:
            continue
        if s > int(E * w / 100):
            continue
        c = 100 * s / (w + s)
        if c > max_c:
            max_c = c
            max_w = w
            max_s = s

print(max_w + max_s, max_s, end = " ")

Solution (Python):
def node(hen, sin):
    if hen == 0 or sin == 0:
        return 0
    return 100 * sin / (hen + sin)


a, b, c, d, e, f = [int(i) for i in input().split()]
node_ans = 0
water_ans = 0
sugar_ans = 0
for A in range(0, f, a * 100):
    for B in range(0, f, b * 100):
        water = A + B
        max_sugar = water * e
        for C in range(0, f, c):
            for D in range(0, f, d):
                sugar = C + D
                if max_sugar < sugar*100 or f < water + sugar or water == 0:
                    break
                elif node_ans <= node(water, sugar):
                    node_ans = node(water, sugar)
                    sugar_ans = sugar
                    water_ans = water

print(water_ans + sugar_ans, sugar_ans)

Solution (Python):


A , B , C , D , E , F = map(int ,input().split())
def solve():
    ans = (100*A , 0)
    for a in range(0,F,100*A):
        for b in range(0,F,100*B):
            water = a + b
            for c in range(0,F,C):
                for d in range(0,F,D):
                    sugar = c + d
                    if water + sugar > F or 100*sugar > E*water or water ==0:
                        break
                    elif 100*sugar == E*water:
                        return (water,sugar)
                    elif sugar*ans[0] > ans[1]*water:
                        ans = (water , sugar)
    return ans
ans = solve()
print(sum(ans),ans[1])

Solution (Python):
def nodef(w,s):
    return (s/(s+w))


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

best_w = 0
best_s = 0
best_node = 0

for i in range(30//a+1):
    for j in range(30//b+1):
        w = 100*(a*i + b*j)
        if w<=f and w:
            max_s = min(f-w,(a*i + b*j)*e)
            for k in range(max_s//c+1):
                l = (max_s-k*c)//d
                s = k*c + l*d
                node = nodef(w,s)
                if node >= best_node and node<=e and w+s<=f:
                    best_w = w
                    best_s = s
                    best_node = node
                    
print("{} {}".format((best_s+best_w ),best_s))

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

    waterA, waterB = 100 * A, 100 * B
    water = set()
    i = 0
    while waterA * i <= F:
        j = 0
        while waterA * i + waterB * j <= F:
            water.add(waterA * i + waterB * j)
            j += 1
        i += 1

    sugar = set()
    i = 0
    while C * i <= F // 100 * E:
        j = 0
        while C * i + D * j <= F // 100 * E:
            sugar.add(C * i + D * j)
            j += 1
        i += 1

    ph = dict()
    for i in persent(water, sugar):
        ph[i[0]] = i[1], i[2]

    a, b = ph[max(ph)]
    print(a + b, b)

def persent(w, s):
    max_ph = 100 * E / (100 + E)
    for a in w:
        for b in s:
            if 0 < a + b <= F:
                x = 100 * b / (a + b)
                if x <= max_ph:
                    yield x, a, b

main()

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
ans = [100*A, 0]
for a in range(0, F+1, A*100):
    for b in range(0, F+1, B*100):
        for c in range(0, F+1, C):
            for d in range(0, F+1, D):
                water = a+b
                sugar = c+d
                if water+sugar > F or water == 0 or 100*sugar > water*E:
                    break
                else:
                    if ans[1]/(ans[0]+ans[1]) < sugar/(water+sugar):
                        ans = [water, sugar]

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

Solution (Python):


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

waterCombinations = {0}
sugarCombinations = {0}

while True:
    copy = set(waterCombinations)
    for i in copy:
        m = i+a * 100
        n = i+b * 100
        if m <= f:
            waterCombinations.add(m)
        if n <= f:
            waterCombinations.add(n)
    if copy==waterCombinations:
        break

while True:
    copy = set(sugarCombinations)
    for i in copy:
        m = i+c
        n = i+d
        if m <= f:
            sugarCombinations.add(m)
        if n <= f:
            sugarCombinations.add(n)
    if copy==sugarCombinations:
        break


best = 0
bestWater = 1
bestSugar = 1
for i in waterCombinations:
    for j in sugarCombinations:
        maxSugarAllowed = e*(i/100)
        if i+j > 0:
            l = (100 * j) / (i + j)
            if best <= l and j <= maxSugarAllowed and i+j <= f:
                bestWater = i
                bestSugar = j
                best = l
print(bestWater + bestSugar, bestSugar)

Solution (Python):

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


ans_mizu = 1
ans_sato = 0
pat = []
mizu = set()
for i in range(int(F/100)+1):
    for j in range(int(F/100)+1):
        if 100*A*i + 100*B*j <= F:
            mizu.add(100*A*i+100*B*j)

mizu.remove(0)

for m in mizu:
    howaryo = (m*E)//100
    for i in range(int(howaryo/C)+1):
        for j in range(int(howaryo/D)+1):
            sato = C*i + D*j
            if (m + sato <= F) & (sato <= howaryo):
                ans_sato = max(ans_sato,sato)
                
    pat.append([m+ans_sato,ans_sato])
    ans_mizu = 1
    ans_sato = 0
    
pat.sort(key = lambda x:x[1]/(x[0]+x[1]), reverse = True)
print(pat[0][0],pat[0][1])

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
def FS():
    ans = (100*A,0)
    for a in range(0,F,100*A):
        for b in range(0,F,100*B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat,sug = (a + b),(c + d)
                    if wat == 0 or wat+sug > F or 100*sug > E*wat:
                        break
                    elif 100*sug == E*wat:
                        return (wat,sug)
                    elif sug*ans[0] > ans[1]*wat:
                        ans = (wat,sug)  
    return ans
ans = FS()
print(sum(ans),ans[1])

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
A,B = 100*A,100*B
def ql():
    ans = (0,A)
    for a in range(0,F,A):
        for b in range(0,F,B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat,sug = (a + b),(c + d)
                    if wat+sug > F or 100*sug > E*wat:
                        break
                    elif sug*ans[1] > ans[0]*wat:
                        ans = (sug,wat)  
    return ans
ans = ql()
print("{} {}".format(sum(ans),ans[0]))

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

def ql():
    ans = (0,A)
    for a in range(0,F,A):
        for b in range(0,F,B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat = (a + b)
                    sug = (c + d)
                    if wat == 0:
                        break
                    if wat+sug > F or 100*sug > E*wat:
                        break
                    elif 100*sug == E*wat:
                        return (sug,wat)
                    elif sug*ans[1] > ans[0]*wat:
                        ans = (sug,wat)  
    return ans
ans = ql()
print(str(ans[0]+ans[1]) + " " + str(ans[0]))

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc074/tasks/arc083_a
WA
"""
import sys
from sys import stdin
input = stdin.readline


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

    w = []
    s = []
    for i in range(int(F/100/A+1)):
        for j in range(int(F/100/B+1)):
            water = 100*A*i + 100*B*j
            if  water <= F and water > 0:
                w.append(water)

    for i in range(int(F/C+1)):
        for j in range(int(F/D+1)):
            sugar = C*i + D*j
            if sugar <= F and sugar > 0:
                s.append(sugar)

    max_density = (E*100) / (E+100)
    record_density = 0.0
    record = [w[0], 0]
    for i in w:
        for j in s:
            if i+j <= F:
                density = (100 * j) / (i + j)
                if density > record_density and density <= max_density:
                        record_density = density
                        record = [i+j, j]

    print(*record)


if __name__ == '__main__':
    main(sys.argv[1:])