import sys

input = lambda: sys.stdin.readline().rstrip()

n = int(input())
mp, mf, ms, mv = map(int, input().split())
foods = [[]]

for _ in range(n):
    food = list(map(int, input().split()))
    foods.append(food)


def back_tracking(index, candidates, p, f, s, v, c, min_price, min_candidates):
    # print("-------")
    # print(index, candidates, p, f, s, v, c, min_price)
    if index > n:
        # print("끝!")
        return min_price, min_candidates

    np = foods[index][0] + p
    nf = foods[index][1] + f
    ns = foods[index][2] + s
    nv = foods[index][3] + v
    nc = foods[index][4] + c

    result_price = 9999
    result_candidates = []

    # 현재 index의 식재료를 넣는 경우
    if np >= mp and nf >= mf and ns >= ms and nv >= mv:
        # 영양소 조건을 모두 만족하면 가격이 낮아야 함
        if nc < min_price:
            # print("제일 낮은 가격!")
            candidates.append(index)
            temp_price, temp_candidates = back_tracking(index + 1, candidates, np, nf, ns, nv, nc, nc, candidates[:])
            candidates.pop()
            if temp_price < result_price:
                result_price = temp_price
                result_candidates = temp_candidates
    else:
        # 아직 더 식재료를 추가해봐야하는 상황
        # print("추가해보자!")
        candidates.append(index)
        temp_price, temp_candidates = back_tracking(index + 1, candidates, np, nf, ns, nv, nc, min_price,
                                                    min_candidates)
        candidates.pop()
        if temp_price < result_price:
            result_price = temp_price
            result_candidates = temp_candidates

    # 현재 index의 식재료를 넣지 않는 경우
    # print("넣지말아보자!")
    temp_price, temp_candidates = back_tracking(index + 1, candidates, p, f, s, v, c, min_price, min_candidates)
    if temp_price < result_price:
        result_price = temp_price
        result_candidates = temp_candidates

    # print("==========")
    # print("지금까지 제일 베스트!", result_candidates, result_price)
    return result_price, result_candidates


answer_price, answer_candidates = back_tracking(1, [], 0, 0, 0, 0, 0, 9999, [])

if answer_candidates:
    print(answer_price)
    print(' '.join(str(e) for e in answer_candidates))
else:
    print("-1")
