Baltic Olympiad in Informatics: 2004 Day 1, Problem 3
A number sequence is given. Your task is to construct an increasing sequence that approximates the given one in the best way. The best approximating sequence is the sequence with the least total deviation from the given sequence.
More precisely, let be the given sequence. Your task is to construct an increasing sequence .
The total deviation, defined as , should be minimized.
Constraints
Input Specification
The first line of input contains an integer .
Each of the next lines describes the given sequence , where the line corresponds to .
Output Specification
The first line of output must contain the single integer – the minimal possible total deviation.
Each of the next lines must describe the best approximating sequence , where the line corresponds to .
If there are several solutions, your program can output any valid sequence with the least total deviation.
Sample Input
7
9
4
8
20
14
15
18
Sample Output
13
6
7
8
13
14
15
18
Comments