#include <bits/stdc++.h>
using namespace std;
const int Orzpsj = 2000010;
inline int read() {
  int f = 1, w = 0;
  char x = 0;
  while (!(x >= '0' && x <= '9')) {
    x = getchar();
    if (x == '-') f = -1;
  }
  while (x != EOF && x >= '0' && x <= '9') {
    w = (w << 3) + (w << 1) + (x ^ 48);
    x = getchar();
  }
  return f * w;
}
struct dian {
  int w, p, l, r, sum, hao;
} d[Orzpsj];
int n, f[Orzpsj], ans, up[Orzpsj], pre[Orzpsj], k1, up1 = 1;
bool cmp(dian a, dian b) {
  if (a.sum == b.sum) return a.hao < b.hao;
  return a.sum < b.sum;
}
void dfs(int x, int p) {
  if (x == 0) {
    cout << p << endl;
    return;
  }
  dfs(pre[x], p + 1);
  cout << x << " ";
}
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) {
    d[i].w = read(), d[i].p = read(), d[i].l = read(), d[i].hao = i;
    d[i].r = read(), d[i].sum = d[i].l + d[i].p + d[i].r;
  }
  sort(d + 1, d + n + 1, cmp);
  int k = d[1].sum;
  for (register int i = 1; i <= n; ++i) {
    if (d[i].sum != k) {
      if (ans < f[k]) {
        ans = f[k];
        k1 = up[k];
      }
      k = d[i].sum;
      for (register int j = up1; j <= i; ++j)
        f[d[j].l + d[j].p] = 0, up[d[j].l + d[j].r] = 0;
      up1 = i;
    }
    if (d[i].l != 0 && f[d[i].l] == 0) continue;
    if (f[d[i].l + d[i].p] > f[d[i].l] + d[i].w) continue;
    f[d[i].l + d[i].p] = f[d[i].l] + d[i].w;
    pre[d[i].hao] = up[d[i].l];
    up[d[i].l + d[i].p] = d[i].hao;
  }
  if (ans < f[k]) {
    ans = f[k];
    k1 = up[k];
  }
  if (ans == 0) {
    cout << 0;
    return 0;
  }
  dfs(pre[k1], 1);
  cout << k1;
  return 0;
}
