atcoder#ABC301B. [ABC301B] Fill the Gaps
[ABC301B] Fill the Gaps
Score : points
Problem Statement
We have a sequence of length consisting of positive integers: . Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
- If every pair of adjacent terms in has an absolute difference of , terminate the procedure.
- Let be the pair of adjacent terms nearest to the beginning of whose absolute difference is not .- If , insert between and .
- If , insert between and .
- Return to step 1.
Print the sequence when the procedure ends.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the terms in the sequence when the procedure ends, separated by spaces.
4
2 5 1 2
2 3 4 5 4 3 2 1 2
The initial sequence is . The procedure goes as follows.
- Insert between the first term and the second term , making the sequence .
- Insert between the fourth term and the fifth term , making the sequence .
6
3 4 5 6 5 4
3 4 5 6 5 4
No insertions may be performed.