#include using namespace std; #define rep(i,a,b) for(int i=(a);i<(int)(b);i++) #define ll long long int main() { int n, W, D; cin>>n>>W>>D; vector t(n),w(n),v(n); rep(i,0,n) { cin>>t[i]>>w[i]>>v[i]; } vector> dp(W+1); dp[0][0] = 0; rep(i,0,n) { for(int j=W;j>=w[i];j--) { vector> updates; for(auto &p:dp[j-w[i]]) { int new_diff = (t[i]==0) ? (p.first+w[i]) : (p.first-w[i]); updates.push_back({new_diff, p.second+v[i]}); } for(auto &u:updates) { if(dp[j].find(u.first)==dp[j].end()||dp[j][u.first]