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


import math



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

  
  dp = [0 for i in range(F+1)]
  dp[100*A]=1
  if 100*B<=F: dp[100*B]=1
  Wn = set([100*A,100*B])
  for i in range(A,F+1):
    if dp[i]>0:
      Wn.add(i)
      if i+100*A<=F: dp[i+100*A]=1
      if i+100*B<=F: dp[i+100*B]=1

  
  dp = [0 for i in range(F+1)]
  dp[C],dp[D]=[1,1]
  Sn = set([C,D])
  for i in range(C,F+1):
    if dp[i]>0:
      Sn.add(i)
      if i+C<=F: dp[i+C]=1
      if i+D<=F: dp[i+D]=1

  
  ret = [0.0, 100*A, 0]
  for w in Wn:
    for s in Sn:
      if w+s>F or 100*s>E*w:
        continue
      elif 100*s/(w+s) > ret[0]:
        ret = [100*s/(w+s),w+s,s]
  return [ret[1],ret[2]]



if __name__ == "__main__":
  w,s = main()
  print(w,s)

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
 
use_water = [] 
for i in range(0,31):
  for j in range(0,31):
    tmp = A*i + B*j
    if((tmp != 0)and(tmp <= 30)): 
      if(tmp*100 <= F):
        use_water.append(tmp)
use_water = list(set(use_water))
use_water.sort()
 
Conc = [] 
for i in range(101):
  for j in range(51):
    for k in range(len(use_water)):
      sugar = C*i + D*j
      water = use_water[k]*100
      if(sugar + water <= F):
       if(sugar <= use_water[k]*E):
        conc = sugar/(sugar + water)
        Conc.append([conc,water+sugar,sugar])
 
Conc.sort(reverse = True)
ans_water,ans_sugar = Conc[0][1],Conc[0][2]
print(ans_water,ans_sugar)

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

w, s = 1, -1
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        m = min(F - a - b, (a + b) * E // 100)
        if (a, b) == (0, 0):
            continue
        for c in range(0, m + 1, C):
            for d in range(0, m - c + 1, D):
                if s / w < (c + d) / (a + b):
                    w, s = a + b, c + d

print(w + s, s)

Solution (Python):


"""解説
https://www.youtube.com/watch?v=nCHz87GMdpo



"""

def solve2():
    """ 全探索O(F**2) """
    A, B, C, D, E, F = list(map(int, input().split()))

    
    sugars = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            y = i*C + j*D
            if y <= F:
                
                sugars.append(y)

    water = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            x = 100*A*i + 100*B*j
            if x <= F:
                
                water.append(x)
    
    sugars.sort()
    water.sort()

    
    concent = 0
    for x in water:
        for y in sugars:
            if x+y > F:
                break
            if x+y > 0 and y/(x+y) <= E/(100+E):
                if y/(x+y) >= concent:
                    concent = y/(x+y)
                    ans = "{} {}".format(x+y, y)
    print(ans)


def solve():
    """ WA """
    A, B, C, D, E, F = list(map(int, input().split()))

    
    
    dp= [0]*(F+1)

    for i in range(0, F+1):
        if i+100*A <= F:
            concent = (dp[i]*i)/(i+100*A)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*A] = max(dp[i+100*A], concent)
        if i+100*B <= F:
            concent = (dp[i]*i)/(i+100*B)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*B] = max(dp[i+100*B], concent)
        if i+C <= F:
            concent = (dp[i]*i+C)/(i+C)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+C] = max(dp[i+C], concent)
        if i+D <= F:
            concent = (dp[i]*i+D)/(i+D)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+D] = max(dp[i+D], concent)
    
    print(dp)
    return
    max_concent = max(dp)
    print(dp.index(max_concent), round(dp.index(max_concent)*max_concent))



if __name__ == "__main__":
    solve2()

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

def noudo(weight,sugar):
    if sugar is None:return -1000000000
    else:return(sugar*100/weight)
    
def noudosafe(w,s):
    if (noudo(w,s)<=noudo(100+E,E)):return s
    else:return None
    
def eraseNone(i):
    if i is None:return 0
    else: return i
    
dp=[None]*(F+1) 
dp[0]=0
for i in range(1,F+1):
    sug1,sug2,sug3,sug4=[None]*4
    if i>=100*A:
        sug1=dp[i-100*A]
        if sug1 is not None:
            sug1=noudosafe(i,sug1)
    if i>=100*B:
        sug2=dp[i-100*B]
        if sug2 is not None:
            sug2=noudosafe(i,sug2)
    if i>=C:
        sug3base=dp[i-C]
        if sug3base is not None:
            sug3=noudosafe(i,sug3base+C)
    if i>=D:
        sug4base=dp[i-D]
        if sug4base is not None:
            sug4=(noudosafe(i,sug4base+D))
            
    sug=(sug1,sug2,sug3,sug4)
    if all([k is None for k in sug]):
        continue
    else:
        dp[i]=max([eraseNone(k) for k in sug])

ansi=0
anssugar=0
maxnoudo=0
for x,s in enumerate(dp):
    if x==0:continue
    if maxnoudo<noudo(x,s):
        maxnoudo=noudo(x,s)
        ansi=x
        anssugar=s
if anssugar:print(ansi,anssugar)
else: print(100*A,0)

Solution (Python):
import sys
sys.setrecursionlimit(65536)

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

def memoize(f):
	memo = {}
	def g(*args):
		if args not in memo:
			memo[args] = f(*args)
		return memo[args]
	return g

@memoize
def search(w, s):
	if 100*w+s > f:
		return (-1, w, s)

	if s > e * w or w == 0:
		return max(search(a+w, s), search(b+w, s))
	else:
		return max(search(w, s+c), search(w, s+d), (100*s/(100*w+s), w, s))

_,w,s=search(0, 0)
print(100*w+s, s)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
l=[]
for i in range(0,(f//(100*a))+1):
  for j in range(0,(f//(100*b))+1):
    if 100*a*i+100*b*j>f:
      pass
    else:
      l.append(100*a*i+100*b*j)
l1=[]
del l[0]
max1=0
g=0
h=0
for i in l:
  l2=[]
  m=min(f-i,(i//100)*e)
  max2=0
  for j in range(0,(m//c)+1):
    for k in range(0,(m//d)+1):
      if j*c+k*d<=m and j*c+k*d>max2:
        max2=j*c+k*d
  if max1<=100*max2/(i+max2):
    g=i
    h=max2
    max1=100*max2/(i+max2)
print(g+h,h)

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
def solve(a,b):
    return 100*b<=E*a
def contain(a,b):
    return 0<a+b<=F
water = []
for i in range(30):
    for j in range(30):
        if 0 < 100*A*i+100*B*j <= F:
            water.append(100*A*i+100*B*j)
sugar = []
for i in range(3000):
    for j in range(3000):
        if C*i + D*j <= F:
            sugar.append(C*i + D*j)
        else:
            break
sugar.sort()
water.sort()
cand=[]
for s in sugar:
    for w in water:
        if contain(w,s):
            if solve(w,s):
                cand.append((w+s,s))
        else:
            break
cand.sort(key=lambda x:x[1]/x[0],reverse=True)
print(*cand[0])

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
ans = ["0","0"]
M = -1
for a in range(31):
    if F < a*A*100:
        break
    for b in range(31-a):
        if a == 0 and b == 0:
            continue
        W = (a*A+b*B)*100
        if F < W:
            break
        CD_max = min((E * W) // 100,F-W)
        for c in range(CD_max//C+1):
            d = max(0,(CD_max-c*C)//D)
            CD = c*C+d*D
            con = CD/(W+CD)
            if con > M:
                M = con
                ans = [str(W+CD),str(CD)]
print(" ".join(ans))

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

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

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

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
sugar_total = [-1, 1]
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        water = a + b
        if water == 0:
            continue
        for c in range(0, F - water + 1, C):
            for d in range(0, min(F - water - c, (water // 100) * E - c) + 1, D):
                sugar = c + d
                total = water + sugar
                if sugar / total > sugar_total[0] / sugar_total[1]:
                    sugar_total[0], sugar_total[1] = sugar, total
print(sugar_total[1], sugar_total[0])

Solution (Python):

import math

def read_input():
    a, b, c, d, e, f = map(int, input().split())
    return a, b, c, d, e, f



def search_water_valiation(a, b, f):
    result = []
    for i in range(30):
        for j in range(30):
            water = 100*a*i + 100*b*j
            if water <= f:
                result.append(water)

    result = list(set(result))
    result.sort()

    return result






def search_most_sweet(c, d, max_sugar):
    sugars = []
    for x in range(math.floor(max_sugar/c) + 1):
        y = math.floor((-c * x + max_sugar)/d)
        sugars.append(c*x + d*y)

    sugars = list(set(sugars))
    return max(sugars)

def submit():
    a, b, c, d, e, f = read_input()

    waters = search_water_valiation(a, b, f)
    max_sugars = [min(w * e // 100, f - w) for w in waters]

    result = []
    for water, max_sugar in zip(waters, max_sugars):
        sugar = search_most_sweet(c, d, max_sugar)
        result.append((water, sugar))

    result = [r for r in result if r[0] + r[1] <= f]
    result = [(w+s, s, 100 * s / (w + s)) for (w, s) in result if (w, s) != (0, 0)]

    r = max(result, key=lambda x:x[2])
    print('{} {}'.format(r[0], r[1]))

if __name__ == '__main__':
    submit()

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

water = []
for a in range(F//A+1):
    for b in range(F//B+1):
        if a + b == 0 or a * A + b * B > F:
            continue
        if not((a * A + b * B) in water):
            water.append(a * A + b * B)

water.sort()

suger = []
for c in range(F//C+1):
    for d in range(F//D+1):
        if c * C + d * D > F:
            continue
        if not((c * C + d * D) in suger):
            suger.append(c * C + d * D)

suger.sort()

max_dense = 0
log = [water[0],0]
for w in water:
    for s in suger:
        dense = 100 * s / w
        if w + s > F or dense > E:
            break
        elif dense == E:
            print(" ".join(map(str,[w+s,s])))
            exit()
        elif dense > max_dense:
            max_dense = dense
            log = [w+s,s]

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

Solution (Python):
import math
A, B, C, D, E, F = map(int, input().split())
limit_r = 100 * E / (100 + E)
max_r, max_w, max_s = -1 * float('inf'), 0, 0
for a in range(math.floor(F/100/A)+1):
  for b in range(math.floor(F/100/B)+1):
    w = 100 * A * a + 100 * B * b
    if w == 0:
      continue
    if w > F:
      break
    for c in range(math.floor((F-w)/C)+1):
      for d in range(math.floor((F-w)/D)+1):
        s = C * c + D * d
        r = 100 * s / (w + s)
        if w + s > F or r > limit_r:
          break
        if r > max_r:
          max_r, max_w, max_s = r, w, s
print("{0} {1}".format(max_w+max_s, max_s))

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    A,B,C,D,E,F = (int(_) for _ in 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
                    elif w + s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100 * s/(w+s)
                            memo[a,b,c,d] = density
    max_density = max(memo.values())
    for k,v in memo.items():
        if v==max_density:
            print((100*A)*k[0] +(100*B)*k[1]+k[2]*C + k[3]*D,k[2]*C + k[3]*D)
            break
    
if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
ans1,ans2=0,0
Wat,Salt=set(),set()
for i in range(f//(100*a)+1):
  for j in range(f//(100*b)+1):
    w=a*i*100+b*j*100
    if w<=f:
      Wat.add(w)
for i in range(f//c+1):
  for j in range(f//d+1):
    s=c*i+d*j
    if s<=f:
      Salt.add(s)
Wat=list(Wat)
Salt=list(Salt)
for i in Wat:
  for j in Salt:
    if i+j<=f and j*(100+e)<=e*(i+j) and j*ans1>=ans2*(i+j):
      ans1,ans2=i+j,j
print(ans1,ans2)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
ans = [[0, 0]]
for i in range(0, F//100):
    if 100*A*i > F:
        break
    for j in range(0, F//100):
        if 100*A*i+100*B*j > F:
            break
        if 100*A*i + 100*B*j == 0:
            continue
        for k in range(0, F//C+1):
            for l in range(0, F//D+1):
                if 100*A*i + 100*B*j + C*k + D*l > F:
                    break
                if  (C*k + D*l)/(100*A*i + 100*B*j) > E/100:
                    break
                ans.append([(100*A*i + 100*B*j + C*k + D*l), (C*k + D*l)])
ans = sorted(ans, key=lambda x: x[1]/x[0] if x[0] != 0 else 0)
print(ans[-1][0], ans[-1][1])

Solution (Python):
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

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

def makeSet(a, b):
  list = []
  for i in range(int(F / a + 2)):
    for j in range(int(F / b + 2)):
      tmp = i * a + j * b
      if tmp > F:
        break
      list.append(tmp)
  return set(list)

W = makeSet(A * 100, B * 100)
S = makeSet(C, D)

def isOK(a, b):
  return b * (100 + E) <= E * (a + b) and a + b <= F

ma = F
mb = 0

def chmax(a, b):
  if b * (ma + mb) >= mb * (a + b):
    return a, b
  return ma, mb

for w in W:
  for s in S:
    if isOK(w, s):
      ma, mb = chmax(w, s)

print(ma + mb, mb)

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

node = 0
aa = 0
bb = 0
cc = 0
dd = 0
na = int(F/(100*A))
nb = int(F/(100*B))
nc = int(F/C)
nd = int(F/D)
for a in range(na+1):
    for b in range(nb+1):
        for c in range(nc+1):
            for d in range(nd+1):
                if 100 * A * a + 100 * B * b + C * c + D * d > F or (A * a + B * b) * E < C * c + D * d:
                    break
                else:
                    if a == b == c == d == 0:
                        continue
                    else:
                        cand = (100 * (C * c + D * d)) / (100 * (A * a + B * b) + (C * c + D * d))
                        if cand > node:
                            node = cand
                            aa = a
                            bb = b
                            cc = c
                            dd = d
if node == 0:
    print("{} {}".format(100*A, 0))
else:
    print("{} {}".format(100*(A * aa + B * bb)+(C * cc + D * dd), C * cc + D * dd))

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

per = 0
ans = []

for i in range(f//(100*a) + 1):
    for j in range(f//(100*b) + 1):
        w = i * a * 100 + j * b * 100
        if w > f or w == 0:
            break
        for k in range((e * w//100)//c + 1):
            for l in range((e * w//100)//d + 1):
                if e * w//100 < c * k + d * l or w + c * k + d * l > f:
                    break
                now = 100 * (c*k+d*l) / (w+c*k+d*l)
                if per < now:
                    per = now
                    ans = [w+c*k+d*l, c*k+d*l]
if ans == []:
    print(100*a, 0)
else:
    print(ans[0], ans[1])

Solution (Python):
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

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

E2 = 100 * E / (100 + E)

@lru_cache(maxsize=10000)
def dfs(w,s):
    global A,B,C,D,E,F
    
    inf = 1 << 60
    if w + s > F:
        return (-1, w, s)
    if w + s == 0:
        d = (-1, w, s)
    else:
        d = ((100 * s) / (w + s), w, s)
    
    d1 = dfs(w + 100*A, s)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w + 100*B, s)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w, s + C)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w, s + D)
    if d1[0] <= E2:
        d = max(d, d1)

    return d

ans = dfs(0,0)
print(ans[1]+ans[2],ans[2])

Solution (Python):
EPS = 1E-8
def solve(a, b, c, d, e, f):
    threshold = e / (100 + e) + EPS
    best = -1
    for x in range(0, f+1, 100*a):
        for y in range(x, f+1, 100*b):
            if y == 0:
                continue
            for z in range(y, f+1, c):
                for w in range(z, f+1, d):
                    p = w - y
                    cur = p / w
                    if best < cur <= threshold:
                        best = cur
                        solution = (w, p)
    return "%d %d" % solution

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

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

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

con = -1
ans_w, ans_s = 0, 0
for i in range(F//(100*A) + 1):
    water = i*100*A
    for j in range((F-water)//(100*B) + 1):
        if i == 0 and j == 0:
            continue
        water += j*100*B
        for k in range((F-water)//C + 1):
            flg = 0
            sugar = k*C
            water += sugar
            if sugar > (A*i+B*j)*E:
                water = i*100*A
                break
            for l in range((F-water)//D + 1):
                sugar += l*D
                water += l*D
                if sugar > (A*i+B*j)*E:
                    water -= sugar
                    flg = 1
                    break
                tmp = 100*sugar/water
                if tmp > con:
                    con = tmp
                    ans_w = water
                    ans_s = sugar
                water -= l*D
                sugar -= l*D
            if flg == 0:
                water -= k*C

print(ans_w, ans_s)

Solution (Python):


import itertools
from collections import Counter
import bisect

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

    ans_nod = -1
    ans_sugar = 0
    ans_water = 0
    for a in range(31):
        for b in range(31):
            water = a * A * 100 + b * B * 100
            if water == 0:
                continue
            if water > F:
                continue
            max_sugar = E * (a * A + b * B)
            for i in range(3000):
                for j in range(3000):
                    sugar = i * C + j * D
                    if sugar > max_sugar:  
                        break
                    if sugar + water > F:  
                        break
                    nod = 100 * sugar / (water + sugar)
                    if nod > ans_nod:
                        ans_nod = nod
                        ans_sugar = sugar
                        ans_water = water
    print("{} {}".format(ans_water + ans_sugar, ans_sugar))


if __name__ == '__main__':
    main()

Solution (Python):
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]  
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)


A, B, C, D, E, F = map(int, input().split())
ma = F // (100 * A)
mb = F // (100 * B)
mc = F // C
md = F // D
a = 0
s = 0
d = 0
sw = 0
ss = 0
sd = 0
for i in range(ma + 1):
    if A * 100 * i > F:
        break
    for j in range(mb + 1):
        if A * 100 * i + B * 100 * j > F:
            break
        for k in range(mc + 1):
            if A * 100 * i + B * 100 * j + C * k > F:
                break
            for l in range(md + 1):
                if A * 100 * i + B * 100 * j + C * k + D * l > F:
                    break
                if i + j == 0:
                    break
                a = A * 100 * i + B * 100 * j + C * k + D * l
                s = C * k + D * l
                d = s / (A * i + B * j)
                
                if a <= F and sd <= d <= E:
                    sd = d
                    sw = a
                    ss = s
                    
print(sw, ss)

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

use_water = [] 
for i in range(0,31):
  for j in range(0,31):
    tmp = A*i + B*j
    if((tmp != 0)and(tmp <= 30)): 
      if(tmp*100 <= F):
        use_water.append(tmp)
use_water = list(set(use_water))
use_water.sort()







Conc = [] 
for i in range(101):
  for j in range(51):
    for k in range(len(use_water)):
      sugar = C*i + D*j
      water = use_water[k]*100
      if(sugar + water <= F):
       if(sugar <= use_water[k]*E):
        
        
        conc = sugar/(sugar + water)
        Conc.append([conc,water+sugar,sugar])

Conc.sort(reverse = True)
ans_water,ans_sugar = Conc[0][1],Conc[0][2]
print(ans_water,ans_sugar)

Solution (Python):

import copy
import numpy as np
import random
import bisect 
import math

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

water = []
for ai in range(int(F/(A*100))+1):
    for bi in range(int(F/(B*100))+1):
        if (ai*A+bi*B)*100>F:pass
        else:
            water.append((ai*A+bi*B)*100)

suger = []
for ci in range(int(F/C)+1):
    for di in range(int(F/D)+1):
        if ci*C+di*D > F:
            pass
        else:suger.append(ci*C+di*D)

water = list(set(water))
suger = list(set(suger))
water.remove(0)
pure = 0
ans_s,ans_w = 0,A*100
for wi in range(len(water)):
    for si in range(len(suger)):
        if water[wi]+suger[si]>F:pass
        else:
            if pure<suger[si]/(water[wi]+suger[si])<=(E/(100+E)):
                ans_s = suger[si]
                ans_w = water[wi]
                pure = suger[si]/(water[wi]+suger[si])

print(ans_s+ans_w,end="")
print(" ",end="")
print(ans_s)

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

for i in range(0,31):
    for j in range(0,31):
        water = 100*a*i+100*b*j
        if water > f:
            break
        Water.append(water)
for i in range(f//min(c,d)+1):
    for j in range(f//min(c,d)+1):
        sugar = c*i + d*j
        if sugar > f:
            break 
        Sugar.append(sugar)
Sugar=list(set(Sugar))
Water = list(set(Water))
        

def Noudo(x,y):
    if(x>0 and y>0):
        return 100*y/(x+y)
    else:
        return 0
Max = 0
tmp_w,tmp_s = 100*a,0
for i in Water:
    for j in Sugar:
        if (i/100*e >= j) and (i+j <= f):
            tmp = Noudo(i,j)
            if Max < tmp:
                Max = tmp
                tmp_w = i+j
                tmp_s = j
print(tmp_w,tmp_s)

Solution (Python):
a,b,c,d,e,f=map(int,input().split());ans,ma=[0]*2,0
for i in range(f//100+1):
  if i%b==0 or i%a==0:
    w=i*100
    x=min(f-w,i*e)
    s=0
    for j in range(x//c+1):
      ss=j*c
      s=max(s,ss+((x-ss)//d)*d)
    if w!=0:
      if ma<=(100*s)/(w+s):ans=[w,s];ma=(100*s)/(w+s)
print(ans[0]+ans[1],ans[1])

Solution (Python):
import bisect
a, b, c, d, e, f = [int(item) for item in input().split()]

water = set()
for i in range(31):
    for j in range(31):
        w = i*a + j*b 
        if w <= f // 100:
            water.add(w)
water = sorted(water)
sugar = set()
for i in range(1501):
    j = 0
    while i*c + j*d <= 1500:
        sugar.add(i*c + j*d)
        j += 1
sugar = sorted(sugar)
ans = []
for w in water:
    sid = bisect.bisect_right(sugar, w*e) - 1
    while sugar[sid] + w*100 > f and sid > 0:
        sid -= 1
    if w != 0:
        total = w*100 + sugar[sid]
        ans.append([sugar[sid]/total, total, sugar[sid]])
ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])

Solution (Python):
A, B, C, D, E, F = map(int, input().rstrip().split())
water = []
for i in range(A+1):
    for j in range(B+1):
        tmp = A*i*100 + B*j*100
        if tmp < F: 
            water.append(tmp)
        else:
            break
water.sort(reverse=True)
water.pop()
maximum = [water[0], 0]
concentration = 0
for i in water:
    multi = i//100
    suger_limit = E*multi if E*multi + i <= F else F - i
    for j in range(100):
        for k in range(100):
            suger = C*j + D*k
            if suger > suger_limit:
                break
            if concentration < 100*suger / (i + suger):
                concentration = 100*suger / (i + suger)
                maximum = [i+suger, suger]
print(*maximum, sep=" ")

Solution (Python):
import itertools

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

a *= 100
b *= 100
waters = set()
for i in range(0, f // a + 1):
    for j in range(0, (f - a * i) // b + 1):
        waters.add(a * i + b * j)

sugers = set()
g = f // 100 * e
for i in range(0, g // c + 1):
    for j in range(0, (g - c * i) // d + 1):
        sugers.add(c * i + d * j)

answers = set()
for water, suger in itertools.product(waters, sugers):
    if water > 0 and water + suger <= f and suger <= water // 100 * e:
        answers.add((suger + water, suger))

weight, suger = max(answers, key=lambda answer: answer[1] / answer[0])
print(weight, suger)

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

W = set()
for a in range(F // (100 * A) + 1):
    for b in range(F // (100 * B) + 1):
        if a == b == 0: continue
        w = 100 * (A * a + B * b)
        if w <= F:
            W.add(w)

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

max_density = -1
max_ws = 0
max_s = 0
for w in W:
    for s in S:
        if w + s > F or E * w / 100 < s: continue
        density = s / (w + s)
        if density > max_density:
            max_density = density
            max_ws = w + s
            max_s = s

print(max_ws, max_s)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in reversed(sorted(list(W))):
  for sgr in reversed(sorted(list(S))):
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
      if anssgr*(100+E)==E*(answtr+anssgr):
        print("{} {}".format(answtr+anssgr, anssgr))
        exit()
print("{} {}".format(answtr+anssgr, anssgr))

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in W:
  for sgr in S:
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
      if anssgr*(100+E)==E*(answtr+anssgr):
        print("{} {}".format(answtr+anssgr, anssgr))
        exit()
print("{} {}".format(answtr+anssgr, anssgr))