#include <bits/stdc++.h>
using namespace std;
int n;
int v[100000], c[100000], l[100000], r[100000];
vector<int> g[300001];
int d[200001] = {};
vector<int> p[200001], pp[200001], px[200001];
vector<int> t;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) cin >> v[i] >> c[i] >> l[i] >> r[i];
  for (int i = 0; i < (int)(n); ++i) g[c[i] + l[i] + r[i]].push_back(i);
  int ans = 0;
  for (int i = 0; i < (int)(200001); ++i)
    if (!g[i].empty()) {
      for (int x : g[i])
        if ((!l[x] || d[l[x]]) && d[l[x] + c[x]] < d[l[x]] + v[x]) {
          d[l[x] + c[x]] = d[l[x]] + v[x];
          p[l[x] + c[x]].push_back(l[x]);
          pp[l[x] + c[x]].push_back((int)p[l[x]].size() - 1);
          px[l[x] + c[x]].push_back(x);
        }
      int ind = i;
      if (d[ind] > ans) {
        int pind = (int)p[ind].size() - 1;
        ans = d[ind];
        t.clear();
        while (ind) {
          t.push_back(px[ind][pind]);
          int nind = p[ind][pind];
          pind = pp[ind][pind];
          ind = nind;
        }
      }
      for (int x : g[i]) {
        int pos = l[x] + c[x];
        d[pos] = 0;
        p[pos].clear();
        pp[pos].clear();
        px[pos].clear();
      }
    }
  cout << (int)t.size() << '\n';
  for (int i = (int)t.size() - 1; i >= 0; --i) cout << t[i] + 1 << ' ';
  cout << '\n';
  return 0;
}
