#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
template <typename T>
inline void read(T& x) {
  x = 0;
  char temp = getchar();
  bool f = false;
  while (!isdigit(temp)) {
    if (temp == '-') f = true;
    temp = getchar();
  }
  while (isdigit(temp)) {
    x = (x << 1) + (x << 3) + temp - '0';
    temp = getchar();
  }
  if (f) x = -x;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
int n;
map<int, int> m[MAXN];
int pre[MAXN], f[MAXN], pos;
int path[MAXN], len;
int main() {
  read(n);
  for (register int i = 1; i <= n; i++) {
    int v, c, l, r;
    read(v), read(c), read(l), read(r);
    if (l == 0 || m[l].find(r + c) != m[l].end()) {
      int trans = m[l][r + c];
      f[i] = f[trans] + v, pre[i] = trans;
      if (r == 0 && f[i] > f[pos]) pos = i;
      if (f[i] > f[m[l + c][r]]) m[l + c][r] = i;
    }
  }
  if (pos == 0) return puts("0"), 0;
  path[++len] = pos;
  while (pre[pos]) path[++len] = (pos = pre[pos]);
  print(len), puts("");
  for (register int i = len; i >= 1; i--) print(path[i]), putchar(' ');
  return 0;
}
