#include <bits/stdc++.h>
using namespace std;
struct T {
  int v, c, l, r;
  void read() { scanf("%d%d%d%d", &v, &c, &l, &r); }
} a[110000];
int n;
map<pair<int, int>, int> f;
map<pair<int, int>, vector<int> > g;
bool update(int &x, int y) {
  if (x > y) return 0;
  return x = y, 1;
}
int main() {
  cin >> n;
  for (int i = (1); i <= (n); i++) a[i].read();
  int ans = 0, End = -1;
  for (int i = (1); i <= (n); i++) {
    if (a[i].l == 0)
      if (update(f[make_pair(a[i].l + a[i].c, a[i].r)], a[i].v)) {
        g[make_pair(a[i].l + a[i].c, a[i].r)].push_back(i);
        if (a[i].r == 0) {
          if (update(ans, f[make_pair(a[i].l + a[i].c, a[i].r)])) End = i;
        }
      }
    map<pair<int, int>, int>::iterator e =
        f.find(make_pair(a[i].l, a[i].r + a[i].c));
    if (e != f.end())
      if (update(f[make_pair(a[i].l + a[i].c, a[i].r)], e->second + a[i].v)) {
        g[make_pair(a[i].l + a[i].c, a[i].r)].push_back(i);
        if (a[i].r == 0)
          if (update(ans, f[make_pair(a[i].l + a[i].c, a[i].r)])) End = i;
      }
  }
  if (End == -1)
    puts("0"), puts("");
  else {
    vector<int> ans;
    while (a[End].l) {
      ans.push_back(End);
      vector<int> &b = g[make_pair(a[End].l, a[End].c + a[End].r)];
      while (b.back() > End) b.pop_back();
      End = b.back();
    }
    ans.push_back(End);
    reverse((ans).begin(), (ans).end());
    cout << ((int)(ans).size()) << endl;
    for (typeof((ans).begin()) e = (ans).begin(); e != (ans).end(); e++)
      cout << *e << " ";
  }
  return 0;
}
