#include <bits/stdc++.h>
using namespace std;
int n, ans, id, s, p[100005];
map<pair<int, int>, int> a, b;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x + (x << 2) << 1) + (ch ^ 48);
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 ^ 48);
}
void print(int x) {
  if (!x) {
    write(s), putchar('\n');
    return;
  }
  s++, print(p[x]), write(x), putchar(32);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int v = read(), c = read(), l = read(), r = read(), f = 0;
    if (l) {
      if (a[make_pair(l, r + c)])
        f = a[make_pair(l, r + c)] + v, p[i] = b[make_pair(l, r + c)];
    } else
      f = v;
    if (r) {
      if (f > a[make_pair(l + c, r)])
        a[make_pair(l + c, r)] = f, b[make_pair(l + c, r)] = i;
    } else if (f > ans)
      ans = f, id = i;
  }
  print(id);
  return 0;
}
