Psychopathic elevator P61342


Statement
 

pdf   zip

thehtml

Sometimes, professor Oak has to use a certain public elevator. That elevator works so badly, is so slow and takes such stupid decisions (going up or down) that it seems ruled by some insane spirit. Or, more likely, the programmer of the elevator had some mental disorder…

Given all the floors that must be visited, and the initial floor of the elevator, your task is to compute the minimum possible distance and the maximum possible distance to visit all the floors. Only movements beetween required floors are allowed.

Input

Input consists of several cases, each one with the initial floor f of the elevator, followed by the number n of floors to be visited, followed by n numbers in ascending order. Assume 1 ≤ n ≤ 106. All floor numbers, including f, are different and between 1 and 109.

Output

For every case, print the minimum and the maximum possible distances to visit all the required floors starting from the initial floor.

Public test cases
  • Input

    9 1  5
    4 3  1 6 10
    1000000000 2  1 999999999
    

    Output

    4 4
    12 20
    999999999 1999999997
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++