#include <bits/stdc++.h>
using namespace std;
const int N = 101;
const int M = 2001;
int n;
int dp[M], vis[N][M];
struct node {
  int t, d, p, id;
  bool operator<(const node& r) const { return d < r.d; }
} a[N];
int b[N];
int main() {
  int i, j, k, t, ed = 0, cnt = 0;
  memset(dp, 0, sizeof(dp));
  memset(vis, 0, sizeof(vis));
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d%d", &a[i].t, &a[i].d, &a[i].p);
    a[i].id = i;
  }
  sort(a + 1, a + 1 + n);
  for (i = 1; i <= n; ++i) {
    t = a[i].t;
    for (j = a[i].d - 1; j >= t; --j) {
      if (dp[j] < dp[j - t] + a[i].p) {
        dp[j] = dp[j - t] + a[i].p;
        vis[i][j] = 1;
      }
    }
  }
  for (i = 1; i < a[n].d; ++i)
    if (dp[i] > dp[ed]) ed = i;
  printf("%d\n", dp[ed]);
  for (i = n; i >= 1; --i) {
    if (vis[i][ed]) {
      b[cnt++] = a[i].id;
      ed -= a[i].t;
    }
  }
  printf("%d\n", cnt);
  for (i = cnt - 1; i > 0; --i) printf("%d ", b[i]);
  if (cnt) printf("%d\n", b[0]);
  return 0;
}
