405346: GYM101911 C Bacteria

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Bacteriatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Recently Monocarp has created his own mini-laboratory!

The laboratory contains $$$n$$$ bacteria. Monocarp knows that he can merge any two bacteria having equal sizes, and the resulting bacterium will have the size equal to the sum of sizes of merged bacteria. For example, if two bacteria having sizes equal to $$$7$$$ merge, one bacterium with size $$$14$$$ is the result.

It becomes hard to watch for many bacteria, so Monocarp wants to merge all of them into one bacterium. It may not be possible to do this with the bacteria Monocarp has, so he can buy any number of bacteria of any possible integer sizes in a special store.

You have to determine the minimum number of bacteria Monocarp has to buy to merge them with the $$$n$$$ bacteria his laboratory contains into exactly one bacterium.

Input

The first line contains one integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$ — the number of bacteria Monocarp's laboratory contains.

The second line contains $$$n$$$ integers $$$a_{1}, a_{2}, \dots, a_{n}$$$ $$$(1 \le a_{i} \le 10^9)$$$, where $$$a_i$$$ is the size of the $$$i$$$-th bacterium in the laboratory.

Output

If it is impossible to merge the bacteria (possibly after buying some) into only one bacterium, print -1.

Otherwise print the minimum number of bacteria Monocarp has to buy to merge them with the $$$n$$$ bacteria his laboratory contains into exactly one bacterium.

ExamplesInput
2
1 4
Output
2
Input
3
3 6 9
Output
-1
Input
7
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Output
1
Note

In the first example Monocarp should buy one bacterium having size $$$1$$$ and one bacterium having size $$$2$$$. Then Monocarp will have $$$4$$$ bacteria having sizes $$$[1, 4, 1, 2]$$$. Then two bacteria having sizes $$$1$$$ can be merged into one having size $$$2$$$. Then Monocarp will have $$$3$$$ bacteria having sizes $$$[2, 4, 2]$$$. Then two bacteria having sizes $$$2$$$ can be merged into one having size $$$4$$$. Then Monocarp will have $$$2$$$ bacteria having sizes $$$[4, 4]$$$, which can be merged into one having size $$$8$$$.

In the second example no matter which bacteria Monocarp will buy, he cannot merge all his bacteria.

In the third example Monocarp needs to buy one bacterium having size $$$1000000000$$$.

加入题单

算法标签: