#include <bits/stdc++.h>
using namespace std;
int v[100000], c[100000], l[100000], r[100000];
int parent[100000], value[100000];
int main() {
  int n, pos = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> v[i] >> c[i] >> l[i] >> r[i];
  map<pair<int, int>, pair<int, int> > hash;
  map<pair<int, int>, pair<int, int> >::iterator it;
  int val = -1, index = -1;
  for (int i = 0; i < n; ++i) parent[i] = i, value[i] = -1;
  for (int i = 0; i < n; ++i) {
    pair<int, int> next = make_pair(l[i], r[i] + c[i]);
    if (l[i] == 0) {
      pair<int, int> make = make_pair(c[i], r[i]);
      if (hash[make].first < v[i]) hash[make] = make_pair(v[i], i);
      if (r[i] == 0 && val < v[i]) {
        val = v[i];
        index = i;
      }
    }
    if ((it = hash.find(next)) == hash.end()) continue;
    int maxi = it->second.first + v[i];
    if (hash[make_pair(l[i] + c[i], r[i])].first < maxi) {
      hash[make_pair(l[i] + c[i], r[i])] = make_pair(maxi, i);
      parent[i] = it->second.second;
    }
    if (r[i] == 0 && maxi > val) val = maxi, index = i;
  }
  if (index == -1)
    cout << 0 << endl;
  else {
    vector<int> ret;
    while (true) {
      ret.push_back(index);
      if (index == parent[index]) break;
      index = parent[index];
    }
    cout << ret.size() << endl;
    for (int i = ret.size() - 1; i >= 0; --i) cout << ret[i] + 1 << " ";
    cout << endl;
  }
}
