#include <bits/stdc++.h>
using namespace std;
long long n, v[100010], c[100010], l[100010], r[100010], dp[100010],
    lst[100010];
map<long long, vector<long long> > mp[100010];
vector<long long> vv, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i] >> c[i] >> l[i] >> r[i];
    mp[l[i]][c[i] + r[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) dp[i] = (l[i] != 0 ? -1 : v[i]), lst[i] = -1;
  for (int i = 0; i < n; i++) {
    if (dp[i] == -1) continue;
    vv = mp[l[i] + c[i]][r[i]];
    if (vv.size() == 0) continue;
    for (int j = vv.size() - 1; j >= 0 && vv[j] > i; j--) {
      if (dp[vv[j]] < dp[i] + v[vv[j]]) {
        dp[vv[j]] = dp[i] + v[vv[j]];
        lst[vv[j]] = i;
      }
    }
  }
  long long mx = 0, pos = -1;
  for (int i = 0; i < n; i++) {
    if (r[i] == 0 && dp[i] > mx) {
      mx = dp[i];
      pos = i;
    }
  }
  while (pos != -1) {
    ans.push_back(pos + 1);
    pos = lst[pos];
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
