#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000");
using namespace std;
struct element {
  long long v, c, l, r;
} q[100008];
map<long long, vector<long long> > vm;
long long n;
long long maxans;
int main() {
  maxans = -1;
  cin >> n;
  set<long long> tes;
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d%I64d%I64d%I64d", &q[i].v, &q[i].c, &q[i].l, &q[i].r);
    vm[q[i].l + q[i].c + q[i].r].push_back(i);
    tes.insert(q[i].l + q[i].c + q[i].r);
  }
  for (set<long long>::iterator it = tes.begin(); it != tes.end(); it++) {
    map<long long, long long> m;
    map<long long, long long> em;
    m[0] = 0;
    for (long long j = 0; j < vm[*it].size(); j++) {
      long long t = vm[*it][j];
      if (m.count(q[t].l))
        m[q[t].l + q[t].c] = max(m[q[t].l + q[t].c], m[q[t].l] + q[t].v);
      if (q[t].r == 0 and m.count(q[t].l))
        em[q[t].l + q[t].c] = max(em[q[t].l + q[t].c], m[q[t].l] + q[t].v);
    }
    map<long long, long long>::iterator t = em.begin();
    while (t != em.end()) {
      maxans = max(maxans, t->second);
      ++t;
    }
  };
  vector<long long> ans;
  for (set<long long>::iterator it = tes.begin(); it != tes.end(); it++) {
    map<long long, long long> m;
    map<long long, long long> em;
    map<int, vector<int> > v;
    m[0] = 0;
    for (long long j = 0; j < vm[*it].size(); j++) {
      long long t = vm[*it][j];
      if (m.count(q[t].l)) {
        if (m[q[t].l + q[t].c] < m[q[t].l] + q[t].v)
          v[q[t].l + q[t].c].push_back(t);
        m[q[t].l + q[t].c] = max(m[q[t].l + q[t].c], m[q[t].l] + q[t].v);
      }
      if (q[t].r == 0 and m.count(q[t].l)) {
        em[q[t].l + q[t].c] = max(em[q[t].l + q[t].c], m[q[t].l] + q[t].v);
        if (em[q[t].l + q[t].c] == maxans) {
          long long now = q[t].l + q[t].c;
          long long flag = 1;
          long long floor = 1e8;
          while (now) {
            long long k;
            if (flag)
              k = t, flag = 0;
            else {
              for (int j = v[now].size() - 1; j >= 0; j--) {
                if (v[now][j] > floor)
                  continue;
                else {
                  k = v[now][j];
                  break;
                }
              }
            }
            if (k) ans.push_back(k);
            floor = min(floor, k);
            now = now - q[k].c;
          }
          reverse(ans.begin(), ans.end());
          cout << ans.size() << "\n";
          for (long long i = 0; i < ans.size(); i++) printf("%I64d ", ans[i]);
          exit(0);
        }
      }
    }
  }
  cout << 0;
  return 0;
}
