#include <bits/stdc++.h>
using namespace std;
const int N = 100020;
map<int, int> g[N];
int best, u, v, c, l, r, n, num;
int ans[N], f[N], p[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d %d", &v, &c, &l, &r);
    if (r + c < N - 10 && (!l || g[l].count(c + r))) {
      int u = g[l][c + r];
      f[i] = f[u] + v;
      p[i] = u;
      if (r == 0 && f[i] > f[best]) best = i;
      if (f[i] > f[g[l + c][r]]) g[l + c][r] = i;
    }
  }
  for (; best; best = p[best]) ans[num++] = best;
  printf("%d\n", num);
  while (num--) printf("%d ", ans[num]);
}
