405953: GYM102191 D Picture Day

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Picture Daytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have a class of even number of students n. The class can be divided into n / 2 pairs of best friends, who always like to stay next to each other. Unfortunately, this makes your job harder because today is picture day.

For a perfect picture, you want to align the students in order of non-decreasing heights then non-increasing heights. Each pair of best friends must be next to each other, however, their relative order does not matter (friends a and b ordered as ab or ba both work).

For example, [1, 2, 4, 3, 3, 1] ,[1, 5, 10, 11], [11, 10, 5, 5], [3, 3, 3, 3] are perfect height arrangements as numbers first do not decrease, then they do not increase.

Given the pairs of best friends, can you arrange them to make a perfect picture?

Input

The first line of input contains a single even integer n (2 ≤ n ≤ 3 × 105), the number of students in the class.

Each of the following n / 2 lines contains two integers ha hb (1 ≤ ha, hb ≤ 109), the heights of a pair of best friends in the class.

Output

Output any valid arrangement of the class' heights such that each pair of best friends are standing next to each other.

If there is no answer, output -1 on a single line.

ExampleInput
8
1 3	
4 2
6 7 
5 7	
Output
2 4 5 7 7 6 3 1 

加入题单

上一题 下一题 算法标签: