B - Ice Rink Game Editorial /

Time Limit: 2 sec / Memory Limit: 512 MB

配点 : 500500

問題文

スケートリンクで、一人の大人の司会と NN 人の子供がゲームを行います。 ゲームは KK ラウンドからなり、ラウンド ii では司会が次のように言います。

  • AiA_i 人組を作って!

すると、まだ脱落していない子供たちは AiA_i 人からなるグループをできるだけ多く組みます。 一人につき一つのグループにしか入れません。 グループに入れなかった子供たちは脱落し、その他は次のラウンドに進みます。 ラウンドで誰も脱落しないこともありえます。

最後まで、つまりラウンド KK のあとまで残ったのは 22 人で、彼らが勝者となりました。

あなたは A1A_1, A2A_2, ..., AKA_K の値を聞き、NN の値は知りませんが、推定してみたくなりました。

ゲームの開始前にいた子供たちの人数として考えられる最小の値と、最大の値を求めてください。もしくは、考えられる NN の値は存在しないと判定してください。

制約

  • 1K1051 \leq K \leq 10^5
  • 2Ai1092 \leq A_i \leq 10^9
  • 入力値はすべて整数である。

入力

入力は標準入力から以下の形式で与えられる。

KK
A1A_1 A2A_2 ...... AKA_K

Output

考えられる最小の NN の値と最大の NN の値をそれぞれ表す二つの整数を出力せよ。ただし、問題文で述べた状況が発生しえない場合は、整数 1-1 を単独で出力せよ。


入力例 1Copy

Copy
4
3 4 3 2

出力例 1Copy

Copy
6 8

例えば、ゲームの開始時に子供が 66 人いた場合、以下のように進行します。

  • ラウンド 11 では、66 人の子供たちが 33 人組を 22 つ作り、誰も脱落しません。
  • ラウンド 22 では、66 人の子供たちが 44 人組を 11 つ作り、22 人が脱落します。
  • ラウンド 33 では、44 人の子供たちが 33 人組を 11 つ作り、11 人が脱落します。
  • ラウンド 44 では、33 人の子供たちが 22 人組を 11 つ作り、11 人が脱落します。

最後まで残った二人が勝者となります。


入力例 2Copy

Copy
5
3 4 100 3 2

出力例 2Copy

Copy
-1

このような状況はありえません。 特に、ゲームの開始時の子供たちの人数が 100100 人未満の場合は、ラウンド 33 で全員が脱落します。


入力例 3Copy

Copy
10
2 2 2 2 2 2 2 2 2 2

出力例 3Copy

Copy
2 3

Score : 500500 points

Problem Statement

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

  • Form groups consisting of AiA_i children each!

Then the children who are still in the game form as many groups of AiA_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 KK-th round, there are exactly two children left, and they are declared the winners.

You have heard the values of A1A_1, A2A_2, ..., AKA_K. You don't know NN, 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 NN exist.

Constraints

  • 1K1051 \leq K \leq 10^5
  • 2Ai1092 \leq A_i \leq 10^9
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

KK
A1A_1 A2A_2 ...... AKA_K

Output

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


Sample Input 1Copy

Copy
4
3 4 3 2

Sample Output 1Copy

Copy
6 8

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

  • In the first round, 66 children form 22 groups of 33 children, and nobody leaves the game.
  • In the second round, 66 children form 11 group of 44 children, and 22 children leave the game.
  • In the third round, 44 children form 11 group of 33 children, and 11 child leaves the game.
  • In the fourth round, 33 children form 11 group of 22 children, and 11 child leaves the game.

The last 22 children are declared the winners.


Sample Input 2Copy

Copy
5
3 4 100 3 2

Sample Output 2Copy

Copy
-1

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


Sample Input 3Copy

Copy
10
2 2 2 2 2 2 2 2 2 2

Sample Output 3Copy

Copy
2 3


2025-04-05 (Sat)
21:19:27 +00:00