#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;
long long int getint() {
  long long int ret = 0;
  bool f = 0;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f ^= 1;
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return f ? -ret : ret;
}
using namespace std;
const int MAXN = 100000;
map<pair<int, int>, int> mp;
int ans[MAXN + 10], lst[MAXN + 10], stk[MAXN + 10], top = 0;
int main() {
  int n = getint(), id = 0;
  for (int i = 1; i <= n; ++i) {
    int v = getint(), c = getint(), l = getint(), r = getint();
    if (l == 0) {
      int &t = mp[make_pair(l + c, r)];
      ans[i] = v;
      if (ans[t] < ans[i]) t = i;
    } else {
      int t = mp[make_pair(l, r + c)];
      if (t) {
        lst[i] = t;
        ans[i] = ans[t] + v;
        int &p = mp[make_pair(l + c, r)];
        if (ans[p] < ans[i]) p = i;
      } else
        ans[i] = lst[i] = 0;
    }
    if (r == 0 && ans[i] > ans[id]) id = i;
  }
  for (int u = id; u; u = lst[u]) stk[++top] = u;
  printf("%d\n", top);
  for (int i = top; i >= 1; --i) printf(i == 1 ? "%d\n" : "%d ", stk[i]);
}
