#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7f7f7f7f;
long long n, m, mx = -INF, mxk, ans[300005], pre[300005];
struct truck {
  long long v, c, l, r, u;
} a[100005];
vector<truck> t[300005];
vector<long long> pth;
long long r0[300005];
long long f[300005], pos[300005];
signed main() {
  memset(f, -INF, sizeof(f));
  cin >> n;
  for (long long i = 1; i <= n;
       scanf("%lld%lld%lld%lld", &a[i].v, &a[i].c, &a[i].l, &a[i].r),
                 a[i].u = i, i++)
    ;
  for (long long i = 1; i <= n; i++) {
    long long k = a[i].l + a[i].r + a[i].c;
    m = max(m, k);
    if (!t[k].empty() || a[i].l == 0) t[k].push_back(a[i]);
    if (!t[k].empty() || a[i].r == 0) r0[k] = 1;
  }
  f[0] = 0;
  for (long long k = 1; k <= m; k++) {
    if (t[k].empty() || !r0[k]) continue;
    for (long long i = 0; i < t[k].size(); i++) {
      long long j = t[k][i].l + t[k][i].c;
      f[j] = max(f[j], f[t[k][i].l] + t[k][i].v);
    }
    if (mx < f[k]) mx = f[k], mxk = k;
    for (long long i = 0; i < t[k].size(); i++) f[t[k][i].l + t[k][i].c] = -INF;
  }
  if (mx <= 0) return puts("0"), 0;
  memset(pos, -1, sizeof(pos));
  memset(pre, -1, sizeof(pre));
  for (long long i = 0; i < t[mxk].size(); i++) {
    long long j = t[mxk][i].l + t[mxk][i].c;
    if (f[j] < f[t[mxk][i].l] + t[mxk][i].v) {
      f[j] = f[t[mxk][i].l] + t[mxk][i].v;
      pre[i] = pos[t[mxk][i].l];
      pos[j] = i;
      ans[j] = ans[t[mxk][i].l] + 1;
    }
  }
  cout << ans[mxk] << endl;
  long long now = pos[mxk];
  while (now != -1) {
    pth.push_back(t[mxk][now].u);
    now = pre[now];
  }
  for (long long i = pth.size() - 1; i >= 0; i--) printf("%lld ", pth[i]);
  return puts(""), 0;
}
