#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int f[4][4];
  cin >> n;
  for (int i = 0; i < 16; i++) {
    cin >> f[i / 4][i % 4];
  }
  int min = 1000000;
  int imin = -1;
  int min1 = 1000000, min2 = 1000000;
  for (int i = 0; i < 4; i++) {
    int minF1 = f[i][0] < f[i][1] ? f[i][0] : f[i][1];
    int minF2 = f[i][2] < f[i][3] ? f[i][2] : f[i][3];
    int minF = minF1 + minF2;
    min1 = min < minF ? min1 : minF1;
    min2 = min < minF ? min2 : minF2;
    imin = min < minF ? imin : i;
    min = min < minF ? min : minF;
  }
  if (min <= n)
    cout << (imin + 1) << " " << min1 << " " << n - min1;
  else
    cout << -1;
  return 0;
}
