#P9412. 「NnOI R1-T1」购物

「NnOI R1-T1」购物

Problem Description

Little R is a girl who likes shopping. She lives in the country OAI.

There are nn kinds of coin denominations in OAI. Their values are 1=a1<a2<a3<<an1=a_1 < a_2 < a_3 < \cdots < a_n, and they satisfy that ai+1a_{i+1} is a multiple of aia_i. In OAI, the only payment method is coins.

Shops in OAI do not support making change. When she shops, she must pay with coins whose total value is exactly equal to the price. For the same price, there can be different payment methods. For example, if the coin denominations in OAI are 11 yuan and 55 yuan, then paying 77 yuan has two methods: pay 77 coins of 11 yuan, or pay 11 coin of 55 yuan and 22 coins of 11 yuan.

Since the coins have roughly the same weight, she does not want to carry coins that are too heavy, so for each purchase she will carry as few coins as possible while meeting the requirement. She discovered a magical phenomenon: sometimes buying an item that costs 11 yuan more can make her carry many fewer coins.

Can you find the smallest mm such that buying an item costing mm yuan requires fewer coins than buying an item costing m1m-1 yuan?

Input Format

The first line contains an integer nn, indicating the number of coin denominations.

The second line contains nn integers. The ii-th integer is aia_i, indicating the value of the ii-th coin denomination.

Output Format

One line containing one integer mm, which is the answer. In particular, if no such mm exists, output 1-1.

4
1 6 12 48
6
3
1 2 8
8
1
1
-1

Hint

Sample Explanation

For sample 11, buying items costing 151\sim 5 yuan requires 151\sim 5 coins of 11 yuan respectively, while buying an item costing 66 yuan only requires 11 coin of 66 yuan.

For sample 22, buying an item costing 11 yuan or 22 yuan both requires 11 coin, which does not satisfy the requirement that the number of coins needed is fewer.

Constraints

For 100%100\% of the testdata, 1n101\le n\le 10, 1=a1<a2<a3<<an1091=a_1 < a_2 < a_3 < \cdots < a_n\le 10^9, and ai+1a_{i+1} is a multiple of aia_i.

Hint: This problem uses bundled tests.

This problem has 44 subtasks.

Subtask ID n n \le Special Property Score
1 1 2 2 None 20
2 2 10 10 Guaranteed ai103a_i\le 10^3
3 3 Guaranteed to have a solution 30
4 4 None

Source

Item Staff
idea rui_er
std
data
check Kevin0501
solution rui_er

Translated by ChatGPT 5