Module: One-dimensional dynamics


Problem

4 /7


carnations

Problem

Carnations are driven into a straight plank. Any two cloves can be connected with a thread. It is required to connect some pairs of studs with threads so that at least one thread is tied to each stud, and the total length of all threads is minimal.
 
Input: 
- the first line contains the number N - the number of studs (\(2 <= N <= 100\));
- the next line contains N numbers - the coordinates of all the studs (non-negative integers, not exceeding 10000).
 
Output: print a single number - the minimum total length of all threads.
 
 
Examples
# Input Output
1
5
4 10 0 12 2
6