#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
int vv[1000000];
int cc[1000000];
int ll[1000000];
int rr[1000000];
int d[1000000];
int bc[1000000];
int bc2[1000000];
int f[1000000];
int n;
vector<int> aa;
void bct(int n) {
  if (ll[n] != 0) bct(bc2[n]);
  aa.push_back(n);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d", &vv[i], &cc[i], &ll[i], &rr[i]);
    a.push_back(make_pair(cc[i] + ll[i] + rr[i], i));
  }
  sort(a.begin(), a.end());
  int pr = -1;
  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if ((i == n - 1) || (a[i].first != a[i + 1].first)) {
      cnt++;
      d[0] = 0;
      f[0] = cnt;
      f[a[i].first] = cnt;
      d[a[i].first] = 0;
      for (int j = pr + 1; j <= i; j++) {
        if (f[ll[a[j].second]] == cnt) {
          if (f[ll[a[j].second] + cc[a[j].second]] != cnt) {
            f[ll[a[j].second] + cc[a[j].second]] = cnt;
            d[ll[a[j].second] + cc[a[j].second]] = 0;
          }
          if (d[ll[a[j].second]] + vv[a[j].second] >
              d[ll[a[j].second] + cc[a[j].second]]) {
            d[ll[a[j].second] + cc[a[j].second]] =
                d[ll[a[j].second]] + vv[a[j].second];
            bc[ll[a[j].second] + cc[a[j].second]] = a[j].second;
            bc2[a[j].second] = bc[ll[a[j].second]];
          }
          if (d[ll[a[j].second] + cc[a[j].second]] == 0) {
            f[ll[a[j].second] + cc[a[j].second]] = cnt - 1;
          }
        }
      }
      if (d[a[i].first] > ans) {
        ans = d[a[i].first];
        aa.clear();
        bct(bc[a[i].first]);
      }
      pr = i;
    }
  }
  printf("%d\n", aa.size());
  for (int i = 0; i < aa.size(); i++) {
    printf("%d ", aa[i] + 1);
  }
}
