#include<bits/stdc++.h>
using namespace std;
int dp[101][101],dp2[101][101],rmb[101],rp[101],times[101];
int main()
{
int mm,m,r;
cin >> mm;
for(int i = 1; i <= mm; i++){
cin >> rmb[i] >> rp[i] >> times[i];
}
cin >> m >> r;
for(int i = 1; i <= mm; i++){
for(int j = 1; j <= m; j++){
if(j < rmb[i]){
dp[i][j] = dp[i-1][j];
} else {
dp[i][j] = max(dp[i-1][j],dp[i-1][j-rmb[i]] + times[i]);
}
}
}
for(int i = 1; i <= mm; i++){
for(int j = 1; j <= r; j++){
if(j < rp[i]){
dp2[i][j] = dp2[i-1][j];
} else {
dp2[i][j] = max(dp2[i-1][j],dp2[i-1][j-rp[i]] + times[i]);
}
}
}
cout << min(dp[mm][m],dp2[mm][r]);
return 0;
}