#include <bits/stdc++.h>
using namespace std;
const int Maxx = 100005, Maxn = 2001, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
inline int read() {
  int res = 0, bj = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') bj |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
  return bj ? -res : res;
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 ^ 48);
}
inline void printnum(int x, char ch) {
  if (x < 0) putchar('-'), x = -x;
  print(x), putchar(ch);
}
struct node {
  int x, y;
  inline node(int a = 0, int b = 0) { x = a, y = b; }
  inline bool operator<(const node &tp) const {
    return x == tp.x ? y < tp.y : x < tp.x;
  }
};
map<node, node> mp;
map<node, node>::iterator it;
int pr[Maxx], tp, stk[Maxx];
inline void ckmax(node &x, const node y) { x = x < y ? y : x; }
int main() {
  int n = read(), v, c, l, r, Ans = 0, id = 0;
  for (int i = 1; i <= n; ++i) {
    v = read(), c = read(), l = read(), r = read();
    it = mp.find(node(l, r + c));
    if (it != mp.end())
      v += it->second.x, pr[i] = it->second.y;
    else if (l)
      continue;
    ckmax(mp[node(l + c, r)], node(v, i));
    if (!r && Ans <= v) Ans = v, id = i;
  }
  for (int i = id; i; i = pr[i]) stk[++tp] = i;
  printnum(tp, '\n');
  for (int i = tp; i; --i) printnum(stk[i], ' ');
  return 0;
}
