#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 100005;
int n, pre[maxn], s[maxn];
map<int, pair<int, int> > m;
pair<int, int> ans;
struct node {
  int v, c, l, r, id, sum;
  bool operator<(const node &b) const {
    if (sum != b.sum) return sum < b.sum;
    return id < b.id;
  }
} a[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &a[i].v, &a[i].c, &a[i].l, &a[i].r);
    a[i].id = i;
    a[i].sum = a[i].c + a[i].l + a[i].r;
  }
  sort(a + 1, a + n + 1);
  int res = 0;
  s[++res] = 1;
  ans.first = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i].sum == a[i - 1].sum) s[++res] = i;
    if (a[i].sum != a[i - 1].sum || i == n) {
      m.clear();
      for (int j = 1; j <= res; j++) {
        node t = a[s[j]];
        if (t.l == 0) {
          if (m.find(t.c) == m.end() || m[t.c].first < t.v) {
            m[t.c] = pair<int, int>(t.v, t.id);
            pre[t.id] = 0;
            if (t.r == 0 && m[t.c].first > ans.first) ans = m[t.c];
          }
        } else {
          if (m.find(t.l) != m.end()) {
            if (m.find(t.l + t.c) == m.end() ||
                m[t.l + t.c].first < m[t.l].first + t.v) {
              m[t.l + t.c] = pair<int, int>(m[t.l].first + t.v, t.id);
              pre[t.id] = m[t.l].second;
            }
            if (t.r == 0 && m[t.l].first + t.v > ans.first)
              ans = pair<int, int>(m[t.l].first + t.v, t.id);
          }
        }
      }
      res = 0;
      s[++res] = i;
    }
  }
  vector<int> vec;
  int pos = ans.second;
  while (pos) {
    vec.push_back(pos);
    pos = pre[pos];
  }
  printf("%d\n", vec.size());
  for (int i = vec.size() - 1; i >= 0; i--)
    printf("%d%c", vec[i], i ? ' ' : '\n');
  return 0;
}
