Problem:
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.

Incorrect submission (verdict: Wrong Answer):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()
  ans_n=-inf
  ans_pair=[0,0]

  z=100*e/(100+e)
  
  for i in range(31):
    for j in range(31):
      for k in range(3001):
        for l in range(3001):
          a=i*100+j*100
          b=k+l

          if a+b>f:
            break

          if a+b==0:
            break

          y=100*b/(a+b)
          if y<z:
            if ans_n<z:
              ans_n=z
              ans_pair=[a+b,b]

  return str(ans_pair[0])+' '+str(ans_pair[1])

# main()
print(main())


Fixed, accepted submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()
  ans_n=-inf
  ans_pair=[0,0]

  z=100*e/(100+e)
  # print(z)
  
  for i in range(31):
    for j in range(31):
      for k in range(3001):
        for l in range(3001):
          _a=a*i*100+b*j*100
          _b=k*c+l*d

          if _a+_b>f:
            break

          if _a+_b==0:
            break

          y=100*_b/(_a+_b)

          if y<=z:
            if ans_n<=y:
              ans_n=y
              ans_pair=[_a+_b,_b]

  return str(ans_pair[0])+' '+str(ans_pair[1])

# main()
print(main())