#include <bits/stdc++.h>
using namespace std;
bool comp(vector<int>& first, vector<int>& second) {
  if (first[1] < second[1])
    return 1;
  else if (first[1] > second[1])
    return 0;
  else
    return (first[2] > second[2]);
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> v(n, vector<int>(4, 0));
  for (int i = 0; i < n; ++i) cin >> v[i][0] >> v[i][1] >> v[i][2];
  for (int i = 0; i < n; ++i) v[i][3] = i;
  sort(v.begin(), v.end(), comp);
  vector<vector<int>> dp(n + 1, vector<int>(2001, 0));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= 2000; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j >= v[i - 1][0] && j < v[i - 1][1]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i - 1][0]] + v[i - 1][2]);
      }
    }
  }
  int ma = 0;
  int ind = 0;
  for (int j = 1; j <= 2000; ++j) {
    ma = max(ma, dp[n][j]);
    if (ma == dp[n][j]) ind = j;
  }
  cout << ma << "\n";
  vector<int> ans;
  int i = n;
  int j = ind;
  while (1) {
    if (!dp[i][j]) break;
    if (dp[i][j] != dp[i - 1][j]) {
      ans.push_back(v[i - 1][3]);
      j -= v[i - 1][0];
    }
    --i;
  }
  cout << ans.size() << "\n";
  for (i = ans.size() - 1; i >= 0; --i) cout << ans[i] + 1 << ' ';
  return 0;
}
