#include <bits/stdc++.h>
using namespace std;
struct truck {
  int l, r, p, v, no;
  void get(int _no) {
    scanf("%d%d%d%d", &v, &p, &l, &r);
    no = _no;
  }
  int sum() { return p + l + r; }
};
vector<truck> V[300001];
vector<int> ans;
int dp[300001], tag[300001], ctag, sv_no[300001], bef[100001], val = -1,
                                                               sv_pos = -1, n;
truck tmp1;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    tmp1.get(i + 1);
    V[tmp1.sum()].push_back(tmp1);
  }
  for (int i = 0; i <= 300000; i++) {
    if (V[i].size() != 0) {
      ctag++;
      tag[0] = ctag, dp[0] = 0;
      sv_no[0] = -1;
      for (int j = 0; j < V[i].size(); j++)
        if (tag[V[i][j].l] == ctag) {
          if (tag[V[i][j].l + V[i][j].p] != ctag ||
              dp[V[i][j].l + V[i][j].p] < (dp[V[i][j].l] + V[i][j].v)) {
            tag[V[i][j].l + V[i][j].p] = ctag;
            dp[V[i][j].l + V[i][j].p] = (dp[V[i][j].l] + V[i][j].v);
            sv_no[V[i][j].l + V[i][j].p] = V[i][j].no;
          }
          bef[V[i][j].no] = sv_no[V[i][j].l];
          if (V[i][j].r == 0 && val < dp[V[i][j].l + V[i][j].p]) {
            val = dp[V[i][j].l + V[i][j].p], sv_pos = V[i][j].no;
          }
        }
    }
  }
  while (sv_pos != -1) {
    ans.push_back(sv_pos);
    sv_pos = bef[sv_pos];
  }
  printf("%d\n", ans.size());
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
