#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int v[N], c[N], l[N], r[N];
int n;
struct point {
  int l, r;
  bool operator<(const point& A) const {
    return l < A.l || (l == A.l && r < A.r);
  }
};
map<point, int> mp;
int dp[N];
int pre[N];
void print(int now) {
  if (now == 0) return;
  print(pre[now]);
  printf("%d ", now);
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &v[i], &c[i], &l[i], &r[i]);
  for (int i = 1; i <= n; i++) {
    if (l[i] == 0) {
      dp[i] = v[i];
      if (dp[mp[(point){c[i], r[i]}]] < v[i]) mp[(point){c[i], r[i]}] = i;
    } else {
      if (mp.find((point){l[i], r[i] + c[i]}) != mp.end())
        dp[i] = v[i] + dp[mp[(point){l[i], r[i] + c[i]}]],
        pre[i] = mp[(point){l[i], r[i] + c[i]}];
      if (dp[mp[(point){l[i] + c[i], r[i]}]] < dp[i])
        mp[(point){l[i] + c[i], r[i]}] = i;
    }
  }
  int Max = 0;
  for (int i = 1; i <= n; i++)
    if (dp[i] > dp[Max] && r[i] == 0) Max = i;
  int sum = 0;
  int now = Max;
  while (now) {
    sum++;
    now = pre[now];
  }
  printf("%d\n", sum);
  print(Max);
  return 0;
}
