#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, maxp = 300005;
int n, stp, inf, maxx, anss;
int v[maxn], c[maxn], l[maxn], r[maxn], f[maxp], chs[maxp], vis[maxp],
    ans[maxn], last[maxp];
vector<int> p[maxp];
void getnew(int x) {
  if (vis[x] != stp) {
    vis[x] = stp, f[x] = inf, chs[x] = 0;
  }
}
int main() {
  memset(f, 128, sizeof(f));
  maxx = inf = f[0];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &v[i], &c[i], &l[i], &r[i]);
    p[c[i] + l[i] + r[i]].push_back(i);
  }
  for (int i = 1; i < maxp; i++)
    if (p[i].size()) {
      stp++;
      getnew(0), f[0] = 0;
      for (int j = 0; j < p[i].size(); j++) {
        int k = p[i][j];
        last[k] = 0;
      }
      for (int j = 0; j < p[i].size(); j++) {
        int k = p[i][j];
        getnew(l[k]), getnew(l[k] + c[k]);
        if (f[l[k]] + v[k] > f[l[k] + c[k]]) {
          f[l[k] + c[k]] = f[l[k]] + v[k], chs[l[k] + c[k]] = k;
          last[k] = chs[l[k]];
        }
      }
      if (f[i] > maxx) {
        int now = chs[i], tmp = chs[i];
        if (r[tmp] != 0) continue;
        while (last[tmp]) tmp = last[tmp];
        if (l[tmp] != 0) continue;
        maxx = f[i], anss = 0;
        while (now) ans[++anss] = now, now = last[now];
      }
    }
  printf("%d\n", anss);
  for (int i = anss; i >= 1; i--) printf("%d%c", ans[i], i == 1 ? '\n' : ' ');
  return 0;
}
