#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
int f[maxn], Link[maxn * 3], pre[maxn], num[maxn], Tnum = 0, g[maxn],
                                                   h[maxn * 3];
int n, l[maxn], r[maxn], c[maxn], v[maxn], lim = 0, ans = 0, cnt = 0, p;
int get() {
  int f = 0, v = 0;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') break;
  if (ch == '-')
    f = 1;
  else
    v = ch - 48;
  while (isdigit(ch = getchar())) v = (v << 3) + (v << 1) + ch - 48;
  if (f == 1)
    return -v;
  else
    return v;
}
int main() {
  n = get();
  for (int i = 1; i <= n; i++) {
    v[i] = get(), c[i] = get(), l[i] = get(), r[i] = get();
    pre[i] = Link[c[i] + l[i] + r[i]];
    Link[c[i] + l[i] + r[i]] = i;
    lim = max(lim, c[i] + l[i] + r[i]);
  }
  f[n + 1] = 0;
  for (int S = 0; S <= lim; S++) {
    Tnum = 0, h[0] = n + 1;
    for (int i = Link[S]; i > 0; i = pre[i]) {
      if (h[r[i]] == 0) continue;
      f[i] = f[h[r[i]]] + v[i];
      g[i] = h[r[i]];
      if (l[i] == 0 && f[i] > ans) ans = f[i], p = i;
      if (h[r[i] + c[i]] == 0)
        h[r[i] + c[i]] = i, num[++Tnum] = r[i] + c[i];
      else if (f[i] > f[h[r[i] + c[i]]])
        h[r[i] + c[i]] = i;
    }
    for (int i = 1; i <= Tnum; i++) h[num[i]] = 0;
  }
  if (ans == 0) return printf("%d\n", 0), 0;
  while (p <= n) v[++cnt] = p, p = g[p];
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d ", v[i]);
  puts("");
  return 0;
}
