#include <bits/stdc++.h>
using namespace std;
int n, f[100011], p[100011], rec;
map<int, int> g[100011];
set<int> x;
int main() {
  cin >> n;
  for (int i = 1, v, c, l, r; i <= n; ++i) {
    cin >> v >> c >> l >> r;
    if (c + r <= 100000 && (!l || g[l].count(c + r))) {
      int j = g[l][c + r];
      if ((f[i] = f[j] + v) > f[rec] && !r) rec = i;
      p[i] = j;
      if (f[i] > f[g[l + c][r]]) g[l + c][r] = i;
    }
  }
  for (int i = rec; i; i = p[i]) x.insert(i);
  cout << x.size() << endl;
  for (int i : x) cout << i << ' ';
  cout << endl;
  return 0;
}
