#include <bits/stdc++.h>
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-') f = -1;
  do {
    x = (x << 3) + (x << 1) + (c ^ 48);
  } while (isdigit(c = getchar()));
  x *= f;
}
using namespace std;
const int N = 1e5 + 5;
int n, dp[N], s[N], p[N], cnt, tp;
map<int, int> Map[N];
int main() {
  rd(n);
  for (int i = 1; i <= n; i++) {
    int v, c, l, r;
    rd(v), rd(c), rd(l), rd(r);
    if (r + c <= 1e5 && (!l || Map[l].find(r + c) != Map[l].end())) {
      int t = Map[l][r + c];
      dp[i] = dp[t] + v;
      p[i] = t;
      if (!r && dp[i] > dp[tp]) tp = i;
      if (dp[i] > dp[Map[l + c][r]]) Map[l + c][r] = i;
    }
  }
  while (tp) s[++cnt] = tp, tp = p[tp];
  printf("%d\n", cnt);
  for (; cnt > 0; cnt--) printf("%d ", s[cnt]);
  return 0;
}
