stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm> 

#include <queue>

#include <functional>

#include <map>

#include <string>

using namespace std;

typedef long long ll;



const int INF = 10000000;

int n, ma, mb;

int a[45], b[45], c[45];

int dp[45][405][405];



int rec(int i, int  A, int B){

    if (dp[i][A][B] > 0){

        return dp[i][A][B];

    }



    if (A > 0 && B > 0 && ma*B == mb*A){

        return dp[i][A][B] = 0;

    }



    if (i == n){

        return INF;

    }



    int ret = INF;

    ret = min(ret, rec(i + 1, A, B));



    ret = min(ret, c[i] + rec(i + 1, A + a[i], B + b[i]));

    



    return dp[i][A][B] = ret;

    

}



int main(void){

   

    cin >> n >> ma >> mb;



    for (int i = 0; i < n; i++){

        cin >> a[i] >> b[i] >> c[i];

    }



    for (int i = 0; i < n; i++){

        for (int j = 0; j <= 400; j++){

            for (int k = 0; k <= 400; k++){

                dp[i][j][k] = -1;

            }

        }

    }



    int ans = rec(0, 0, 0);

    

    if (ans >= INF){

        cout << -1 << endl;

    }

    else{

        cout << ans << endl;

    }

    

}

// Faster C++ solution for the same problem (measured speedup: 2.2031460753308845x):
#include <iostream>

#include <iomanip>

#include <cstring>

#include <algorithm> 

#include <queue>

#include <functional>

#include <map>

#include <vector>

#include <string>

using namespace std;

typedef long long ll;

const int INF = 100000;



int dp[45][405][405];



int main(void){

    int n, a[45], b[45], c[45], ma, mb, suma = 0, sumb = 0;



    cin >> n >> ma >> mb;

    for (int i = 0; i < n; i++){

        cin >> a[i] >> b[i] >> c[i];

        suma += a[i]; sumb += b[i];

    }



    for (int i = 0; i <= suma; i++)

        for (int j = 0; j <= sumb; j++) dp[0][i][j] = INF;



    dp[0][0][0] = 0;



    for (int i = 0; i < n; i++){

        for (int j = 0; j <= suma; j++){

            for (int k = 0; k <= sumb; k++){

                dp[i + 1][j][k] = dp[i][j][k];

                if (a[i] <= j && b[i] <= k) dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);

            }

        }

    }



    int ans = INF;

    for (int i = 1; i <= suma; i++){

        for (int j = 1; j <= sumb; j++){

            if (ma*j == mb*i) ans = min(ans, dp[n][i][j]);

        }

    }



    if (ans == INF) ans = -1;

    cout << ans << endl;



}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vll;

#define pb push_back

#define mp make_pair

#define eps 1e-9

#define INF 1000000000

#define sz(x) ((int)(x).size())

#define fi first

#define sec second

#define all(x) (x).begin(),(x).end()

#define sq(x) ((x)*(x))

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)

#define EQ(a,b) (abs((a)-(b))<eps)

template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}

template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}

int N,Ma,Mb;

int a[45],b[45],c[45],d[45];

map<int,int> m;

int main(){

	cin >> N >> Ma >> Mb;

	for(int i=0;i<N;i++){

		cin >> a[i] >> b[i] >> c[i];

		a[i]*=Mb;

		b[i]*=Ma;

		d[i]=a[i]-b[i];

	}

	int M = N/2;

	int ans = INF;

	for(int i=1;i<(1<<M);i++){

		int s = 0, cost = 0;

		for(int j=0;j<M;j++){

			if((i>>j)&1){

				s+=d[j];

				cost+=c[j];

			}

		}

		map<int,int>::iterator it = m.find(s);

		if(s==0)ans = min(ans,cost);

		if(it==m.end())m[s]=cost;

		else (it->sec)=min((it->sec),cost);

	}

	for(int i=1;i<(1<<(N-M));i++){

		int s = 0, cost = 0;

		for(int j=0;j<(N-M);j++){

			if((i>>j)&1){

				s+=d[j+M];

				cost+=c[j+M];

			}

		}

		int tar = -s;

		map<int,int>::iterator it = m.find(tar);

		if(tar==0)ans = min(ans,cost);

		if(it!=m.end()){

			ans = min(ans,cost+(it->sec));

		}

	}

	if(ans==INF)ans = -1;

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.084908259760479x):
#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <string.h>

 

#define mod 1e9+7

#define ll long long int

#define epsilon 1e-7

 

ll min(ll x, ll y){

    if(x < y)return x;

    else return y;

}

 

int main(void){

    int n, ma, mb;

    scanf("%d %d %d", &n, &ma, &mb);

    int ab[n], c[n];

    for(int i = 0;i < n;i++){

        int a, b;

        scanf("%d %d %d", &a, &b, &c[i]);

        ab[i] = b * ma - a * mb;

    }

    int dp[n+1][8000];

    for(int i = 0;i <= n;i++){

        for(int j = 0;j < 8000;j++){

            dp[i][j] = mod;

        }

    }

    for(int i = 0;i < n;i++){

        for(int j = 0;j < 8000;j++){

            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);

            if(j==4000){

                dp[i+1][j+ab[i]]=min(dp[i+1][j+ab[i]],c[i]);

            }else if(dp[i][j]==mod){

                continue;

            }else{

                if(j+ab[i]>=0&&j+ab[i]<8000)dp[i+1][j+ab[i]] = min(dp[i+1][j+ab[i]],dp[i][j]+c[i]);

            }

        }

    }

    if(dp[n][4000] != mod)printf("%d\n", dp[n][4000]);

    else printf("-1\n");

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<math.h>

#include<string>

#include<string.h>

#include<stack>

#include<queue>

#include<vector>

#include<utility>

#include<set>

#include<map>

#include<stdlib.h>

#include<iomanip>



using namespace std;



#define ll long long

#define ld long double

#define EPS 0.0000000001

#define INF 1e9

#define MOD 1000000007

#define rep(i,n) for(i=0;i<n;i++)

#define loop(i,a,n) for(i=a;i<n;i++)

#define all(in) in.begin(),in.end()

#define shosu(x) fixed<<setprecision(x)



typedef vector<int> vi;

typedef pair<int,int> pii;





int main(void) {

  int i,j,k;

  int n,ma,mb;

  cin>>n>>ma>>mb;

  ll dp[2][405][405];

  rep(i,2)rep(j,405)rep(k,405)

    dp[i][j][k]=INF;

  dp[0][0][0]=0;



  rep(i,n){

    int a,b,c;

    cin>>a>>b>>c;

    rep(j,405)rep(k,405)

      if(dp[i%2][j][k]<INF){

        dp[(i+1)%2][j][k]=min(dp[(i+1)%2][j][k],dp[i%2][j][k]);

        if(j+a<405 && k+b<405)

          dp[(i+1)%2][j+a][k+b]=min(dp[(i+1)%2][j+a][k+b],dp[i%2][j][k]+c);

        dp[i%2][j][k]=INF;

     }

  }



  ll ans=INF;

  for(i=1;i*max(ma,mb)<405;i++)

    ans=min(ans,dp[n%2][i*ma][i*mb]);

  if(ans<INF)

    cout<<ans<<endl;

  else

    cout<<-1<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.6841073854129427x):
#include<iostream>

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<math.h>

#include<string>

#include<string.h>

#include<stack>

#include<queue>

#include<vector>

#include<utility>

#include<set>

#include<map>

#include<stdlib.h>

#include<iomanip>



using namespace std;



#define ll long long

#define ld long double

#define EPS 0.0000000001

#define INF 1e9

#define MOD 1000000007

#define rep(i,n) for(i=0;i<n;i++)

#define loop(i,a,n) for(i=a;i<n;i++)

#define all(in) in.begin(),in.end()

#define shosu(x) fixed<<setprecision(x)



typedef vector<int> vi;

typedef pair<int,int> pii;



int main(void) {

  int i,j;

  ll n,ma,mb;

  cin>>n>>ma>>mb;



  int cnst=4000;



  int dp[45][8005];

  rep(i,45)rep(j,8005)

    dp[i][j]=INF;



  rep(i,n){

    int a,b,c;

    cin>>a>>b>>c;

    int diff=a*mb-b*ma;

    dp[i+1][diff+cnst]=min(dp[i+1][diff+cnst],c);

    rep(j,8005){

      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);

      if(j+diff<8005 && j+diff>=0)

         dp[i+1][j+diff]=min(dp[i+1][j+diff],dp[i][j]+c);

    }

  }

  if(dp[n][cnst]<INF)

    cout<<dp[n][cnst]<<endl;

  else

    cout<<-1<<endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int maxn=405,INF=1e9;

int dp[maxn+100][maxn+100]; // i个a j个b最小的消耗

int a[maxn],b[maxn],c[maxn];

int main() {

	int n,A,B;

	cin>>n>>A>>B;

	for(int i=1; i<=n; i++)

		cin>>a[i]>>b[i]>>c[i];

	for(int i=0; i<=400; i++)

		for(int j=0; j<=400; j++)

			dp[i][j]=INF;

	dp[0][0]=0;

	for(int x=1; x<=n; x++) {

		for(int i=400; i>=0; i--)

			for(int j=400; j>=0; j--)

				if(dp[i][j]!=INF)

					dp[i+a[x]][j+b[x]]=min(dp[i+a[x]][j+b[x]],dp[i][j]+c[x]);

	}

	int ans=INF;

	for(int i=1; i<=400; i++) {

		for(int j=1; j<=400; j++)

			if(dp[i][j]!=INF && i*B==A*j)

				ans=min(ans,dp[i][j]);

	}

	printf("%d\n",ans==INF?-1:ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.391819543627126x):
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <algorithm>

#include <cmath>

#define FUP(i,x,y) for(int i=(x);i<=(y);i++)

#define FDW(i,x,y) for(int i=(x);i>=(y);i--)

#define MAXN 40

#define INF 0x3f3f3f3f

#define MOD 1000000007

#define ll long long

#define db double

using namespace std;

int read(){

    int w=0,flg=1;

    char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}

    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}

    return w*flg;

}

int n,m1,m2,a[MAXN],b[MAXN],c[MAXN],ans=INF,cnt=1,suma,sumb;

int f[410][410];

int gcd(int a,int b)

{

	return b==0?a:gcd(b,a%b);

}

int main(){

	

	memset(f,0x3f,sizeof(f));

	f[0][0]=0;

	n=read(),m1=read(),m2=read();

	FUP(i,1,n)

	{

		a[i]=read(),b[i]=read(),c[i]=read();

		suma+=a[i],sumb+=b[i];

		FDW(j,suma,a[i])

		{

			FDW(k,sumb,b[i])

			{

				f[j][k]=min(f[j][k],f[j-a[i]][k-b[i]]+c[i]);

				if(j*1.0/m1==k*1.0/m2)

				{

					ans=min(ans,f[j][k]);

					//printf("%d,%d\n",j,k);

				}

			}

		}

		//printf("%d\n",f[2][2]);

	}

	printf("%d\n",ans==INF?-1:ans);

    return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;

const int MAX = 500;

const int INF = (int)1e9 + 7;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {

    int n, ma, mb; cin >> n >> ma >> mb;

    vector<vector<int>> dp(MAX, vector<int>(MAX, INF));

    dp[0][0] = 0;

    while (n--) {

        int a, b, c; cin >> a >> b >> c;

        for (int na = MAX - 1; na >= a; na--) {

            for (int nb = MAX - 1; nb >= b; nb--) {

                chmin(dp[na][nb], dp[na - a][nb - b] + c);

            }

        }

    }

    int ans = INF;

    for (int a = 1; a < MAX; a++) for (int b = 1; b < MAX; b++) {

        if (a * mb == b * ma) chmin(ans, dp[a][b]);

    }

    if (ans == INF) {

        cout << -1 << endl;

    } else {

        cout << ans << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2199521398027378x):
#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;

const int INF = (int)1e9 + 7;

template<class T> inline bool chmin(T &a, T b) { return a > b ? (a = b, 1) : 0; }



int main() {

    const int MAX = 400;

    int n; cin >> n;

    int ma, mb; cin >> ma >> mb;

    vector<vector<int>> dp(MAX + 1, vector<int>(MAX + 1, INF));

    dp[0][0] = 0;

    while (n--) {

        int a, b, c; cin >> a >> b >> c;

        for (int na = MAX; na >= a; na--) {

            // for (int nb = MAX; nb >= b; nb--) {

            for (int nb = b; nb <= MAX; nb++) {

                chmin(dp[na][nb], dp[na - a][nb - b] + c);

            }

        }

    }

    int mi = INF;

    for (int a = 1; a <= MAX; a++) for (int b = 1; b <= MAX; b++) {

        if (a * mb == b * ma) chmin(mi, dp[a][b]);

    }

    cout << (mi == INF ? -1 : mi) << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



using namespace std;

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int MD = (int)1e9 + 7;

void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

template <class T> void amin(T& a,T b){ a=min(a,b);}





int main(){

	//cin.tie(0); ios_base::sync_with_stdio(false);

	int n,ma,mb;

	cin >>n >>ma >>mb;

	

	vector<VI> id(n, VI(3));

	rep(i, n) cin >>id[i][0] >>id[i][1] >>id[i][2];

	

	const int INF = 1<<29;

	vector<VI> dp(440, VI(440, INF));

	dp[0][0] = 0;

	for(auto& z: id){

		vector<VI> np(440, VI(440, INF));

		rep(j, 405) rep(k, 405) if(dp[j][k]>=0){

			amin(np[j][k], dp[j][k]);

			if(j+z[0]<=400 &&  k+z[1] <=400)

				amin(np[j+z[0]][k+z[1]], dp[j][k] + z[2]); 

		}

		swap(dp, np);

	}

	int ans = INF;

	rep(i,  401) rep(j, 401){

		if(dp[i][j] >0 && dp[i][j] < INF && i * mb == j * ma){

			amin(ans,  dp[i][j]);

		}

	}

	cout << (ans<INF? ans: -1) <<endl;

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.686290221084807x):
#include <bits/stdc++.h>





#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



using namespace std;

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int MD = (int)1e9 + 7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  template <class T, class ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}



int main()

{

	cin.tie(0); ios_base::sync_with_stdio(false);

	int n, ma, mb;

	cin >>n >>ma >>mb;

	VI a(n), b(n), c(n);

	rep(i, n) cin >>a[i] >>b[i] >>c[i];

	

	const int jmx = n*11;

	vector<VL> dp(jmx+11, VL(jmx+11, MD));

	dp[0][0] = 0;

	rep(i, n){

		vector<VL> np(jmx+10, VL(jmx+10, MD));

		rep(j, jmx) rep(k, jmx) if(dp[j][k] < MD){

			amin(np[j+a[i]][k+b[i]] , dp[j][k] + c[i]);

			amin(np[j][k], dp[j][k]);

		}

		swap(dp, np);

	}

	//for(auto xl: dp){for(auto x :xl) cerr<<x<<" ";dbg("");}

	ll ans = MD;

	rep2(j, 1, jmx){

		if( j*mb % ma) continue;

		ll tk = (ll)j * mb / ma;

		if( tk > jmx) continue;

		if(dp[j][tk] < MD) ans = min(ans, dp[j][tk]);

	}

	cout << (ans !=MD? ans: -1) <<"\n";

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



using namespace std;

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int MD = (int)1e9 + 7;

void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

template <class T> void amin(T& a,T b){ a=min(a,b);}





int main(){

	//cin.tie(0); ios_base::sync_with_stdio(false);

	int n,ma,mb;

	cin >>n >>ma >>mb;

	

	vector<VI> id(n, VI(3));

	rep(i, n) cin >>id[i][0] >>id[i][1] >>id[i][2];

	

	const int INF = 1<<29;

	vector<VI> dp(440, VI(440, INF));

	dp[0][0] = 0;

	for(auto& z: id){

		vector<VI> np(440, VI(440, INF));

		rep(j, 405) rep(k, 405) if(dp[j][k]>=0){

			amin(np[j][k], dp[j][k]);

			if(j+z[0]<=400 &&  k+z[1] <=400)

				amin(np[j+z[0]][k+z[1]], dp[j][k] + z[2]); 

		}

		swap(dp, np);

	}

	int ans = INF;

	rep(i,  401) rep(j, 401){

		if(dp[i][j] >0 && dp[i][j] < INF && i * mb == j * ma){

			amin(ans,  dp[i][j]);

		}

	}

	cout << (ans<INF? ans: -1) <<endl;

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.88070339254494x):
#include <bits/stdc++.h>





#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



using namespace std;

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int MD = (int)1e9 + 7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  template <class T, class ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}



int main()

{

	cin.tie(0); ios_base::sync_with_stdio(false);

	int n, ma, mb;

	cin >>n >>ma >>mb;

	VI a(n), b(n), c(n);

	rep(i, n) cin >>a[i] >>b[i] >>c[i];

	

	const int jmx = n*11;

	vector<VL> dp(jmx+11, VL(jmx+11, MD));

	dp[0][0] = 0;

	rep(i, n){

		repr(j, jmx, 0) repr(k, jmx, 0) if(dp[j][k] < MD){

			amin(dp[j+a[i]][k+b[i]] , dp[j][k] + c[i]);

		}

	}



	ll ans = MD;

	rep2(j, 1, jmx){

		if( j*mb % ma) continue;

		ll tk = (ll)j * mb / ma;

		if( tk > jmx) continue;

		if(dp[j][tk] < MD) ans = min(ans, dp[j][tk]);

	}

	cout << (ans !=MD? ans: -1) <<"\n";

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define G() Cr=getchar()

int Xr;char Cr;

inline int  rd(){

	Xr=0;G();

	while(Cr<'0'||Cr>'9')G();

	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();

	return Xr;

}

int n,Ma,Mb,ans=99999999;

int dp[405][405];

int a[100],b[100],c[100];

int main(){

	n=rd(),Ma=rd(),Mb=rd();

	for(int i=1;i<=n;i++)

		a[i]=rd(),b[i]=rd(),c[i]=rd();

	

	for(int i=0;i<=400;i++)

		for(int j=0;j<=400;j++)

			dp[i][j]=99999999;

	dp[0][0]=0;	

	

	for(int k=1;k<=n;k++)

		for(int i=400;i>=a[k];i--)

			for(int j=400;j>=b[k];j--)

				dp[i][j]=min(dp[i][j],dp[i-a[k]][j-b[k]]+c[k]);		

				

			

	for(int i=1;i<=400;i++)

		for(int j=1;j<=400;j++)

			if(i*Mb==j*Ma)

				ans=min(ans,dp[i][j]);

	

	printf("%d\n", (ans==99999999)?-1:ans );		

}


// Faster C++ solution for the same problem (measured speedup: 1.33723468072243x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define G() Cr=getchar()

int Xr;char Cr;

inline int  rd(){

	Xr=0;G();

	while(Cr<'0'||Cr>'9')G();

	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();

	return Xr;

}

int n,Ma,Mb,ans=99999999;

int dp[405][405];

int a[100],b[100],c[100];

int suma[100],sumb[100];

int main(){

	n=rd(),Ma=rd(),Mb=rd();

	for(int i=1;i<=n;i++)

		a[i]=rd(),b[i]=rd(),c[i]=rd(),suma[i]=suma[i-1]+a[i],sumb[i]=sumb[i-1]+b[i];

	

	for(int i=0;i<=400;i++)

		for(int j=0;j<=400;j++)

			dp[i][j]=99999999;

	dp[0][0]=0;	

	

	for(int k=1;k<=n;k++)

		for(int i=suma[k];i>=a[k];i--)

			for(int j=sumb[k];j>=b[k];j--)

				dp[i][j]=min(dp[i][j],dp[i-a[k]][j-b[k]]+c[k]);		

				

			

	for(int i=1;i<=suma[n];i++)

		for(int j=1;j<=sumb[n];j++)

			if(i*Mb==j*Ma)

				ans=min(ans,dp[i][j]);

	

	printf("%d\n", (ans==99999999)?-1:ans );		

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define G() Cr=getchar()

int Xr;char Cr;

inline int  rd(){

	Xr=0;G();

	while(Cr<'0'||Cr>'9')G();

	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();

	return Xr;

}

int n,Ma,Mb,ans=99999999;

int dp[405][405];

int a[100],b[100],c[100];

int main(){

	n=rd(),Ma=rd(),Mb=rd();

	for(int i=1;i<=n;i++)

		a[i]=rd(),b[i]=rd(),c[i]=rd();

	

	for(int i=0;i<=400;i++)

		for(int j=0;j<=400;j++)

			dp[i][j]=99999999;

	dp[0][0]=0;	

	

	for(int k=1;k<=n;k++)

		for(int i=400;i>=a[k];i--)

			for(int j=400;j>=b[k];j--)

				dp[i][j]=min(dp[i][j],dp[i-a[k]][j-b[k]]+c[k]);		

				

			

	for(int i=1;i<=400;i++)

		for(int j=1;j<=400;j++)

			if(i*Mb==j*Ma)

				ans=min(ans,dp[i][j]);

	

	printf("%d\n", (ans==99999999)?-1:ans );		

}


// Faster C++ solution for the same problem (measured speedup: 2.2188468634759104x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define G() Cr=getchar()

int Xr;char Cr;

inline int  rd(){

	Xr=0;G();

	while(Cr<'0'||Cr>'9')G();

	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();

	return Xr;

}

int n,Ma,Mb,ans=99999999;

int dp[405][405];

int a[100],b[100],c[100];

int suma[100],sumb[100];

int main(){

	n=rd(),Ma=rd(),Mb=rd();

	for(int i=1;i<=n;i++)

		a[i]=rd(),b[i]=rd(),c[i]=rd(),suma[i]=suma[i-1]+a[i],sumb[i]=sumb[i-1]+b[i];

	

	for(int i=0;i<=suma[n];i++)

		for(int j=0;j<=sumb[n];j++)

			dp[i][j]=99999999;

	dp[0][0]=0;	

	

	for(int k=1;k<=n;k++)

		for(int i=suma[k];i>=a[k];i--)

			for(int j=sumb[k];j>=b[k];j--)

				dp[i][j]=min(dp[i][j],dp[i-a[k]][j-b[k]]+c[k]);		

	

	int aa=Ma,bb=Mb;

	while(Ma<=suma[n]&&Mb<=sumb[n]){

		ans=min(ans,dp[Ma][Mb]);

		Ma+=aa,Mb+=bb;

	}

	

	printf("%d\n", (ans==99999999)?-1:ans );		

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define G() Cr=getchar()

int Xr;char Cr;

inline int  rd(){

	Xr=0;G();

	while(Cr<'0'||Cr>'9')G();

	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();

	return Xr;

}

int n,Ma,Mb,ans=99999999;

int dp[405][405];

int a[100],b[100],c[100];

int suma[100],sumb[100];

int main(){

	n=rd(),Ma=rd(),Mb=rd();

	for(int i=1;i<=n;i++)

		a[i]=rd(),b[i]=rd(),c[i]=rd(),suma[i]=suma[i-1]+a[i],sumb[i]=sumb[i-1]+b[i];

	

	for(int i=0;i<=400;i++)

		for(int j=0;j<=400;j++)

			dp[i][j]=99999999;

	dp[0][0]=0;	

	

	for(int k=1;k<=n;k++)

		for(int i=suma[k];i>=a[k];i--)

			for(int j=sumb[k];j>=b[k];j--)

				dp[i][j]=min(dp[i][j],dp[i-a[k]][j-b[k]]+c[k]);		

				

			

	for(int i=1;i<=suma[n];i++)

		for(int j=1;j<=sumb[n];j++)

			if(i*Mb==j*Ma)

				ans=min(ans,dp[i][j]);

	

	printf("%d\n", (ans==99999999)?-1:ans );		

}


// Faster C++ solution for the same problem (measured speedup: 1.6592800766109332x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define G() Cr=getchar()

int Xr;char Cr;

inline int  rd(){

	Xr=0;G();

	while(Cr<'0'||Cr>'9')G();

	while(Cr>='0'&&Cr<='9')Xr=(Xr<<1)+(Xr<<3)+Cr-'0',G();

	return Xr;

}

int n,Ma,Mb,ans=99999999;

int dp[405][405];

int a[100],b[100],c[100];

int suma[100],sumb[100];

int main(){

	n=rd(),Ma=rd(),Mb=rd();

	for(int i=1;i<=n;i++)

		a[i]=rd(),b[i]=rd(),c[i]=rd(),suma[i]=suma[i-1]+a[i],sumb[i]=sumb[i-1]+b[i];

	

	for(int i=0;i<=suma[n];i++)

		for(int j=0;j<=sumb[n];j++)

			dp[i][j]=99999999;

	dp[0][0]=0;	

	

	for(int k=1;k<=n;k++)

		for(int i=suma[k];i>=a[k];i--)

			for(int j=sumb[k];j>=b[k];j--)

				dp[i][j]=min(dp[i][j],dp[i-a[k]][j-b[k]]+c[k]);		

	

	int aa=Ma,bb=Mb;

	while(Ma<=suma[n]&&Mb<=sumb[n]){

		ans=min(ans,dp[Ma][Mb]);

		Ma+=aa,Mb+=bb;

	}

	

	printf("%d\n", (ans==99999999)?-1:ans );		

}