#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, pair<int, int> > mp;
int l[1001000], r[1001000], c[1001000], v[1001000], n, i, fa[1001000], ans,
    anss;
vector<int> b[1001000], o;
void solve(int t) {
  vector<int> &a = b[t];
  mp.clear();
  for (int i = 0; i < (int)a.size(); i++) {
    int x = a[i];
    if (l[x] == 0) {
      mp[make_pair(l[x] + c[x], r[x])] =
          max(mp[make_pair(l[x] + c[x], r[x])], make_pair(v[x], x));
      if (r[x] == 0 && v[x] > ans) ans = v[x], anss = x;
    } else {
      if (mp.find(make_pair(l[x], r[x] + c[x])) == mp.end()) continue;
      pair<int, int> tmp = mp[make_pair(l[x], r[x] + c[x])];
      tmp.first += v[x];
      fa[x] = tmp.second;
      tmp.second = x;
      if (r[x] == 0 && tmp.first > ans) ans = tmp.first, anss = tmp.second;
      mp[make_pair(l[x] + c[x], r[x])] =
          max(tmp, mp[make_pair(l[x] + c[x], r[x])]);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d %d %d %d", &v[i], &c[i], &l[i], &r[i]),
        b[c[i] + l[i] + r[i]].push_back(i);
  for (i = 1; i <= 300000; i++) {
    if (b[i].size() > 0) solve(i);
  }
  int x = anss;
  o.push_back(x);
  if (anss == 0) {
    printf("0\n");
    return 0;
  }
  while (fa[x] != 0) x = fa[x], o.push_back(x);
  printf("%d\n", (int)o.size());
  for (i = o.size() - 1; i >= 0; i--) printf("%d ", o[i]);
}
