#include <bits/stdc++.h>
using std::map;
const int maxn = 1e5 + 1;
template <class T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x * 10) + (s & 15);
    s = getchar();
  }
  x *= f;
}
map<long long, long long> idx[maxn];
long long f[maxn], n, v[maxn], c[maxn], l[maxn], r[maxn], x, fr[maxn], ans, pos,
    Ans[maxn];
signed main() {
  read(n);
  for (long long i = 1; i <= n; i++)
    read(v[i]), read(c[i]), read(l[i]), read(r[i]);
  for (long long i = 1; i <= n; i++) {
    if (!l[i]) {
      f[i] = v[i];
      if (!idx[l[i] + c[i]][r[i]])
        idx[l[i] + c[i]][r[i]] = i;
      else if (f[idx[l[i] + c[i]][r[i]]] < f[i])
        idx[l[i] + c[i]][r[i]] = i;
    } else {
      x = idx[l[i]][r[i] + c[i]];
      if (!x) continue;
      fr[i] = x;
      f[i] = f[x] + v[i];
      if ((l[i] + c[i]) > 1e5) continue;
      if (!idx[l[i] + c[i]][r[i]])
        idx[l[i] + c[i]][r[i]] = i;
      else if (f[idx[l[i] + c[i]][r[i]]] < f[i])
        idx[l[i] + c[i]][r[i]] = i;
    }
  }
  for (long long i = 1; i <= n; i++)
    if (f[i] > f[pos] && (!r[i])) pos = i;
  while (pos) Ans[++ans] = pos, pos = fr[pos];
  printf("%lld\n", ans);
  while (ans) printf("%lld ", Ans[ans--]);
}
