#include <bits/stdc++.h>
using namespace std;
struct Truck {
  int V, C, L, R, Total, Number;
};
bool operator<(Truck A, Truck B) {
  return (A.Total == B.Total) ? (A.Number < B.Number) : (A.Total < B.Total);
}
const int inf = 1000000000;
int Get() {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  int X = c - 48;
  while (c = getchar(), c >= '0' && c <= '9') X = X * 10 + c - 48;
  return X;
}
int main() {
  int N = Get();
  static Truck A[100000];
  for (int i = 0; i < N; i++) {
    A[i].V = Get();
    A[i].C = Get();
    A[i].L = Get();
    A[i].R = Get();
    A[i].Total = A[i].C + A[i].L + A[i].R;
    A[i].Number = i + 1;
  }
  sort(A, A + N);
  int Ans = 0, Start;
  static int DP[100000], Pre[100000];
  static int Best[300001], Last[300001], Time[300001];
  for (int i = 0; i < N; i++) DP[i] = -inf;
  memset(Time, -1, sizeof(Time));
  for (int i = 0, j = 0; i < N; i = j) {
    while (j < N && A[i].Total == A[j].Total) j++;
    for (int k = i; k < j; k++) {
      if (!A[k].L) {
        DP[k] = A[k].V;
        Pre[k] = -1;
      } else if (Time[A[k].L] == i) {
        DP[k] = Best[A[k].L] + A[k].V;
        Pre[k] = Last[A[k].L];
      }
      int X = A[k].L + A[k].C;
      if (DP[k] > Best[X] || Time[X] != i) {
        Time[X] = i;
        Best[X] = DP[k];
        Last[X] = k;
      }
      if (!A[k].R && DP[k] > Ans) {
        Ans = DP[k];
        Start = k;
      }
    }
  }
  vector<int> List;
  int P = Start;
  while (P != -1) {
    List.push_back(A[P].Number);
    P = Pre[P];
  }
  sort(List.begin(), List.end());
  printf("%d\n", (int)List.size());
  for (int i = 0; i < List.size(); i++) {
    printf("%d", List[i]);
    putchar((i + 1 == List.size()) ? '\n' : ' ');
  }
  return 0;
}
