#include <bits/stdc++.h>
using namespace std;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false;
    }
  }
}
int gcd(int x, int y) {
  if (x == 0) {
    return y;
  } else
    return gcd(x % y, y);
}
struct node {
  int t;
  int d;
  int p;
  int idx;
};
bool comp(node a, node b) {
  if (a.d < b.d) return true;
  return false;
}
int main() {
  int n;
  cin >> n;
  node a[n];
  int q, w, e;
  int nn = 0;
  int max_price = 0;
  for (int i = 0; i < n; i++) {
    cin >> q >> w >> e;
    a[i].t = q;
    a[i].d = w;
    a[i].p = e;
    a[i].idx = i;
    if (a[i].d > nn) nn = a[i].d;
    if (a[i].p > max_price) max_price = a[i].p;
  }
  sort(a, a + n, comp);
  int dp[n + 1][nn + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= nn; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else {
        int temp = 0;
        if (j - a[i - 1].t >= 0) {
          temp = dp[i - 1][j - a[i - 1].t];
          int temp2 = 0;
          if (j < a[i - 1].d) temp2 = a[i - 1].p;
          dp[i][j] = max(dp[i - 1][j], temp + temp2);
        } else {
          dp[i][j] = dp[i - 1][j];
        }
      }
    }
  }
  int ans = 0;
  int pi = 0, pj = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= nn; j++) {
      if (dp[i][j] > ans) {
        ans = dp[i][j];
        pi = i;
        pj = j;
      }
    }
  }
  int count = 0;
  vector<int> vec;
  while (pi != 0 && pj != 0) {
    if (dp[pi][pj] == dp[pi - 1][pj]) {
      pi--;
    } else {
      count++;
      vec.push_back(a[pi - 1].idx + 1);
      pj = max(0, pj - a[pi - 1].t);
      pi--;
    }
  }
  cout << ans << endl;
  cout << count << endl;
  if (vec.size() != 0) {
    for (int i = vec.size() - 1; i >= 0; i--) cout << vec[i] << " ";
  }
  cout << endl;
  return 0;
}
