#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
inline void getint(int& num) {
  char c;
  bool flag = 0;
  num = 0;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = 1;
  while (c >= '0' && c <= '9') {
    num = num * 10 + c - 48;
    c = getchar();
  }
  if (flag) num = -num;
}
int n, tot, v[N], c[N], l[N], r[N], Ans[N];
map<pair<int, int>, pair<int, int> > dp;
pair<int, int> f[N];
int main() {
  getint(n);
  for (int i = 1; i <= n; i++) {
    getint(v[i]), getint(c[i]);
    getint(l[i]), getint(r[i]);
  }
  int id = 0;
  for (int i = 1; i <= n; i++) {
    pair<int, int> tmp = make_pair(l[i], r[i] + c[i]);
    if (dp.count(tmp))
      f[i] = dp[tmp], f[i].first += v[i];
    else {
      if (l[i])
        continue;
      else
        f[i] = make_pair(v[i], 0);
    }
    tmp = make_pair(l[i] + c[i], r[i]);
    if (!dp.count(tmp))
      dp[tmp] = make_pair(f[i].first, i);
    else if (dp[tmp] < f[i])
      dp[tmp] = make_pair(f[i].first, i);
    if (!r[i]) id = ((!id) || f[i] > f[id]) ? i : id;
  }
  while (id) Ans[++tot] = id, id = f[id].second;
  printf("%d\n", tot);
  for (int i = tot; i; i--) printf("%d%c", Ans[i], i == 1 ? 10 : 32);
  return 0;
}
