#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 10;
map<pair<int, int>, int> m;
long long Max[maxn];
long long par[maxn];
long long dp[maxn];
int n;
long long v[maxn], c[maxn], l[maxn], r[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> v[i] >> c[i] >> l[i] >> r[i];
  int cur = 1;
  for (int i = 1; i <= n; ++i)
    if (l[i] == 0) {
      dp[i] = v[i];
      if (m.find(pair<int, int>(c[i] + l[i], r[i])) != m.end()) {
        int ind = m[pair<int, int>(c[i] + l[i], r[i])];
        if (dp[Max[ind]] < dp[i]) Max[ind] = i;
      } else {
        m[pair<int, int>(c[i] + l[i], r[i])] = cur++;
        int ind = cur - 1;
        Max[ind] = i;
      }
    } else {
      if (m.find(pair<int, int>(l[i], c[i] + r[i])) != m.end()) {
        int ind = Max[m[pair<int, int>(l[i], c[i] + r[i])]];
        par[i] = ind;
        dp[i] = dp[ind] + v[i];
        if (m.find(pair<int, int>(c[i] + l[i], r[i])) != m.end()) {
          int ind_ = m[pair<int, int>(c[i] + l[i], r[i])];
          if (dp[Max[ind_]] < dp[i]) Max[ind_] = i;
        } else {
          m[pair<int, int>(c[i] + l[i], r[i])] = cur++;
          ind = cur - 1;
          Max[ind] = i;
        }
      } else
        ;
    }
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    if (r[i] == 0)
      if (dp[i] > dp[ans]) ans = i;
  vector<int> Ans;
  for (int i = ans; i != 0; i = par[i]) Ans.push_back(i);
  cout << Ans.size() << endl;
  for (int i = Ans.size() - 1; i >= 0; --i) cout << Ans[i] << " ";
  cout << endl;
  return 0;
}
