Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...

There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.

In order to pass through a guardpost, one needs to bribe both guards.

The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.

Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!


-----Input-----

The first line of the input contains integer n (1 ≤ n ≤ 10^5) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 10^5) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.


-----Output-----

In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line. 

The guardposts are numbered from 1 to 4 according to the order given in the input.

If there are multiple solutions, you can print any of them.


-----Examples-----
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9

Output
1 5 5

Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8

Output
3 4 6

Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3

Output
-1



-----Note-----

Explanation of the first example.

The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.

Explanation of the second example.

Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
def arr_inp():
	return [[int(x) for x in stdin.readline().split()] for i in range(4)]
from sys import stdin
(n, a) = (int(input()), arr_inp())
for i in range(4):
	if sum(a[i][0::2]) <= n:
		exit(print(i + 1, a[i][0], n - a[i][0]))
	if sum(a[i][1::2]) <= n:
		exit(print(i + 1, a[i][1], n - a[i][1]))
	if sum(a[i][1:3]) <= n:
		exit(print(i + 1, a[i][1], n - a[i][1]))
	if a[i][0] + a[i][3] <= n:
		exit(print(i + 1, a[i][0], n - a[i][0]))
print(-1)


import sys
import math
import itertools
import functools
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
d = [li() for i in range(4)]
for i in range(4):
	if min(d[i][:2]) + min(d[i][2:]) <= n:
		exit(print(i + 1, min(d[i][:2]), n - min(d[i][:2])))
print(-1)


for _ in range(1):
	n = int(input())
	ans = 10 ** 9
	v = -1
	for i in range(4):
		(a, b, c, d) = map(int, input().split())
		x = min(a, b)
		y = min(c, d)
		if x + y > n:
			continue
		y += n - x - y
		print(i + 1, x, y)
		break
	else:
		print(-1)


n = int(input())
a = []
for i in range(4):
	a.append(list(map(int, input().split())))
for i in range(4):
	if min(a[i][:2]) + min(a[i][2:]) <= n:
		print(i + 1, min(a[i][:2]), n - min(a[i][:2]))
		exit(0)
print(-1)


import sys
import math
n = int(sys.stdin.readline())
for i in range(4):
	(a, b, c, d) = [int(x) for x in sys.stdin.readline().split()]
	v1 = min(a, b)
	v2 = min(c, d)
	if n - v1 >= v2:
		print(str(i + 1) + ' ' + str(v1) + ' ' + str(n - v1))
		exit()
print(-1)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = [rr() for i in range(4)]
a = [0] * 4
for i in range(4):
	a[i] = min(arr[i][0], arr[i][1]) + min(arr[i][2], arr[i][3])
for i in range(4):
	if a[i] <= n:
		x = min(arr[i][0], arr[i][1])
		y = n - x
		print(i + 1, x, y)
		exit()
print(-1)


n = int(input())
M = [list(map(int, input().split())) for i in range(4)]
t = 0
for x in M:
	t += 1
	if min(x[0], x[1]) + min(x[2], x[3]) > n:
		continue
	else:
		print(t, min(x[0], x[1]), n - min(x[0], x[1]))
		exit()
print(-1)


n = int(input())
flag = True
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	if a + c <= n:
		print(i + 1, a, n - a)
		flag = False
		break
	elif a + d <= n:
		print(i + 1, a, n - a)
		flag = False
		break
	elif b + c <= n:
		print(i + 1, b, n - b)
		flag = False
		break
	elif b + d <= n:
		print(i + 1, b, n - b)
		flag = False
		break
if flag:
	print(-1)


__author__ = 'Lipen'

def actions(n, data):
	for i in range(4):
		v = data[i]
		x = min(v[0], v[1])
		y = min(v[2], v[3])
		if x + y <= n:
			return '{} {} {}'.format(i + 1, x, n - x)
	return -1

def main():
	n = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	a3 = list(map(int, input().split()))
	a4 = list(map(int, input().split()))
	print(actions(n, [a1, a2, a3, a4]))
main()


n = int(input())
mi = (1000000.0, 1000000.0)
imi = -1
for i in range(4):
	m = tuple(map(int, input().split()))
	if min(m[0], m[1]) + min(m[2], m[3]) <= n:
		if min(m[0], m[1]) + min(m[2], m[3]) < mi[0] + mi[1]:
			if n - min(m[0], m[1]) >= min(m[2], m[3]):
				mi = (min(m[0], m[1]), n - min(m[0], m[1]))
			else:
				mi = (n - min(m[2], m[3]), min(m[2], m[3]))
			imi = i + 1
if imi == -1:
	print(imi)
else:
	print(imi, mi[0], mi[1])


n = int(input())
a = [[], [], [], []]
for i in range(4):
	a[i] = list(map(int, input().split()))
ans = [-1]
flag = False
for i in range(4):
	for j in range(2):
		for k in range(2, 4):
			if a[i][j] + a[i][k] <= n:
				flag = True
				ans = [i + 1, a[i][j], n - a[i][j]]
				break
		if flag:
			break
	if flag:
		break
for i in ans:
	print(i)


def vahta(x, lst):
	for elem in lst:
		(ra, rb) = (min(elem[0], elem[1]), min(elem[2], elem[3]))
		if ra + rb <= x:
			return (lst.index(elem) + 1, ra, x - ra)
	return [-1]
n = int(input())
a = list()
for i in range(4):
	t = [int(j) for j in input().split()]
	a.append(t)
print(*vahta(n, a))


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
n = INT()
v = []
for i in range(4):
	m = n
	(a, b, c, d) = MAP()
	k1 = min(a, b)
	m -= k1
	f = 1
	if m <= 0:
		f = 0
	if f != 0:
		k2 = min(c, d)
		if m >= k2:
			v.append([k1, m, i + 1])
if len(v) == 0:
	print('-1')
else:
	print(v[0][2], v[0][0], v[0][1])


def read_args():
	n = int(input())
	guards = []
	for i in range(4):
		a = list(map(int, input().split()))
		guards.append(get_couples(a))
	return (n, guards)

def get_couples(a):
	return [(a[0], a[2]), (a[0], a[3]), (a[1], a[2]), (a[1], a[3])]

def get_guards(n, guards):
	index = 1
	for guard in guards:
		for couple in guard:
			if couple[0] + couple[1] <= n:
				return str(index) + ' ' + str(couple[0]) + ' ' + str(n - couple[0])
		index += 1
	return -1

def main():
	(n, guards) = read_args()
	print(get_guards(n, guards))
main()


n = int(input())
flag = 0
l = []
for i in range(4):
	(a, c, b, d) = map(int, input().split())
	if a + b <= n:
		flag = 1
		l.append(a)
		l.append(b)
		l.append(i + 1)
	elif c + d <= n:
		flag = 1
		l.append(c)
		l.append(d)
		l.append(i + 1)
	elif a + d <= n:
		flag = 1
		l.append(a)
		l.append(d)
		l.append(i + 1)
	elif b + c <= n:
		flag = 1
		l.append(b)
		l.append(c)
		l.append(i + 1)
if flag == 1:
	print(l[2], end=' ')
	print(l[0], end=' ')
	print(n - l[0], end=' ')
else:
	print(-1)


Money = int(input())
for i in range(4):
	X = list(map(int, input().split()))
	if min(X[0], X[1]) + min(X[2], X[3]) <= Money:
		print(i + 1, min(X[0], X[1]), Money - min(X[0], X[1]))
		exit()
print(-1)


n = int(input())
guardp_ = [list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))]
for i in range(4):
	if guardp_[i][0] + guardp_[i][3] <= n:
		print(i + 1, guardp_[i][0], n - guardp_[i][0])
		exit()
	elif guardp_[i][1] + guardp_[i][2] <= n:
		print(i + 1, guardp_[i][1], n - guardp_[i][1])
		exit()
	elif guardp_[i][0] + guardp_[i][2] <= n:
		print(i + 1, guardp_[i][0], n - guardp_[i][0])
		exit()
	elif guardp_[i][1] + guardp_[i][3] <= n:
		print(i + 1, guardp_[i][1], n - guardp_[i][1])
		exit()
print(-1)


import sys

def readInputs():
	global budget, prices
	budget = int(f.readline())
	prices = []
	for _ in range(4):
		(a1, b1, a2, b2) = map(int, f.readline().split())
		prices += [((a1, b1), (a2, b2))]

def isPartOk(a, b):
	for i in range(4):
		((a1, b1), (a2, b2)) = prices[i]
		if (a >= a1 or a >= b1) and (b >= a2 or b >= b2):
			return i + 1
	return -1

def solve():
	for a in range(1, budget):
		res = isPartOk(a, budget - a)
		if res != -1:
			return ' '.join([str(res), str(a), str(budget - a)])
	return -1

def main():
	global f
	f = sys.stdin
	readInputs()
	print(solve())
main()


def solve():
	n = int(input())
	for i in range(1, 5):
		(a, b, c, d) = map(int, input().split())
		if min(a, b) + min(c, d) <= n:
			print(i, min(a, b), n - min(a, b))
			exit()
	print(-1)
solve()


n = int(input())
L1 = list(map(int, input().split()))
L2 = list(map(int, input().split()))
L3 = list(map(int, input().split()))
L4 = list(map(int, input().split()))
if min(L1[0], L1[1]) + min(L1[2], L1[3]) <= n:
	print(1, min(L1[0], L1[1]), n - min(L1[0], L1[1]))
elif min(L2[0], L2[1]) + min(L2[2], L2[3]) <= n:
	print(2, min(L2[0], L2[1]), n - min(L2[0], L2[1]))
elif min(L3[0], L3[1]) + min(L3[2], L3[3]) <= n:
	print(3, min(L3[0], L3[1]), n - min(L3[0], L3[1]))
elif min(L4[0], L4[1]) + min(L4[2], L4[3]) <= n:
	print(4, min(L4[0], L4[1]), n - min(L4[0], L4[1]))
else:
	print(-1)


n = int(input())
m_min = n + 1
tmp_min = n + 1
m_i = 0
j = 0
b = 0
c = 0
for i in range(4):
	j += 1
	a = list(map(int, input().split()))
	temp_min = min(a[0], a[1]) + min(a[2], a[3])
	m_min = min(m_min, temp_min)
	if m_min == temp_min:
		m_i = j
		b = min(a[0], a[1])
		c = min(a[2], a[3])
if m_min > n:
	print('-1')
else:
	print(m_i, b, n - b)


n = int(input())
ans = None
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	if min(a, b) + min(c, d) > n:
		continue
	ans = [i + 1, min(a, b), n - min(a, b)]
if ans is None:
	ans = [-1]
print(*ans)


n = int(input())
a = [list(map(int, input().split())) for i in range(4)]
b = []
c = []
d = []
for i in range(4):
	b.append(min(a[i][:2]))
	b.append(min(a[i][2:]))
	b.insert(0, sum(b))
	d.append(b[0])
	c.append(b)
	b = []
k = d.index(min(d))
if c[k][0] <= n:
	print(k + 1, c[k][1], n - c[k][1])
else:
	print(-1)


n = int(input())
ans = 1
d = {}
for i in range(4):
	d[i + 1] = list(map(int, input().split()))
g = 1
k = 0
for i in range(1, 5):
	a1 = min(d[i][0], d[i][1])
	a2 = min(d[i][2], d[i][3])
	if a1 + a2 <= n:
		g = i
		k = 1
		break
if k == 0:
	print(-1)
else:
	print(g, a1, n - a1)


n = int(input())
lista = []
for i in range(4):
	lista.append(input().split())
	aux = [int(i) for i in lista[-1]]
	lista[-1] = aux
flag = 0
for i in range(4):
	m1 = min(lista[i][0], lista[i][1])
	m2 = min(lista[i][2], lista[i][3])
	if m1 + m2 <= n:
		print(i + 1, end=' ')
		print(m1, end=' ')
		print(n - m1)
		flag = 1
		break
if flag == 0:
	print(-1)


n = int(input())
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	a = min(a, b)
	c = min(c, d)
	if a + c <= n:
		print(i + 1, a, n - a)
		break
else:
	print(-1)


n = int(input())
flag = 0
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	f = n - min(a, b) - min(c, d)
	if f >= 0 and flag == 0:
		print(i + 1, min(a, b), n - min(a, b))
		flag = 1
if flag == 0:
	print(-1)


n = int(input())
arr = []
for i in range(0, 4):
	a = [int(x) for x in input().split()]
	arr.append(a)
found = False
for a in arr:
	m1 = min(a[0], a[1])
	m2 = min(a[2], a[3])
	if m1 + m2 <= n:
		found = True
		print(str(arr.index(a) + 1) + ' ' + str(m1) + ' ' + str(n - m1))
		break
if found == False:
	print('-1')


n = int(input())
guards = []
pos = 0
for i in range(4):
	guardpost = list(map(int, input().split(' ')))
	if i == 0:
		guards = guardpost
	elif sum(guards) > sum(guardpost) and guardpost.count(n) <= 0:
		guards = guardpost
		pos = i
guard1 = min(guards[0], guards[1])
guard2 = min(guards[2], guards[3])
if guard1 >= n or guard2 > n - guard1:
	print(-1)
else:
	print(pos + 1, guard1, n - guard1)


def min_sum(s):
	a = (s[0] + s[2], 0, 2)
	b = (s[0] + s[3], 0, 3)
	c = (s[1] + s[2], 1, 2)
	d = (s[1] + s[3], 1, 3)
	return min(a, b, c, d)

def free_vahta(a, b, c, d):
	if a <= b and a <= c and (a <= d):
		return 0
	if b <= a and b <= c and (b <= d):
		return 1
	if c <= b and c <= a and (c <= d):
		return 2
	if d <= b and d <= c and (d <= a):
		return 3
price = int(input())
vahta = []
vahta.append(list(map(int, input().split())))
vahta.append(list(map(int, input().split())))
vahta.append(list(map(int, input().split())))
vahta.append(list(map(int, input().split())))
min_sum_vahta = []
min_sum_vahta.append(min_sum(vahta[0]))
min_sum_vahta.append(min_sum(vahta[1]))
min_sum_vahta.append(min_sum(vahta[2]))
min_sum_vahta.append(min_sum(vahta[3]))
a = min_sum_vahta
num = free_vahta(a[0][0], a[1][0], a[2][0], a[3][0])
if a[num][0] > price:
	print(-1)
else:
	print(num + 1, vahta[num][a[num][1]], price - vahta[num][a[num][1]])


n = int(input())
a = list()
for _ in range(4):
	a.append([int(i) for i in input().split()])
for (i, c) in enumerate(a):
	c[0] = n - c[0]
	c[1] = n - c[1]
	if c[0] >= min(c[2:4]):
		print(i + 1, n - c[0], c[0])
		break
	if c[1] >= min(c[2:4]):
		print(i + 1, n - c[1], c[1])
		break
else:
	print(-1)


N = int(input())
ans = -1
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	if min(a, b) + min(c, d) <= N:
		ans = 1
		print(i + 1, end=' ')
		print(min(a, b), end=' ')
		print(N - min(a, b))
		break
if ans == -1:
	print(ans)


n = int(input())
flag = False
for i in range(4):
	l = [int(i) for i in input().split()]
	if not flag and n >= min(l[0], l[1]) + min(l[2], l[3]):
		print(i + 1, min(l[0], l[1]), n - min(l[0], l[1]))
		flag = True
if not flag:
	print(-1)


n = int(input())
s = []
for _ in range(4):
	s.append(list(map(int, input().split())))
a = -1
b = -1
c = -1
for i in range(4):
	x1 = min(s[i][0], s[i][1])
	x2 = min(s[i][2], s[i][3])
	if x1 + x2 > n:
		continue
	else:
		a = i + 1
		b = x1
		c = n - x1
		break
if a < 0:
	print(-1)
else:
	print(a, b, c)


n = int(input())
for i in range(1, 5):
	(a, b, c, d) = list(map(int, input().split()))
	(m1, m2) = (min(a, b), min(c, d))
	if m1 + m2 > n:
		continue
	if m2 <= n - m1:
		print(i, m1, n - m1)
		exit()
	if m1 <= n - m2:
		print(i, n - m2, m2)
print(-1)


def guardpost(m, cash):
	for v in range(4):
		a = m[v][0]
		b = m[v][1]
		c = m[v][2]
		d = m[v][3]
		minimo = min(a, b) + min(c, d)
		if minimo <= cash:
			print(str(v + 1) + ' ' + str(min(a, b)) + ' ' + str(cash - min(a, b)))
			return None
	print('-1')
	return None
cash = int(input())
matriz = []
for i in range(4):
	matriz.append([int(item) for item in input().split()])
guardpost(matriz, cash)


n = int(input())
w = 0
for i in range(4):
	l = list(map(int, input().split()))
	k = i + 1
	if l[0] + l[2] <= n:
		w = 1
		print(k, l[0], n - l[0])
		break
	elif l[0] + l[3] <= n:
		w = 1
		print(k, l[0], n - l[0])
		break
	elif l[1] + l[2] <= n:
		w = 1
		print(k, l[1], n - l[1])
		break
	elif l[1] + l[3] <= n:
		w = 1
		print(k, l[1], n - l[1])
		break
for j in range(k, 4):
	list(map(int, input().split()))
if not w:
	print(-1)


def search_guardports(guardports, n):
	for i in range(4):
		for k in range(2):
			for j in range(2, 4):
				if guardports[i][j] + guardports[i][k] <= n:
					return [i + 1, guardports[i][k], n - guardports[i][k]]
	return []
n = int(input())
guardports = []
for _ in range(4):
	guardports.append([int(x) for x in input().split()])
res = search_guardports(guardports, n)
if res:
	print(' '.join(map(str, res)))
else:
	print(-1)


n = int(input())
for x in range(4):
	(a, b, c, d) = map(int, input().split())
	k1 = min(a, b)
	k2 = min(c, d)
	ans = -1
	con = 0
	while True:
		if n - k1 >= 0:
			if n - k1 >= k2:
				ans = [x + 1, k1, n - k1]
				con = 1
				break
			else:
				k1 += 1
		else:
			break
	if con:
		print(*ans)
		break
else:
	print(ans)


import sys
n = int(input())
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	if min(a, b) + min(c, d) <= n:
		print('{} {} {}'.format(i + 1, min(a, b), n - min(a, b)))
		sys.exit(0)
print(-1)


n = int(input())
gp1 = input().split(' ')
gp2 = input().split(' ')
gp3 = input().split(' ')
gp4 = input().split(' ')
i = 0
while i < 4:
	gp1[i] = int(gp1[i])
	gp2[i] = int(gp2[i])
	gp3[i] = int(gp3[i])
	gp4[i] = int(gp4[i])
	i += 1
lista = [gp1, gp2, gp3, gp4]
i = 1
for (p_num, gpt) in enumerate(lista):
	if gpt[0] <= gpt[1]:
		min1 = gpt[0]
	else:
		min1 = gpt[1]
	if gpt[2] <= gpt[3]:
		min2 = gpt[2]
	else:
		min2 = gpt[3]
	if min1 + min2 <= n:
		print(p_num + 1, end=' ')
		print(min1, end=' ')
		print(min2 + (n - min1 - min2), end=' ')
		break
	i += 1
if i == 5:
	print(-1)


def readln():
	return tuple(map(int, input().split()))

def main():
	(n,) = readln()
	for _ in range(4):
		(a, b, c, d) = readln()
		a = min(a, b)
		c = min(c, d)
		if a + c <= n:
			print(_ + 1, a, n - a)
			return
	print(-1)
main()


import sys
input = sys.stdin.readline
n = int(input())
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
z = min(a, b)
y = min(c, d)
if z + y <= n:
	print(1, z, n - z)
	quit()
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
z = min(a, b)
y = min(c, d)
if z + y <= n:
	print(2, z, n - z)
	quit()
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
z = min(a, b)
y = min(c, d)
if z + y <= n:
	print(3, z, n - z)
	quit()
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
z = min(a, b)
y = min(c, d)
if z + y <= n:
	print(4, z, n - z)
	quit()
print(-1)


n = int(input())
for _ in range(4):
	(a, b, c, d) = map(int, input().split())
	for i in [a, b]:
		for j in [c, d]:
			if i + j <= n:
				print(_ + 1, i, n - i)
				exit(0)
print(-1)


n = int(input())
i = 0
val1 = val2 = float('inf')
for z in range(4):
	(a, b, c, d) = map(int, input().split())
	x1 = min(a, b)
	x2 = min(c, d)
	if x1 + x2 < val1 + val2:
		val1 = x1
		val2 = x2
		i = z + 1
if val1 + val2 > n:
	print(-1)
else:
	print(i, val1, max(val2, n - val1))


n = int(input())
ans = -1
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	if min(a, b) + min(c, d) <= n:
		ans = [i + 1, min(a, b), n - min(a, b)]
if ans == -1:
	print(-1)
else:
	for i in range(3):
		print(ans[i], end=' ')


n = int(input())
for g in range(4):
	i = list(map(int, input().split()))
	(a, b) = (min(i[:2]), min(i[2:]))
	if a + b <= n:
		print(g + 1, a, n - a)
		break
else:
	print(-1)


n = int(input())
w = False
arr = []
for i in range(4):
	arr.append([int(x) for x in input().split()])
for i in range(4):
	(a, b, c, d) = arr[i]
	m1 = min(a, b)
	m2 = min(c, d)
	if m1 + m2 <= n:
		print(str(i + 1) + ' ' + str(m1) + ' ' + str(n - m1))
		w = True
		break
if not w:
	print(-1)


p = int(input())
l = []
(a1, b1, c1, d1) = map(int, input().split())
(a2, b2, c2, d2) = map(int, input().split())
(a3, b3, c3, d3) = map(int, input().split())
(a4, b4, c4, d4) = map(int, input().split())
a11 = min(a1, b1) + min(c1, d1)
a22 = min(a2, b2) + min(c2, d2)
a33 = min(a3, b3) + min(c3, d3)
a44 = min(a4, b4) + min(c4, d4)
l.append(a11)
l.append(a22)
l.append(a33)
l.append(a44)
a = 1000
for i in range(4):
	if l[i] <= p:
		a = i
		break
	else:
		a = 1000
if a == 0:
	print(a + 1, min(a1, b1), p - min(a1, b1))
elif a == 1:
	print(a + 1, min(a2, b2), p - min(a2, b2))
elif a == 2:
	print(a + 1, min(a3, b3), p - min(a3, b3))
elif a == 3:
	print(a + 1, min(a4, b4), p - min(a4, b4))
else:
	print('-1')


a = int(input())
d = ''
for x in range(1, 5):
	c = list(map(int, input().split()))
	if d == '':
		if c[0] + c[2] <= a:
			d += str(x) + ' ' + str(c[0]) + ' ' + str(a - c[0])
		elif c[1] + c[3] <= a:
			d += str(x) + ' ' + str(c[1]) + ' ' + str(a - c[1])
		elif c[1] + c[2] <= a:
			d += str(x) + ' ' + str(c[1]) + ' ' + str(a - c[1])
		elif c[0] + c[3] <= a:
			d += str(x) + ' ' + str(c[0]) + ' ' + str(a - c[0])
if d == '':
	print(-1)
else:
	print(d)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
n = inp()
a = []
for i in range(4):
	a.append(inlist() + [i + 1])
a = sorted(a, key=lambda d: min(d[0], d[1]) + min(d[2], d[3]))
b = a[0]
if min(b[0], b[1]) + min(b[2], b[3]) > n:
	print(-1)
else:
	c1 = min(b[0], b[1])
	c2 = n - c1
	print(b[4], c1, c2)


def main():
	n = int(input())
	g = []
	for i in range(4):
		g.append(list(map(int, input().split(' '))))
	for i in range(4):
		a = min(g[i][0], g[i][1])
		b = min(g[i][2], g[i][3])
		if a + b <= n:
			return '{} {} {}'.format(i + 1, a, b + (n - a - b))
	return -1
print(main())


n = int(input())
for i in range(4):
	(a, b, c, d) = list(map(int, input().split()))
	if min(a, b) + min(c, d) <= n:
		print(i + 1, min(a, b), n - min(a, b))
		exit()
	elif i == 3:
		print('-1')


n = int(input())
guardposts = []
for i in range(4):
	guardposts.append([int(i) for i in input().split()])
achou = False
for i in range(4):
	for j in range(2):
		for k in range(2, 4):
			if guardposts[i][j] + guardposts[i][k] <= n:
				print(i + 1, guardposts[i][j], n - guardposts[i][j], sep=' ')
				achou = True
				break
		if achou:
			break
	if achou:
		break
if not achou:
	print(-1)


import itertools as it
n = int(input())
res = None
for i in range(4):
	a = list(map(int, input().split()))
	for v in list(it.product(a[:2], a[2:])):
		if sum(v) <= n:
			res = [i + 1, v[0], n - v[0]]
			break
	if res is not None:
		break
print(-1 if res is None else ' '.join(map(str, res)))


from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
n = RI()[0]
ind = 0
(ans1, ans2) = (10 ** 6, 10 ** 6)
for i in range(4):
	(a, b, c, d) = RI()
	a = min(a, b)
	c = min(c, d)
	if a + c < ans1 + ans2:
		ind = i + 1
		ans1 = a
		ans2 = c
if n - ans1 < ans2:
	print(-1)
else:
	print(ind, ans1, n - ans1)


n = int(input())
for i in range(4):
	u = 0
	(a, b, c, d) = map(int, input().split())
	e = min(a, b)
	f = min(c, d)
	if e + f <= n:
		print(i + 1, e, n - e)
		u = 1
		break
if u == 0:
	print('-1')


def return_solution(posto, dinheiro):
	presentes = []
	for presente_a in posto[:2]:
		for presente_b in posto[2:]:
			if presente_a + presente_b <= dinheiro:
				presentes.append(presente_a)
				presentes.append(presente_b)
				break
	if not presentes:
		return (False, None)
	else:
		return (True, [presentes[0], dinheiro - presentes[0]])
dinheiro = int(input())
postos = []
for p in range(4):
	postos.append([int(i) for i in input().split()])
solution_found = False
for posto in range(len(postos)):
	ans = return_solution(postos[posto], dinheiro)
	if ans[0]:
		print(posto + 1, ans[1][0], ans[1][1])
		solution_found = True
		break
if not solution_found:
	print(-1)


n = int(input())
for i in range(4):
	(a, b, *l) = [int(x) for x in input().split()]
	for c in [a, b]:
		for d in l:
			if c + d <= n:
				print(i + 1, c, n - c)
				exit()
print(-1)


n = int(input())
arr = [list(map(int, input().split())) for _ in range(4)]
ans = -1
for i in range(4):
	for j in [0, 1]:
		for k in [2, 3]:
			val = arr[i][j] + arr[i][k]
			if val <= n:
				ans = i
				a = arr[i][j]
				b = n - arr[i][j]
if ans == -1:
	print(-1)
else:
	print(ans + 1, a, b)


n = int(input())
guards = []
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	guards.append([a, b, c, d])
for i in range(4):
	g1c = guards[i][0]
	g1j = guards[i][1]
	g2c = guards[i][2]
	g2j = guards[i][3]
	if g1c + g2c <= n and g2c <= n - g1c:
		print(i + 1, g1c, n - g1c)
		break
	elif g1c + g2j <= n and g2j <= n - g1c:
		print(i + 1, g1c, n - g1c)
		break
	elif g1j + g2c <= n and g2c <= n - g1j:
		print(i + 1, g1j, n - g1j)
		break
	elif g1j + g2j <= n and g2j <= n - g1j:
		print(i + 1, g1j, n - g1j)
		break
	elif i == 3:
		print(-1)


n = int(input())
l1 = [int(v) for v in input().split()]
l2 = [int(v) for v in input().split()]
l3 = [int(v) for v in input().split()]
l4 = [int(v) for v in input().split()]
if min(l1[0], l1[1]) + min(l1[2], l1[3]) <= n:
	print('1 %d %d' % (min(l1[0], l1[1]), n - min(l1[0], l1[1])))
elif min(l2[0], l2[1]) + min(l2[2], l2[3]) <= n:
	print('2 %d %d' % (min(l2[0], l2[1]), n - min(l2[0], l2[1])))
elif min(l3[0], l3[1]) + min(l3[2], l3[3]) <= n:
	print('3 %d %d' % (min(l3[0], l3[1]), n - min(l3[0], l3[1])))
elif min(l4[0], l4[1]) + min(l4[2], l4[3]) <= n:
	print('4 %d %d' % (min(l4[0], l4[1]), n - min(l4[0], l4[1])))
else:
	print('-1')


import sys
n = int(sys.stdin.readline())
A = []
t = 0
for i in range(1, 5):
	A.append(list(map(int, sys.stdin.readline().split())))
for i in range(0, 4):
	if A[i][0] + A[i][2] <= n:
		print(i + 1, A[i][0], n - A[i][0])
		t = 1
		break
	elif A[i][0] + A[i][3] <= n:
		print(i + 1, A[i][0], n - A[i][0])
		t = 1
		break
	elif A[i][1] + A[i][2] <= n:
		print(i + 1, A[i][1], n - A[i][1])
		t = 1
		break
	elif A[i][1] + A[i][3] <= n:
		print(i + 1, A[i][1], n - A[i][1])
		t = 1
		break
if t == 0:
	print(-1)


n = int(input())
l = []
for i in range(4):
	l.append(list(map(int, input().split())))
j = -1
m = 0
q = 0
for i in range(4):
	a = l[i][0]
	b = l[i][1]
	c = l[i][2]
	d = l[i][3]
	if min(a, b) + min(c, d) <= n:
		j = i + 1
		m = min(a, b)
		q = n - min(a, b)
		break
if j < 0:
	print(j)
else:
	print(j, m, q)


n = int(input())
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	e = min(a, b)
	f = min(c, d)
	if e + f <= n:
		print(i + 1, e, n - e)
		exit()
print(-1)


import sys

def i():
	return sys.stdin.readline()[:-1]
n = int(i())
done = False
for x in range(4):
	if not done:
		(a, b, c, d) = map(int, i().split())
		first = min(a, b)
		second = min(c, d)
		if first + second <= n:
			print(x + 1, first, n - first)
			done = True
if not done:
	print(-1)


def main():
	n = int(input())
	for _ in range(1, 5):
		(a, b, c, d) = map(int, input().split())
		for (x, y) in ((a, c), (a, d), (b, c), (b, d)):
			if x + y <= n:
				print(_, x, n - x)
				return
	print(-1)
main()


L = lambda : list(map(int, input().split()))
I = lambda : int(input())
(n, t) = (I(), [L() for i in range(4)])
p = [min(i[0], i[1]) + min(i[2], i[3]) for i in t]
x = min(p)
if x > n:
	print(-1)
else:
	k = p.index(x)
	p = min(t[k][0], t[k][1])
	print(k + 1, p, n - p)


def solve(arr, n):
	for (i, v) in enumerate(arr):
		c1 = min(v[0], v[1])
		c2 = min(v[2], v[3])
		if c1 + c2 <= n:
			return [i + 1, c1, n - c1]
	return [-1]

def main():
	n = int(input())
	arr = []
	for _ in range(4):
		i = list(map(int, input().split(' ')))
		arr.append(i)
	print(*solve(arr, n))
main()


n = int(input())
for i in range(4):
	x = list(map(int, input().split()))
	if min(x[0], x[1]) + min(x[2], x[3]) <= n:
		print(i + 1, min(x[0], x[1]), n - min(x[0], x[1]))
		exit()
print(-1)