#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, w[N], p[N], L[N], R[N], Ans, sch[N], tim, dp[N], pre[N];
map<int, int> sta[N * 10];
inline int read() {
  int x = 0, o = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
void work2() {
  memset(dp, -63, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    if (sta[L[i] + R[i] + p[i]].count(L[i])) {
      int x = sta[L[i] + R[i] + p[i]][L[i]];
      if (dp[i] < dp[x] + w[i]) dp[i] = dp[x] + w[i], pre[i] = x;
    }
    if (!L[i] && dp[i] < w[i]) dp[i] = w[i];
    if (dp[i] != dp[0]) {
      int x = sta[L[i] + R[i] + p[i]][L[i] + p[i]];
      if (dp[i] > dp[x]) sta[L[i] + R[i] + p[i]][L[i] + p[i]] = i;
    }
  }
  int id = 0;
  for (int i = 1; i <= n; i++)
    if (!R[i] && dp[i] > Ans) id = i, Ans = dp[i];
  while (id) sch[++tim] = id, id = pre[id];
  printf("%d\n", tim);
  for (int i = tim; i >= 1; i--) printf("%d ", sch[i]);
  puts("");
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    w[i] = read(), p[i] = read();
    L[i] = read(), R[i] = read();
  }
  work2();
  return 0;
}
