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):
from math import ceil, floor


def exist(A, B, x):
    """
    check if i and j exist such that Ai + Bj = x
    """
    max_i = x // A
    for i in range(max_i + 1):
        if (x - A * i) % B == 0:
            return True
    else:
        return False


A, B, C, D, E, F = [int(elem) for elem in input().split(' ')]

max_density = 0.
status_when_max_dens = {'water': 0, 'sugar': 0}
for x in range(1, F + 1):
    if exist(100 * A, 100 * B, x):
        for y in range(F - x + 1):
            if exist(C, D, y):
                density = y / (x + y)
                if (density >= max_density)\
                and (y <= x / 100 * E)\
                and (x + y <= F):
                    max_density = density
                    status_when_max_dens['water'] = x
                    status_when_max_dens['sugar'] = y


water = status_when_max_dens['water']
sugar = status_when_max_dens['sugar']
print(water + sugar, sugar)

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

for i in range(100*a, f+1, 100):
    b_max = i // (100*b)
    for j in range(0, b_max+1):
        if (i-j*b*100) % (100*a) == 0:
            break
    else:
        continue

    sugar = 0
    for k in range(0, i//100*e+1):
        d_max = k // d
        for l in range(0, d_max+1):
            if (k-d*l) % c == 0:
                if k > sugar and i + k <= f:
                    sugar = k

    if sugar / (i+sugar) * 100 >= con:
        con = sugar / (i+sugar) * 100
        w, s = i, sugar

print("{} {}".format(w+s, s))

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

for a in range(1+F//100):
    for b in range(1+F//100):
        if 100*(a*A+b*B)<=F:
            M.append(100*(a*A+b*B))
for c in range(F//C):
    for d in range(F//D):
        if c*C+d*D<=F:
            S.append(c*C+d*D)
M = set(M)
S = set(S)

t = -1
ans1 = 0
ans2 = 0
for m in M:
    for s in S:
        if m==s==0:
            pass
        elif s<=E*m//100 and m+s<=F and t<(s*100)/(m+s):
            t = (s*100)/(m+s)
            ans1 = m+s
            ans2 = s

print(ans1, ans2)

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

for a in range(1+F//100):
    for b in range(1+F//100):
        if 100*(a*A+b*B)<=F:
            M.append(100*(a*A+b*B))

for c in range(1+F//C):
    for d in range(1+F//D):
        if c*C+d*D<=F:
            S.append(c*C+d*D)

ans1 = 0
ans2 = 0
t = -1
for m in M:
    for s in S:
        if m==s==0:
            pass
        elif m+s<=F and s<=E*m//100 and t<(100*s)/(s+m):
            t = (100*s)/(s+m)
            ans1 = m+s
            ans2 = s

print(ans1, ans2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
w=[]
for i in range(f//100+1):
    for j in range(f//100+1):
        x=100*a*i+100*b*j
        if x<=f:
            w.append(x)
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i!=0 or j!=0:
            if j<=e*(i//100):
                if i+j<=f:
                    con=(100*j)/(i+j)
                    if max_con<=con:
                        max_con=con
                        ans,ans_2=i+j,j
print(ans,ans_2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
w=[]
for i in range(f//100+1):
    for j in range(f//100+1):
        x=100*a*i+100*b*j
        if x<=f:
            w.append(x)
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i!=0 or j!=0:
            if j<=e*(i//100):
                if i+j<=f:
                    con=(100*j)/(i+j)
                    if max_con<=con:
                        max_con=con
                        ans=i+j
                        ans_2=j
print(ans,ans_2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
w=[]
for i in range(f//100+1):
    for j in range(f//100+1):
        x=100*a*i+100*b*j
        if x<=f:
            w.append(x)
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i==0 and j==0:
            continue
        elif e*(i//100)<j:
            continue
        elif f<i+j:
            continue
        else:
            con=(100*j)/(i+j)
            if max_con<=con:
                max_con=con
                ans=i+j
                ans_2=j
print(ans,ans_2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
w=[]
for i in range(0,f//100+1):
    for j in range(0,f//100+1):
        x=i*a*100+j*b*100
        if x<=f:
            w.append(x)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i==0 and j==0:
            continue
        elif e*(i//100)<j:
            continue
        elif f<i+j:
            continue
        else:
            con=(100*j)/(i+j)
            if max_con<=con:
                max_con=con
                ans=i+j
                ans_2=j
print(ans,ans_2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
w=[]
for i in range(0,f//100+1):
    for j in range(0,f//100+1):
        x=i*a*100+j*b*100
        if x<=f:
            w.append(x)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i==0 and j==0:
            continue
        elif e*(i//100)<j:
            continue
        elif i+j>f:
            continue
        else:
            con=(100*j)/(i+j)
            if max_con<=con:
                max_con=con
                ans=i+j
                ans_2=j
print(ans,ans_2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
w=[]
for i in range(0,f//100+1):
    for j in range(0,f//100+1):
        x=i*a*100+j*b*100
        if x<=f:
            w.append(x)
max_con=0
ans,ans_2=0,0
for x in w:
    for y in s:
        if x==0 and y==0:
            continue
        elif e*(x//100)<y:
            continue
        elif x+y>f:
            continue
        else:
            con=(100*y)/(x+y)
            if max_con<=con:
                max_con=con
                ans=x+y
                ans_2=y
print(ans,ans_2)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
w=[]
for i in range(0,f//100+1):
    for j in range(0,f//100+1):
        x=i*a*100+j*b*100
        if x<=f:
            w.append(x)
max_con=0
ans,ans_2=0,0
for x in w:
    for y in s:
        if x==0 and y==0:
            continue
        elif e*(x//100)<y:
            continue
        elif x+y>f:
            continue
        else:
            con=(100*y)/(x+y)
            if max_con<=con:
                max_con=con
                ans=x+y
                ans_2=y
print("{} {}".format(ans,ans_2))

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

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

water = []
for i in range(0, f//100+1):
    for j in range(0, f//100+1):
        x = i*a*100 + j*b*100
        if x <= f:
            water.append(x)
max_concentration = 0
ans1, ans2 = 0, 0
for x in water:
    for y in sugar:
        if x == 0 and y == 0:
            continue
        elif e * (x // 100) < y:
            continue
        elif x + y > f:
            continue
        else:
            concentration = (100 * y) / (x+y)
            if max_concentration <= concentration:
                max_concentration = concentration
                ans1 = x+y
                ans2 = y
print("{} {}".format(ans1, ans2))

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

W,S = [],[0]

for ai in range(ceil(F/A)):
    for bi in range(ceil(F/B)):
        w = 100*A*ai+100*B*bi
        if w <= F and 0 < w and w not in W:
            W.append(w)
for ci in range(ceil(F/C)):
    for di in range(ceil(F/D)):
        s = C*ci+D*di
        if s <= F and 0 < s and s not in S:
            S.append(s)

AnsWS,AnsS,r = 0,0,-1
for wi in W:
    for si in S:
        if r < si/wi and si <= E*(wi//100) and (wi+si) <= F:
            AnsWS,AnsS,r = wi+si,si,si/wi

print(AnsWS,AnsS)

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

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

water = []
for i in range(0, f//100+1):
    for j in range(0, f//100+1):
        x = i*a*100 + j*b*100
        if x <= f:
            water.append(x)
max_concentration = 0
ans1, ans2 = 0, 0
for x in water:
    for y in sugar:
        if x == 0 and y == 0:
            continue
        elif e * (x // 100) < y:
            continue
        elif x + y > f:
            continue
        else:
            concentration = (100 * y) / (x+y)
            if max_concentration <= concentration:
                max_concentration = concentration
                ans1 = x+y
                ans2 = y
print("{} {}".format(ans1, ans2))

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
max_concentration = 0
for i in range(0, f + 1, 100 * a):
    for j in range(0, f - i + 1, 100 * b):
        if i == 0 and j == 0:
            continue
        y = min((i + j) * e // 100, f - i - j)
        for k in range(0, y + 1, c):
            for l in range(0, y - k + 1, d):
                concentration = 100 * (k + l) / (i + j + k + l)
                if max_concentration <= concentration:
                    max_concentration = concentration
                    res1 = i + j + k + l
                    res2 = k + l
print(str(res1) + ' ' + str(res2))

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
t=100
for i in range(0,f+1,a*100):
    for j in range(0,f-i+1,b*100):
        k=i+j
        if k==0:
            continue
        s=min(f-i-j,(i+j)*e//100)
        for ii in range(0,s+1,c):
            for jj in range(0,s-ii+1,d):
                if t>e-(ii+jj)*100/(i+j):
                    t=e-(ii+jj)*100/(i+j)
                    x,y=ii+jj+i+j,ii+jj
print(str(x)+" "+str(y))

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
concentration_max = 0
tatal_max = 0
sugar_max = 0
for a in range(int(F/100/A)+1):
    rest_F = F - 100*A*a
    for b in range(int(rest_F/100/B)+1):
        sum_water = 100*(A*a+b*B)
        sum_sugar_max = min(sum_water/100*E,F-sum_water)
        for c in range(int(sum_sugar_max/C)+1):
            sum_sugar_max_rest = sum_sugar_max - c*C
            for d in range(int(sum_sugar_max_rest/D)+1):
                
                sum_sugar = c*C+d*D
                sum_total = sum_water+sum_sugar
                if sum_total == 0:
                    break
                concentration = sum_sugar/(sum_water+sum_sugar)
                if concentration >= concentration_max:
                    concentration_max = concentration
                    total_max = sum_total
                    sugar_max = sum_sugar
print(total_max,sugar_max)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
x=[]
for i in range(int(f/100+0.9)):
    for j in range(int(f/100+0.9)):
        if (100*a*i+100*b*j)<= f:
            x.append(100*a*i+100*b*j)
y=[]
for i in range(int(f/c+0.9)):
    for j in range(int(f/d+0.9)):
        if (c*i+d*j)<= f:
            y.append(c*i+d*j)
p=e/(100+e)
maxp=0
mj=0
mi=0
for i in x:
    for j in y:
        if((i+j<=f) and (i+j)>0 and (j/(i+j)<=p)):
            if(j/(i+j)>=maxp):
                mj=j
                mi=i
                maxp=j/(i+j)
print(str(mj+mi)+" "+str(mj))

Solution (Python):
def c_sugar_water(A, B, C, D, E, F):
    x = set()  
    y = set()  
    for i in range(F // 100 + 1):
        for j in range(F // 100 + 1):
            tmp = 100 * A * i + 100 * B * j
            if tmp <= F:
                x.add(tmp)
    for i in range(F):
        for j in range(F):
            tmp = C * i + D * j
            if tmp <= F:
                y.add(tmp)

    concentration = 0  
    tmp = [0, 0]
    for water in x:
        for sugar in y:
            if water == 0 and sugar == 0:
                
                continue
            elif E * (water // 100) < sugar:
                
                continue
            elif water + sugar > F:
                
                continue
            else:
                if (100 * sugar) / (water + sugar) >= concentration:
                    concentration = (100 * sugar) / (water + sugar)
                    tmp = [water + sugar, sugar]
    ans = '{} {}'.format(tmp[0], tmp[1])
    return ans

A,B,C,D,E,F = [int(i) for i in input().split()]
print(c_sugar_water(A, B, C, D, E, F))

Solution (Python):
a,b,c,d,e,f = (int(i) for i in input().split())
w,s,num,answer = set(),set(),0,[a*100,0]
for i in range((f-f%(a*100))//(a*100)+1):
	for j in range((f-f%(b*100))//(b*100)+1):
		if i*a*100+j*b*100 <= f:
			w.add(i*a*100+j*b*100)
		else:
			break
smax = int(e*f/((100+e)*1.0))
for i in range((smax-smax%c)//c+1):
	for j in range((smax-smax%d)//d+1):
		if i*c+j*d <= smax:
			s.add(i*c+j*d)
		else:
			break
w2,s2 = sorted(list(w))[::-1],sorted(list(s))[::-1]
for i in w2:
	for j in s2:
		if 0 < i+j <= f and e*i>=100*j and num<(j/((i+j)*1.0)):
			num =  j/((i+j)*1.0)
			answer = [i,j]
print(sum(answer),answer[1])

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

mizu_arr = []
for i in range(F // (A*100) + 1):
    for j in range((F - i * A * 100) // (B*100) + 1):
        mizu = i * A * 100 + j * B * 100
        if mizu > 0:
            mizu_arr.append(mizu)

mizu_arr = sorted(mizu_arr)

def func(sato):
    min_mizu = sato * 100.0 / E
    max_mizu = F - sato
    for mizu in mizu_arr:
        if max_mizu < mizu:
            return None
        if min_mizu <= mizu:
            return mizu
    return None

max_nodo = 0
ans = [A*100, 0]
max_sato = (F // (100 + E)) * E
for i in range(max_sato // C + 1):
    for j in range((max_sato - i * C) // D + 1):
        sato = i * C + j * D
        mizu = func(sato)
        if not mizu == None:
            if 100 * sato / (mizu + sato) > max_nodo:
                ans = [mizu + sato, sato]
                max_nodo = 100 * sato / (mizu + sato)
              
print("{} {}".format(ans[0], ans[1]))

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
sugar = []
for i in range(f//c):
	for k in range(f//d):
		sugartotal = i*c+k*d
		if sugartotal <= f:
			sugar.append([i,k])
n = len(sugar)
ans = []
cans = []
for i in range(n):
	sugartotal = sugar[i][0]*c+sugar[i][1]*d
	watermax = f-sugartotal
	for k in range(watermax//(100*a)+1):
		for p in range(watermax//(100*b)+1):
			if k>0 or p>0:
				watertotal = k*100*a+p*100*b
				if watertotal <= watermax and (watertotal/100)*e>=sugartotal:
					ans.append(sugartotal/(sugartotal+watertotal))
					cans.append([watertotal+sugartotal,sugartotal])

mdensity = max(ans)
ind = ans.index(mdensity)
print(cans[ind][0],cans[ind][1])

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
maxden = 0
amax = f //(a*100)
water=a*100
sugar=0
for i in range(amax+1):
  waterA = i*100*a
  res = f-waterA
  bmax = res // (b*100)
  for j in range(bmax+1):
    waterB = j*100*b
    waterS =waterA+waterB
    res = f-waterS
    cmax = res // c
    for k in range(cmax+1):
      sugarC = k*c
      res = f-waterS-sugarC
      dmax = res // d
      for l in range(dmax+1):
        sugarD = l*d
        sugarS = sugarC+sugarD
        if(sugarS+waterS==0):break
        den = (sugarS)*100/(sugarS+waterS)
        
        
        
        if(den>maxden and (den*(100+e)/100)-e<=10**-5):
          maxden = den
          sugar = sugarS
          water = waterS

print(str(water+sugar)+" "+str(sugar))

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

for a in range(F//100*A+1):
    for b in range((F-a*A*100)//100*B+1):
        water = 100*(a*A+b*B)
        limit = F-water
        for c in range(limit//C+1):
            for d in range((limit-c*C)//D+1):

                sugar = c*C + d*D

                if water == 0 or sugar == 0:
                    continue
                conc = sugar / (sugar + water)
                if sugar/(water//100) <= E and conc > c_max:
                    c_max = conc
                    sw_max = sugar + water
                    s_max = sugar
if c_max ==0:
    sw_max = 100*A
    s_max=0
print(sw_max,s_max)

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

for a in range(F//100*A+1):
    for b in range((F-a*A*100)//100*B+1):
        water = 100*(a*A+b*B)
        limit = F-water
        for c in range(limit//C+1):
            for d in range((limit-c*C)//D+1):

                sugar = c*C + d*D
                
                if water == 0 or sugar == 0:
                    continue
                conc = sugar / (sugar + water)
                if water + sugar <= F and sugar/(water//100) <= E and conc > c_max:
                    c_max = conc
                    sw_max = sugar + water
                    s_max = sugar
if c_max ==0:
    sw_max = 100*A
    s_max=0
print(sw_max,s_max)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)
 
g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar
import time
time.sleep(A*0.08)
print("{0} {1}".format(Smax+Hmax, Smax))

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)

g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar

print("{0} {1}".format(Smax+Hmax, Smax))

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
x = 1
y = -1
for i in range(0, F+1, 100*A):
    for j in range(0, F-i+1, 100*B):
        m = min(F - i - j, (i + j) * E // 100)
        if i + j == 0:
            continue
        for k in range(0, m+1, C):
            for l in range(0, m-k+1, D):
                if y / x < (k+l) / (i+j):
                    x = i + j
                    y = k + l
print(x+y, y)

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


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

waters = []
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        amount = 100 * (i * a + j * b)
        if amount <= f:
            waters.append(amount)

sugers = []
for i in range(f // c + 1):
    for j in range(f // d + 1):
        amount = i * c + j * d
        if amount <= f:
            sugers.append(amount)

waters = set(waters)
sugers = set(sugers)

maxp = -1.0
res_w = 0
res_s = 0

for w in waters:
    for s in sugers:
        if w + s > f or w + s == 0:
            continue
        capa = w // 100 * e
        if s > capa:
            continue
        p = 100 * s / (w + s)
        if maxp < p:
            maxp, res_w, res_s = p, w + s, s

print("%d %d" % (res_w, res_s))

Solution (Python):


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

waters = []
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        amount = 100 * (i * a + j * b)
        if amount <= f:
            waters.append(amount)

sugers = []
for i in range(f // c + 1):
    for j in range(f // d + 1):
        amount = i * c + j * d
        if amount <= f:
            sugers.append(amount)

maxp = -1.0
res_w = 0
res_s = 0

for w in waters:
    for s in sugers:
        if w + s > f or w + s == 0:
            continue
        capa = w // 100 * e
        if s > capa:
            continue
        p = 100 * s / (w + s)
        if maxp < p:
            maxp, res_w, res_s = p, w + s, s

print("%d %d" % (res_w, res_s))

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

ans_cons = 0
whole_weight = 100 * a
suger_weight = 0

water = []
suger = []

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

for k in range(f-(100*a)+1):
  for l in range(f-(100*a)+1):
    s = c * k + d * l
    if s <= f:
      suger.append(s)
for wa in water:
  for su in suger:
    if (wa + su) == 0:
      continue
    if (wa + su) > f:
      continue
    cons = su * 100 / (wa + su)
    limit = e * 100 / (100 + e)

    if cons > limit:
      continue

    if cons > ans_cons:
      ans_cons = cons
      whole_weight = wa + su
      suger_weight = su

print("{} {}".format(whole_weight, suger_weight))

Solution (Python):
a,b,c,d,e,f=[int(i) for i in input().split(' ')]
a=a*100
b=b*100
am = f//a
bm = f//b
cm = int((f/((100+e)/e))//c)
dm = int((f/((100+e)/e))//d)

yl=0
yn=0
ys=0
for i_a in range(am+1):
  la=i_a*a
  for i_b in range(bm+1):
    lb=i_b*b
    if 0<la+lb<=f:
      for i_c in range(cm+1):
        lc=i_c*c
        if 0<la+lb+lc<=f:
          for i_d in range(dm+1):
            ld=i_d*d
            if 0<la+lb+lc+ld<=f:
              if (lc+ld)/(la+lb+lc+ld) <= e/(100+e):
                n=(lc+ld)/(la+lb+lc+ld)
                if n >= yn:
                  yn=n
                  yl=la+lb+lc+ld
                  ys=lc+ld
print(yl,ys)

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

INF = 100
ans = 0
ans2 = [100 * A, 0]
for i in range(INF):
    if A * 100 * i > F:
        break

    for j in range(INF):
        if A * 100 * i + B * 100 * j > F:
            break

        for k in range(INF):
            if A * 100 * i + B * 100 * j + C * k > F:
                break

            for l in range(INF):
                if A * 100 * i + B * 100 * j + C * k + D * l > F:
                    break

                if i == 0 and j == 0 and k == 0 and l == 0:
                    continue
                tmp = (C * k + D * l) / (A * 100 * i + B * 100 * j + C * k + D * l) 
                if tmp <= E / (E + 100) and tmp > ans:
                    ans = tmp
                    ans2[0] = A * 100 * i + B * 100 * j + C * k + D * l
                    ans2[1] = C * k + D * l
print("%d %d" % (ans2[0], ans2[1]))

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

AMAX = F // (A * 100)
BMAX = F // (B * 100)
sugar = 0
water = min(A,B)*100

res = 0
for i in range(AMAX + 1):
	for j in range(BMAX + 1):
		if i == 0 and j == 0:
			continue
		cwater = A * i + B * j
		CMAX = (F - cwater * 100) // C
		DMAX = (F - cwater * 100) // D
		for k in range(CMAX + 1):
			for l in range(DMAX + 1):
				csugar = k * C + l * D
				if cwater * E < csugar:
					break;
				if F < cwater * 100 + csugar:
					break;
				curr = csugar / (cwater * 100 + csugar)
				if curr > res:
					water = cwater * 100
					sugar = csugar
					res = curr

print(water + sugar, sugar)

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

w = 0
s = 0
ratio = 0

for i in range((f // (b*100))+1):
    for j in range(((f-(i*b*100))//(a*100))+1):
        if i == 0 and j == 0:
            continue
        smax = min(f-(j*a+i*b)*100,(j*a+i*b)*e)
        sm = 0
        for k in range((smax//d)+1):
            sm = max(sm, k*d+c*((smax-(k*d))//c))
        if ratio <= sm/((j*a+i*b)*100+sm):
            ratio = sm/((j*a+i*b)*100+sm)
            w = (j*a+i*b)*100
            s = sm


print("%i %i" %(w+s,s))

Solution (Python):






from sys import stdin









def solve(A, B, C, D, E, F):
  max_concent = (0, 0, 0)  
  for wa in range(0, F + 1, 100 * A):   
    for w in range(wa, F + 1, 100 * B): 
      cap = min(F - w, E * w // 100)    
      for sc in range(0, cap + 1, C):   
        for s in range(sc, cap + 1, D): 
          concent = 100.0 * s / (s + w) if s > 0 else 0.0  
          max_concent = max(max_concent, (concent, s + w, s))
  return max_concent[1:]

A, B, C, D, E, F = [int(w) for w in stdin.readline().split()]
print('%d %d' % solve(A, B, C, D, E, F))

Solution (Python):


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

amax = f // (a * 100)
bmax = f // (b * 100)

maxd = 0
maxw = min(a, b) * 100
maxs = 0
for i in range(amax + 1):
    for j in range(bmax + 1):
        if i == j == 0:
            continue
        w = i * a + j * b
        if w * 100 > f:
            continue
        cmax = (f - w * 100) // c
        dmax = (f - w * 100) // d
        for k in range(cmax + 1):
            for l in range(dmax + 1):
                s = k * c + l * d
                if w * e < s:
                    break
                if f < w * 100 + s:
                    break
                div = s / (w * 100 + s)
                if maxd < div:
                    maxw = w * 100 + s
                    maxs = s
                    maxd = div

print(maxw, maxs)

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

mx = 0
mx_x = 100*A
mx_y = 0
for i in xrange(31):
    for j in xrange(16):
        if i + j == 0 or 100*A*i + 100*B*j >= F: continue
        for k in xrange(101):
            for l in xrange(51):
                if 100*A*i + 100*B*j + C*k + D*l > F: continue
                if (A*i + B*j)*E < C*k + D*l: continue
                a = 100*A*i + 100*B*j
                b = C*k + D*l
                if 100.0*b/(a + b) > mx:
                    mx_x = a + b
                    mx_y = b
                    mx = 100.0*b/(a + b)
print mx_x, mx_y

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

mx = 0
mx_x = 100*A
mx_y = 0
for i in xrange(31):
    for j in xrange(16):
        for k in xrange(101):
            for l in xrange(51):
                if 100*A*i + 100*B*j + C*k + D*l > F: continue
                if (A*i + B*j)*E < C*k + D*l: continue
                a = 100*A*i + 100*B*j
                b = C*k + D*l
                if a > 0 and 100.0*b/(a + b) > mx:
                    mx_x = a + b
                    mx_y = b
                    mx = 100.0*b/(a + b)
print mx_x, mx_y