#include <bits/stdc++.h>
using namespace std;
struct M {
  int l, r, ind;
  int cost;
  int lind;
  bool operator<(const M& m) const {
    if (l != m.l) return l < m.l;
    if (r != m.r) return r < m.r;
    if (cost != m.cost) return cost > m.cost;
    return ind < m.ind;
  }
};
int v[101010];
int c[101010];
int l[101010];
int r[101010];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d %d", &v[i], &c[i], &l[i], &r[i]);
  }
  set<M> s;
  for (int i = 0; i < n; ++i) {
    M m;
    m.l = l[i];
    m.r = r[i] + c[i];
    m.ind = -1;
    m.cost = 2000000000;
    set<M>::const_iterator it = s.lower_bound(m);
    bool ok = false;
    if (it != s.end()) {
      if (it->l == l[i] && it->r == m.r) {
        ok = true;
        M nm;
        nm.cost = it->cost + v[i];
        nm.l = c[i] + l[i];
        nm.r = r[i];
        nm.ind = i;
        nm.lind = it->ind;
        s.insert(nm);
      }
    }
    if (l[i] == 0) {
      M nm;
      nm.cost = v[i];
      nm.ind = i;
      nm.l = c[i];
      nm.r = r[i];
      nm.lind = -1;
      s.insert(nm);
    }
  }
  set<M>::const_iterator res_it = s.begin();
  int res = 0;
  for (set<M>::const_iterator it = s.begin(); it != s.end(); ++it) {
    if (it->r == 0) {
      if (it->cost > res) {
        res = it->cost;
        res_it = it;
      }
    }
  }
  if (res == 0) {
    printf("0");
    return 0;
  }
  vector<int> ans;
  while (1) {
    ans.push_back(res_it->ind);
    M m;
    m.l = res_it->l - c[res_it->ind];
    m.cost = res_it->cost - v[res_it->ind];
    m.ind = res_it->lind;
    if (m.ind == -1) break;
    m.r = res_it->r + c[res_it->ind];
    res_it = s.find(m);
  }
  printf("%d\n", ans.size());
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); ++i) printf("%d ", ans[i] + 1);
  return 0;
}
