#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, inf = 0x3f3f3f3f;
int n, ans, v[N], c[N], l[N], r[N], dp[N], last[N];
stack<int> st;
void qwq(int x) {
  if (!x) return;
  st.push(x);
  qwq(last[x]);
}
int main() {
  map<pair<int, int>, int> b;
  scanf("%d", &n);
  for (int i = (1), iend = (n); i <= iend; i++) {
    scanf("%d%d%d%d", &v[i], &c[i], &l[i], &r[i]);
    if (!l[i]) dp[i] = v[i];
    if (dp[b[make_pair(l[i], r[i] + c[i])]] > dp[i]) {
      last[i] = b[make_pair(l[i], r[i] + c[i])];
      dp[i] = dp[last[i]] + v[i];
    }
    if (!r[i] && dp[ans] < dp[i]) ans = i;
    b[make_pair(l[i] + c[i], r[i])] =
        dp[b[make_pair(l[i] + c[i], r[i])]] > dp[i]
            ? b[make_pair(l[i] + c[i], r[i])]
            : i;
  }
  qwq(ans);
  printf("%d\n", st.size());
  while (st.size()) {
    printf("%d ", st.top());
    st.pop();
  }
  return 0;
}
