#include <bits/stdc++.h>
using namespace std;
const int MAX_N = int(1e5) + 10;
int n, maxv = 0;
int dp[MAX_N], pre[MAX_N], ans[MAX_N];
map<int, int> g[MAX_N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int v, c, l, r;
    scanf("%d%d%d%d", &v, &c, &l, &r);
    if (r + c < MAX_N && (l == 0 || g[l].find(r + c) != g[l].end())) {
      int tmp = g[l][r + c];
      pre[i] = tmp;
      dp[i] = dp[tmp] + v;
      if (r == 0 && dp[i] > dp[maxv]) maxv = i;
      if (dp[i] > dp[g[l + c][r]]) g[l + c][r] = i;
    }
  }
  int tot = 0;
  while (maxv != 0) {
    ans[tot++] = maxv;
    maxv = pre[maxv];
  }
  printf("%d\n", tot);
  for (int i = tot - 1; i >= 0; --i) printf("%d ", ans[i]);
  return 0;
}
