#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
map<int, int> m[N];
int f[N], s[N], p[N], k, z, n;
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 < N && (!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[k++] = z, z = p[z];
  printf("%d\n", k);
  while (k--) printf("%d ", s[k]);
  return 0;
}
