#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; struct UnionFind{ int n; vector par; explicit UnionFind(int v): n(v), par(v,-1) {} void merge(int a, int b){ int x = find(a); int y = find(b); if (x == y) return; if (-par[x] < -par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return; } int find(int x){ if (par[x] < 0) return x; return par[x] = find(par[x]); } }; int main(){ int n, x, y; cin >> n >> x >> y; const ll INF = 1e18; vector> dp(x+1, vector(y+1, -INF)); dp[0][0] = 0; for (int i=0; i> a >> b >> c; vector> ndp = dp; for (int s=0; s<=x; s++){ if (s+a > x) break; for (int t=0; t<=y; t++){ if (t+b > y) break; ndp[s+a][t+b] = max(ndp[s+a][t+b], dp[s][t] + c); } } dp = ndp; } ll ans = 0; for (int i=0; i<=x; i++){ for (int j=0; j<=y; j++){ ans = max(ans, dp[i][j]); } } cout << ans << endl; }