name group
题号:NC252110
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

In an alternate universe, every person has a three-letter name, and each letter must have a distinct reading. For example, "JWS" is a valid name, but "JW" is not because it has only two letters, and "JWJ" is not a valid name because two of the letters are same.

If there are three people whose names have a magical characteristic, we call them a "name group". The characteristics of a name group are as follows: you can choose three different letters such that each letter is contained in the names of at least two people in the group.

For example, if the first person is named "ACD", the second person is named "ABE", and the third person is named "BCF", then selecting "A" would include the first two people, selecting "C" would include the first and third people, and selecting "B" would include the second and third people. (Only the inclusion of a letter is necessary, not the position of the letter in the name.)

That is, for the letters 'A', 'B' and 'C', each letter is contained in the names of at least two people.

Note: each person can only be in one name group, and different people can have the same name.

Now, you have a library of n unique letters, and each letter can be used a_i times, with the total number of uses of all letters guaranteed to be a multiple of 3. You can create sum/3 people names with them, where sum is the sum of all a_i. Please determine the maximum number of name groups you can create. If it is impossible to create sum/3 valid name groups, output -1.

输入描述:

The first line contains an integer n (1\leq n\leq 10^5), representing the number of unique letters in the library.

The second line contains n positive integers, a_1,a_2,\cdots,a_n (1\leq a_i\leq 10^{13}), representing the number of times each letter can be used. The sum of all a_i is guaranteed to be a multiple of 3.

输出描述:

Output a single integer, representing the maximum number of name groups you can create.
示例1

输入

复制
3
4 4 4

输出

复制
1

说明

A total of 4 people with the same name can be created, but since a name group needs to include 3 people,
there can only be one name group.
示例2

输入

复制
1
9

输出

复制
-1
示例3

输入

复制
6
2 2 2 1 1 1

输出

复制
1

说明

This is the example in the problem statement.

示例4

输入

复制
8
4 3 3 3 2 1 1 1

输出

复制
2