/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

#include <cstdio>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

typedef pair <int, int> pii;

const int N = 15000;

int s, an, bn, cn;
pii a[N], b[N], c[N];

void read( int &n, pii *a ) {
  assert(scanf("%d", &n) == 1 && n <= N);
  forn(i, n)
    scanf("%d", &a[i].first), a[i].second = i;
}

int main() {
  scanf("%d", &s);
  read(an, a);
  read(bn, b);
  read(cn, c);

  sort(b, b + bn);
  sort(c, c + cn);

  int rj = -1, rk = -1;
  forn(i, an) {
    int x = s - a[i].first, k = cn - 1;
    forn(j, bn) {
      while (k && b[j].first + c[k - 1].first >= x)
        k--;
      if (b[j].first + c[k].first == x && (rj == -1 || rj > b[j].second))
        rj = b[j].second, rk = c[k].second;
    }
    if (rj != -1) {
      printf("%d %d %d\n", i, rj, rk);
      return 0;
    }
  }
  puts("-1");
  return 0;
}