#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {}
int n;
struct mono {
  int t, d, p, id;
  bool operator<(const mono &x) const { return d < x.d; }
} a[N];
int dp[101][2005];
vector<mono> pre[2005];
inline void solve() {
  scanf("%d", &n);
  for (int 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 + n + 1);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = a[i].d - 1; j >= 0; --j) {
      dp[i][j] = dp[i - 1][j];
      if (j >= a[i].t) {
        if (dp[i][j] < dp[i - 1][j - a[i].t] + a[i].p) {
          dp[i][j] = dp[i - 1][j - a[i].t] + a[i].p;
          pre[j] = pre[j - a[i].t];
          pre[j].push_back(a[i]);
        }
      }
    }
  int ansid = 0;
  for (int j = 0; j <= 2000; ++j) {
    if (dp[n][j] > ans) {
      ans = dp[n][j];
      ansid = j;
    }
  }
  printf("%d\n", ans);
  cout << pre[ansid].size() << '\n';
  for (auto i : pre[ansid]) {
    printf("%d ", i.id);
  }
}
int main() {
  TIME__START = clock();
  int Test = 1;
  while (Test--) {
    solve();
  }
  TIME__END = clock();
  program_end();
  return 0;
}
