#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 2010;
const int inf = 1e9;
int dp[N][M], path[N][M], q[N];
struct P {
  int t, d, p, id;
} p[N];
int n, m;
bool cmp(P a, P b) { return a.d < b.d; }
int main() {
  scanf("%d", &n);
  m = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &p[i].t, &p[i].d, &p[i].p), p[i].id = i;
    m = max(m, p[i].d);
  }
  sort(p + 1, p + 1 + n, cmp);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j) dp[i][j] = -inf;
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i][j] = dp[i - 1][j];
      path[i][j] = 0;
      if (j < p[i].d && j >= p[i].t &&
          dp[i][j] < dp[i - 1][j - p[i].t] + p[i].p) {
        dp[i][j] = dp[i - 1][j - p[i].t] + p[i].p;
        path[i][j] = 1;
      }
    }
  }
  int ans = -inf, now;
  for (int j = 0; j <= m; ++j)
    if (ans < dp[n][j]) {
      ans = dp[n][j];
      now = j;
    }
  printf("%d\n", ans);
  int tot = 0;
  for (int i = n; i >= 1; --i) {
    int tmp = path[i][now];
    if (tmp) {
      q[tot++] = p[i].id;
      now = now - p[i].t;
    }
  }
  printf("%d\n", tot);
  for (int i = tot - 1; i >= 0; --i) printf("%d%s", q[i], i == 0 ? "\n" : " ");
  return 0;
}
