Question
Intellect Pairing Challenge

At a vibrant educational camp, there are N enthusiastic learners, each possessing a distinct level of intellect represented by dᵢ. The camp leader faces an intriguing challenge: they wish to pair up each student, ensuring that every student is in one pair only, and that the total intellect of each pair matches. Additionally, the leader defines the efficiency of a pair of learners i and j as the product of their intellect, dᵢ * dⱼ. Your task is to calculate the total efficiency for all the pairs formed. If it’s not feasible to create such pairs with equal total intellect, you must return -1. Can you assist the camp leader in solving this problem and optimizing the effectiveness of the learners’ collaboration?

Input
The first line of the input contains a single integer N.
The second line contains N space-separated integers.

Constraints:
1 ≤ N ≤ 105
1 ≤ Ai ≤ 106
It is given that N is always even.
Output
Print the sum of the efficiencies of all the groups in the science camp.
If a legit distribution of students is not possible, print -1.
Example
Sample Input
6
4 5 3 6 1 2
Sample Output
28
Explaination
We can divide groups of students like:
[3, 4] Efficiency = 3*4 = 12
[2, 5] Efficiency = 2*5 = 10
[1, 6] Efficiency = 1*6 = 6
Total efficiency = 12 + 10 + 6 = 28

Online