""" Solution Author: Andrew Rayskiy Date: 29.04.2018 """ from collections import Counter K = 10000 + 1 d = [0] * K n = input() for i in range(1, K): for j in range(i, K, i): d[j] += 1 #print(d) t = Counter([int(x) for x in input().split()]) j, ans = -1, 10 ** 9 for i in range(1, K): if d[i] >= ans or any(t.get(key, 0) < val for key, val in Counter([int(x) for x in list(str(i))]).items()): continue j, ans = i, d[i] print(ans, j)