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 satou(a,b):
    return 100 * b / (a+b)

a,b,c,d,e,f = map(int,input().split())
water = [-1 for j in range(f+2)]
sugar = [-1 for i in range(f+2)]
water[0] = 0
sugar[0] = 0

for i in range(f+1):
    if water[i] > -1:
        if i+100*a <= f :
            water[i+100*a] = i+100*a 
        if i+100*b <= f :
            water[i+100*b] = i+100*b
    if sugar[i] > -1:
        if i+c <= f :
            sugar[i+c] = i+c
        if i+d <= f :
            sugar[i+d] = i+d
w = list(set(water))
w.remove(-1)
w.remove(0)
s = list(set(sugar))
s.remove(-1)
s.remove(0)

mx = 0
ws = [100*a,0]
for i in w:
    for j in s:
        x = ((f-i) // j) * j
        y = ((e*i/100)//j) * j
        t = satou(i, min(x,y))
        if mx < t:
            mx = t
            ws = [i, min(x,y)]

print(int(sum(ws)), int(ws[1]))

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

tmp = 0
ans = [0,0]
for i in range(31):
  a = A*i
  if a*100 >= F:
    break
  for j in range(31):
    b = B*j
    if a+b == 0:
      continue
    w = (a+b)*100
    if w >= F:
      break
    for k in range(3001):
      c = C*k
      for l in range(3001):
        d = D*l
        s = c+d
        if w + s > F:
          break
        if (c+d) <= (a+b)*E:
          if (s*100)/w >= tmp:
            tmp = (s*100)/w
            ans = [s+w,s]
        else:
          break

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

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

ans_w = 0
ans_s = 0
max_ans = 0.0
for a in range(31):
    for b in range(31):
        w = 100 * (A * a + B * b)
        if w > F:
            break
        for c in range((w // 100 * E) // C + 1):
            for d in range(((w // 100 * E) - c) // D + 1):
                s = C * c + D * d
                if s > (w // 100 * E) or (w + s) > F:
                    break
                if w + s != 0:
                    n = (100 * s) / (w + s)
                    if n > max_ans:
                        max_ans = n
                        ans_w = w
                        ans_s = s

if ans_w == 0 and ans_s == 0:
    print(100 * A, 0)
else:
    print(ans_w + ans_s, ans_s)

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

tmp = 0
ans_A = 0
ans_B = 0
for a in range(31):
    for b in range(31):
        x = 100 * (a * A + b * B)
        if x > F:
            break
        for c in range((x // 100 * E) // C + 1):
            for d in range(((x // 100 * E) - c) // D + 1):
                y = c * C + d * D
                if x + y > F or y > x * E // 100:
                    break
                if x + y != 0:
                    if y / (x + y) > tmp:
                        ans_A = x + y
                        ans_B = y
                        tmp = y / (x + y)

if ans_A == 0:
    print(100 * A, 0)
else:
    print(ans_A, ans_B)

Solution (Python):
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int e = Integer.parseInt(sc.next());
		int f = Integer.parseInt(sc.next());
		int water = 0;
		int sugar = 0;
		for (int i = 0; i <= f; i += 100 * a) {
			for (int j = 0; i + j <= f; j += 100 * b) {
				for (int k = 0; i + j + k <= f; k += c) {
					for (int l = 0; i + j + k + l <= f; l += d) {
						if ((k + l) * 100 <= e * (i + j)) {
							if ((water == 0 && sugar == 0)|| sugar * (i + j + k + l) < (k + l) * water) {
								water = i + j + k + l;
								sugar = k + l;
							}
						}
					}
				}
			}
		}
		System.out.println(water + " " + sugar);
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Solution (Python):
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int e = Integer.parseInt(sc.next());
		int f = Integer.parseInt(sc.next());
		int water = 0;
		int sugar = 0;
		for (int i = 0; i <= f; i += 100 * a) {
			for (int j = 0; i + j <= f; j += 100 * b) {
				for (int k = 0; i + j + k <= f; k += c) {
					for (int l = 0; i + j + k + l <= f; l += d) {
						if ((k + l) * 100 <= e * (i + j)) {
							if ((water == 0 && sugar == 0)|| sugar * (i + j + k + l) < (k + l) * water) {
								water = i + j + k + l;
								sugar = k + l;
							}
						}
					}
				}
			}
		}
		System.out.println(water + " " + sugar);
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Solution (Python):
def solve(C, D, lim):
    ans = 0
    for i in range(3000):
        if C*i > lim:
            break
        for j in range(3000):
            eval = C*i + D*j
            if eval > lim:
                break
            elif eval > ans:
                ans = eval
    return ans

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

water = [] 
waterlen = 0
ans = [0, 0]
noudo = 0
for i in range(30):
    for j in range(30):
        val = 100*A*i + 100*B*j
        if val <= F:
            water.append(val)
            waterlen += 1
        else:
            break
water.pop(0)
waterlen -= 1
for i in range(waterlen):
    sugarlim = min(water[i] // 100 * E, F-water[i])
    sugar = solve(C, D, sugarlim)
    
    val = 100*sugar/(water[i]+sugar)
    if val > noudo:
        noudo = val
        ans[0] = water[i] + sugar
        ans[1] = sugar
if ans[0] == 0 and ans[1] == 0:
    ans[0] = 100*A
print(*ans)

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

water = set()
sugar = set()

i = 0
while 100*a*i<=f:
    j = 0
    while 100*a*i+100*b*j<=f:
        water.add(100*a*i+100*b*j)
        j+=1
    i+=1

i = 0
while c*i<=f:
    j = 0
    while c*i+d*j<=f:
        sugar.add(c*i+d*j)
        j+=1
    i+=1

sugar.add(0)

water = list(water)
sugar = list(sugar)
water.sort()
sugar.sort()

sugar2 = [0]*(f+1)
for i in range(len(sugar)-1):
    sugar2[sugar[i]:sugar[i+1]] = [sugar[i]]*(sugar[i+1]-sugar[i])

ans = [a*100,0]

for i in range(1,len(water)):
    s = min(f-water[i],water[i]*e//100)
    if ans[1]/ans[0]<sugar2[s]/(water[i]+sugar2[s]):
        ans = [water[i]+sugar2[s], sugar2[s]]

print(ans[0],end=' ')
print(ans[1])

Solution (Python):

def main():
    
    a, b, c, d, e, f = list(map(int, input().rstrip().split()))
    A = a * 100
    B = b * 100

    
    x, y = min(a, b) * 100, 0  
    dens = y / x

    
    for i in range(f // A + 1):
        for j in range(((f - A * i) // B) + 1):
            if i == 0 and j == 0:
                continue
            water = i * A + j * B
            rest = f - water
            for k in range(rest // c + 1):
                for l in range((rest - c * k) // d + 1):
                    sugar = c * k + d * l
                    total = water + sugar

                    if sugar / total > e / (e + 100):  
                        break
                    else:
                        if sugar / total > dens:
                            dens = sugar / total
                            x, y = total, sugar
    print(x, y)


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product

A, B, C, D, E, F = map(int, input().split())
conc = 0
water, sugar = 100*A, 0
for i, j in product(range(F // (100*A) + 1), range(F // (100*B) + 1)):
    wt = 100*(A*i + B*j)
    if wt > F or wt == 0:
        continue
    rem = F - wt
    for k, l in product(range(rem // C + 1), range(rem // D + 1)):
        sg = C*k + D*l
        sugar_water = wt + sg
        if sg <= wt*E // 100 and 0 < sugar_water <= F:
            temp = 100*sg/sugar_water
            if conc < temp:
                conc = temp
                water, sugar = wt, sg
print(water+sugar, sugar)

Solution (Python):


a, b, c, d, e, f = list(map(int, input().rstrip().split()))
A = a * 100
B = b * 100


x, y = min(a, b) * 100, 0  
dens = y / x



for i in range(f // A + 1):
    for j in range(((f - A * i) // B) + 1):
        if i == 0 and j == 0:
            continue
        water = i * A + j * B
        rest = f - water
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                total = water + sugar

                if sugar / total > e / (e + 100):  
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x, y = total, sugar
print(x, y)

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

ans = [0,A*100]

for a in range(31):
    for b in range(31):
        if a*A+b*B==0 or a*A+b*B>=F:
            continue
        for c in range((3000//C)+1):
            if c*C>E*(a*A+b*B) or (a*A+b*B)*100+c*C>F:
                continue
            d = min((E*(a*A+b*B)-c*C)//D,(F-((a*A+b*B)*100+c*C))//D)
            if (a*A+b*B)*100+(c*C+d*D)>F or c*C+d*D>(a*A+b*B)*E:
                continue
            ans_tmp = [c*C+d*D,(a*A+b*B)*100]
            if ans_tmp[0]*ans[1] > ans[0]*ans_tmp[1]:
                ans = ans_tmp
print(ans[1]+ans[0],ans[0])

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

sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)

water=[]
for i in range(int(maxwater//100+2)//min(a,b)+2):
    for j in range(int(maxwater//100+2)//min(a,b)+2):
        y=i*a+j*b
        water.append(y)

water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)

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

sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)

water=[]
for i in range(int(maxwater//100+2)//min(a,b)+5):
    for j in range(int(maxwater//100+2)//min(a,b)+5):
        y=i*a+j*b
        water.append(y)

water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)

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

maxn = .0
total, sato = 0, 0
for _a in range(0, f+1, 100*a):
  for _b in range(0, f-_a+1, 100*b):
    if _a == 0 and _b == 0:
      continue
    for _c in range(0, f-_a-_b+1, c):
      for _d in range(0, f-_a-_b-_c+1, d):
        if ((_a + _b) // 100) * e < _c + _d:
          break
        if 100 * (_c + _d) / (_a + _b + _c + _d) >= maxn:
          maxn = 100 * (_c + _d) / (_a + _b + _c + _d)
          total = _a + _b + _c + _d
          sato = _c + _d
print(total, sato)

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

maxn = .0
total, sato = 0, 0
for _a in range(0, f+1, 100*a):
  for _b in range(0, f-_a+1, 100*b):
    if _a == 0 and _b == 0:
      continue
    for _c in range(0, f-_a-_b+1, c):
      for _d in range(0, f-_a-_b-_c+1, d):
        if ((_a + _b) // 100) * e < _c + _d:
          break
        if 100 * (_c + _d) / (_a + _b + _c + _d) >= maxn:
          maxn = 100 * (_c + _d) / (_a + _b + _c + _d)
          total = _a + _b + _c + _d
          sato = _c + _d
print(total, sato)

Solution (Python):
a,b,c,d,e,f=[int(i) for i in input().split(' ')]
ans = -1.0
maxx = 0
maxy = 0
for i in range(0, 31):
  for j in range(0, 31):
    if i * a * 100 + j * b * 100 > f:
      continue
    for k in range(0, 3001):
      if i * a * 100 + j * b * 100 + k * c > f:
        continue
      for l in range(0, 3001):
        if i * a * 100 + j * b * 100 + k * c + l * d > f:
          continue
        if (i * a + j * b) * e < k * c + l * d:
          continue
        x = 100 * a * i + 100 * b * j
        y = k * c + l * d
        if (not x + y == 0) and (x + y) * ans < y:
          ans = max(ans, y / (x + y))
          maxx = x
          maxy = y
print(maxx + maxy, maxy)

Solution (Python):
import fractions as frac
a, b, c, d, e, f = map(int, input().split())
memo=[[(-1, -1)]*1000 for i in range(10000)]
func = lambda t: frac.Fraction(t[0], t[1]) if t[1]>0 else -10
def dp(s, w):
    if w*e<s or w*100+s>f:
        return (-1, -1)
    m=memo[s][w]
    if m[0]>0:
        return m
    p0=(s,w) 
    p1=dp(s, w+a)
    p2=dp(s, w+b)
    p3=dp(s+c, w)
    p4=dp(s+d, w)
    memo[s][w]=max(p0, p1, p2, p3, p4, key = func) if w>0 else max(p1, p2, key = func)
    return memo[s][w]
    
ans=dp(0,0)
print(ans[0]+ans[1]*100, ans[0])

Solution (Python):
A,B,C,D,E,F = map(int, input().split())
ans = {"w":A*100, "s":0}
def density(water, sugar):
    return 100*sugar/(water+sugar)

for a in range(31):
    for b in range(31):
        water = (a*A+b*B)*100
        if water>F:
            continue
        max_sugar = min((a*A+b*B)*E, F-water)
        for c in range(max_sugar//C+1):
            sugar = c*C
            sugar += ((max_sugar-sugar)//D)*D
            if water+sugar==0: 
                continue
            if density(water, sugar)>density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
print(ans["w"]+ans["s"], ans["s"])

Solution (Python):
from fractions import gcd
def solve():
    A,B,C,D,E,F = map(int, input().split())
    ans = {"w":A*100, "s":0}
    def density(water, sugar):
        return 100*sugar/(water+sugar)

    G = gcd(C,D)
    for a in range(31):
        for b in range(31):
            water = (a*A+b*B)*100
            if water>F:
                continue
            max_sugar = min((a*A+b*B)*E, F-water)
            sugar = int(G*(max_sugar//G))
            if sugar<min(C,D): continue
            if water+sugar==0: 
                continue
            if density(water, sugar)>density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
                
    print(ans["w"]+ans["s"], ans["s"])
    
if __name__ == '__main__':
    solve()

Solution (Python):
from fractions import gcd
A,B,C,D,E,F = map(int, input().split())
ans = {"w":A*100, "s":0}
def density(water, sugar):
    return 100*sugar/(water+sugar)

G = gcd(C,D)
for a in range(31):
    for b in range(31):
        water = (a*A+b*B)*100
        if water>F:
            continue
        max_sugar = min((a*A+b*B)*E, F-water)
        sugar = int(G*(max_sugar//G))
        if sugar<min(C,D): continue
        if water+sugar==0: 
            continue
        if density(water, sugar)>density(ans["w"], ans["s"]):
            ans["w"] = water
            ans["s"] = sugar
            
print(ans["w"]+ans["s"], ans["s"])

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
x=1
y=-1
for i in range(0,f+1,a*100):
    for j in range(0,f+1-i,b*100):
        s=min(f-i-j,(i+j)*e//100)
        if i+j==0:
            continue
        else:
            for p in range(0,s+1,c):
                for q in range(0,s+1-p,d):
                    if y/x<=(p+q)/(i+j):
                        y=p+q
                        x=i+j
print(x+y,y)

Solution (Python):


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

    A100 = A * 100
    B100 = B * 100


    d_max = 0
    d_w = A100
    d_s = 0

    i2_max = F // B100 + 1
    for i2 in range(i2_max):
        w2 = B100 * i2
        i1_max = (F - w2) // A100 + 1
        for i1 in range(i1_max):
            w = w2 + A100 * i1
            if w == 0:
                continue
            if F <= w:
                break
            target = (w // 100) * E
            if F - w < target:
                target = F - w
            if target / (w + target) < d_max:
                continue
            q = target // (C * D)
            r = target % (C * D)
            r_max = 0
            for i3 in range(D + 1):
                x3 = C * i3
                if r < x3:
                    break
                if x3 == r:
                    r_max = r
                    break
                for i4 in range(C + 1):
                    x = x3 + D * i4
                    if r < x:
                        break
                    if x == r:
                        r_max = r
                        break
                    r_max = max(r_max, x)
                if r_max == r:
                    break
            s = C * D * q + r_max
            d = s / (w + s)
            if d_max < d:
                d_max = d
                d_w = w
                d_s = s

    print('{} {}'.format(d_w + d_s, d_s))


if __name__ == '__main__':
    main()

Solution (Python):


from fractions import Fraction
from collections import Counter, defaultdict

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    A, B, C, D, E, F = MI()
    A *= 100
    B *= 100

    water_ws = set()
    for a in range(F//A + 1):
        for b in range(F//B + 1):
            w = a * A + b * B
            if w <= F: water_ws.add(w)
    water_ws.remove(0)
    sugar_w_max = max([ww // 100 * E for ww in water_ws])
    sugar_ws = set()
    for c in range(sugar_w_max // C):
        for d in range(sugar_w_max // D):
            w = c * C + d * D
            if w <= sugar_w_max: sugar_ws.add(w)
    ans_w, ans_s = A, 0
    dens_max = -1
    for ww in water_ws:
        for sw in sugar_ws:
            dens = Fraction(sw, ww + sw)
            if ww + sw <= F and sw <= ww // 100 * E and dens > dens_max:
                ans_w = ww + sw
                ans_s = sw
                dens_max = dens
    print(ans_w, ans_s)


if __name__ == "__main__":
    main()

Solution (Python):



def main():
    a, b, c, d, e, f = map(int, input().split())
    ab = list()
    cd = list()

    for i in range(30 + 1):
        for j in range(30 + 1):
            if 100 * a * i + 100 * b * j <= f:
                ab.append((i, j))

    for x in range(100 + 1):
        for y in range(100 + 1):
            if c * x + d * y <= 30 * e:
                cd.append((x, y))

    ans = 0
    ans_water = 0
    ans_sugar = 0

    for i, j in ab:
        for x, y in cd:
            total_water = 100 * (a * i + b * j)
            total_sugar = c * x + d * y

            if total_water > 0 and total_water + total_sugar <= f and total_sugar <= e * total_water // 100:
                rate = 100 * total_sugar / (total_water + total_sugar)

                if rate - ans >= 0:
                    ans = rate
                    ans_water = total_water
                    ans_sugar = total_sugar

    print(ans_water + ans_sugar, ans_sugar)


if __name__ == '__main__':
    main()

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

max_sugar = 0
max_water = 100*A
max_conc = 0.0
A_limit = F // (100*A)
for i in range(A_limit + 1):
    B_limit = (F-100*A*i) // (100*B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A*i+B*j), F-100*(A*i+B*j))

        sugar_ = 0
        for c in range(sugar_limit//C + 1):
            d = (sugar_limit-c*C)//D
            temp_sugar = c*C + d*D
            sugar_ = max(sugar_, temp_sugar)
        temp_conc = sugar_/(sugar_+100*(A*i+B*j))
        if temp_conc > max_conc:
            max_conc = temp_conc
            max_water = 100*(A*i + B*j)
            max_sugar = sugar_
print('{0} {1}'.format(max_water+max_sugar, max_sugar))

Solution (Python):
A, B, C, D, E, F = map(int, input().split(' '))
water = []
for i in range(31):
    if A*i >= F:
        break
    for j in range(16):
        if 100 * (A*i + B*j) < F:
            water.append(100*(A*i+B*j))
        else:
            break
water = sorted(list(set(water)))

sugar = []
for i in range(max(water)//100*E//C + 1):
    for j in range(max(water)//100*E//D + 1):
        temp_sugar = C*i + D*j
        if temp_sugar + water[1] <= F:
            sugar.append(temp_sugar)
        else:
            break
sugar = sorted(list(set(sugar)))

max_conc = 0
ans_W = 100*A
ans_sugar = 0
for W in water:
    if W == 0:
        continue
    for S in sugar:
        if S+W <= F and S <= W*E//100:
            if max_conc < S/(W+S):
                max_conc = S/(S+W)
                ans_W = W
                ans_sugar = S
        else:
            break
print('{0} {1}'.format(ans_W+ans_sugar, ans_sugar))

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict

A, B, C, D, E, F = inpl()
H = defaultdict(lambda: 0)
H[(0,0)] = 1
x = [(100*A, 0), (100*B, 0), (0, C), (0, D)]
flag = True
while flag:
    flag = False
    for i, j in x:
        for ni,nj in H.copy().keys():
            if i+j+ni+nj <= F and ni+i:
                if (nj+j)/(ni+i) <= E/100:
                    if not H[(i+ni, j+nj)]:
                        H[(i+ni, j+nj)] = 1
                        flag = True
anssw, anss = (100*A, 0)
for k, l in H.keys():
    if not k:
        continue
    if anss/anssw < l/(k+l):
        anssw, anss =k+l, l
print(anssw, anss)

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

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

sugars = set()
for c in range(0,F+1,C):
    for d in range(0,F+1,D):
        if c+d > F:
            break
        sugars.add(c+d)

best_r = -1
best_w = best_s = 0

for w in waters:
    for s in sugars:
        if w+s > F: continue
        if E*w < s*100: continue
        r = s / (w+s)
        if r > best_r:
            best_r = r
            best_s = s
            best_w = w
print(best_w+best_s, best_s)

Solution (Python):
A, B, C, D, E, F=map(int, input().split())
wans=0
sans=0
for i in range(31):
    w=100*A*i
    s=0
    if s+w>F:
        break
    for j in range(31):
        w=100*A*i+100*B*j
        s=0
        if s+w>F:
            break
        for k in range(3001):
            w=100*A*i+100*B*j
            s=C*k
            if s+w>F:
                break
            for l in range(3001):
                w=100*A*i+100*B*j
                s=C*k+D*l
                if s+w>F:
                    break
                if w!=0 and s*(100+E)<=(s+w)*E and sans*(s+w)<=s*(sans+wans) and w+s<=F:
                    sans=s
                    wans=w
                
print(sans+wans,sans)

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


ablist = []

a, b = 0, 0
while (100 * A * a + 100 * B * b <= F):
    while (100 * A * a + 100 * B * b <= F):
        ablist.append((a, b))
        b += 1
    a += 1
    b = 0
ablist.remove((0, 0))

wlist = [100 * A * ab[0] + 100 * B * ab[1] for ab in ablist]
wset = set(wlist)

cdlist = []
c, d = 0, 0
while (C * c + D*d <= F):
    while (C * c + D * d <= F):
        cdlist.append((c, d))
        d += 1
    c += 1
    d = 0

slist = [C * cd[0] + D * cd[1] for cd in cdlist]
sset = set(slist)

max_rate = -1
ret_sw = 0
ret_s = 0

for w in wset:
    for s in sset:
        if s + w <= F:
            rate = s / (s + w)
            if rate <= E/(E+100):
                if max_rate < rate:
                    max_rate = rate
                    ret_sw = s + w
                    ret_s = s

print("{} {}".format(ret_sw, ret_s))

Solution (Python):
a,b,c,d,e,f=map(int, input().split())
x,y,z=100*a,0,0
for i in range(31):
    for j in range(31):
        mizu=(a*i+b*j)*100
        if mizu==0 or mizu>f:break
        for k in range(int((f-mizu)//c)+1):
            for l in range(int((f-mizu)//d)+1):
                sato=c*k+d*l
                noudo=100*sato/(mizu+sato)
                if mizu+sato>f or mizu/100*e<sato:break
                if noudo>z: z,x,y = noudo,mizu+sato,sato
print(x,y)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
x = set()
y = set()
for A in range(0, f + 1, 100 * a):
    for B in range(0, f + 1, 100 * b):
        if A + B > f:
            break
        if A + B:
            x.add(A + B)
for C in range(0, f + 1, c):
    for D in range(0, f + 1, d):
        if C + D > f:
            break
        y.add(C + D)
ans = 0
w = 100 * a
s = 0
for X in x:
    for Y in y:
        if X + Y <= f and 100 * Y / X <= e:
                if ans < Y / (X + Y):
                    ans = Y / (X + Y)
                    w = X
                    s = Y
print(w + s, s)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
ans = 100 * A, 0
w = set()
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        if a + 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)
for wi in w:
    for sj in s:
        if wi + sj <= F and 100 * sj / wi <= E:
            ans = max(ans, (wi + sj, sj), key=lambda x: x[1] / x[0])

print(*ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
f = lambda: map(int,input().split())

a,b,c,d,melt,mass = f()
wat = []
for i in range(mass//100//a+1):
    for j in range(mass//100//b+1):
        if i*a + j*b <= mass/100:
            wat.append((i*a + j*b)*100)
        else:
            break
sug = []
for i in range(mass//c+1):
    for j in range(mass//d+1):
        if i*c + j*d <= mass:
            sug.append(i*c + j*d)
        else:
            break
ans = [0,0]
cons = -float('inf')
for s in sug:
    for w in wat:
        if w > 0 and s/w > cons and s+w <= mass and s <= w*melt/100:
            cons = s/w
            ans = [s+w,s]
print(*ans)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

maxd = -1
ans = None

A, B, C, D, E, F = reads()
for i, j, k in product(range(31), range(31), range(3001)):
  water100 = A * i + B * j
  if C * k > water100 * E or C * k > F - water100 * 100 or water100 == 0:
    continue
  l = min(water100 * E - C * k, F - water100 * 100 - C * k) // D
  sugar = C * k + D * l
  mass = water100 * 100 + sugar
  density = sugar / mass
  if mass <= F and maxd < density:
    maxd = density
    ans = (mass, sugar)

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

Solution (Python):

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

ra = 2
rb = -1
for ai in range(f//(100*a)+2):
    for bi in range(f//(100*b)+2):
        if 100*a*ai+100*b*bi>f:
            break
        for ci in range(f//c+2):
            if 100*a*ai+100*b*bi+c*ci>f:
                break
            elif c*ci>(a*ai+b*bi)*e:
                break
            for di in range(f//d+2):
                sa = 100*a*ai+100*b*bi
                sb = c*ci+d*di
                if sa+sb>f:
                    break
                elif sb>(a*ai+b*bi)*e:
                    break
                elif sa+sb==0:
                    continue
                if sb/(sa+sb) > rb/(ra+rb):
                    ra = sa
                    rb = sb
                    
                    
                    
                    

print(ra+rb,rb)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
ans=0
s=0
t=0
for i in range(f//100+1):
    w=(f-100*a*i)//100
    for j in range(w+1):
        if i==0 and j==0:
            continue
        x=a*i+b*j
        for k in range(x*e//c+1):
            v=(x*e-c*k)//d
            for l in range(v+1):
                y=c*k+d*l
                if 100*x+y <=f:
                    p=100*y/(100*x+y)
                    if ans<=p:
                        s=100*x+y
                        t=y
                        ans=p
print(s,t)

Solution (Python):
a,b,c,d,e,f = list(map(int,input().split()))
ans = []
g = 0
for i in range(f//(a*100)+1):
    for j in range((f-a*i*100)//(b*100)+1):
        for k in range(min((f-a*i*100-b*j*100)//c,e*(a*i+b*j)//c)+1):
            l = min((e*(a*i+b*j) - k*c)//d,(f-100*a*i-100*b*j-c*k)//d)
            if (a*i*100+b*j*100+c*k+d*l)>0 and (a*i*100+b*j*100+c*k+d*l)<=f:
                if g < (k*c+d*l)/(a*i*100+b*j*100+c*k+d*l):
                    g = (k*c+d*l)/(a*i*100+b*j*100+c*k+d*l)
                    ans = [a*i*100+b*j*100+c*k+d*l,k*c+d*l]
if len(ans) == 0:
    print(min(a,b)*100,0)
else:
    print(' '.join(map(str,ans)))

Solution (Python):
a, b, c, d, e, f = list(map(int, input().split()))
ans1, ans2 = 100*a, 0
t = 0
for i in range(31):
  for j in range(31):
    if i==j==0:
      break
    w = (a*i+b*j)*100
    if w>f:
      break
    for k in range((f-w)//c+1):
      for l in range((f-w)//d+1):
        s = c*k+d*l
        if w+s>f:
          break
        if w/100*e<s:
          break
        if t<100*s/(w+s):
          ans1 = w+s
          ans2 = s
          t = 100*s/(w+s)
print(ans1, ans2)