#ABC054D. Mixing Experiment

Mixing Experiment

Problem Statement

Dolphin is planning to generate a small amount of a certain chemical substance CC.

In order to generate the substance CC, he must prepare a solution which is a mixture of two substances AA and BB in the ratio of Ma:MbM_a​:M_b​.

He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.

The pharmacy sells NN kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.

The package of chemical ii contains aia_i​ grams of the substance AA and bi​ grams of the substance BB, and is sold for cic_i​ yen (the currency of Japan).

Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance CC.

Find the minimum amount of money required to generate the substance CC.

If it is not possible to generate the substance CC by purchasing any combination of packages at the pharmacy, report that fact.

Constraints

  • 1N401≤N≤40
  • 1ai,bi101≤a_i​,b_i​≤10
  • 1ci1001≤c_i​≤100
  • 1Ma,Mb101≤M_a​,M_b​≤10
  • gcd(Ma,Mb)=1gcd(M_a​,M_b​)=1
  • ai,bi,ci,Maa_i​, b_i​, c_i​, M_a​ and MbM_b​ are integers.

Input

The input is given from Standard Input in the following format:

N Ma​ Mb​
a1​ b1​ c1​
a2​ b2​ c2​
:  
aN​ bN​ cN​

Output

Print the minimum amount of money required to generate the substance CC. If it is not possible to generate the substance CC, print -1 instead.

Samples

3 1 1
1 2 1
2 1 2
3 3 10
3

The amount of money spent will be minimized by purchasing the packages of chemicals 11 and 22.

In this case, the mixture of the purchased chemicals will contain 33 grams of the substance AA and 33 grams of the substance BB, which are in the desired ratio: 3:3=1:13:3=1:1. The total price of these packages is 33 yen.

1 1 10
10 10 10
-1

The ratio 1:101:10 of the two substances AA and BB cannot be satisfied by purchasing any combination of the packages. Thus, the output should be -1.