#include <bits/stdc++.h>
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
using namespace std;
const int N = 1e2 + 10;
const int inf = 1e18 + 10;
const long double Pi = 3.14159265;
int n, t[N], d[N], p[N], pos[N], dp[102][2002][2];
bool cmp(int x, int y) {
  if (d[x] == d[y]) return p[x] > p[y];
  return d[x] < d[y];
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> d[i] >> p[i];
    pos[i] = i;
  }
  sort(pos + 1, pos + 1 + n, cmp);
  for (int cnt = 1; cnt <= n; cnt++) {
    for (int j = 0; j <= 2000; j++) {
      int i = pos[cnt], last = pos[cnt - 1];
      if (t[i] <= j and dp[i][j][0] < p[i] + dp[last][j - t[i]][0] and j < d[i])
        dp[i][j][0] = p[i] + dp[last][j - t[i]][0],
        dp[i][j][1] = 1 + dp[last][j - t[i]][1];
      if (dp[i][j][0] < dp[last][j][0])
        dp[i][j][0] = dp[last][j][0], dp[i][j][1] = dp[last][j][1];
    }
  }
  int ind, val = -inf, ans = 0;
  for (int j = 0; j <= 2000; j++) {
    int i = pos[n];
    if (dp[i][j][0] > val) {
      val = dp[i][j][0], ind = j, ans = dp[i][j][1];
    }
  }
  cout << val << "\n";
  vi v;
  int j = ind;
  for (int cnt = n; cnt >= 1; cnt--) {
    int i = pos[cnt], last = pos[cnt - 1];
    if (j >= t[i] and p[i] + dp[last][j - t[i]][0] == dp[i][j][0])
      j -= t[i], v.push_back(i);
  }
  cout << v.size() << "\n";
  reverse(v.begin(), v.end());
  for (auto i : v) cout << i << " ";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  int xx = 0;
  return 0;
}
