#include <bits/stdc++.h>
using namespace std;
namespace fio {
streambuf* in = cin.rdbuf();
char bb[1000000], *s = bb, *t = bb;
inline int read() {
  int x = 0;
  char ch =
      (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF : *s++);
  while (ch < 48)
    ch = (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF
                                                                    : *s++);
  while (ch >= 48)
    x = x * 10 + ch - 48,
    ch = (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF
                                                                    : *s++);
  return x;
}
}  // namespace fio
using fio::read;
map<int, int> dp[100005];
int n, f[100005], pre[100005], as, ans[100005], top;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int v = read(), c = read(), l = read(), r = read();
    if (r + c <= 100000 && (!l || dp[l].find(r + c) != dp[l].end()))
      pre[i] = dp[l][r + c], f[i] = f[pre[i]] + v,
      as = (!r && f[i] > f[as]) ? i : as,
      f[i] > f[dp[l + c][r]] ? dp[l + c][r] = i : 0;
  }
  while (as) ans[++top] = as, as = pre[as];
  printf("%d\n", top);
  while (top) printf("%d ", ans[top--]);
}
