#include <bits/stdc++.h>
using namespace std;
const int N = 101 * 1001;
int licznosc[N], lewo[N], prawo[N];
int wartosc[N];
map<pair<int, int>, pair<long long, int> > mapa;
int parent[N];
void ustaw(pair<int, int> p, long long val, int ktory) {
  if (mapa.count(p) == 0 || mapa[p].first < val)
    mapa[p] = make_pair(val, ktory);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%d %d %d %d", wartosc + i, licznosc + i, lewo + i, prawo + i);
  }
  for (int i = 0; i < (n); ++i) {
    if (lewo[i] == 0) {
      pair<int, int> p = make_pair(lewo[i] + licznosc[i], prawo[i]);
      ustaw(p, wartosc[i], i);
      parent[i] = -1;
    } else {
      pair<int, int> p = make_pair(lewo[i], prawo[i] + licznosc[i]);
      if (mapa.count(p)) {
        pair<long long, int> old = mapa[p];
        long long kand = wartosc[i] + old.first;
        parent[i] = old.second;
        ustaw(make_pair(lewo[i] + licznosc[i], prawo[i]), kand, i);
      }
    }
  }
  long long res = 0;
  int ktory = -1;
  for (__typeof((mapa).begin()) it = (mapa).begin(); it != (mapa).end(); ++it)
    if (it->first.second == 0 && it->second.first > res) {
      res = it->second.first;
      ktory = it->second.second;
    }
  vector<int> v;
  while (ktory >= 0) {
    v.push_back(ktory);
    ktory = parent[ktory];
  }
  reverse(v.begin(), v.end());
  printf("%d\n", (int)v.size());
  for (int i = 0; i < ((int)v.size()); ++i) {
    if (i) printf(" ");
    printf("%d", v[i] + 1);
  }
  puts("");
  return 0;
}
