#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <memory>
#include <cstring>
using namespace std;

#include <stdio.h>
#include <stdlib.h>

int main() {
  map<int, int> h;
  map<int, int> v;
  int d, n, m;
  cin >> d >> n >> m;
  vector<int> x1(d);
  vector<int> x2(d);
  vector<int> y1(d);
  vector<int> y2(d);
  for (int i = 0; i < d; ++i) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    h[x1[i] + x2[i]]++;
    v[y1[i] + y2[i]]++;
  }
  int l, r, t, b;
  cin >> l >> r >> t >> b;
  int ll = l + 1;
  int hsum;
  for (auto ii = h.begin(); ii != h.end(); ++ii) {
    int cur = ii->second;
    if (ll > cur) {
        ll -= cur;
    } else {
        if (l + r > d - cur + cur - 1 + cur - 1 || l + r <= d - cur) {
            cout << -1 << endl;
            return 0;
        }
        hsum = ii->first;
        break;
    }
  }
  int tt = t + 1;
  int vsum;
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    int cur = ii->second;
    if (tt > cur) {
        tt -= cur;
    } else {
        if (t + b > d - cur + cur - 1 + cur - 1 || t + b <= d - cur) {
            cout << -1 << endl;
            return 0;
        }
        vsum = ii->first;
        break;
    }
  }
  for (int i = 0; i < d; ++i) {
    if (x1[i] + x2[i] == hsum && y1[i] + y2[i] == vsum) {
        cout << i + 1 << endl;
        return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
 int d;
 int n, m;
 cin >> d >> n >> m;
 vector<int> x1(d);
 vector<int> y1(d);
 vector<int> x2(d);
 vector<int> y2(d);
 vector<int> xx(d);
 vector<int> yy(d);
 for (int i = 0; i < d; ++i) {
   cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
   xx[i] = x1[i] + x2[i];
   yy[i] = y1[i] + y2[i];
 }
 sort(xx.begin(), xx.end());
 sort(yy.begin(), yy.end());
 int l, r, t, b;
 cin >> l >> r >> t >> b;
 int vl = xx[l];
 int vr = xx[d - r - 1];
 int vt = yy[t];
 int vb = yy[d - b - 1];
 if (vl != vr || vb != vt) {
   cout << -1 << endl;
 } else {
   int idx = -1;
   for (int i = 0; i < d; ++i) {
     if (x1[i] + x2[i] == vl && y1[i] + y2[i] == vt) {
        idx = i + 1;
        break;
     }
   }
   cout << idx << endl;
 }
 return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <memory>
#include <cstring>
using namespace std;

#include <stdio.h>
#include <stdlib.h>

int main() {
  map<int, int> h;
  map<int, int> v;
  int d, n, m;
  cin >> d >> n >> m;
  vector<int> x1(d);
  vector<int> x2(d);
  vector<int> y1(d);
  vector<int> y2(d);
  for (int i = 0; i < d; ++i) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    h[x1[i] + x2[i]]++;
    v[y1[i] + y2[i]]++;
  }
  int l, r, t, b;
  cin >> l >> r >> t >> b;
  int ll = l + 1;
  int hsum;
  for (auto ii = h.begin(); ii != h.end(); ++ii) {
    int cur = ii->second;
    if (ll > cur) {
        ll -= cur;
    } else {
        if (l + r > d - cur + cur - 1 + cur - 1 || l + r <= d - cur) {
            cout << -1 << endl;
            return 0;
        }
        hsum = ii->first;
        break;
    }
  }
  int tt = t + 1;
  int vsum;
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    int cur = ii->second;
    if (tt > cur) {
        tt -= cur;
    } else {
        if (t + b > d - cur + cur - 1 + cur - 1 || l + r <= d - cur) {
            cout << -1 << endl;
            return 0;
        }
        vsum = ii->first;
        break;
    }
  }
  for (int i = 0; i < d; ++i) {
    if (x1[i] + x2[i] == hsum && y1[i] + y2[i] == vsum) {
        cout << i + 1 << endl;
        return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
 int d;
 int n, m;
 cin >> d >> n >> m;
 vector<int> x1(d);
 vector<int> y1(d);
 vector<int> x2(d);
 vector<int> y2(d);
 vector<int> xx(d);
 vector<int> yy(d);
 for (int i = 0; i < d; ++i) {
   cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
   xx[i] = x1[i] + x2[i];
   yy[i] = y1[i] + y2[i];
 }
 sort(xx.begin(), xx.end());
 sort(yy.begin(), yy.end());
 int l, r, t, b;
 cin >> l >> r >> t >> b;
 int vl = xx[l];
 int vr = xx[d - r - 1];
 int vt = yy[t];
 int vb = yy[d - b - 1];
 int idx = -1;
 if (vl == vr && vb == vt) {
     for (int i = 0; i < d; ++i) {
       if (x1[i] + x2[i] == vl && y1[i] + y2[i] == vt) {
          idx = i + 1;
          break;
       }
     }
 }
 cout << idx << endl;
 return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool is_lower_bound(vector<int>& v, int idx) {
  if (idx == 0 || v[idx - 1] != v[idx]) return true;
  return false;
}

bool is_upper_bound(vector<int>& v, int idx) {
  if (idx + 1 == v.size() || v[idx + 1] != v[idx]) return true;
  return false;
}

int main() {
 int d;
 int n, m;
 cin >> d >> n >> m;
 vector<int> x1(d);
 vector<int> y1(d);
 vector<int> x2(d);
 vector<int> y2(d);
 vector<int> xx(d);
 vector<int> yy(d);
 for (int i = 0; i < d; ++i) {
   cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
   xx[i] = x1[i] + x2[i];
   yy[i] = y1[i] + y2[i];
 }
 sort(xx.begin(), xx.end());
 sort(yy.begin(), yy.end());
 int l, r, t, b;
 cin >> l >> r >> t >> b;
 int vl = xx[l];
 int vr = xx[d - r - 1];
 int vt = yy[t];
 int vb = yy[d - b - 1];
 int idx = -1;
 if (vl == vr && vb == vt) {
     bool flag = true;
     if (vl % 2) {
       flag = flag && is_lower_bound(xx, d - r - 1) && is_upper_bound(xx, l);
     } else {
       flag = flag && is_lower_bound(xx, l) && is_upper_bound(xx, d - r - 1);
     }
     if (vb % 2) {
       flag = flag && is_lower_bound(yy, d - b - 1) && is_upper_bound(yy, t);
     } else {
       flag = flag && is_lower_bound(yy, t) && is_upper_bound(yy, d - b - 1);
     }

     if (flag) {

       for (int i = 0; i < d; ++i) {
         if (x1[i] + x2[i] == vl && y1[i] + y2[i] == vt) {
            idx = i + 1;
            break;
         }
       }
     }
 }
 cout << idx << endl;
 return 0;
}


#include<string>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
int n,m,maxn;
int cntl,cntr,cntt,cntb;// zuo you shang xia
int tree[4][100005];//0:：small x , 1 big x, 2 small y, 3 big y;
int lowbit(int x){return x&(-x);}
int xa[100005],xb[100005],yb[100005],ya[100005];
void addval(int x,int val,int state)
{
    while(x<=maxn)
    {
        tree[state][x]+=val;
        x+=lowbit(x);
    }
}
int query(int x,int state)
{
    int ans=0;
    while(x)
    {
        ans+=tree[state][x];
        x-=lowbit(x);
    }
    return ans;
}
int main()
{
    int i,j;
    int nums;
    scanf("%d",&nums);
    scanf("%d%d",&n,&m);
    maxn=max(n,m)+50;
    memset(tree,0,sizeof(tree));
    for(i=0;i<nums;i++)
    {
        scanf("%d%d%d%d",&xa[i],&ya[i],&xb[i],&yb[i]);//0:：small x , 1 big x, 2 small y, 3 big y;
        ya[i]++,yb[i]++,xa[i]++,xb[i]++;
        //printf("xa:%d xb:%d ya:%d yb:%d \n",xa[i],xb[i],ya[i],yb[i]);
        int maxx=max(xa[i],xb[i]),maxy=max(ya[i],yb[i]),minx=min(xa[i],xb[i]),miny=min(ya[i],yb[i]);
        //printf("i:%d maxx:%d minx:%d maxy:%d miny:%d\n",i+1,maxx,minx,maxy,miny);
        addval(minx,1,0);
        addval(maxn-30-maxx,1,1);
        addval(miny,1,2);
        addval(maxn-30-maxy,1,3);
    }
    scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
    for(i=0;i<nums;i++)
    {
        int maxx=max(xa[i],xb[i]),maxy=max(ya[i],yb[i]),minx=min(xa[i],xb[i]),miny=min(ya[i],yb[i]);
        int ansl=query(maxx-1,0);
        int ansr=query(maxn-30-minx-1,1);
        if(xa[i]!=xb[i])ansl--,ansr--;
        int anst=query(maxy-1,2);
        int ansb=query(maxn-30-miny-1,3);
        if(ya[i]!=yb[i])anst--,ansb--;
        //printf("ansl:%d ansr:%d anst:%d ansb:%d\n",ansl,ansr,anst,ansb);
        if(ansl==cntl&&ansr==cntr&&ansb==cntb&&anst==cntt)
        {
            printf("%d\n",i+1);
            return 0;
        }
    }
    printf("-1\n");
}


#include<string>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
int n,m,maxn;
int cntl,cntr,cntt,cntb;// zuo you shang xia
int tree[4][210005];//0:：small x , 1 big x, 2 small y, 3 big y;
int lowbit(int x){return x&(-x);}
int xa[100005],xb[100005],yb[100005],ya[100005];
void addval(int x,int val,int state)
{
    while(x<=maxn)
    {
        tree[state][x]+=val;
        x+=lowbit(x);
    }
}
int query(int x,int state)
{
    int ans=0;
    while(x)
    {
        ans+=tree[state][x];
        x-=lowbit(x);
    }
    return ans;
}
int main()
{
    int i,j;
    int nums;
    scanf("%d",&nums);
    scanf("%d%d",&n,&m);
    maxn=n+m+50;
    memset(tree,0,sizeof(tree));
    for(i=0;i<nums;i++)
    {
        scanf("%d%d%d%d",&xa[i],&ya[i],&xb[i],&yb[i]);//0:：small x , 1 big x, 2 small y, 3 big y;
        ya[i]++,yb[i]++,xa[i]++,xb[i]++;
        //printf("xa:%d xb:%d ya:%d yb:%d \n",xa[i],xb[i],ya[i],yb[i]);
        int maxx=max(xa[i],xb[i]),maxy=max(ya[i],yb[i]),minx=min(xa[i],xb[i]),miny=min(ya[i],yb[i]);
        //printf("i:%d maxx:%d minx:%d maxy:%d miny:%d\n",i+1,maxx,minx,maxy,miny);
        addval(minx,1,0);
        addval(maxn-30-maxx,1,1);
        addval(miny,1,2);
        addval(maxn-30-maxy,1,3);
    }
    scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
    for(i=0;i<nums;i++)
    {
        int maxx=max(xa[i],xb[i]),maxy=max(ya[i],yb[i]),minx=min(xa[i],xb[i]),miny=min(ya[i],yb[i]);
        int ansl=query(maxx-1,0);
        int ansr=query(maxn-30-minx-1,1);
        if(xa[i]!=xb[i])ansl--,ansr--;
        int anst=query(maxy-1,2);
        int ansb=query(maxn-30-miny-1,3);
        if(ya[i]!=yb[i])anst--,ansb--;
        //printf("ansl:%d ansr:%d anst:%d ansb:%d\n",ansl,ansr,anst,ansb);
        if(ansl==cntl&&ansr==cntr&&ansb==cntb&&anst==cntt)
        {
            printf("%d\n",i+1);
            return 0;
        }
    }
    printf("-1\n");
}


#include <iostream>
/* CodeForces CF818C problem */
using namespace std;

struct P {
	int x, y;
};

constexpr int sz = 100000+2;

int hl[sz]; // horiz to the left
int hr[sz]; // horiz to the right
int vu[sz]; // vert up
int vd[sz]; // vert down

int main(int argc, char **argv) {
	int d, n, m;
	cin >> d >> n >> m;
	P dd[d][2];
	for (auto &c:dd)
		cin >> c[0].x >> c[0].y >> c[1].x >> c[1].y;
	int cl, cr, ct, cb;
	cin >> cl >> cr >> ct >> cb;
	for (auto &c:dd) {
		if (c[0].x == c[1].x) {
			// vert
			hl[c[0].x+1]++;
			hr[c[0].x-1]++;
			vu[c[1].y]++;
			vd[c[0].y]++;
		} else {
			// horiz
			hl[c[1].x]++;
			hr[c[0].x]++;
			vu[c[0].y+1]++;
			vd[c[0].y-1]++;
		}
	}
	for (int i=1; i<sz; i++) {
		hl[i] += hl[i-1];
		vu[i] += vu[i-1];
	}
	for (int i=sz-2; i>=0; i--) {
		hr[i] += hr[i+1];
		vd[i] += vd[i+1];
	}
#if 0
	cerr << "hl: ";
	for (int i=0; i<=n+1; i++)
		cerr << hl[i] << ' ';
	cerr << endl;
	cerr << "hr: ";
	for (int i=0; i<=n+1; i++)
		cerr << hr[i] << ' ';
	cerr << endl;
#endif
	int ans = 0;
	for (int i=0; i<d; i++) {
		auto &c = dd[i];
		if (c[0].x == c[1].x) {
			// vert
			if (hl[c[0].x] == cl && hr[c[0].x] == cr &&
				vu[c[1].y] == ct+1 && vd[c[0].y] == cb+1) {
				ans = i+2;
				break;
			}
		} else {
			// horiz
			if (vu[c[0].y] == ct && vd[c[0].y] == cb &&
				hl[c[1].x] == cl+1 && hr[c[0].x] == cr+1) {
				ans = i+2;
				break;
			}
		}
	}
	cout << (ans-1) << endl;
	return 0;
}


#include <iostream>
/* CodeForces CF818C problem */
using namespace std;

struct P {
	int x, y;
};

constexpr int sz = 100000+2;

int hl[sz]; // horiz to the left
int hr[sz]; // horiz to the right
int vu[sz]; // vert up
int vd[sz]; // vert down

int main(int argc, char **argv) {
	int d, n, m;
	cin >> d >> n >> m;
	P dd[d][2];
	for (auto &c:dd) {
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		c[0] = {min(x1,x2), min(y1,y2)};
		c[1] = {max(x1,x2), max(y1,y2)};
	}
	int cl, cr, ct, cb;
	cin >> cl >> cr >> ct >> cb;
	for (auto &c:dd) {
		if (c[0].x == c[1].x) {
			// vert
			hl[c[0].x+1]++;
			hr[c[0].x-1]++;
			vu[c[1].y]++;
			vd[c[0].y]++;
		} else {
			// horiz
			hl[c[1].x]++;
			hr[c[0].x]++;
			vu[c[0].y+1]++;
			vd[c[0].y-1]++;
		}
	}
	for (int i=1; i<sz; i++) {
		hl[i] += hl[i-1];
		vu[i] += vu[i-1];
	}
	for (int i=sz-2; i>=0; i--) {
		hr[i] += hr[i+1];
		vd[i] += vd[i+1];
	}
#if 0
	cerr << "hl: ";
	for (int i=0; i<=n+1; i++)
		cerr << hl[i] << ' ';
	cerr << endl;
	cerr << "hr: ";
	for (int i=0; i<=n+1; i++)
		cerr << hr[i] << ' ';
	cerr << endl;
	cerr << "vu: ";
	for (int i=0; i<=m+1; i++)
		cerr << vu[i] << ' ';
	cerr << endl;
	cerr << "vd: ";
	for (int i=0; i<=m+1; i++)
		cerr << vd[i] << ' ';
	cerr << endl;
#endif
	int ans = 0;
	for (int i=0; i<d; i++) {
		auto &c = dd[i];
		if (c[0].x == c[1].x) {
			// vert
			if (hl[c[0].x] == cl && hr[c[0].x] == cr &&
				vu[c[1].y] == ct+1 && vd[c[0].y] == cb+1) {
				ans = i+2;
				break;
			}
		} else {
			// horiz
			if (vu[c[0].y] == ct && vd[c[0].y] == cb &&
				hl[c[1].x] == cl+1 && hr[c[0].x] == cr+1) {
				ans = i+2;
				break;
			}
		}
	}
	cout << (ans-1) << endl;
	return 0;
}


//In the name of Allah

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e5+10 , mod = 1e9+7;

int cnt[4][N] , a1[N] , a2[N] , b1[N] , b2[N];
vector <int> v[4];

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int d , n , m;
    cin >> d >> n >> m;
    for(int i = 0 ; i < d ; i++){
        cin >> a1[i] >> b1[i] >> a2[i] >> b2[i];
        if(a1[i] > a2[i])
            swap(a1[i] , a2[i]);
        if(b1[i] > b2[i])
            swap(b1[i] , b2[i]);
        v[0].push_back(a1[i]);
        v[2].push_back(b1[i]);
        v[1].push_back(a2[i]);
        v[3].push_back(b2[i]);
    }
    for(int i = 0 ; i < 4 ; i++)
        sort(v[i].begin() , v[i].end());
    for(int k = 0 ; k < 4 ; k++){
        for(int i = 0 ; i < d ; i++){
            if(k == 0){
                cnt[k][i] = lower_bound(v[k].begin() , v[k].end() , a2[i]) - v[k].begin();
                if(i == 1)
                    cout << cnt[k][i] << endl;
                if(a1[i] < a2[i])
                    cnt[k][i]--;
            }
            if(k == 1){
                cnt[k][i] = v[k].end() - upper_bound(v[k].begin() , v[k].end() , a1[i]);
                if(a2[i] > a1[i])
                    cnt[k][i]--;
            }
            if(k == 2){
                cnt[k][i] = lower_bound(v[k].begin() , v[k].end() , b2[i]) - v[k].begin();
                if(b1[i] < b2[i])
                    cnt[k][i]--;
            }
            if(k == 3){
                cnt[k][i] = v[k].end() - upper_bound(v[k].begin() , v[k].end() , b1[i]);
                if(b2[i] > b1[i])
                    cnt[k][i]--;
            }
        }
    }
    int x , y , z , w;
    cin >> x >> y >> z >> w;
    for(int i = 0 ; i < d ; i++){
        if(cnt[0][i] == x && cnt[1][i] == y && cnt[2][i] == z && cnt[3][i] == w)
            return cout << i + 1 , 0;
    }
    cout << -1;
    return 0;
}


//In the name of Allah

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e5+10 , mod = 1e9+7;

int cnt[4][N] , a1[N] , a2[N] , b1[N] , b2[N];
vector <int> v[4];

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int d , n , m;
    cin >> d >> n >> m;
    for(int i = 0 ; i < d ; i++){
        cin >> a1[i] >> b1[i] >> a2[i] >> b2[i];
        if(a1[i] > a2[i])
            swap(a1[i] , a2[i]);
        if(b1[i] > b2[i])
            swap(b1[i] , b2[i]);
        v[0].push_back(a1[i]);
        v[2].push_back(b1[i]);
        v[1].push_back(a2[i]);
        v[3].push_back(b2[i]);
    }
    for(int i = 0 ; i < 4 ; i++)
        sort(v[i].begin() , v[i].end());
    for(int k = 0 ; k < 4 ; k++){
        for(int i = 0 ; i < d ; i++){
            if(k == 0){
                cnt[k][i] = lower_bound(v[k].begin() , v[k].end() , a2[i]) - v[k].begin();
                if(a1[i] < a2[i])
                    cnt[k][i]--;
            }
            if(k == 1){
                cnt[k][i] = v[k].end() - upper_bound(v[k].begin() , v[k].end() , a1[i]);
                if(a2[i] > a1[i])
                    cnt[k][i]--;
            }
            if(k == 2){
                cnt[k][i] = lower_bound(v[k].begin() , v[k].end() , b2[i]) - v[k].begin();
                if(b1[i] < b2[i])
                    cnt[k][i]--;
            }
            if(k == 3){
                cnt[k][i] = v[k].end() - upper_bound(v[k].begin() , v[k].end() , b1[i]);
                if(b2[i] > b1[i])
                    cnt[k][i]--;
            }
        }
    }
    int x , y , z , w;
    cin >> x >> y >> z >> w;
    for(int i = 0 ; i < d ; i++){
        if(cnt[0][i] == x && cnt[1][i] == y && cnt[2][i] == z && cnt[3][i] == w)
            return cout << i + 1 , 0;
    }
    cout << -1;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

struct p
{
    int t,d,v,i;
}a[110];

bool cmp(p a,p b)
{
    if(a.d != b.d)
        return a.d < b.d;
    return a.v < b.v;
}

int dp[2008];
vector<int> s[2008];

int main()
{
    int n, i, j;
    scanf("%d",&n);
    for(i = 0; i < n;i++)
    {
        scanf("%d %d %d", &a[i].t,&a[i].d,&a[i].v);
        a[i].i = i+1;
    }
    sort(a,a + n,cmp);
    for(i = 0;i < n; i++)
    {
        for(j = a[i].d-1; j >= a[i].t;j--)
        {
            if(dp[j] < dp[j-a[i].t]+ a[i].v)
            {
                dp[j] = dp[j-a[i].t]+ a[i].v;
                s[j]  = s[j-a[i].t];
                s[j].push_back(a[i].i);
            }
        }
    }
    int ans = -100;
    int ansi;
    for(i = 0;i <= 2000; i++)
    {
        if(dp[i] > ans)
        {
            ans = dp[i];
            ansi = i;
        }
    }
    printf("%d\n%d\n",ans,s[ansi].size());
    for(i = 0;i < s[ansi].size();i++)
    {
        if(i) printf(" ");
        printf("%d",s[ansi][i]);
    }
    printf("\n");
    return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int Maxn=110,Maxm=2010,inf=0x3f3f3f3f;
int f[Maxm],n,ans;
struct node{
    int d,t,v,id;
}a[Maxn];
vector <int> bin[Maxm];
inline bool cmp(node x,node y)
{
    return x.d<y.d;
}
inline int read()
{
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
    return s*w;
}
int main()
{
    //freopen("in.txt","r",stdin);
    n=read();
    for(int i=1;i<=n;++i)
    {
        a[i].t=read(),a[i].d=read(),a[i].v=read();
        a[i].id=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;++i)
    for(int j=a[i].d-1;j>=a[i].t;--j)
    if(f[j]<f[j-a[i].t]+a[i].v)
    {
        f[j]=f[j-a[i].t]+a[i].v;
        //bin[j].clear();
        bin[j]=bin[j-a[i].t];
        bin[j].push_back(a[i].id);
    }
    for(int i=1;i<=2000;++i)
    if(f[i]>f[ans])ans=i;
    printf("%d\n%d\n",f[ans],bin[ans].size());
    for(int i=0;i<bin[ans].size();++i)
    printf("%d ",bin[ans][i]);
    printf("\n");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t[110],d[110],p[110];
struct node
{
	int ans,s[110],len;
	node()
	{
		ans=0;len=0;
	}
}f[2100];
int main()
{
	int n,maxx=0;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d%d",&t[i],&d[i],&p[i]),maxx=max(maxx,d[i]);
	maxx--;
	for(int i=1;i<=n;i++)
		for(int j=maxx;j>=t[i];j--)
		{
			if(f[j].ans<f[j-t[i]].ans+p[i]&&j<d[i])
			{
				f[j]=f[j-t[i]];
				f[j].ans+=p[i];
				f[j].len++;
				f[j].s[f[j].len]=i;
			}
		}
	printf("%d\n%d\n",f[maxx].ans,f[maxx].len);
	for(int i=1;i<f[maxx].len;i++)printf("%d ",f[maxx].s[i]);
	printf("%d\n",f[maxx].s[f[maxx].len]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,mmax,ans;
struct bfc{
	int t,d,p;
}a[1001];
int dp[2001];
bool cmp(bfc x,bfc y){
	return x.d<y.d;
}
void solve() {
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].t>>a[i].d>>a[i].p;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		for(int j=a[i].d;j>a[i].t;j--){
			dp[j]=max(dp[j-a[i].t]+a[i].p,dp[j]);
		}
	}
	for(int i=1;i<=2000;i++)
		ans=max(ans,dp[i]);
	cout<<ans;
	return;
}
int main() {
//	freopen("fire.in","r",stdin);
//	freopen("fire.out","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define M 105
#define INF 0x3f3f3f3f

struct node {
	int t, d, p, id;
}a[M];
int dp[2005];
int n, maxn, ans;
vector <int> vc[2005];

bool cmp (node a, node b){
	return a.d - a.t < b.d - b.t;
}
int main (){
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++){
		scanf ("%d %d %d", &a[i].t, &a[i].d, &a[i].p);
		maxn = max (maxn, a[i].d);
		a[i].id = i;
	}
	sort (a + 1, a + 1 + n, cmp);
	for (int i = 1; i <= maxn; i ++)
		dp[i] = -INF;
	for (int i = 1; i <= n; i ++){
		for (int j = a[i].d - 1; j >= a[i].t; j --){
			if (dp[j] < dp[j - a[i].t] + a[i].p){
				dp[j] = dp[j - a[i].t] + a[i].p;
				vc[j] = vc[j - a[i].t];
				vc[j].push_back (a[i].id);
			}
		}
	}
	for (int i = 1; i <= maxn; i ++)
		if (dp[i] > dp[ans])
			ans = i;
	printf ("%d\n%d\n", dp[ans], vc[ans].size());
	for (int i = 0; i < vc[ans].size(); i ++)
		printf ("%d ", vc[ans][i]);
	printf ("\n");
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f[2100],len,s[110];
bool road[110][2100];
struct wuti
{
	int t,d,p,num;
}wt[110];
bool cmp(wuti n1,wuti n2){return n1.d<n2.d;}
int main()
{
	int n,ans=0;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d%d",&wt[i].t,&wt[i].d,&wt[i].p),wt[i].num=i;
	sort(wt+1,wt+n+1,cmp);
	memset(f,0,sizeof(f));memset(road,false,sizeof(road));
	for(int i=1;i<=n;i++)
	{
		int t=wt[i].t,d=wt[i].d,p=wt[i].p,num=wt[i].num;
		for(int j=d-1;j>=t;j--)
		{
			if(f[j]<f[j-t]+p)
			{
				f[j]=f[j-t]+p;
				road[num][j]=true;
			}
			if(f[ans]<f[j])ans=j;
		}
	}
	printf("%d\n",f[ans]);
	len=0;
	for(int i=n;i>=1;i--)if(road[i][ans]&&ans){ans-=wt[i].t;s[++len]=i;}
	printf("%d\n",len);
	for(int i=len;i>1;i--)printf("%d ",s[i]);
	printf("%d\n",s[1]);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define M 105
#define INF 0x3f3f3f3f

struct node {
	int t, d, p, id;
}a[M];
struct fuck{
	int hav[105], val, cnt;
}dp[2005];
int n, maxn, ans;

bool cmp (node a, node b){
	return a.d - a.t < b.d - b.t;
}
int main (){
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++){
		scanf ("%d %d %d", &a[i].t, &a[i].d, &a[i].p);
		maxn = max (maxn, a[i].d);
		a[i].id = i;
	}
	sort (a + 1, a + 1 + n, cmp);
	for (int i = 1; i <= maxn; i ++)
		dp[i].val = -INF;
	for (int i = 1; i <= n; i ++){
		for (int j = a[i].d - 1; j >= a[i].t; j --){
			if (dp[j].val < dp[j - a[i].t].val + a[i].p){
				dp[j].val = dp[j - a[i].t].val + a[i].p;
				for (int k = 1; k <= dp[j - a[i].t].cnt; k ++)
					dp[j].hav[k] = dp[j - a[i].t].hav[k];
				dp[j].cnt = dp[j - a[i].t].cnt + 1;
				dp[j].hav[dp[j].cnt] = a[i].id;
				if (dp[j].val > dp[ans].val)
					ans = j;
			}
		}
	}
	printf ("%d\n%d\n", dp[ans].val, dp[ans].cnt);
	sort (dp[ans].hav + 1, dp[ans].hav + 1 + dp[ans].cnt);
	for (int i = 1; i <= dp[ans].cnt; i ++)
		printf ("%d ", dp[ans].hav[i]);
	printf ("\n");
	return 0;
}
/*
3
3 7 4
3 7 6
2 6 5
*/


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define M 105
#define INF 0x3f3f3f3f

struct node {
	int t, d, p, id;
}a[M];
int dp[2005];
int n, maxn, ans;
vector <int> vc[2005];

bool cmp (node a, node b){
	return a.d < b.d;
}
int main (){
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++){
		scanf ("%d %d %d", &a[i].t, &a[i].d, &a[i].p);
		maxn = max (maxn, a[i].d);
		a[i].id = i;
	}
	sort (a + 1, a + 1 + n, cmp);
	for (int i = 1; i <= maxn; i ++)
		dp[i] = -INF;
	for (int i = 1; i <= n; i ++){
		for (int j = a[i].d - 1; j >= a[i].t; j --){
			if (dp[j] < dp[j - a[i].t] + a[i].p){
				dp[j] = dp[j - a[i].t] + a[i].p;
				vc[j] = vc[j - a[i].t];
				vc[j].push_back (a[i].id);
			}
		}
	}
	for (int i = 1; i <= maxn; i ++)
		if (dp[i] > dp[ans])
			ans = i;
	printf ("%d\n%d\n", dp[ans], vc[ans].size());
	for (int i = 0; i < vc[ans].size(); i ++)
		printf ("%d ", vc[ans][i]);
	printf ("\n");
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define NMAX 110
#define CMAX 2010
typedef struct
{
	int c,w,v;//代价、价值、开始燃烧时间(每个物品的容量限制)
	int id;//物品编号
}node;
node a[NMAX];
bool cmp(node a,node b){return a.v<b.v;}
int f[CMAX];
int N;//n个东西
bool vis[NMAX][CMAX];
int cnt,can[NMAX];
int main()
{
	cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>a[i].c>>a[i].v>>a[i].w;
        a[i].id=i;
    }
    sort(a+1,a+N+1,cmp);
    for(int i=1;i<=N;i++)
    {
    	for(int j=a[i].v-1;j>=a[i].c;j--)
    	{
        	//f[v]=max(f[v],f[v-cost]+weight);
    		if(f[j-a[i].c]+a[i].w>f[j])
    		{
    			f[j]=f[j-a[i].c]+a[i].w;
    			vis[i][j]=1;//记录第i个物品在时间j时有更新
			}
		}
	}
	int ans=0;
	for(int i=1;i<=a[N].v;i++)
		if(f[i]>f[ans]) ans=i;
	cout<<f[ans]<<endl;

	for(int i=1;i<=N;i++)
    	if(vis[i][ans]) can[++cnt]=a[i].id,ans-=a[i].c; //贪心
    cout<<cnt<<endl;
    for(int i=1;i<=cnt;i++) cout<<can[i]<<" "; // 按照读入顺序从小到大输出所选物品的编号
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
	int ans,s[110],len;
	node()
	{
		ans=0;len=0;
	}
}f[2100];
struct wuti
{
	int t,d,p,num;
}wt[110];
bool cmp(wuti n1,wuti n2){return n1.d<n2.d;}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d%d",&wt[i].t,&wt[i].d,&wt[i].p),wt[i].num=i;
	sort(wt+1,wt+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		int t=wt[i].t,d=wt[i].d,p=wt[i].p,num=wt[i].num;
		for(int j=d-1;j>=t;j--)
		{
			if(f[j].ans<f[j-t].ans+p)
			{
				f[j]=f[j-t];
				f[j].ans+=p;
				f[j].len++;
				f[j].s[f[j].len]=num;
			}
		}
	}
	node ans;ans.ans=0;
	for(int i=1;i<wt[n].d;i++)if(ans.ans<f[i].ans)ans=f[i];
	printf("%d\n%d\n",ans.ans,ans.len);
	sort(ans.s+1,ans.s+ans.len+1);
	for(int i=1;i<ans.len;i++)printf("%d ",ans.s[i]);
	printf("%d\n",ans.s[ans.len]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
	int ans,s[110],len;
	node()
	{
		ans=0;len=0;
	}
}f[2100];
struct wuti
{
	int t,d,p,num;
}wt[110];
bool cmp(wuti n1,wuti n2){return n1.d<n2.d;}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d%d",&wt[i].t,&wt[i].d,&wt[i].p),wt[i].num=i;
	sort(wt+1,wt+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		int t=wt[i].t,d=wt[i].d,p=wt[i].p,num=wt[i].num;
		for(int j=d-1;j>=t;j--)
		{
			if(f[j].ans<f[j-t].ans+p)
			{
				f[j]=f[j-t];
				f[j].ans+=p;
				f[j].len++;
				f[j].s[f[j].len]=num;
			}
		}
	}
	int d=wt[n].d-1;
	printf("%d\n%d\n",f[d].ans,f[d].len);
	for(int i=1;i<f[d].len;i++)printf("%d ",f[d].s[i]);
	printf("%d\n",f[d].s[f[d].len]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ri register int

using namespace std;

struct node{
	int t,d,p,num;
}a[105];
vector<int> v[2010];
int n,dp[2005],ans;

inline bool cmp(node x,node y){
	return x.d < y.d;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(ri i = 1; i <= n; i++){
		cin >> a[i].t >> a[i].d >> a[i].p;
		a[i].num = i;
	}
	sort(a+1,a+1+n,cmp);
	for(ri i = 1; i <= n; i++){
		for(ri j = a[i].d - 1; j >= a[i].t; j--){
			if(dp[j] < dp[j-a[i].t]+a[i].p){
				dp[j] = dp[j-a[i].t]+a[i].p;
				v[j] = v[j-a[i].t];
				v[j].push_back(a[i].num);
			}
		}
	}
	int mid = 0;
	for(ri i = 0; i <= 2000; i++){
		if(dp[i] > ans){
			ans = dp[i];
			mid = i;
		}
	}
	cout << ans << "\n" << v[mid].size() << "\n";
	for(ri i = 0; i < v[mid].size(); i++){
		cout << v[mid][i] << " ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,ans,dp[2005];
vector<int> v[2005];
struct data
{
	int t,d,p,number;
}a[105];
bool cmp(data t1,data t2)
{
	return t1.d<t2.d;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].t>>a[i].d>>a[i].p;
		a[i].number=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		for(int j=a[i].d-1;j>=a[i].t;j--)
			if(dp[j]<dp[j-a[i].t]+a[i].p)
			{
				dp[j]=dp[j-a[i].t]+a[i].p;
				v[j]=v[j-a[i].t];
				v[j].push_back(a[i].number);
			}
	for(int i=1;i<a[n].d;i++)
		if(dp[ans]<dp[i])
			ans=i;
	cout<<dp[ans]<<endl;
	cout<<v[ans].size()<<endl;
	for(int i=0;i<v[ans].size();i++)
		cout<<v[ans][i]<<" ";
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=101;
int n;
struct object{
	int need,start,val,id;
}e[maxn];
bool cmp(object a,object b){
	return a.start<b.start;
}
bool rcmp(int a,int b){
	return e[a].id<e[b].id;
}
int dp[102][2011],f[102][2011];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>e[i].need>>e[i].start>>e[i].val;
		e[i].id=i;
	}
	sort(e+1,e+1+n,cmp);
	for(int i=1;i<=n;i++){
		for(int j=0;j<2001;j++){
			dp[i][j]=dp[i-1][j];
			f[i][j]=-1;
		}
		for(int j=e[i].need;j<e[i].start;j++){
			int tmp=dp[i][j];
			dp[i][j]=max(dp[i][j],dp[i-1][j-e[i].need]+e[i].val);
			if(dp[i][j]!=tmp){
				f[i][j]=true;
			}
		}
	}
	int ans=0,pb=0;
	for(int i=1;i<maxn;i++){
		if(dp[n][i]>ans){
			ans=dp[n][i];
			pb=i;
		}
	}
	cout<<ans<<endl;
	vector<int> out;
	out.clear();
	for(int i=n;i>=1;i--){
		if(f[i][pb]==1){
			out.push_back(e[i].id);
			pb-=e[i].need;
		}
	}
	reverse(out.begin(),out.end());
	cout<<out.size()<<endl;
	for(int i=0;i<out.size();i++){
		cout<<out[i]<<" ";
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const double eps=1e-7;
typedef pair<int,int> pii;
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
int dp[2005],n,maxx,ans,ansi,pre[105][2005],stak,sta[105];
struct ming{int t,d,p,id;}a[105];
bool cmp(ming x,ming y){return x.d<y.d;}
void print(int x,int sum,int ti){
	if(!pre[ti][x])printf("%d\n",sum);
	else print(x-a[pre[ti][x]].t,sum+1,pre[ti][x]-1),sta[++stak]=a[pre[ti][x]].id;
}
signed main(){
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i].t),read(a[i].d),read(a[i].p),
		maxx=max(maxx,a[i].d),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		for(int j=a[i].d-1;j>=a[i].t;j--)
			if(dp[j-a[i].t]+a[i].p>dp[j])
				pre[i][j]=i,dp[j]=dp[j-a[i].t]+a[i].p;
			else pre[i][j]=pre[i-1][j];
		for(int j=a[i].t-1;j>=0;j--)pre[i][j]=pre[i-1][j];
	}
	for(int i=1;i<=maxx;i++)
		if(dp[i]>ans)ans=dp[i],ansi=i;
	printf("%d\n",ans);print(ansi,0,n);
	//sort(sta+1,sta+stak+1);
	for(int i=1;i<=stak;i++)printf("%d ",sta[i]);puts("");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int w[2005],b[2005],c[2005],dp[100005];
int main()
{
	int n,V=0,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&w[i],&b[i],&c[i]);
		V=max(V,b[i]);
	}
	for(int i=1;i<=n;i++)
		for(int j=b[i]-1;j>=w[i];j--)
		{
			if(dp[j-w[i]]+c[i]>dp[j])
			{
				dp[j]=dp[j-w[i]]+c[i];
			}
		}
	for(int i=1;i<=V;i++)
		ans=max(ans,dp[i]);
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<cmath>
#include<vector>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<ctime>
using namespace std;
struct St{
	int v,w,fire,id;
	bool operator <(const St &b) const{
		return fire<b.fire;
	}
}wu[2000];
int n,dp[105][10001],pre[105][10001];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>wu[i].w>>wu[i].fire>>wu[i].v;
		wu[i].id=i;
	}
	sort(wu+1,wu+n+1);
	for(int i=1;i<=n;i++)
		for(int j=0;j<=2000;j++){
			dp[i][j]=dp[i-1][j]; pre[i][j]=j;
			if(j>=wu[i].w&&j<wu[i].fire&&dp[i][j]<dp[i-1][j-wu[i].w]+wu[i].v){
				dp[i][j]=dp[i-1][j-wu[i].w]+wu[i].v;
				pre[i][j]=j-wu[i].w;
			}
		}
	int ans=-1,maxid;
	for(int i=0;i<=2000;i++){
		if(ans<dp[n][i]){
			ans=dp[n][i];
			maxid=i;
		}
	}
	cout<<ans<<'\n';
	vector<int > vec;
	int j = maxid;
	for(int i=n;i>=1;i--){
		if(pre[i][j]!=j){
			vec.push_back(wu[i].id);
			j=pre[i][j];
		}
	}
	cout<<vec.size()<<'\n';
	for(int i=vec.size() - 1;i>=0;i--)
		cout<<vec[i]<<' ';
	cout<<'\n';
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 2010
#define N 110
using namespace std;

inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
	return x*f;
}

struct node{
	int t,d,p,id;
}A[N];

int n,f[MAXN];
vector<int> Q[MAXN];

inline bool cmp(const node x,const node y)
{
	return x.d<y.d;
}

int main()
{
	n=read();int pos=0;
	for(int i=1;i<=n;++i){
		A[i].t=read(),A[i].d=read(),A[i].p=read(),A[i].id=i;
	}
	sort(A+1,A+1+n,cmp);
	for(int i=1;i<=n;++i){
		for(int j=A[i].d-1;j>=A[i].t;--j){
			if(f[j]<f[j-A[i].t]+A[i].p){
				f[j]=f[j-A[i].t]+A[i].p;
				Q[j].clear();
				Q[j]=Q[j-A[i].t];
                Q[j].push_back(A[i].id);
                if(f[j]>f[pos]) pos=j;
			}
		}
	}
	printf("%d\n%d\n",f[pos],Q[pos].size());
	for(int i=0;i<Q[pos].size();++i)
        printf("%d ",Q[pos][i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int dp[105][2005];
int pre[105][2005];
struct item{
	int t, d, p, id;
}m[105];
bool bijiao(const item &a, const item &b){
	if (a.d != b.d) return a.d < b.d;
	else return a.id < b.id;
}
int main(){
	int n;
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf ("%d%d%d", &m[i].t, &m[i].d, &m[i].p);
		m[i].id = i;
	}
	sort(m + 1, m + n + 1, bijiao);
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= 2000; j++){
			dp[i][j] = dp[i - 1][j];
			pre[i][j] = j;
			if (j >= m[i].t && j < m[i].d && dp[i - 1][j - m[i].t] + m[i].p > dp[i][j]){
				dp[i][j] =  dp[i - 1][j - m[i].t] + m[i].p;
				pre[i][j] = j - m[i].t;
			}
		}
	}
	int maxn = 0, maxid = 0;
	for (int i = 0; i <= 2000; i++){
		if (maxn < dp[n][i]){
			maxn = dp[n][i];
			maxid = i;
		}
	}
	printf ("%d\n", maxn);
	int j = maxid;
	vector<int> ans;
	for (int i = n; i >= 1; i--){
		if (pre[i][j] != j){
			ans.push_back(m[i].id);
			j = pre[i][j];
		}
	}
	printf("%d\n", (int)ans.size());
	for (int i = ans.size() - 1; i >= 0; i--) printf("%d ", ans[i]);
	printf ("\n");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#include<cstring>
#include<sstream>
#define inf 0x7ffffff
using namespace std;
int v[105], c[105], t[105];//v：价值，c：花费的时间，t：再当前时间之前必须救出；
pair<int, vector<int> > dp[2005];
int main(int n, int bag) {
	bag = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> c[i] >> t[i] >> v[i];
		bag = max(bag, t[i]);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = t[i]-1; j >= c[i]; j--) {
			if (dp[j].first < dp[j - c[i]].first + v[i])
				if ((bag - j) + c[i] < t[i]) {
					dp[j].first = dp[j - c[i]].first + v[i];
					dp[j].second = dp[j - c[i]].second;
					dp[j].second.push_back(i);
				}
		}
	}
	cout << dp[bag].first << endl;
	cout << dp[bag].second.size() << endl;
	for (int i = 0; i < dp[bag].second.size(); i++) {
		if (i == dp[bag].second.size() - 1)
			cout << dp[bag].second[i];
		else
			cout << dp[bag].second[i] << ' ';
	}

}


#include <iostream>
#include <algorithm>

using namespace std;

struct ITEM
{
    int o;
    int t;
    int d;
    int p;
};

ITEM item[101];
int list[101];

int n;

bool cmp(ITEM x, ITEM y)
{
    return x.p>y.p;
}

int main()
{
	cin>>n;

    int i;
	for (i=1; i<=n; i++)
	{
        item[i].o=i;
        cin>>item[i].t>>item[i].d>>item[i].p;
	}

    sort(item+1, item+1+n, cmp);

    int sum=0, count=0, time=0;
    for (i=1; i<=n; i++)
    {
        if(item[i].d>time+item[i].t)
        {
            count++;
            sum+=item[i].p;
            time+=item[i].t;
            list[count]=item[i].o;
        }
    }

    sort(list+1, list+1+count);

    cout<<sum<<endl;
    cout<<count<<endl;
    for (i=1; i<=count; i++)
        cout<<list[i]<<" ";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(0,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0;i<=n;i++)
    {
        for(int j=tim;j<4000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

   // vector < pair < pii , pii > > temp;
    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a,  pair < pii, pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii, pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx, int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = -1;
    int na_niye_pabo = -1;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1, time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1, time_needed_till_now);
    if(na_niye_pabo >niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }
    else
    {
        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;

    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d, i), mp (t, p)) );
    }
    a.pb(mp(mp(0,0), mp(1,0)));
    sort(a.begin(), a.end(), cmp);

    int ans = call( 0, 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0; i<=n; i++)
    {
        for(int j=tim; j<4000; j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

    // vector < pair < pii , pii > > temp;
    for(int i=0; i<bal.size(); i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(0,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i  = 1;i<=n;i++)
    {
        for(int j=tim;j<3000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    val-=a[i].S.S;
                    tim+=j;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();

    cout<<cnt<<endl;;

    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
       // cout<<a[indx].F.F<<" "<<a[indx].F.S<<endl;
        int asol_indx = a[indx].F.S;
        cout<<asol_indx<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(na_niye_pabo >niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;
 dp[indx][time_needed_till_now] = na_niye_pabo;

    }
    else
    {
        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;

    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(1,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<4000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

   // vector < pair < pii , pii > > temp;
    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a,  pair < pii, pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii, pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx, int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = -1;
    int na_niye_pabo = -1;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1, time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1, time_needed_till_now);
    if(na_niye_pabo >niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }
    else
    {
        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;

    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d, i), mp (t, p)) );
    }
    a.pb(mp(mp(0,0), mp(1,0)));
    sort(a.begin(), a.end(), cmp);

    int ans = call( 0, 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<4000; j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

    // vector < pair < pii , pii > > temp;
    for(int i=0; i<bal.size(); i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a,  pair < pii, pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii, pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;
vector<int> bal;

int call(int indx, int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = -1;
    int na_niye_pabo = -1;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1, time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1, time_needed_till_now);
    if(na_niye_pabo >niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }
    else
    {
        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;

    }

    return dp[indx][time_needed_till_now];
}

void get_item(int i, int time)
{
    if(i==n)return;
    if(dp[i][time]==dp[i+1][time])
    {
        get_item(i+1,time);
    }
    else
    {
        bal.pb(a[i].F.S);
        get_item(i+1, time+a[i].S.F);
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d, i), mp (t, p)) );
    }
    a.pb(mp(mp(0,0), mp(1,0)));
    sort(a.begin(), a.end(), cmp);

    int ans = call( 0, 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0; i<=n; i++)
    {
        int indx = tim;
        for(int j=tim; j<4000; j++)
        {
            if(dp[i][j]==val)
            {
                tim=j;
                indx = j;
            }
        }
        if(mark[i][indx]==1)
        {
            val-=a[i].S.S;
            bal.push_back(i);
        }
    }

    //get_item(0,0);
    int cnt = bal.size();
    cout<<cnt<<endl;;

    // vector < pair < pii , pii > > temp;
    for(int i=0; i<bal.size(); i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F <= eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(1,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<4000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

   // vector < pair < pii , pii > > temp;
    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][3000];
int mark[200][3000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(0,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;

    for(int i  = 1;i<=n;i++)
    {
        for(int j=0;j<3000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }

    int cnt = bal.size();

    cout<<cnt<<endl;;

    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
       // cout<<a[indx].F.F<<" "<<a[indx].F.S<<endl;

        int asol_indx = a[indx].F.S;

        cout<<asol_indx<<" ";

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(1,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<4000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

   // vector < pair < pii , pii > > temp;
    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a,  pair < pii, pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii, pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;
vector<int> item;

int call(int indx, int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = -1;
    int na_niye_pabo = -1;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1, time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1, time_needed_till_now);
    if(na_niye_pabo >niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }
    else
    {
        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;

    }

    return dp[indx][time_needed_till_now];
}

void get_item(int i , int time)
{
    if(i==n)return;
    if(dp[i][time]==dp[i+1][time])
    {
        get_item(i+1,time);
    }
    else
    {
        item.pb(a[i].F.S);
        get_item(i+1 , time+a[i].S.F);
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d, i), mp (t, p)) );
    }
    a.pb(mp(mp(0,0), mp(1,0)));
    sort(a.begin(), a.end(), cmp);

    int ans = call( 0, 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0; i<=n; i++)
    {
        for(int j=tim; j<4000; j++)
        {
            if(dp[i][j]==val)
            {
                tim=j;
                if(mark[i][j]==1)
                {

                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

    // vector < pair < pii , pii > > temp;
    for(int i=0; i<bal.size(); i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(0,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int time = 0;

    for(int i  = 1;i<=n;i++)
    {
        for(int j=time;j<3000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    val-=a[i].S.S;
                    time+=j;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();

    cout<<cnt<<endl;;

    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
       // cout<<a[indx].F.F<<" "<<a[indx].F.S<<endl;
        int asol_indx = a[indx].F.S;
        cout<<asol_indx<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(0,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<4000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

   // vector < pair < pii , pii > > temp;
    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a,  pair < pii, pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii, pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx, int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = -1;
    int na_niye_pabo = -1;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1, time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1, time_needed_till_now);
    if(na_niye_pabo >niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }
    else
    {
        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;

    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d, i), mp (t, p)) );
    }
    a.pb(mp(mp(0,0), mp(1,0)));
    sort(a.begin(), a.end(), cmp);

    int ans = call( 0, 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0; i<=n; i++)
    {
        for(int j=tim+1; j<4000; j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

    // vector < pair < pii , pii > > temp;
    for(int i=0; i<bal.size(); i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair

#define _ ios_base::sync_with_stdio(0);
#define fastt ios_base::sync_with_stdio(false); cin.tie(0);
//#define prec  cout<<fixed<<setprecision(16);
//# define sess cout<<endl;

#define file freopen("000.txt","r",stdin);
#define balsal cout<<"dhukse"<<endl;

#define pi acos(-1.0)
#define PI 3.141592653589793
#define INF 1e9

#define si(n)                        scanf("%d",&n)
#define sii(a,b)                    scanf("%d%d",&a,&b)
#define siii(a,b,c)                scanf("%d%d%d",&a,&b,&c)
#define sl(a)                        scanf("%lld",&a)
#define sll(a,b)                    scanf("%lld%lld",&a,&b)
#define slll(a,b,c)                scanf("%lld%lld%lld",&a,&b,&c)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define it_multiset  std::multiset<int>::iterator it;
#define it_mii std::map<int, int>::iterator it;

#define MOD 1000000007
#define mod  1000000007
//#define con continue;
//#define ret return
#define mx_value 1e19

long long int sett(long long int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void update(long long &x, long long val)
{
    x = x+val;
    if(x>mod)x-=mod;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

typedef long long int ll;
ll poww(ll a, ll b)
{
    ll ans = 1;
    while(b--)
    {
        ans*=a;
    }
    return ans;
}
int moves[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };

//typedef long long int ll;
typedef  float flt;
typedef double dbl;
typedef vector<int >  vi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef map<int, int> mii;

bool cmp(pair< pii, pii > a ,  pair < pii , pii > b)
{
    if(a.F.F < b.F.F)return 1;
    return 0;
}

int n;
vector< pair < pii , pii > > a;
int dp[105][5000];
int mark[200][5000] = {};
int mn_time = 1000000;

int call(int indx , int time_needed_till_now)
{
    //cout<<indx<<" "<<time_needed_till_now<<endl;

    if(indx>n)return 0;
    if(dp[indx][time_needed_till_now]!=-1)return dp[indx][time_needed_till_now];

    int eita_nosto_hoye_jabe = a[indx].F.F;
    int niye_pabo = 0;
    int na_niye_pabo = 0;
    if(time_needed_till_now + a[indx].S.F < eita_nosto_hoye_jabe)
    {
        niye_pabo = a[indx].S.S + call(indx+1 , time_needed_till_now +a[indx].S.F );
    }
    na_niye_pabo = call(indx+1 , time_needed_till_now);

    if(niye_pabo > na_niye_pabo)
    {
        //cout<<"paisi ekta    "<<indx<<endl;

        mark[indx][time_needed_till_now] = 1;
        dp[indx][time_needed_till_now] = niye_pabo;
    }
    else
    {
        dp[indx][time_needed_till_now] = na_niye_pabo;
    }

    return dp[indx][time_needed_till_now];
}

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif // ONLINE_JUDGE

    si(n);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int t,d,p;
        siii(t,d,p);
        a.push_back( mp(mp(d , i) , mp (t , p)) );
    }
    a.pb(mp(mp(0,0) , mp(0,0)));
    sort(a.begin() , a.end() , cmp);

    int ans = call( 0 , 0);

    cout<<ans<<endl;
    vector<int> bal;
    //cout<<"mark    "<<endl;
    int time = 0;

    int val = ans;
    int tim = 0;

    for(int i=0;i<=n;i++)
    {
        for(int j=tim-1;j<4000;j++)
        {
            if(dp[i][j]==val)
            {
                if(mark[i][j]==1)
                {
                    tim=j;
                    val-=a[i].S.S;
                    bal.push_back(i);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    int cnt = bal.size();
    cout<<cnt<<endl;;

   // vector < pair < pii , pii > > temp;
    for(int i=0;i<bal.size();i++)
    {
        int indx = bal[i];
        int asol_indx = a[indx].F.S;
        if(indx>0)cout<<asol_indx<<" ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=105;
const int Maxt=2005;
int ti[Maxn],d[Maxn],p[Maxn];
int order[Maxn];
int dp[Maxn][Maxt];
int pre[Maxn][Maxt];
bool cmp(int x,int y){
	return d[x]<d[y];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&ti[i],&d[i],&p[i]);
		order[i]=i;
	}
	sort(order+1,order+n+1,cmp);
	rep(i,n){
		rep(T,Maxt){
			dp[i+1][T]=dp[i][T];
		}
		rep(T,Maxt){
			if(T+ti[order[i+1]]<d[order[i+1]])chkmax(dp[i+1][T+ti[order[i+1]]],dp[i][T]+p[order[i+1]]);
		}
	}
	int mx=0,j=-1;
	rep(T,Maxt)if(chkmax(mx,dp[n][T]))j=T;
	printf("%d\n",mx);
	vector<int>seq;
	for(int i=n-1;i>=0;i--){
		if(ti[order[i+1]]<=j&&j<d[order[i+1]]&&dp[i][j-ti[order[i+1]]]+p[order[i+1]]==dp[i+1][j]){
			seq.push_back(order[i+1]);
			j-=ti[order[i+1]];
		}
	}
	reverse(all(seq));
	printf("%d\n",SZ(seq));
	rep(i,SZ(seq))printf("%d%c",seq[i],((i==SZ(seq)-1)?'\n':' '));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int n;
const int Maxn=105;
const int Maxt=2005;
pair<int,P>in[Maxn];
map<pair<int,P>,vector<int> >Mx;
int dp[Maxn][Maxt];
int pre[Maxn][Maxt];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&in[i].second.first,&in[i].first,&in[i].second.second);
		Mx[in[i]].push_back(i);
	}
	sort(in+1,in+n+1);
	rep(i,n){
		rep(j,Maxt){
			dp[i+1][j]=dp[i][j];
			pre[i+1][j]=j;
		}
		for(int j=0;j+in[i+1].second.first<in[i+1].first;j++){
			int t=j+in[i+1].second.first;
			if(chkmax(dp[i+1][t],dp[i][j]+in[i+1].second.second)){
				pre[i+1][t]=j;
			}
		}
	}
	int mx=0,ans=0;
	rep(i,Maxt){
		if(chkmax(ans,dp[n][i])){
			mx=i;
		}
	}
	printf("%d\n",ans);
	vector<int>seq;
	for(int i=n;i>0;i--){
		if(pre[i][mx]!=mx){
			auto it=Mx[in[i]];
			seq.push_back(it.back());
			it.pop_back();
			Mx[in[i]]=it;
		}
		mx=pre[i][mx];
	}
	reverse(all(seq));
	printf("%d\n",SZ(seq));
	rep(i,SZ(seq))printf("%d%c",seq[i],(i==SZ(seq)-1?'\n':' '));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=105;
const int Maxt=2005;
struct Item{
	int need,lim,val,id;
}a[Maxn];
bool cmp(Item x,Item y){
	return x.lim<y.lim;
}
int dp[Maxn][Maxt];
int pre[Maxn][Maxt];
int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d%d",&a[i].need,&a[i].lim,&a[i].val);
		a[i].id=i;
	}
	sort(a,a+n,cmp);
	memset(pre,-1,sizeof(pre));
	rep(i,n){
		rep(j,Maxt){
			dp[i+1][j]=dp[i][j];
			pre[i+1][j]=pre[i][j];
		}
		for(int j=0;j+a[i].need<a[i].lim;j++){
			int t=j+a[i].need;
			if(chkmax(dp[i+1][t],dp[i][j]+a[i].val)){
				pre[i+1][t]=i;
			}
		}
	}
	int ans=0,mx=0;
	rep(j,Maxt){
		if(chkmax(ans,dp[n][j])){
			mx=j;
		}
	}
	printf("%d\n",ans);
	vector<int>seq;
	while(pre[n][mx]!=-1){
		seq.push_back(a[pre[n][mx]].id+1);
		mx=pre[n][mx];
		n--;
	}
	reverse(all(seq));
	printf("%d\n",SZ(seq));
	rep(i,SZ(seq))printf("%d%c",seq[i],(i==SZ(seq)-1?'\n':' '));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=105;
const int Maxt=2005;
struct node{
	int tim,d,p,id;
	node(){};
	node(int _tim,int _d,int _p,int _id):tim(_tim),d(_d),p(_p),id(_id){};
}a[Maxn];
inline bool cmp(const node &x,const node &y){
	return x.d<y.d;
}
int dp[Maxn][Maxt],pre[Maxn][Maxt];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		a[i].id=i;
		scanf("%d%d%d",&a[i].tim,&a[i].d,&a[i].p);
	}
	sort(a+1,a+n+1,cmp);
//	printf("a:\n");
//	for(int i=1;i<=n;i++)printf("%d %d %d %d\n",a[i].tim,a[i].d,a[i].p,a[i].id);

	memset(pre,-1,sizeof(pre));
	rep(i,Maxn)rep(j,Maxt)dp[i][j]=-INF;

	dp[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int w=0;w<Maxt;w++){
			if(dp[i-1][w]!=INF){
				if(chkmax(dp[i][w],dp[i-1][w])){
					pre[i][w]=w;
				}
			}
			if(w+a[i].tim<a[i].d&&w+a[i].tim<Maxt&&dp[i-1][w]!=-INF){
				if(chkmax(dp[i][w+a[i].tim],dp[i-1][w]+a[i].p)){
					pre[i][w+a[i].tim]=w;
				}
			}
		}
	}
	int ans=-1,ans_tim=-1;
	for(int w=0;w<Maxt;w++){
		if(chkmax(ans,dp[n][w])){
			ans_tim=w;
		}
	}
	printf("%d\n",ans);
	int x=n,y=ans_tim;
	vector<int>seq;
	while(pre[x][y]!=-1){
		if(pre[x][y]!=y)seq.push_back(x);
		y=pre[x][y];
		x--;
	}

//	printf("seq:");rep(i,SZ(seq))printf("%d ",seq[i]);printf("\n");
	vector<int>op;
	rep(i,SZ(seq)){
		op.push_back(a[seq[i]].id);
	}
	reverse(all(op));
	printf("%d\n",SZ(op));
	rep(i,SZ(op))printf("%d ",op[i]);printf("\n");
	return 0;
}