#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
int n;
struct node {
  long long v, l, c, r, id, las;
} a[N];
bool cmp(node x, node y) { return x.l + x.c + x.r < y.l + y.c + y.r; }
vector<int> v[3 * N];
long long dp[3 * N];
long long last[3 * N];
int main() {
  int i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld%lld%lld", &a[i].v, &a[i].c, &a[i].l, &a[i].r);
    v[a[i].c + a[i].l + a[i].r].push_back(i);
    a[i].id = i;
  }
  long long ans = 0, ansi = 0;
  for (int k = 1; k <= 3 * 100000; k++) {
    if (v[k].empty()) continue;
    for (j = 0; j < v[k].size(); j++) {
      int i = v[k][j];
      if (dp[a[i].r + a[i].c] + a[i].v > dp[a[i].r] &&
          (dp[a[i].r + a[i].c] || a[i].l == 0)) {
        dp[a[i].r] = dp[a[i].r + a[i].c] + a[i].v;
      }
    }
    if (dp[0] > ans) {
      ansi = k;
      ans = dp[0];
    }
    for (j = 0; j < v[k].size(); j++) {
      int i = v[k][j];
      dp[a[i].r + a[i].c] = dp[a[i].r] = 0;
    }
  }
  for (j = 0; j < v[ansi].size(); j++) {
    int i = v[ansi][j];
    if (dp[a[i].r + a[i].c] + a[i].v > dp[a[i].r] &&
        (dp[a[i].r + a[i].c] || a[i].l == 0)) {
      dp[a[i].r] = dp[a[i].r + a[i].c] + a[i].v;
      a[i].las = (a[i].l == 0) ? 0 : last[a[i].r + a[i].c];
      last[a[i].r] = i;
      if (dp[0] == ans) {
        break;
      }
    }
  }
  vector<long long> v1;
  j = last[0];
  while (j != 0) {
    v1.push_back(j);
    j = a[j].las;
  }
  cout << v1.size() << endl;
  for (i = v1.size() - 1; i >= 0; i--) printf("%d ", v1[i]);
  printf("\n");
}
