int main()
{
int i, j, k, n, m, r;
int rmb[101], rp[101], time[101];
int a[101][101][2] = {0};
scanf("%d", &n);
for(i = 0; i < n; i++)scanf("%d%d%d", &rmb[i], &rp[i], &time[i]);
scanf("%d%d", &m, &r);
for(i = 0; i < n; i++)
for(j = m; j >= rmb[i]; j--)
for(k = r; k >= rp[i]; k--)
if(a[j][k][0]==a[j-rmb[i]][k-rp[i]][0]+1 && a[j][k][1]>a[j-rmb[i]][k-rp[i]][1]+time[i] || a[j][k][0]<a[j-rmb[i]][k-rp[i]][0]+1)
{
a[j][k][1] = a[j - rmb[i]][k - rp[i]][1] + time[i];
a[j][k][0] = a[j - rmb[i]][k - rp[i]][0] + 1;
}
printf("%d", a[m][r][1]);
return 0;
}