#!/usr/bin/python3
with open("input") as fh:
now = int(fh.readline())
ids = [int(x) for x in fh.readline().split(",") if x != "x"]
min_dt = now # arbitrary large number
for id in ids:
dt = -now % id
if dt < min_dt:
print(id, dt, id * dt)
min_dt = dt