#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, v, c, l, r, ans, pos, st[N], pre[N];
map<int, int> s[N], p[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &v, &c, &l, &r);
    int a = l, b = r + c, val = s[a][b];
    if (!val && l) continue;
    val += v;
    pre[i] = p[a][b];
    a = c + l, b = r;
    int vals = s[a][b];
    if (vals > val) continue;
    p[a][b] = i, s[a][b] = val;
    if (!r && ans < val) ans = val, pos = i;
  }
  while (pos > 0) st[++st[0]] = pos, pos = pre[pos];
  printf("%d\n", st[0]);
  for (int i = st[0]; i > 0; i--) printf("%d ", st[i]);
  return 0;
}
