The story of Harry Potter begins when Lord Voldemort arrives at his house at Privet Drive. Harry's house has N rooms placed in one line. Each room has its own energy level and no two rooms have exactly same energy. Lord Voldemort arrives at the room which has lowest energy while Harry is at the room having highest energy.

Lord Voldemort has to reach Harry's room. Voldemort can travel from a room having energy X to any other room having energy Y such that |X-Y| is minimum and that room hasn't been visited before. The energy required for moving from room having energy X to room having energy Y is X*Y.

Since Lord Voldemort is busy practicing Avada Kedavra to kill Harry, so he asks you to find the energy required to reach Harry's room.

------ Input ------ 

The first line of input contains 1 integer N denoting the number of rooms.
The second line contains N space separated integers denoting energy levels of each room.

------ Output ------ 

Print the required energy.

------ Constraints ------ 

$2 ≤ N ≤ 1000$
$1 ≤ E_{i} ≤ 10000$

----- Sample Input 1 ------ 
3
4 2 1
----- Sample Output 1 ------ 
10
----- explanation 1 ------ 
Lord Voldemort arrives at room 3 and Harry is in room 1.

Total energy consumed = 1*2 + 2*4 = 10.

Difficulty: EASY

Solutions:
n = int(input())
Ar = list(map(int, input().split()))
Ar.sort()
E = 0
for i in range(n - 1):
	e = Ar[i] * Ar[i + 1]
	E = E + e
print(E)


n = int(input())
l = list(map(int, input().split()))
l.sort()
min1 = min(l)
max1 = max(l)
i1 = l.index(min1)
i2 = l.index(max1)
s = 0
if i1 < i2:
	for i in range(i1, i2):
		s = s + l[i] * l[i + 1]
	print(s)
elif i1 == i2:
	print(0)
else:
	for i in range(i2, i1):
		s = s + l[i] * l[i + 1]
	print(s)


number_of_rooms = int(input())
rooms = [int(s) for s in str(input()).split()]
rooms.sort()
sum = 0
for (i, r) in enumerate(rooms):
	if i == 0:
		continue
	sum += rooms[i - 1] * rooms[i]
print(sum)


t = int(input())
l = sorted(list(map(int, input().split())))
s = 0
for i in range(t - 1):
	s += l[i] * l[i + 1]
print(s)


n = int(input().strip())
energy = list(map(int, input().split()))
energy.sort()
consumed = 0
for i in range(len(energy) - 1):
	consumed += energy[i] * energy[i + 1]
print(consumed)


n = int(input())
a = sorted([int(x) for x in input().split()])
ans = 0
for i in range(n - 1):
	ans += a[i] * a[i + 1]
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 0
for i in range(0, len(l) - 1):
	c += l[i] * l[i + 1]
print(c)


N = int(input())
A = list(map(int, input().split()))
A.sort()
sum = 0
for i in range(0, len(A) - 1):
	pro = A[i] * A[i + 1]
	sum += pro
print(sum)


N = int(input())
s = input()
L = s.split()
A = []
for i in L:
	x = int(i)
	A.append(x)
A.sort()
sum = 0
for i in range(0, len(A) - 1):
	pro = A[i] * A[i + 1]
	sum += pro
print(sum)


t = int(input())
l = [int(i) for i in input().split()]
l.sort()
s = 0
for i in range(1, t):
	s = s + l[i] * l[i - 1]
print(s)


n = int(input())
l = sorted(list(map(int, input().split())))
total = 0
for i in range(n - 1):
	total += l[i + 1] * l[i]
print(total)


n = int(input())
a = [int(num) for num in input().split()]
a.sort()
prod = 0
for i in range(len(a) - 1):
	prod = prod + a[i] * a[i + 1]
print(prod)


x = int(input())
l = list(map(int, input().split()))
t = 0
l.sort()
l = l[::-1]
for i in range(1, x):
	t = t + l[i] * l[i - 1]
print(t)


n = int(input())
a = list(map(int, input().split()))
a.sort()
v = 0
for i in range(n - 1):
	v += a[i] * a[i + 1]
print(v)


n = int(input())
sum1 = 0
a = list(map(int, input().split()))
a.sort()
for i in range(1, len(a)):
	b = a[i] * a[i - 1]
	sum1 += b
print(sum1)


n = int(input())
x = list(map(int, input().split()))
x.sort()
s = 0
for i in range(n - 1):
	s = s + x[i] * x[i + 1]
print(s)


n = int(input())
a = list(map(int, input().split()))
b = set(a)
c = sorted(list(b))
energy = 0
for i in range(n - 1):
	energy += c[i] * c[i + 1]
print(energy)


n = int(input())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(1, len(l)):
	prod = l[i] * l[i - 1]
	res += prod
print(res)


N = int(input())
A = list(map(int, input().split()))
A.sort()
energy = 0
for i in range(N - 1):
	energy += A[i] * A[i + 1]
print(energy)


t = int(input())
a = [int(t) for t in input().split()]
a.sort()
s = 0
for j in range(t - 1):
	s = s + a[j] * a[j + 1]
print(s)


n = int(input())
l = list(map(int, input().split()))
l.sort()
sumi = 0
for i in range(n - 1):
	sumi += l[i] * l[i + 1]
print(sumi)


test_cases = input()
ind_energy = list(map(int, input().strip().split()))
energy = sorted(ind_energy)
op = 0
for val in zip(energy, energy[1:]):
	op += val[0] * val[1]
print(op)


n = int(input())
energy = list(map(int, input().split()))
energy = sorted(energy)
g = 0
for i in range(0, n - 1):
	g = g + energy[i] * energy[i + 1]
print(g)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = 0
for k in range(n - 1):
	s += l[k] * l[k + 1]
print(s)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
x = 0
for i in range(len(lst) - 1):
	x += lst[i] * lst[i + 1]
print(x)


n = int(input())
rooms = list(map(int, input().split()))
rooms.sort()
energy_required = 0
for idx in range(n - 1):
	energy_required += rooms[idx] * rooms[idx + 1]
print(energy_required)


n = int(input())
e = list(map(int, input().split()))
e.sort()
res = 0
for i in range(1, len(e)):
	res += e[i - 1] * e[i]
print(res)


n = int(input())
i = 0
a = list(map(int, input().split()))
a.sort()
k = 0
c = 0
while k < n - 1:
	c = c + a[k] * a[k + 1]
	k = k + 1
print(c)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = []
for i in range(0, n - 1):
	s = l[i] * l[i + 1]
	l1.append(s)
print(sum(l1))


n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(0, n - 1):
	s = l[i] * l[i + 1]
	count += s
print(count)


H = int(input())
X = list(map(int, input().split()))[:H]
X.sort()
sum = 0
for i in range(len(X) - 1):
	k = X[i] * X[i + 1]
	sum = sum + k
print(sum)


n = int(input())
rooms = list(map(int, input().split()))
rooms.sort()
energy = 0
for i in range(len(rooms) - 1):
	energy += rooms[i] * rooms[i + 1]
print(energy)


n = int(input())
x = list(map(int, input().split()))[:n]
x.sort()
sum = 0
for i in range(len(x) - 1):
	k = x[i] * x[i + 1]
	sum = sum + k
print(sum)


n = int(input())
a = sorted(list(map(int, input().split())))
res = 0
for i in range(n - 1):
	res += a[i] * a[i + 1]
print(res)


N = int(input())
E = list(map(int, input().split()))
E.sort()
sum = 0
for i in range(N - 1):
	sum += E[i] * E[i + 1]
print(sum)


(rooms, tot_energy) = (int(input()), 0)
energies = list(map(int, input().split()))
energies.sort()
for i in range(len(energies) - 1):
	tot_energy += energies[i] * energies[i + 1]
print(tot_energy)


n = int(input())
r = list(map(int, input().split()))
r = sorted(r)
e = 0
for i in range(n - 1):
	e = e + r[i + 1] * r[i]
print(e)


N = int(input())
l = list(map(int, input().split()))
energy = 0
for i in range(len(l) - 1):
	a = min(l)
	l.remove(a)
	b = min(l)
	energy += a * b
print(energy)


def energy_calc(lst, length):
	total = 0
	for i in range(length - 1):
		total += lst[i] * lst[i + 1]
	return total
n = int(input())
L = sorted(list(map(int, input().split())))
print(energy_calc(L, n))


n = int(input())
l = list(map(int, input().split()))
s = sorted(l)
cnt = 0
for i in range(1, n):
	cnt = cnt + s[i - 1] * s[i]
print(cnt)


a = int(input())
l = [int(i) for i in input().split()]
c = 0
l.sort()
for i in range(len(l) - 1):
	c += l[i] * l[i + 1]
print(c)


N = int(input())
lis = sorted(list(map(int, input().split())))
energy = 0
for i in range(N - 1):
	energy = energy + lis[i] * lis[i + 1]
print(energy)


n = int(input())
e = set(map(int, input().split()))
s = sorted(list(e.copy()))
suma = []
gets = 0
for i in range(len(s) - 1):
	result = s[i] * s[i + 1]
	gets += result
	suma.append(result)
	i = i + 1
print(gets)


k = int(input())
l = sorted(list(map(int, input().split())))
(m, tot) = (1, 0)
for i in range(len(l) - 1):
	m = l[i] * l[i + 1]
	tot += m
print(tot)


s = int(input())
H = sorted(list(map(int, input().split())))
ra = 0
for i in range(len(H) - 1):
	a = H[i]
	ga = H[i + 1]
	ra += a * ga
print(ra)


nor = int(input())
E = sorted(list(map(int, input().split())))
te = 0
for i in range(len(E) - 1):
	m = E[i]
	nm = E[i + 1]
	te += m * nm
print(te)


n = input()
l = sorted(list(map(int, input().split())))
s = 0
for i in range(len(l) - 1):
	cur = l[i]
	next = l[i + 1]
	s += cur * next
print(s)


n = int(input())
a = list(map(int, input().split()))[:n]
a.sort()
z = 0
for i in range(len(a) - 1):
	z = z + a[i] * a[i + 1]
print(z)


t = int(input())
listx = list(map(int, input().split()))
listx.sort()
answ = 0
for m in range(1, t):
	answ += listx[m] * listx[m - 1]
print(answ)


l = int(input())
a = list(map(int, input().split()))
a.sort()
r = 0
for i in range(l - 1):
	r = r + a[i] * a[i + 1]
print(r)


def main():
	N = int(input())
	e = list(map(int, input().split()))
	e.sort()
	sum = 0
	for (i, elem) in enumerate(e[:-1]):
		sum += elem * e[i + 1]
	print(sum)
main()


n = int(input())
e = input().split()
e = [int(a) for a in e]
e.sort()
answer = 0
for i in range(len(e)):
	if i < len(e) - 1:
		answer += e[i] * e[i + 1]
print(answer)


N = int(input())
rooms = input().split()
for i in range(0, len(rooms)):
	rooms[i] = int(rooms[i])
rooms.sort()
sum1 = 0
for i in range(0, len(rooms) - 1):
	sum1 += rooms[i] * rooms[i + 1]
print(sum1)


n = int(input())
l = sorted(list(map(int, input().split())))
sum = 0
for i in range(len(l) - 1):
	sum = sum + l[i] * l[i + 1]
print(sum)


N = int(input())
E = sorted(list(map(int, input().split())))
sum = 0
for i in range(len(E) - 1):
	sum = sum + E[i] * E[i + 1]
print(sum)


n = int(input())
l = input()
l = l.split()
l = [int(i) for i in l]
l = sorted(l)
s = 0
for i in range(1, n):
	s = s + l[i] * l[i - 1]
print(s)


x = int(input())
a = sorted(list(map(int, input().split())))
b = []
for i in range(len(a) - 1):
	b.append(a[i] * a[i + 1])
print(sum(b))


n = int(input())
a = [int(s) for s in input().split()]
a.sort()
pro = 0
for i in range(n - 1):
	pro = pro + a[i] * a[i + 1]
print(pro)


a = int(input())
ad = [int(s) for s in input().split()]
da = 0
ad.sort()
for i in range(a - 1):
	da = da + ad[i] * ad[i + 1]
print(da)