#include <bits/stdc++.h>
using namespace std;
void fff() {
  freopen("dravde.in", "r", stdin);
  freopen("dravde.out", "w", stdout);
}
const int MAXN = 100001;
int n;
map<int, int> m[MAXN];
int f[MAXN], s[MAXN], p[MAXN], cnt = 0, z;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v, c, l, r;
    scanf("%d%d%d%d", &v, &c, &l, &r);
    if (r + c < MAXN && (!l || m[l].find(r + c) != m[l].end())) {
      int u = m[l][r + c];
      f[i] = f[u] + v, p[i] = u;
      if (!r && f[i] > f[z]) {
        z = i;
      }
      if (f[i] > f[m[l + c][r]]) {
        m[l + c][r] = i;
      }
    }
  }
  while (z) {
    s[cnt++] = z;
    z = p[z];
  }
  printf("%d\n", cnt);
  while (cnt--) {
    printf("%d ", s[cnt]);
  }
  return 0;
}
