#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, y = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') y = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * y;
}
int n, v[100010], c[100010], l[100010], r[100010], ji[100010], cnt;
struct node {
  int dat, pre;
} dp[100010], ans;
map<int, node> q[200010];
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    v[i] = read(), c[i] = read(), l[i] = read(), r[i] = read();
    if (q[l[i]][r[i] + c[i]].dat + v[i] > dp[i].dat &&
        (q[l[i]][r[i] + c[i]].dat || l[i] == 0)) {
      dp[i].dat = q[l[i]][r[i] + c[i]].dat + v[i];
      dp[i].pre = q[l[i]][r[i] + c[i]].pre;
    }
    if (dp[i].dat > q[l[i] + c[i]][r[i]].dat) {
      q[l[i] + c[i]][r[i]].dat = dp[i].dat;
      q[l[i] + c[i]][r[i]].pre = i;
    }
    if (dp[i].dat > ans.dat && r[i] == 0) {
      ans.pre = i;
      ans.dat = dp[i].dat;
    }
  }
  while (ans.pre) {
    ji[++cnt] = ans.pre;
    ans = dp[ans.pre];
  }
  cout << cnt << ' ' << endl;
  for (int i = cnt; i >= 1; i--) cout << ji[i] << " ";
}
