#include <bits/stdc++.h>
using namespace std;
int tmp, a[1000008], v[1000008], c[1000008], l[1000008], r[1000008], e[1000008],
    f[1000008], p[1000008], q[1000008], pre[1000008], nxt[1000008],
    head[1000008], cln[1000008];
void add(int, int);
int main() {
  int i, j, k, n, cnt, ax = 0, ans = 0, top;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d %d %d %d", &v[i], &c[i], &l[i], &r[i]);
    add(l[i] + c[i] + r[i], i);
    ax = max(ax, l[i] + c[i] + r[i]);
  }
  f[0] = 0;
  for (i = 1; i <= ax; ++i) f[i] = -0x3f3f3f3f;
  for (k = 1; k <= ax; ++k) {
    cnt = tmp = 0;
    for (i = head[k]; i; i = nxt[i]) a[++cnt] = e[i];
    for (i = 1; i <= cnt / 2; ++i) swap(a[i], a[cnt - i + 1]);
    for (i = 1; i <= cnt; ++i) {
      j = a[i];
      pre[j] = p[l[j]];
      if (f[l[j] + c[j]] < f[l[j]] + v[j]) {
        f[l[j] + c[j]] = f[l[j]] + v[j];
        p[l[j] + c[j]] = j;
        cln[++tmp] = l[j] + c[j];
      }
    }
    if (ans < f[k]) {
      ans = f[k];
      top = 0;
      i = p[k];
      while (i) {
        q[++top] = i;
        i = pre[i];
      }
    }
    for (i = 1; i <= tmp; ++i) {
      f[cln[i]] = -0x3f3f3f3f;
      p[cln[i]] = 0;
    }
  }
  printf("%d\n", top);
  for (i = top; i; --i) printf("%d ", q[i]);
  return 0;
}
void add(int u, int id) {
  ++tmp;
  e[tmp] = id;
  nxt[tmp] = head[u];
  head[u] = tmp;
}
