#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n >> x >> y; vector> dp(x+1,vector(y+1,0)); rep(i,n){ int a,b,c; auto upd = dp; cin >> a >> b >> c; rep(j,x)rep(k,y){ if(j+a<=x && k+b<=y) chmax(upd[j+a][k+b], dp[j][k]+c); } dp = upd; } cout << dp[x][y] << '\n'; return 0; }