#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, d, p;
  int id;
} a[111];
bool cmp(node x, node y) { return x.d < y.d; }
pair<int, int> fa[111][2222];
long long dp[111][2222];
long long ans[111];
int n;
int cnt;
long long f(int i, int j) {
  if (dp[i][j]) return dp[i][j];
  if (i == n + 1) {
    fa[i][j] = make_pair(-1, -1);
    return dp[i][j] = 0;
  }
  if (a[i].d <= a[i].t) {
    fa[i][j] = make_pair(i + 1, j);
    return dp[i][j] = f(i + 1, j);
  }
  long long temp = 0;
  if (j + a[i].t < a[i].d) temp = f(i + 1, j + a[i].t) + a[i].p;
  if (temp > f(i + 1, j)) {
    fa[i][j] = make_pair(i + 1, j + a[i].t);
    return dp[i][j] = temp;
  } else {
    fa[i][j] = make_pair(i + 1, j);
    return dp[i][j] = f(i + 1, j);
  }
}
void trace(int i, int j) {
  if (i == -1 && j == -1) return;
  int x = fa[i][j].first, y = fa[i][j].second;
  if (y > j) ans[cnt++] = a[i].id;
  trace(x, y);
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i].t >> a[i].d >> a[i].p, a[i].id = i;
    memset(dp, 0, sizeof(dp));
    memset(fa, 0, sizeof(fa));
    memset(ans, 0, sizeof(ans));
    sort(a + 1, a + 1 + n, cmp);
    cout << f(1, 0) << endl;
    cnt = 0;
    trace(1, 0);
    cout << cnt << endl;
    for (int i = 0; i < cnt; i++) cout << ans[i] << (i == cnt - 1 ? '\n' : ' ');
  }
  return 0;
}
