#include <bits/stdc++.h>
using namespace std;
static const int MAXN = 2e5 + 10;
map<int, int> ghs[MAXN];
int dp[MAXN], nxt[MAXN], n, head;
int ans[MAXN];
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 (!l || ghs[l].count(r + c)) {
      dp[i] = dp[ghs[l][r + c]] + v;
      nxt[i] = ghs[l][r + c];
      if (!r && dp[i] > dp[head]) head = i;
      if (dp[i] > dp[ghs[l + c][r]]) ghs[l + c][r] = i;
    }
  }
  int idx = 0;
  for (int i = head; i; i = nxt[i]) ans[idx++] = i;
  printf("%d\n", idx);
  for (int i = idx - 1; i >= 0; i--) printf("%d ", ans[i]);
  return 0;
}
