Cupid's workload keeps growing, so he is bringing in new technology. He put the best programmers on his staff on a project called Advanced Couples Matching (ACM). The project needs an algorithm that takes an even number N of single people and splits them into N/2 couples, so that every person belongs to exactly one couple.
The data available about each person is thin. Gender, ethnicity, age and nationality are not sensible criteria for forming couples, so the programmers may use only data about each candidate's internet connection. For this stage they settled on time zones. People who live in nearby time zones find it easier to be online at the same moment, so the programmers decided to build the couples so that the total time difference is as small as possible.
A time zone is an integer from −11 to 12 that gives its offset in hours from Coordinated Universal Time (UTC). For two people living in time zones i and j, the time difference is the smaller of ∣i−j∣ and 24−∣i−j∣. Given a partition of the N candidates into N/2 couples, its total time difference is the sum of the time difference of every couple.
Write a program that reads the time zones of N candidates and prints the minimum total time difference over all partitions of the candidates into couples.
The first line contains an even integer N (2≤N≤1000), the number of candidates to be coupled. The second line contains N integers T1,T2,…,TN (−11≤Ti≤12), the time zones of the candidates.
Print one line with an integer, the minimum total time difference over all partitions of the candidates into couples.