#include <bits/stdc++.h>
using namespace std;
map<int, int> f[300010], p[300010], q[300010];
void print(int x, int y, int n) {
  if (y)
    print(x, q[x][y], n + 1), printf("%d ", y);
  else
    printf("%d\n", n);
}
int main() {
  int i, n, x, y, v, c, l, r, s = 0, x1 = 0, y1 = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &v, &c, &l, &r);
    x = l + c + r;
    if (!l || f[x].count(l)) {
      y = (l ? f[x][l] : 0) + v;
      if (y > f[x][l + c]) f[x][l + c] = y, p[x][l + c] = i, q[x][i] = p[x][l];
      if (!r && y > s) s = y, x1 = x, y1 = i;
    }
  }
  print(x1, y1, 0);
  return 0;
}
