Psychopathic elevator

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 ff of the elevator, followed by the number nn of floors to be visited, followed by nn numbers in ascending order. Assume 1n1061 \le n \le 10^6. All floor numbers, including ff, are different and between 1 and 10910^9.

Output

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

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:08:41.393Z

© Jutge.org, 2006–2026.
https://jutge.org