#include <bits/stdc++.h>
using namespace std;
const int mN = 100010;
map<pair<int, int>, pair<int, int> > f;
int pre[mN];
int main() {
  int n, v, c, l, r, ans = 0, ansi = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i == 3) v = v + 1;
    cin >> v >> c >> l >> r;
    pair<int, int> a(l, r + c);
    map<pair<int, int>, pair<int, int> >::iterator it = f.find(a);
    int o = 0;
    if (l != 0) {
      if (it == f.end()) continue;
    }
    if (it != f.end()) {
      o = it->second.first;
      pre[i] = it->second.second;
    }
    a.first = l + c;
    a.second = r;
    it = f.find(a);
    if (it == f.end() || (it->second).first < o + v) {
      f[a] = pair<int, int>(o + v, i);
      if (r == 0 && ans < o + v) {
        ans = o + v;
        ansi = i;
      }
    }
  }
  int pp = 0, p[mN];
  while (ansi != 0) {
    pp++;
    p[pp] = ansi;
    ansi = pre[ansi];
  }
  cout << pp << endl;
  if (pp == 0) return 0;
  for (int i = pp; i > 1; i--) {
    cout << p[i] << ' ';
  }
  cout << p[1] << endl;
}
