Bored of Long Statements?
Execution time limit is 1 second
Runtime memory usage limit is 256 megabytes
You are given an array of integers .
You can perform the following operation any number of times (possibly zero):
choose indexes and swap and .
Let be:
In other words, is equal to the sum of squared differences of adjacent elements of .
Find the minimum possible value of after performing any number of operations (possibly zero).
Input
The first line contains a single integer — the length of .
The second line contains integers — elements of .
Output
Output a single integer — minimum possible .
Examples
Input #1
Answer #1
Input #2
Answer #2
Input #3
Answer #3
Note
For the first example, after several operations, the possible values of are:
;
;
;
;
;
.
Scoring
( points): ;
( points): ;
( points): ;
( points): there are at most ten different in the array;
( points): ;
( points): no additional restrictions.
Submissions 3
Acceptance rate 67%