#include <bits/stdc++.h>
using namespace std;
int n;
int dp[100004], fr[100004];
map<pair<int, int>, pair<int, int> > mp;
int ans, pos, l[100004];
vector<int> res;
void dfs(int p) {
  if (l[p] > 0) dfs(fr[p]);
  res.push_back(p);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v, c, r;
    scanf("%d%d%d%d", &v, &c, &l[i], &r);
    if (l[i] == 0) dp[i] = v;
    pair<int, int> go = make_pair(l[i], r + c);
    if (mp.find(go) != mp.end()) {
      pair<int, int> ret = mp[go];
      ret.first += v;
      if (dp[i] < ret.first) dp[i] = ret.first, fr[i] = ret.second;
    }
    pair<int, int> GO = make_pair(l[i] + c, r), ADD = make_pair(dp[i], i);
    if (dp[i] > 0) mp[GO] = max(mp[GO], ADD);
    if (r == 0 && ans < dp[i]) ans = dp[i], pos = i;
  }
  if (ans < 1) {
    puts("0\n");
    return 0;
  }
  dfs(pos);
  printf("%d\n", res.size());
  for (int i = 0; i < res.size(); i++) printf("%d ", res[i]);
}
