eolymp
bolt
Try our new interface for solving problems
Problems

Journey

Journey

Cossack Vus is going on a journey. In Potokolandia $n$ cities are located on a straight line and numbered with integers from $1$ to $n$. Each city is characterized by a certain value $x_i$ ~--- the city coordinate. The distance between the cities with numbers $i$ and $j$ is equal to $|x_i-x_j|$. Cossack Vus wants to know the minimum distance he will have to travel when traveling through Potokolandia, provided that he must visit each city at least once and complete the journey in the city where he started. Your task is to find the minimum length of the route, provided that the city where the journey starts and the route remains at your discretion. \InputFile The first line contains one integer $n$ ($1\le n\le 100$). The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1\le x_i\le 1000$). \OutputFile Print one integer~--- the minimum length of the route of Cossack Vus.
Time limit 1 second
Memory limit 128 MiB
Input example #1
2
1 4
Output example #1
6
Input example #2
3
1 3 1
Output example #2
4
Author Ihor Barenblat
Source Ukrainian Olympiad in Informatics 2020/2021, I stage