cswork / OAOpen practice workspace

AmazonOA #169

Find Minimum Trips

Estimated MediumJudge-ready

Topics (AI-labelled)HashingBits & Math

Each trip must deliver exactly 2 or 3 packages of the same weight, and every package must be delivered exactly once. Find the minimum number of trips, or output -1 if it cannot be done.

Input

The first line contains n; the second line contains the weights. Weights are in 1..10^9. The original upper bound on n had an extra trailing character 5; this site explicitly uses 1≤n≤100000 and does not treat the typesetting damage as a new order of magnitude.

Output

Output a single integer, the answer.

Example 1

Input:

5
1 1 1 2 2

Output:

2

Example 2

Input:

1
1

Output:

-1

Example 3

Input:

4
5 5 5 5

Output:

2

Example notes

Example 1: the three packages of weight 1 go in one trip and the two of weight 2 in another, 2 trips in total. Example 2: a single package cannot form a group of 2 or 3, so there is no solution: -1. Example 3: the 4 packages split into two groups of 2, which takes 2 trips.

Editorial

Loading solution…