#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
int n;
struct Tcxx {
  int v, c, l, r, w, S;
} A[maxn];
namespace Ninit {
inline bool cmp(const Tcxx &a, const Tcxx &b) { return a.S < b.S; }
void init() {
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d%d%d%d", &A[i].v, &A[i].c, &A[i].l, &A[i].r);
    A[i].w = i + 1, A[i].S = A[i].l + A[i].c + A[i].r;
  }
  stable_sort(A, A + n, cmp);
}
}  // namespace Ninit
namespace Nsolve {
struct Tans {
  int v, n, a[maxn];
  inline void push(int x) { a[n++] = x; }
  bool operator<(const Tans &b) const { return v < b.v; }
  void print() {
    int i;
    if (n) sort(a, a + n);
    printf("%d\n", n);
    for (i = 0; i < n; ++i) printf("%d ", a[i]);
    printf("\n");
  }
} ans, res;
namespace Nwork {
struct Tuse {
  int n, a[maxn];
  inline void set() { ++n; }
  inline void cov(int x) { a[x] = n; }
  inline bool at(int x) { return a[x] == n; }
} B;
struct Tstt {
  int v, w;
  Tstt(int _v = -1, int _w = 0) { v = _v, w = _w; }
  bool operator<(const Tstt &b) const { return v < b.v; }
} F[maxn];
int G[maxn];
void solve(int n, Tcxx *A) {
  int i;
  Tcxx *p;
  Tstt Fx;
  B.set();
  F[0].v = 0, F[0].w = 0, B.cov(0);
  for (p = A; p < A + n; ++p) {
    G[p->w] = 0;
    if (!B.at(p->l)) continue;
    if (!B.at(p->l + p->c)) F[p->l + p->c].v = -1, B.cov(p->l + p->c);
    Fx = Tstt(F[p->l].v + p->v, p->w), G[p->w] = F[p->l].w;
    F[p->l + p->c] = max(F[p->l + p->c], Fx);
  }
  if (!B.at(A->S) || F[A->S].v == -1) return;
  res.v = F[A->S].v, res.n = 0;
  for (i = F[A->S].w; i; i = G[i]) res.push(i);
  if (res.n == 27413) cout << "A->S :" << A->S << ' ' << n << endl;
  ans = max(ans, res);
}
}  // namespace Nwork
inline bool cmp(const Tcxx &a, const Tcxx &b) { return a.w < b.w; }
void check() {
  int *i;
  int x, S;
  sort(A, A + n, cmp);
  sort(ans.a, ans.a + ans.n);
  cout << A[45534].S << endl;
  S = A[ans.a[0]].S;
  cout << S << endl;
  for (i = ans.a; i < ans.a + ans.n; ++i) {
    if (A[*i - 1].S != S) cout << *i - 1 << ' ' << A[*i - 1].S << endl;
    if (A[*i - 1].S != S) return cout << "WA1" << endl, ans.print(), void();
  }
  for (x = 0, i = ans.a; i < ans.a + ans.n; ++i) {
    if (x != A[*i - 1].l) return cout << "WA2" << endl, ans.print(), void();
    x += A[*i - 1].c;
    if (S - x != A[*i - 1].r) return cout << "WA3" << endl, ans.print(), void();
  }
  if (x != S) return cout << "WA4" << endl, ans.print(), void();
}
void solve() {
  Tcxx *p, *q;
  ans.v = -1, ans.n = 0;
  for (p = A, q = A; q < A + n; p = q) {
    for (q = p; p->S == q->S && q < A + n; ++q)
      ;
    Nwork::solve(q - p, p);
  }
  if (ans.n == 27413) {
    for (p = A, q = A; q < A + n; p = q) {
      for (q = p; p->S == q->S && q < A + n; ++q)
        ;
      if (q - p > 20000) cout << "T :" << p->S << ' ' << q - p << endl;
    }
    check();
  } else
    ans.print();
}
}  // namespace Nsolve
int main() {
  Ninit::init();
  Nsolve::solve();
  return 0;
}
