#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
map<pair<int, int>, int> m;
int c[111111], l[11111], r[111111], v[111111], n, pos, tot;
int num[111111], lst[111111], wgt[111111];
int main() {
  cin >> n;
  pos = -1;
  tot = 0;
  for (int(i) = 0; (i) < (n); ++(i)) {
    cin >> v[i] >> c[i] >> l[i] >> r[i];
    if (m.find(make_pair(l[i], c[i] + r[i])) == m.end()) {
      if (l[i] == 0) {
        num[i] = 1;
        wgt[i] = v[i];
        lst[i] = -1;
      } else
        continue;
    } else {
      lst[i] = m[make_pair(l[i], c[i] + r[i])];
      num[i] = 1 + num[lst[i]];
      wgt[i] = v[i] + wgt[lst[i]];
    }
    if (m.find(make_pair(l[i] + c[i], r[i])) == m.end())
      m[make_pair(c[i] + l[i], r[i])] = i;
    else {
      int pos = m[make_pair(c[i] + l[i], r[i])];
      if (wgt[pos] < wgt[i]) m[make_pair(c[i] + l[i], r[i])] = i;
    }
    if (wgt[i] > tot && r[i] == 0) {
      tot = wgt[i];
      pos = i;
    }
  }
  if (pos == -1) {
    cout << "0\n";
    return 0;
  }
  cout << num[pos] << endl;
  vector<int> v;
  v.clear();
  while (pos != -1) {
    v.push_back(pos);
    pos = lst[pos];
  }
  reverse((v).begin(), v.end());
  for (int(i) = 0; (i) < ((int)((v).end() - (v).begin())); ++(i)) {
    cout << v[i] + 1;
    if (i < (int)((v).end() - (v).begin()) - 1)
      cout << " ";
    else
      cout << endl;
  }
}
