#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, v[N], c[N], l[N], r[N], dp[N], pre[N], ans;
map<pair<int, int>, int> m;
void print(int x, int val) {
  if (!x) {
    printf("%d\n", val);
    return;
  }
  print(pre[x], val + 1);
  printf("%d ", x);
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++)
    scanf("%d%d%d%d", &v[i], &c[i], &l[i], &r[i]);
  for (register int i = 1; i <= n; i++) {
    if (!l[i]) {
      dp[i] = v[i];
      if (!m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])])
        m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])] = i;
      else if (dp[i] > dp[m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])]])
        m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])] = i;
    } else {
      if (!m[make_pair(l[i] + c[i] + r[i], l[i])])
        continue;
      else
        pre[i] = m[make_pair(l[i] + c[i] + r[i], l[i])],
        dp[i] = dp[m[make_pair(l[i] + c[i] + r[i], l[i])]] + v[i];
      if (!m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])])
        m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])] = i;
      else if (dp[i] > dp[m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])]])
        m[make_pair(l[i] + r[i] + c[i], l[i] + c[i])] = i;
    }
    if (!r[i] && dp[i] > dp[ans]) ans = i;
  }
  print(ans, 0);
}
