Problem:
 Score : 300 points    Problem Statement Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.   Operation 1: Pour 100A grams of water into the beaker.  Operation 2: Pour 100B grams of water into the beaker.  Operation 3: Put C grams of sugar into the beaker.  Operation 4: Put D grams of sugar into the beaker.   In our experimental environment, E grams of sugar can dissolve into 100 grams of water.  Snuke will make sugar water with the highest possible density.  The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.  We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.      Constraints  1 \leq A < B \leq 30  1 \leq C < D \leq 30  1 \leq E \leq 100  100A \leq F \leq 3  000  A , B , C , D , E and F are all integers.         Inputs Input is given from Standard Input in the following format:  A  B  C  D  E  F       Outputs Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.        Sample Input 1 1 2 10 20 15 200      Sample Output 1 110 10  In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.  We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:   If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.  If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.        Sample Input 2 1 2 1 2 100 1000      Sample Output 2 200 100  There are other acceptable outputs, such as:  400 200  However, the output below is not acceptable:  300 150  This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.       Sample Input 3 17 19 22 26 55 2802      Sample Output 3 2634 934

Solution (Python):


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

dp_sugar = [0 for i in range(3001)]
dp_sugar[0] = True
for i in range(1, 3001):
    if i >= C:
        dp_sugar[i] |= dp_sugar[i-C]
    if i >= D:
        dp_sugar[i] |= dp_sugar[i-D]

dp_water = [0 for i in range(3001)]
dp_water[0] = 1
for i in range(1, 3001):
    if i >= 100*A:
        dp_water[i] |= dp_water[i-100*A]
    if i >= 100*B:
        dp_water[i] |= dp_water[i-100*B]

data = []
for i in range(1, F+1):
    
    if dp_water[i]:
        submax = 0
        for j in range(F+1-i):
            
            if dp_sugar[j] and 100*j <= E*i:
                submax = j
        data.append((i+submax, submax, 100*submax/(i+submax)))
data.sort(key=lambda x: x[-1])
x,y,z=data[-1]
print(x,y)

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

density = -1
s_water = -1
sugar = -1
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:
                    continue
                if w + s > F or w + s < 100*A:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = w + s
                        sugar = s
print(s_water, sugar)

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

density = -1
s_water = -1
sugar = -1
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:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)

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

DP=[-1 for _ in range(f+1)]
DP[a]=0
if b<=f:DP[b]=0
for i in range(f+1):
    if DP[i]==-1:continue
    for j in a,b:
        if i+j<=f:DP[i+j]=DP[i]
    for j in c,d:
        if i+j<=f and 100*(DP[i]+j)/(i+j)<=100*e/(100+e):
            DP[i+j]=DP[i]+j

ans,water=0,[a,0]
for i,j in enumerate(DP):
    if i==0 or j==-1:continue
    if ans<100*j/i:
        ans=100*j/i
        water=[i,j]
print(*water)

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

DP=[-1 for _ in range(f+3000)]
DP[a],DP[b]=0,0
for i in range(f+1):
    if DP[i]==-1:continue
    for j in a,b:
        if i+j<=f:DP[i+j]=DP[i]
    for j in c,d:
        if i+j<=f and 100*(DP[i]+j)/(i+j)<=100*e/(100+e):
            DP[i+j]=DP[i]+j

ans,water=0,[a,0]
for i,j in enumerate(DP):
    if i==0:continue
    if ans<100*j/i:
        ans=100*j/i
        water=[i,j]
print(*water)

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

a *=100
b *=100
DP=[[0,0] for _ in range(f+3000)]
DP[a][0]=a
DP[b][0]=b

for i in range(f+1):
    if DP[i][0]==0:continue
    for j in a,b:
        if i+j<=f:
            if DP[i][1]*100/(i+j)>=DP[i+j][1]*100/(i+j):
                DP[i+j]=[i+j,DP[i][1]]
    for j in c,d:
        if i+j<=f:
            if 100*(DP[i][1]+j)/(i+j)<=100*e/(100+e):
                if 100*(DP[i][1]+j)/(i+j)>=100*(DP[i+j][1])/(i+j):
                    DP[i+j]=[i+j,DP[i][1]+j]

ans,water=0,[a,0]
for x,y in DP:
    if x==0:continue
    if 100*y/x>ans:
        ans=100*y/x
        water=[x,y]
print(*water)

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

DP=[[0,0] for _ in range(f+3000)]
DP[a*100][0]=a*100
DP[b*100][0]=b*100

for i in range(f+1):
    if DP[i][0]==0:continue
    for j in a,b:
        if i+j*100<=f:
            j *=100
            if DP[i][1]*100/(i+j)>=DP[i+j][1]*100/(i+j):
                DP[i+j]=[i+j,DP[i][1]]
    for j in c,d:
        if i+j<=f:
            if 100*(DP[i][1]+j)/(i+j)<=100*e/(100+e):
                if 100*(DP[i][1]+j)/(i+j)>=100*(DP[i+j][1])/(i+j):
                    DP[i+j]=[i+j,DP[i][1]+j]

ans,water=0,[a*100,0]
for x,y in DP:
    if x==0:continue
    if 100*y/x>ans:
        ans=100*y/x
        water=[x,y]
print(*water)

Solution (Python):
inf=10**8
a,b,c,d,e,f=map(int,input().split())
a,b=100*a,100*b
DP=[inf]*(f+max(a,b)+1)
DP[a],DP[b]=0,0

for i in range(f+1):
    if DP[i]!=inf:
        DP[i+a]=DP[i]
        DP[i+b]=DP[i]
        for j in c,d:
            if 100*(DP[i]+j)/(i+j)<=100*e/(100+e):
                DP[i+j]=max(DP[i],DP[i]+j)

ans,index=0,[a,0]
for i in range(f+1):
    if DP[i]!=inf:
        if ans<100*DP[i]/i:
            ans=100*DP[i]/i
            index=[i,DP[i]]

print(*index)

Solution (Python):
A,B,C,D,E,F=list(map(int,input().split()))
max=0
satou=0
water=0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                a=100*A*i+100*B*j
                s=C*k +D*l
                if a==0:break
                if a+s<=F and (a/100)*E>=s :
                    if max<100*s/(a+s):
                        max=100*s/(a+s)
                        water=a+s
                        satou=s
if satou>0:
    print(water,satou)
else:
    print(100*A,0)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
maxsugar=0
maxwater=100*a
for i in range(31):
    for j in range(31):
        for k in range(3001):
            water=100*a*i+100*b*j
            sugar=c*k
            if water+sugar>f:
                continue
            if sugar>(a*i+b*j)*e:
                continue
            sugar+=min((f-(water+sugar))//d*d,((a*i+b*j)*e-c*k)//d*d)
            if 100*maxsugar*(water+sugar)<100*sugar*(maxsugar+maxwater):
                maxsugar=sugar
                maxwater=water
print(maxsugar+maxwater,maxsugar)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
kouho = 0
jisho = {}
max_a = 30 // a
max_b = 30 // b
for i in range(max_a + 1):
    for j in range(max_b + 1):
        water = (a * i + b * j) * 100
        if water == 0:
            continue
        lim1 = e * (a * i + b * j)
        lim2 = f - water
        lim = min(lim1, lim2)
        max_c = lim // c
        max_d = lim // d
        for k in range(max_c + 1):
            for m in range(max_d + 1):
                sugar = k * c + m * d
                if sugar > lim:
                    continue
                satoumizu = water + sugar
                if satoumizu > f:
                    continue
                if sugar == 0:
                    continue

                noudo = 100 * sugar / satoumizu
                if noudo > kouho:
                    kouho = noudo
                    jisho[noudo] = (sugar, satoumizu)
if kouho == 0:
    print(100 * a, 0)
    exit()
ans2, ans1 = jisho[kouho]
print(ans1, ans2)

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

dp=[[False]*(f+2) for i in range(f+2)]


dp[0][0]=True

for j in range(f+1):
    i=0
    if dp[i][j] and j<=f:
        if 0<i+j+100*a<=f:
            dp[i][j+100*a]=True
        if 0<i+j+100*b<=f:
            dp[i][j+100*b]=True

for i in range(f+1):
    for j in range(1,f+1):
        if dp[i][j] and i+j<=f:
            if 0<i+c+j<=f:
                dp[i+c][j]=True
            if 0<i+d+j<=f:
                dp[i+d][j]=True

tmpi=0
tmpj=min(a*100,b*100)
for i in range(f+1):
    for j in range(1,f+1):
        if dp[i][j] and i*100<=e*j and 0<j+i<=f and tmpi*j<i*tmpj:
            tmpi=i
            tmpj=j
        if i*100==e*j:
            break

print(tmpi+tmpj, tmpi)

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
a,b,e = 100*a,100*b,e/(100+e)
best = [max(0,(f//a)*a,(f//b)*b),0,0] 

for n in range(f//a+1):
    na = n*a
    for m in range((f-na)//b+1):
        if n==m==0:
            continue
        mb = m*b
        for k in range((f-na-mb)//c+1):
            kc = k*c
            for l in range((f-na-mb-kc)//d+1):
                ld = l*d
                sugar = (kc+ld)
                sugarwater = (na+mb+kc+ld)
                if best[2] < sugar/sugarwater <= e:
                    best = [sugarwater,sugar,sugar/sugarwater]
                
best.pop()
print(*best)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

    kouho = []
    for w in water:
        ma = (E * w) // 100
        for c in range(ma // C + 1):
            for d in range(ma // D + 1):
                sugar = c * C + d * D
                if 0 < sugar <= ma and w + sugar <= F:
                    kouho.append([w, sugar])

    if len(kouho) == 0:
        print(list(water)[0], 0)
        exit()

    max_noudo = 0
    res = []
    for w, sugar in kouho:
        noudo = sugar / (w + sugar)
        if max_noudo < noudo:
            max_noudo = noudo
            res = [w + sugar, sugar]
    print(*res)


if __name__ == '__main__':
    resolve()

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

dp = [[-1]*3 for _ in range(f + 1)]
dp[0] = [0, 0, 0]
for i in range(1, f+1):
    lst = []
    if i >= 100*a and dp[i-100*a][1] != -1:
        h = dp[i-100*a][2] / i
        lst.append([h, dp[i-100*a][1] + 100*a, dp[i-100*a][2]])
    if i >= 100*b and dp[i-100*b][1] != -1:
        h = dp[i-100*b][2] / i
        lst.append([h, dp[i-100*b][1] + 100*b, dp[i-100*b][2]])
    if i >= c and dp[i-c][1] > 0:
        h = (dp[i-c][2] + c) / i
        if h <= e/(100 + e):
            lst.append([h, dp[i-c][1], dp[i-c][2] + c])
    if i >= d and dp[i-d][1] > 0:
        h = (dp[i-d][2] + d) / i
        if h <= e/(100 + e):
            lst.append([h, dp[i-d][1], dp[i-d][2] + d])
    if lst:
        dp[i] = max(lst)
ans = max(dp)
print(ans[1] + ans[2], ans[2])

Solution (Python):
a,b,c,d,e,f = map(int,input().split())
"""
100a 水 <= 30
100b 水 <= 30
c 砂糖 <= 30
d 砂糖 <= 30
e 100gにとける砂糖の量
f 最大質量

全探索の時間ですか！？ 高々 30*30*1000*1000 工夫っすれば  oK.
"""
ans = 0
ansl = [a*100, 0]
for a_times in range(f//(a*100) + 1):
	a_g = a_times * a * 100
	for b_times in range(f//(b*100) + 1):
		b_g = b_times * b * 100
		for c_times in range(f//c + 1):
			c_g = c_times * c
			for d_times in range(f//d + 1):
				d_g = d_times * d
				targ = a_g+b_g+c_g+d_g
				if targ > f:
					break
				elif targ != 0:
					if (a_g+b_g)//100*e >= c_g+d_g:
						if (c_g+d_g)/targ > ans:
							ans = (c_g+d_g)/targ
							ansl = [targ, c_g+d_g]
print(*ansl)

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
ws = []
for i in range(f//100//a+1):
    for j in range(f//100//b+1):
        w = 100*(a*i+b*j)
        if 0 < w <= f:
            ws.append(w)
        if w >= f:
            break
ss = []
for i in range(f*e//(100+e)//c+1):
    for j in range(f*e//(100+e)//d+1):
        s = c*i+d*j
        if 0 <= s <= f*e//(100+e):
            ss.append(s)
n = []
for w in ws:
    for s in ss:
        if w+s > f:
            continue
        if s > e*w//100:
            continue
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])

Solution (Python):



import numpy
from queue import deque

def main():
  l = list(map(int, input().split()))
  w1, w2, s1, s2, spwr, mm = l
  w1, w2 = 100*w1, 100*w2
  flags = numpy.zeros((mm+1, mm+1))
  dq = deque([(w1, 0)])
  max_conc = -1.0
  ans = (0, 0)
  while dq:
    w, s = dq.pop()
    flags[w, s] = 1
    if w != 0 and s <= spwr * w // 100:
      conc = s / (w + s)
      if max_conc < conc:
        max_conc = conc
        ans = (w+s, s)
    for sx in [s1, s2]:
      if w + s+sx <= mm and flags[w, s+sx] == 0:
        flags[w, s+sx] = 1
        dq.append((w, s+sx))
    for wx in [w1, w2]:
      if w+wx + s <= mm and flags[w+wx, s] == 0:
        flags[w+wx, s] = 1
        dq.append((w+wx, s))
  print(*ans)
  
if __name__=='__main__':
  main()

Solution (Python):
a,b,c,d,e,f = map(int, input().split())
sugar = []
for i in range(1501):
    if (i%c==0):
        sugar.append(i)
    else:
        for j in range(i//c+1):
            if (i-j*c)%d==0:
                sugar.append(i)

ans = 0
ax = 100*a
ay = 0
for i in range(30):
    for j in range(30):
        if (i==0 and j==0):
            continue
        if (a*i+b*j <= f//100):
            w = (a*i+b*j)*100
            for k in sugar:
                if ((100*k)/(w+k)<=(100*e)/(100+e) and (w+k)<=f):
                    if ((100*k)/(w+k) > ans):
                        
                        ans = 100*k/(w+k)
                        
                        ax = w
                        ay = k
print(ax+ay,ay)

Solution (Python):
a, b, c, d, e, f = map(int, input().split())
dp = [[False] * 3001 for _ in range(3001)]
dp[0][0] = True
satomizumax = 0
satomax = 0
for sm in range(f + 1):
    for sg in range(f + 1):
        
        
        if sg * (100 + e) > e * sm:
            break

        if dp[sm][sg]:
            if satomax * sm <= sg * satomizumax:
                satomizumax = sm
                satomax = sg
            if sm + 100 * a <= f + 1:
                dp[sm + 100 * a][sg] = True
            if sm + 100 * b <= f + 1:
                dp[sm + 100 * b][sg] = True
            if sm + c <= f + 1 and sg + c <= f + 1:
                dp[sm + c][sg + c] = True
            if sm + d <= f + 1 and sg + d <= f + 1:
                dp[sm + d][sg + d] = True
print(satomizumax, satomax)

Solution (Python):
import sys
readline = sys.stdin.readline





A,B,C,D,E,F = map(int,readline().split())
max_rate = -1
ans_water = 0
ans_sugar = 0
for a in range(30):
  for b in range(30):
    if a * A * 100 + b * B * 100 >= F:
      continue
    water = a * A * 100 + b * B * 100
    if water == 0:
      continue
    max_sugar = water * E // 100 
    if max_sugar + water > F:
      max_sugar = F - water
      
    dp = [False] * (max_sugar + 1)
    dp[0] = True
    for i in range(len(dp)):
      if dp[i]:
        if i + C >= len(dp):
          break
        dp[i + C] = True
    
    for i in range(len(dp)):
      if dp[i]:
        if i + D >= len(dp):
          break
        dp[i + D] = True
        
    for i in range(len(dp) - 1, -1, -1):
      if dp[i]:
        rate = (i * 100) / (water + i)
        break
    if rate >= max_rate:
      max_rate = rate
      ans_water = water
      ans_sugar = i
    
print(ans_water + ans_sugar,ans_sugar)

Solution (Python):
a , b , c , d , e , f = map(int,input().split())
midp = [-1 for i in range(f+1)]
mizu = []
midp[0] = 0
for i in range(f+1):
    if midp[i] != -1:
        if i + a*100 <= f and midp[i+a*100] != 0:
            midp[i+a*100] = 0
            mizu.append(i+a*100)
        if i + b*100 <= f and midp[i+b*100] != 0:
            midp[i+b*100] = 0
            mizu.append(i+b*100)
ans = 0
cou = [a*100,0]
for i in mizu:
    sai = i*e//100
    sadp = [-1 for f in range(sai+1)]
    sadp[0] = 0
    maxsa = 0
    for j in range(sai+1):
        if sadp[j] != -1:
            if j + c <= sai and i + j + c <= f and sadp[j+c] != 0:
                sadp[j+c] = 0
                maxsa = max(maxsa,j+c)
            if j + d <= sai and i + j + d <= f and sadp[j+d] != 0:
                sadp[j+d] = 0
                maxsa = max(maxsa,j+d)
    if ans < maxsa/(i+maxsa):
        ans = maxsa/(i+maxsa)
        cou = [i+maxsa,maxsa]

print(*cou)

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
mx =- 1
S = set()
W = set()

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

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

for w in W:
  for s in S:
    if 0<w+s<=F and s<=w*E//100:
      if mx<s/(w+s):
        ans=w+s,s
        mx=s/(w+s)

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

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
maxim=-1
ans=[0,0]
for i in range(F//100//A+2):
  for j in range(F//100//B+2):
    if A*100*i+B*100*j >= F:
      break
    for k in range(F//C+2):
      if A*100*i+B*100*j+C*k >= F:
        break
      for l in range(F//D+2):
        s=D*l+C*k
        w=A*100*i+B*100*j
        if s+w<=F:
          if w//100*E>=s:
            if s+w!=0:
              if maxim<100*s/(s+w):
                maxim=100*s/(s+w)
                ans=[w+s,s]
print(*ans)

Solution (Python):


LI = lambda: list(map(int, input().split()))


A, B, C, D, E, F = LI()


def main():
    ans = (0, 0, 0)
    for b in range(F // 100 // B + 1):
        water = 100 * B * b
        for a in range((F - water) // 100 // A + 1):
            water += 100 * A * a
            if water == 0:
                continue
            
            s = min(F - water, water // 100 * E)
            for d in range(s // D + 1):
                sugar = d * D
                sugar += (s - sugar) // C * C
                t = (sugar / (water + sugar), water + sugar, sugar)
                if ans < t:
                    ans = t
    print(*ans[1:])


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	A, B, C, D, E, F = NMI()
	W = []
	for i in range(31):
		for j in range(16):
			if 0 < (A*i + B*j) * 100 <= F:
				W.append(A*i + B*j)
	W = set(W)
	S = set()
	for i in range(3001):
		if C*i > 30 * E:
			break
		for j in range(1501):
			if 0 < C*i + D*j <= 30 * E:
				S.add(C*i + D*j)
	con = 0
	ans = [100*A, 0]
	for w in W:
		for s in S:
			if s <= F - 100 * w and s <= w * E and 100 * s / w >= con:
				con = 100 * s / w
				ans = [100*w + s, s]
	print(ans[0], ans[1])



if __name__ == "__main__":
	main()

Solution (Python):
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


a, b, c, d, e, f = map(int, input().split())
density = 0
ans = [100 * a, 0]
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                s = c * k + d * l
                total = s + 100 * a * i + 100 * b * j
                if total > f or total == 0 or s / total > e / (100 + e):
                    continue
                if s / total > density:
                    density = s / total
                    ans = [total, s]
print(*ans)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
a=100*a
b=100*b
dp1=[0]*(f+1)
dp2=[0]*(f+1)
for i in range(f+1):
    if i%a==0:
        if i+a<=f:
            dp1[i+a]=1
for i in range(f+1):
    if i==0 or dp1[i]==1:
        if i+b<=f:
            dp1[i+b]=1
for i in range(f+1):
    if i%c==0:
        if i+c<=f:
            dp2[i+c]=1
for i in range(f+1):
    if i==0 or dp2[i]==1:
        if i+d<=f:
            dp2[i+d]=1

ans=[-1,-1,-1]
for i in range(f+1):
    if dp1[i]==1:
        x=min(f-i,(i//100)*e)
        k=-1
        for j in range(x,-1,-1):
            if dp2[j]==1 or j==0:
                k=j
                if ans[0]<100*k/(i+k):
                    ans=[100*k/(i+k),i+k,k]
                break
print(str(ans[1])+" "+str(ans[2]))

Solution (Python):
from bisect import bisect_right
a, b, c, d, e, f = map(int, input().split())
waters = set(i*a+j*b if (i*a+j*b)*100<=f else 0 for i in range(31) for j in range(31))
sugers = list(set(i*c+j*d if i*c+j*d<=f else 0 for i in range(1501) for j in range(1501)))
sugers.sort()
ans_water = 0
ans_suger = 0
ans_conc = -1
for water in waters:
    if water==0:
        continue
    tmp = bisect_right(sugers, e*water)-1
    while tmp>=0:
        suger = sugers[tmp]
        if water*100+suger<=f:
            break
        tmp -= 1
    if ans_conc < suger/(water*100+suger):
        ans_conc = suger/(water*100+suger)
        ans_suger = suger
        ans_water = water*100
print(ans_water+ans_suger, ans_suger)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
ans = 0
answ = A*100
anss = 0
for a in range(30//A+1):
    for b in range((30-a*A)//B+1):
        
        w = (a*A + b*B) * 100
        if w > F:
            break
        elif w == 0:
            continue
        
        sc = (w / 100) * E
        
        for c in range(int(sc//C)+1):
            for d in range(int((sc-c*C)//D)+1):
                s = c*C + d*D
                if s > sc or w + s > F:
                    break
                tmp = s / (w + s)
                
                if ans < tmp:
                    ans = tmp
                    answ = w
                    anss = s
print(answ+anss, anss)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 0 < 100 * A * a + 100 * B * b <= F:
                W.add(100 * A * a + 100 * B * b)
    W = sorted(list(W))
    kouho = []
    for w in W:
        max_S = (w // 100) * E
        tmp = 0
        for c in range(0, max_S + 1, C):
            for d in range(0, max_S + 1 - c, D):
                s = c + d
                if s + w <= F:
                    tmp = max(tmp, s)
        kouho.append([w + tmp, tmp])

    ma = 0
    res = [W[0], 0]
    for total, sugar in kouho:
        noudo = (sugar * 100) / total
        if ma < noudo:
            ma = noudo
            res = [total, sugar]

    print(*res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 0 < 100 * A * a + 100 * B * b <= F:
                W.add(100 * A * a + 100 * B * b)
    W = sorted(list(W))
    kouho = []
    for w in W:
        max_S = (w // 100) * E
        tmp = 0
        for c in range(0, max_S + 1, C):
            for d in range(0, max_S + 1 - c, D):
                s = c + d
                if s + w <= F:
                    tmp = max(tmp, s)
        kouho.append([w + tmp, tmp])

    ma = 0
    res = [W[0], 0]
    for total, sugar in kouho:
        noudo = (sugar * 100) / total
        if ma < noudo:
            ma = noudo
            res = [total, sugar]

    print(*res)


if __name__ == '__main__':
    resolve()

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
able_water=[]
for na in range(1+f//(a*100)):
  for nb in range(1+(f-na*a*100)//(b*100)):
    water=na*a*100+nb*b*100
    if water and water<=f:
      able_water.append(water)
able_water.sort()
import bisect
from fractions import Fraction
ans=[0,0,0]
max_s=(f*e+100-1)//100
for nd in range(1+max_s//d):
  for nc in range(1+(max_s-nd*d)//c):
    sugger=nc*c+nd*d
    min_water=(sugger*100+e-1)//e
    if min_water+sugger>f:continue
    idx=bisect.bisect_left(able_water,min_water)
    if idx <len(able_water) and able_water[idx]+sugger<=f:
      if ans[0]<=Fraction(sugger,(able_water[idx]+sugger)):
        ans=[Fraction(sugger,(able_water[idx]+sugger)),able_water[idx]+sugger,sugger]
print(ans[1],ans[2])

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
able_water=[]
for na in range(1+f//(a*100)):
  for nb in range(1+(f-na*a*100)//(b*100)):
    water=na*a*100+nb*b*100
    if water and water<=f:
      able_water.append(water)
able_water.sort()
import bisect
ans=[0,0,0]
max_s=(f*e+100-1)//100
for nd in range(1+max_s//d):
  for nc in range(1+(max_s-nd*d)//c):
    sugger=nc*c+nd*d
    min_water=(sugger*100+e-1)//e
    if min_water+sugger>f:continue
    idx=bisect.bisect_left(able_water,min_water)
    if idx <len(able_water) and able_water[idx]+sugger<=f:
      if ans[0]<=(100*sugger/(able_water[idx]+sugger)):
        ans=[100*sugger/(able_water[idx]+sugger),able_water[idx]+sugger,sugger]
print(ans[1],ans[2])

Solution (Python):
def main():
    a, b, c, d, e, f = map(int, input().split())
    x, y = set(), set()
    for i in range(f // (100 * a) + 1):
        for j in range((f - 100 * a * i) // (100 * b) + 1):
            x.add(100 * a * i + 100 * b * j)
    for i in range(f // c + 1):
        for j in range((f - c * i) // d + 1):
            y.add(c * i + d * j)
    m = (-1, -1, -1)
    for xi in x:
        for yi in y:
            if xi == 0:
                continue
            if xi + yi > f:
                continue
            if 100 * yi > xi * e:
                continue
            s = yi / (xi + yi)
            if s > m[0]:
                m = (s, xi + yi, yi)
    print(m[1], m[2])


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100
    m = (-1, 0, 0)
    for i in range(f // a + 1):
        for j in range((f - (a * i)) // b + 1):
            ma = a * i + b * j
            if ma == 0:
                continue
            for k in range((f - ma) // c + 1):
                if 100 * c * k > ma * e:
                    break
                for l in range((f - (ma + c * k)) // d + 1):
                    mb = c * k + d * l
                    if 100 * mb > ma * e:
                        break
                    dab = mb / (ma + mb)
                    if dab > m[0]:
                        m = (dab, ma + mb, mb)
    print(m[1], m[2])


if __name__ == '__main__':
    main()