stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 );		

}


// Optimized solution to the same problem (faster):
#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 );		

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 );		

}


// Optimized solution to the same problem (faster):
#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 );		

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

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

using namespace std;

typedef long long ll;

ll mod = 1000000007;



const int nmax = 40, abmax = 10, INF = 1000000;

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

int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];



int main() {

    int n, ma, mb;

    cin >> n >> ma >> mb;

    rep(i, n) {

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

    }

    rep(i, n+1) {

        for(int ca = 0; ca <= nmax*abmax; ca++){

            for(int cb = 0; cb <= nmax*abmax; cb++){

                dp[i][ca][cb] = INF;

            }

        }

    }



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

    rep(i, n) {

        for(int ca = 0; ca <= nmax*abmax; ca++) {

            for(int cb = 0; cb <= nmax*abmax; cb++) {

                if(dp[i][ca][cb] == INF) {

                    continue;

                }

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

                dp[i+1][ca+a[i]][cb+b[i]] = min( dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i] );

            }

        }

    }



    int ans = INF;

    for(int ca = 1; ca <= nmax*abmax; ca++) {

        for(int cb = 1; cb <= nmax*abmax; cb++) {

            if(ca*mb == cb*ma) {

                ans = min(ans, dp[n][ca][cb]);

            }

        }

    }

    if(ans == INF) {

        ans = -1;

    }

    

    cout << ans << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

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

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

const int INF = 10000;



int main() {

    int n, ma, mb;

    cin >> n >> ma >> mb;



    vector<int> a(n), b(n), c(n);

    int suma = 0, sumb = 0; 

    rep(i, n) {

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

        suma += a[i];

        sumb += b[i];

    }



    int dp[n+1][suma+1][sumb+1];  // dp[i+1][j][k] : i番目(iは0-index)までの薬品でAをjグラム,Bをkグラムとするときに必要な予算の最小値



    rep(i, n+1) {

        rep(j, suma+1) {

            rep(k, sumb+1) {

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

            }

        }

    }



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

    rep(i, n) {

        rep(j, suma+1) {

            rep(k, sumb+1) {

                if(j >= a[i] && k >= b[i]) {

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

                }

                else {

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

                }

            }

        }

    }

    

    int ans = INF;

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

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

            if(mb*j == ma*k) {

                ans = min(ans, dp[n][j][k]);

            }

        }

    }



    if(ans == INF) {

        cout << -1;

    }

    else {

        cout << ans;

    }



    cout << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <map>

#include <cmath>

using namespace std;

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

#define rep(i,a,b) for(int i=a;i<(b);++i)

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

template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}

using ll = long long;

constexpr long long INF = 1LL << 62;

constexpr int MOD = 1e9 + 7;



ll dp[44][444][444];

ll a[44],b[44],c[44];



int main() {

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

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

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

    REP(i,n+1) REP(j,404) REP(k,404) dp[i][j][k] = INF;



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

    REP(i,n) {

        REP(j,404) {

            REP(k,404) {

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

                chmin(dp[i+1][j][k], dp[i][j][k]);

            }

        }

    }



    ll ans = INF;

    rep(i,1,404) rep(j,1,404) if(i*mb == j*ma) chmin(ans, dp[n][i][j]);

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

    else cout << ans;

    cout << '\n';



    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <map>

#include <cmath>

using namespace std;

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

#define rep(i,a,b) for(int i=a;i<(b);++i)

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

template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}

constexpr int INF = 1e9;



int dp[44][444][444];

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



int main() {

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

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

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

    REP(i,n+1) REP(j,404) REP(k,404) dp[i][j][k] = INF;



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

    REP(i,n) {

        REP(j,404) {

            REP(k,404) {

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

                chmin(dp[i+1][j][k], dp[i][j][k]);

            }

        }

    }



    int ans = INF;

    rep(i,1,404) rep(j,1,404) if(i*mb == j*ma) chmin(ans, dp[n][i][j]);

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

    else cout << ans;

    cout << '\n';



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define INF 1e9

using namespace std;



signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n, m1, m2;

    cin >> n >> m1 >> m2;

    vector<int> a(n), b(n), c(n);

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

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

    int dp[500][500], nxt[500][500];

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

    {

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

        {

            dp[i][j] = INF;

        }

    }

    dp[0][0] = 0;

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

    {

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

        {

            for (int k = 0; k < 500; k++)

            {

                nxt[j][k] = INF;

            }

        }

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

        {

            for (int k = 0; k < 500; k++)

            {

                if (j - a[i] < 0 || k - b[i] < 0)

                    nxt[j][k] = dp[j][k];

                else

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

            }

        }

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

        {

            for (int k = 0; k < 500; k++)

            {

                dp[j][k] = nxt[j][k];

            }

        }

    }

    int ans = INF;

    for (int i = 1; m1 * i < 500 && m2 * i < 500; i++)

        ans = min(ans, dp[m1 * i][m2 * i]);

    if (ans == INF)

        ans = -1;

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define INF 1e18

#define int long long

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

#define rep(i, n) Rep(i, 0, n)

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

using namespace std;

typedef pair<int, int> P;

typedef pair<int, P> PP;

const int mod = 1000000007;



#define MAX_N 41

#define MAX_M 401



int n, ma, mb;

vector<int> a, b, c;

int dp[MAX_N][MAX_M][MAX_M];

bool vis[MAX_N][MAX_M][MAX_M];



int solve(int N, int A, int B)

{

    if (vis[N][A][B])

        return dp[N][A][B];

    vis[N][A][B] = true;

    if (N == n)

    {

        if (A != 0 && B != 0 && ma * B == A * mb)

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

        else

            return dp[N][A][B] = INF;

    }

    return dp[N][A][B] = min(solve(N + 1, A, B), solve(N + 1, A + a[N], B + b[N]) + c[N]);

}



signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> ma >> mb;

    a.resize(n), b.resize(n), c.resize(n);

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

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

    if (ans >= INF)

        ans = -1;

    cout << ans << endl;

}

// Fastest known solution for this problem: