#include <bits/stdc++.h>
const double pi = acos(-1.0);
using namespace std;
inline long long MAX2(long long a, long long b) {
  return (a) > (b) ? (a) : (b);
}
inline long long MAX3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long MIN2(long long a, long long b) {
  return (a) < (b) ? (a) : (b);
}
inline long long MIN3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
const int mod = 1000000007;
int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
  if (!a) {
    x = 0;
    y = 1;
    return b;
  }
  int64_t x1, y1;
  int64_t d = extGcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
inline long long addmod(long long a, long long b) {
  a = a % mod + b % mod;
  if (a > mod) a %= mod;
  return a;
}
inline long long submod(long long a, long long b) {
  a = a % mod - b % mod;
  if (a < 0) a += mod;
  return a;
}
inline long long mulmod(long long a, long long b) {
  return (a % mod * b % mod) % mod;
}
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
inline long long exp(long long a, long long b) {
  if (a == 0) return 0ll;
  long long r = 1LL;
  while (b > 0) {
    if (b & 1) {
      r = r * (a % mod);
      r = (r + mod) % mod;
    }
    b /= 2;
    a = (a % mod) * (a % mod);
    a = (a + mod) % mod;
  }
  return (r + mod) % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  if (a == 0) return b;
  return gcd(b, a % b);
}
unsigned long int setbits(long long n) {
  unsigned long int count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
struct node {
  int T, D, Val, id;
  node(int T = 0, int D = 0, int Val = 0, int id = -1) {
    this->T = T;
    this->D = D;
    this->Val = Val;
    this->id = id;
  }
};
vector<node> g1;
map<pair<int, int>, pair<long long, vector<int>>> dp;
long long solve(int i, int t) {
  if (i == g1.size()) return 0;
  if (dp.count({i, t})) return dp[{i, t}].first;
  long long op1 = 0;
  long long op2 = 0;
  if (g1[i].T + t < g1[i].D) {
    op1 = g1[i].Val + solve(i + 1, t + g1[i].T);
  }
  op2 = solve(i + 1, t);
  if (op1 > op2) {
    dp[{i, t}] = {op1, dp[{i + 1, t + g1[i].T}].second};
    dp[{i, t}].second.push_back(g1[i].id);
  } else {
    dp[{i, t}] = {op2, dp[{i + 1, t}].second};
  }
  return dp[{i, t}].first;
}
bool cmp(node a, node b) { return a.D < b.D; }
int main() {
  if (fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  g1 = vector<node>(n);
  for (int i = 0; i < n; i++) {
    int t, d, val;
    cin >> t >> d >> val;
    node curr(t, d, val, i + 1);
    g1[i] = curr;
  }
  sort(g1.begin(), g1.end(), cmp);
  int ans = solve(0, 0);
  vector<int> g2;
  for (auto x : dp) {
    if (x.second.first == ans) {
      g2 = x.second.second;
      break;
    }
  }
  cout << ans << '\n';
  cout << g2.size() << '\n';
  reverse(g2.begin(), g2.end());
  for (auto x : g2) cout << x << " ";
  return 0;
}
