#include <bits/stdc++.h>
using namespace std;
struct node {
  int ned, d, val, id;
} a[1500];
vector<int> ans;
int cmp(node a, node b) { return a.d < b.d; }
int dp[150][2500];
int last[150][2500];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++)
      scanf("%d%d%d", &a[i].ned, &a[i].d, &a[i].val), a[i].id = i;
    sort(a + 1, a + 1 + n, cmp);
    memset(dp, 0, sizeof(dp));
    memset(last, 0, sizeof(last));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 2000; j++) {
        dp[i][j] = dp[i - 1][j];
        if (j >= a[i].ned && j < a[i].d) {
          if (dp[i - 1][j - a[i].ned] + a[i].val > dp[i][j]) {
            dp[i][j] = dp[i - 1][j - a[i].ned] + a[i].val;
            last[i][j] = i;
          }
        }
      }
    }
    int output = 0, pos;
    for (int i = 1; i <= 2000; i++) {
      if (output < dp[n][i]) {
        output = dp[n][i];
        pos = i;
      }
    }
    printf("%d\n", output);
    int level = n;
    ans.clear();
    while (pos > 0 && level > 0) {
      if (last[level][pos] > 0) ans.push_back(a[last[level][pos]].id);
      pos -= a[last[level][pos]].ned;
      level--;
    }
    reverse(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for (int j = 0; j < ans.size(); j++) {
      printf("%d ", ans[j]);
    }
    printf("\n");
  }
}
