#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, v, c, l, r, ans, kek, kurer, e;
map<int, int> q[N * 4], p[N * 4], dp[N * 4];
void dfs(int v) {
  if (v == 0) {
    cout << e << "\n";
    return;
  }
  e++;
  dfs(q[kek][v]);
  cout << v << " ";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v >> c >> l >> r;
    int sum = c + l + r;
    if (l == 0 || (dp[sum].find(l) != dp[sum].end())) {
      int cur = l ? dp[sum][l] : 0;
      cur += v;
      if (cur > dp[sum][l + c]) {
        dp[sum][l + c] = cur;
        p[sum][l + c] = i;
        q[sum][i] = p[sum][l];
      }
      if (r == 0 && cur > ans) {
        ans = cur;
        kurer = i;
        kek = sum;
      }
    }
  }
  dfs(kurer);
}
