Mr. A's Magic Balls
Mr. A discovered a sequence of magical balls in his closet. Each ball is a unique color, conveniently numbered from to . Importantly, is an even number.
Mr. A also has an empty array , where he plans to record the colors of these balls.
He will perform operations, each involving the following steps: Mr. A selects a pair of adjacent balls from the sequence, removes them, and appends their colors to the beginning of array . The order of the colors in will match their order in the original sequence. After removing a pair, the sequence is rejoined, forming a new sequence.
For instance, if the sequence of ball colors is , Mr. A could first add the pair to the start of , then , and finally . This results in the array .
Mr. A wants to know the lexicographically smallest array possible after performing all operations. Lexicographical order is determined by comparing arrays element by element from the start: the first differing element decides which array is smaller. For example, , , and .
Your task is to help Mr. A find the first elements of the smallest possible array .
Input
The first line contains two integers and . It is guaranteed that is even.
The second line contains distinct integers , representing the colors of the balls in the sequence.
Output
Output integers —the first elements of the smallest possible array .
Examples
Scoring
( points): ;
( points): ;
( points): ;
( points): ;
( points): ;
( points): ;
( points): without additional constraints.