#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const pair<int, int> INF = make_pair(0, 0);
int v[maxn], c[maxn], l[maxn], r[maxn], maxx[3 * maxn];
vector<int> arr[3 * maxn], dp[3 * maxn], pre[3 * maxn];
set<int> all;
vector<int> out;
int main() {
  int n;
  scanf("%d", &n);
  int maxc = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &v[i], &c[i], &l[i], &r[i]);
    int cur = c[i] + l[i] + r[i];
    if (arr[cur].empty()) {
      arr[cur].push_back(0);
      pre[cur].push_back(0);
      dp[cur].push_back(0);
    }
    arr[cur].push_back(i);
    maxc = max(maxc, cur);
  }
  int ans = 0;
  pair<int, int> which = INF;
  memset(maxx, -1, sizeof(maxx));
  for (int i = 1; i <= maxc; i++) {
    if ((int)arr[i].size() == 0) continue;
    int len = (int)arr[i].size() - 1;
    pre[i].resize(len + 1, 0);
    dp[i].resize(len + 1, 0);
    all.clear();
    all.insert(i);
    maxx[i] = 0;
    for (int j = 1; j <= len; j++) {
      int id = arr[i][j];
      int delta = c[id] + r[id];
      int last = maxx[delta];
      if (last == -1) {
        pre[i][j] = dp[i][j] = -1;
        continue;
      }
      pre[i][j] = last;
      int val = dp[i][last] + v[id];
      dp[i][j] = val;
      all.insert(r[id]);
      if (maxx[r[id]] == -1 || val > dp[i][maxx[r[id]]]) maxx[r[id]] = j;
      if (r[id] == 0 && val > ans) {
        ans = val;
        which = make_pair(i, j);
      }
    }
    for (set<int>::iterator it = all.begin(); it != all.end(); it++)
      maxx[*it] = -1;
  }
  while (which.second != 0) {
    out.push_back(arr[which.first][which.second]);
    which.second = pre[which.first][which.second];
  }
  printf("%d\n", (int)out.size());
  for (int i = (int)out.size() - 1; i >= 0; i--)
    printf("%d%c", out[i], (i ? ' ' : '\n'));
  return 0;
}
