#include <bits/stdc++.h>
using namespace std;
void read(int &digit) {
  digit = 0;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  bool type = false;
  if (c == '-') type = true, c = getchar();
  for (; c >= '0' && c <= '9'; digit = digit * 10 + c - '0', c = getchar())
    ;
  if (type == true) digit = -digit;
}
int v[100010], c[100010], l[100010], r[100010];
int n, m;
map<pair<int, int>, int> S;
long long f[100010];
bool vis[100010];
int from[100010];
int cnt, ans[100010];
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(v[i]), read(c[i]), read(l[i]), read(r[i]);
  for (int i = 1; i <= n; i++) {
    if (l[i] == 0) {
      f[i] = v[i];
      from[i] = 0;
      int x = c[i], y = r[i];
      int q = S[make_pair(x, y)];
      if (q == 0 || f[q] < f[i]) S[make_pair(x, y)] = i;
      vis[i] = true;
    } else {
      int x = l[i], y = r[i] + c[i];
      int q = S[make_pair(x, y)];
      if (q == 0) continue;
      from[i] = q;
      f[i] = f[q] + v[i];
      x = l[i] + c[i], y = r[i];
      q = S[make_pair(x, y)];
      if (q == 0 || f[q] < f[i]) S[make_pair(x, y)] = i;
      vis[i] = true;
    }
  }
  long long mjy = 0, pos = 0;
  for (int i = 1; i <= n; i++)
    if (r[i] == 0 && vis[i])
      if (mjy < f[i]) mjy = f[i], pos = i;
  while (pos) {
    ans[++cnt] = pos;
    pos = from[pos];
  }
  printf("%d\n", cnt);
  for (int i = cnt; i >= 1; i--) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
