#include <bits/stdc++.h>
const int maxl = 110000;
const int maxc = 110000;
const int maxn = 100000;
std::vector<int> avl(maxn, -1), prev(maxn, -2);
std::map<int, int> mvl, mvl_i;
std::vector<int> result;
int get_ans_value;
std::vector<int> get_ans_ans;
void get_ans(int n, const int* v, const int* c, const int* l, const int* r) {
  std::fill_n(&avl[0], n, -1);
  std::fill_n(&prev[0], n, -2);
  int max_lc = l[0] + c[0];
  for (int i = 0; i < n; ++i)
    if (l[i] + c[i] > max_lc) max_lc = l[i] + c[i];
  mvl.clear();
  mvl_i.clear();
  for (int i = 0; i < n; ++i) {
    int ci = c[i], lci = l[i] + ci;
    if (0 == l[i]) {
      avl[i] = v[i];
      prev[i] = -1;
      if (mvl.find(c[i]) == mvl.end() || mvl[c[i]] < v[i]) {
        mvl[c[i]] = v[i];
        mvl_i[c[i]] = i;
      }
    } else if (mvl.find(l[i]) != mvl.end()) {
      avl[i] = mvl[l[i]] + v[i];
      prev[i] = mvl_i[l[i]];
      if (mvl.find(l[i] + c[i]) == mvl.end() ||
          mvl[l[i] + c[i]] <= mvl[l[i]] + v[i]) {
        mvl[l[i] + c[i]] = mvl[l[i]] + v[i];
        mvl_i[l[i] + c[i]] = i;
      }
    }
  }
  int max_i = -1;
  for (int i = 0; i < n; ++i)
    if (r[i] == 0 && avl[i] != -1 && (max_i == -1 || avl[i] > avl[max_i]))
      max_i = i;
  get_ans_ans.clear();
  if (max_i != -1)
    for (int i = max_i; i >= 0; i = prev[i]) get_ans_ans.push_back(i);
  int max_v;
  if (max_i != -1)
    max_v = avl[max_i];
  else
    max_v = 0;
  std::reverse(get_ans_ans.begin(), get_ans_ans.end());
  get_ans_value = max_v;
}
bool magic_less(const std::pair<int, int>& p1, const std::pair<int, int>& p2) {
  if (p1.first != p2.first)
    return p1.first < p2.first;
  else
    return p1.second < p2.second;
}
void permutate(std::vector<int>& a, const std::vector<int>& p) {
  std::vector<int> t(a.size());
  for (int i = 0; i < a.size(); ++i) t[i] = a[p[i]];
  a = t;
}
std::vector<std::pair<int, int> > magic_vector(maxn);
void quick_sort(std::vector<int>& a, std::vector<int>& b, std::vector<int>& c,
                std::vector<int>& d, std::vector<int>& e,
                std::vector<int>& perm) {
  for (int i = 0; i < a.size(); ++i) {
    magic_vector[i].first = a[i];
    magic_vector[i].second = i;
  }
  std::sort(magic_vector.begin(), magic_vector.begin() + a.size(), magic_less);
  perm.resize(a.size());
  for (int i = 0; i < a.size(); ++i) {
    perm[i] = magic_vector[i].second;
    a[i] = magic_vector[i].first;
  }
  permutate(b, perm);
  permutate(c, perm);
  permutate(d, perm);
  permutate(e, perm);
}
void output(std::string prefix, const std::vector<int>& array, bool end_line) {
  std::cout << prefix;
  for (int i = 0; i + 1 < array.size(); ++i) std::cout << array[i] << " ";
  std::cout << array.back();
  if (end_line) std::cout << std::endl;
}
int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> v(n), c(n), l(n), r(n), s(n), p(n), q(n);
  for (int i = 0; i < n; ++i) scanf("%d%d%d%d", &v[i], &c[i], &l[i], &r[i]);
  for (int i = 0; i < n; ++i) s[i] = l[i] + c[i] + r[i];
  quick_sort(s, v, c, l, r, p);
  for (int i = 0; i < n; ++i) q[p[i]] = i;
  int left = 0, right = 0;
  int max_value = 0;
  std::vector<int> max_answer;
  while (left < n) {
    while (right + 1 < n && s[right + 1] == s[right]) right++;
    int csize = right - left + 1;
    get_ans(csize, &v[left], &c[left], &l[left], &r[left]);
    if (get_ans_value > max_value) {
      max_value = get_ans_value;
      max_answer.resize(get_ans_ans.size());
      for (int i = 0; i < get_ans_ans.size(); ++i)
        max_answer[i] = p[left + get_ans_ans[i]];
    }
    left = right + 1;
    right = left;
  }
  printf("%d\n", max_answer.size());
  for (int i = 0; i < max_answer.size(); ++i) printf("%d ", max_answer[i] + 1);
  return 0;
}
