def price(a, b, c, n):
    p = []
    di = []
    dj = []
    tag = 0
    for i in range(1, 10):
        for j in range(10):
            s = i * 10000 + a * 1000 + b * 100 + c * 10 + j
            if s % n == 0:
                di.append(i)
                dj.append(j)
                p.append(s)
                tag = 1
    if tag == 1:
        #return , di[-1], dj[-1]
        print("{} {} {}".format(di[-1], dj[-1], int(max(p)/ n)))
    else:
        print(0)

while True:
    try:
        n = int(input())
        a, b, c = map(int, input().split())
        price(a, b, c, n)
        
    except:
        break