#C7939. Minimum Drone Delivery Distance

    ID: 51865 Type: Default 1000ms 256MiB

Minimum Drone Delivery Distance

Minimum Drone Delivery Distance

Problem Statement:

A drone starting from the origin (0) needs to deliver packages to n stores that are located along a one-dimensional line. After delivering the packages, the drone must return to the starting point. The goal is to determine the minimum distance the drone must travel to complete its route.

Let the coordinates of the stores be given by a sequence \(x_1, x_2, \dots, x_n\). Define \(m = \min\{x_i\}\) and \(M = \max\{x_i\}\). Then the minimum distance that the drone must travel is given by:

\( |m| + |M| + (M - m) \)

This formula accounts for the distance from the origin to the farthest negative coordinate, the distance from the origin to the farthest positive coordinate, and the distance between these two extreme points.

inputFormat

The first line contains an integer \(n\) (\(1 \leq n \leq 10^5\)) representing the number of store locations.

The second line contains \(n\) space-separated integers representing the coordinates of the stores.

outputFormat

Output a single integer, which is the minimum distance the drone must travel to deliver packages to all stores and return to the starting point.

## sample
3
1 3 6
12