#include <bits/stdc++.h>
using namespace std;
int N, i, j, Ans;
int Opt[100010], V[100010], C[100010], L[100010], R[100010], Pri[100010];
map<int, int> No1[300010], No2[300010];
void print(int i, int j) {
  if (i == 0) {
    printf("%d\n", j);
    return;
  }
  print(Pri[i], j + 1);
  if (j == 0)
    printf("%d\n", i);
  else
    printf("%d ", i);
}
int main() {
  scanf("%d\n", &N);
  for (i = 1; i <= N; i++) scanf("%d%d%d%d\n", V + i, C + i, L + i, R + i);
  for (i = 1; i <= N; i++) {
    if (L[i] == 0)
      Opt[i] = V[i], Pri[i] = 0;
    else if (No1[C[i] + L[i] + R[i]][L[i]] > 0) {
      Opt[i] = No1[C[i] + L[i] + R[i]][L[i]] + V[i];
      Pri[i] = No2[C[i] + L[i] + R[i]][L[i]];
    }
    if (No1[C[i] + L[i] + R[i]][C[i] + L[i]] < Opt[i]) {
      No1[C[i] + L[i] + R[i]][C[i] + L[i]] = Opt[i];
      No2[C[i] + L[i] + R[i]][C[i] + L[i]] = i;
    }
  }
  j = 0;
  for (i = 1; i <= N; i++)
    if (R[i] == 0 && Opt[j] < Opt[i]) j = i;
  print(j, 0);
  return 0;
}
