#include <bits/stdc++.h>
using namespace std;
int n, dp[200][3000], maxx, sol[1000000], idx;
struct node {
  int t, d, p, idx;
};
struct node1 {
  int x, y, idx;
};
map<int, int> mapa;
node a[10000];
node1 prosli[200][3000];
set<int> s;
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), a[i].idx = i;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 2000; j++) {
      if (dp[i + 1][j + a[i + 1].t] < dp[i][j] + a[i + 1].p &&
          j + a[i + 1].t < a[i + 1].d) {
        prosli[i + 1][j + a[i + 1].t].idx = a[i + 1].idx;
        prosli[i + 1][j + a[i + 1].t].x = i;
        prosli[i + 1][j + a[i + 1].t].y = j;
        dp[i + 1][j + a[i + 1].t] = dp[i][j] + a[i + 1].p;
      }
      if (dp[i + 1][j] < dp[i][j]) {
        prosli[i + 1][j].idx = prosli[i][j].idx;
        prosli[i + 1][j].x = i;
        prosli[i + 1][j].y = j;
        dp[i + 1][j] = dp[i][j];
      }
      maxx = max(maxx, dp[i][j]);
    }
  }
  cout << maxx << endl;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 2000; j++) {
      if (dp[i][j] == maxx) {
        int x = i, y = j;
        int t = prosli[x][y].idx;
        while (t != 0) {
          if (!mapa[t]) sol[++idx] = t;
          mapa[t] = 1;
          int p = prosli[x][y].x;
          int p1 = prosli[x][y].y;
          x = p;
          y = p1;
          t = prosli[p][p1].idx;
        }
        cout << idx << endl;
        for (int i = idx; i >= 1; i--) printf("%d ", sol[i]);
        return 0;
      }
    }
  }
  return 0;
}
