Problem:
Score : 500 points

Problem Statement

An adult game master and N children are playing a game on an ice rink.
The game consists of K rounds.
In the i-th round, the game master announces:

Form groups consisting of A_i children each!

Then the children who are still in the game form as many groups of A_i children as possible.
One child may belong to at most one group.
Those who are left without a group leave the game. The others proceed to the next round.
Note that it's possible that nobody leaves the game in some round.

In the end, after the K-th round, there are exactly two children left, and they are declared the winners.

You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it.

Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.

Constraints

1 \leq K \leq 10^5

2 \leq A_i \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

K
A_1 A_2 ... A_K

Output

Print two integers representing the smallest and the largest possible value of N, respectively,
or a single integer -1 if the described situation is impossible.

Sample Input 1

4
3 4 3 2

Sample Output 1

6 8

For example, if the game starts with 6 children, then it proceeds as follows:

In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.

In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.

In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.

In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.

The last 2 children are declared the winners.

Sample Input 2

5
3 4 100 3 2

Sample Output 2

-1

This situation is impossible.
In particular, if the game starts with less than 100 children, everyone leaves after the third round.

Sample Input 3

10
2 2 2 2 2 2 2 2 2 2

Sample Output 3

2 3

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using static MyBinarySearch;


public class B
{
	public static void Main()
	{
		(new Solver()).Solve();	
	}
}


public class Solver
{
	private long K;
	private long[] A;

	public Solver()
	{
		K = GetInt();
		A = new long[K];
		for(int i = 0; i < K; i++)
			A[i] = GetLong();
	}

	public void Solve()
	{
		long max = 2 + K * A.Max();
		Func<long, long> eval = alive;
		long lb = LowerBound(0, max, 2, eval);
		long ub = UpperBound(0, max, 2, eval);

		Console.WriteLine((lb <= ub) ? $"{lb} {ub}" : "-1");
	}
	
	private long alive(long x)
	{
		long res = x;
		for(int i = 0; i < K; i++)
			res = res - (res % A[i]);
		return res;
	}
}


public static class MyBinarySearch
{
	public static int LowerBound<T>(T[] array, T key, Comparison<T> comp)
	{
		int len = array.Length;
		if(comp(array[len - 1], key) < 0)
			return -1;

		int left = 0;
		int right = len - 1;
		while(right > left)
		{
			int mid = (left + right) / 2;
			if(comp(array[mid], key) >= 0)
				right = mid;
			else
				left = mid + 1;
		}

		return left;
	}

	public static int LowerBound<T>(List<T> list, T key, Comparison<T> comp)
	{
		return LowerBound(list.ToArray(), key, comp);
	}

	public static long LowerBound(long left, long right, long target, Func<long, long> eval)
	{
		while(right > left)
		{
			long mid = (left + right) / 2;
			if(eval(mid) >= target)
				right = mid;
			else
				left = mid + 1;
		}

		return left;
	}

	public static long UpperBound(long left, long right, long target, Func<long, long> eval)
	{
		while(right > left)
		{
			long mid = (left + right) / 2;
			if(eval(mid) <= target)
				left = mid + 1;
			else
				right = mid;
		}

		return left - 1;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}