PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000159. Những vách núi thử thách (Challenging Cliffs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những vách núi thử thách (Challenging Cliffs)

Challenging Cliffs

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Arrange all nn given cliff heights in a line. First minimize the absolute difference between the first and last heights. Subject to that minimum, maximize the number of adjacent pairs ii satisfying hi≤hi+1h_i\le h_{i+1}. Output any optimal arrangement.

Input

The first line contains nn. The second line contains the nn positive heights.

Output

Print exactly nn heights forming a permutation of the input multiset and satisfying both optimization objectives.

Subtasks

  • Subtask 1 (20 points): 2≤n≤82\le n\le 8; 1≤hi≤1091\le h_i\le 10^9.
  • Subtask 2 (30 points): 2≤n≤30002\le n\le 3000; 1≤hi≤1091\le h_i\le 10^9.
  • Subtask 3 (50 points): 2≤n≤2⋅1052\le n\le 2\cdot10^5; 1≤hi≤1091\le h_i\le 10^9.

Examples

Input

4
4 2 1 2

Output

2 4 1 2

Explanation

The order [2,4,1,2][2,4,1,2] has equal endpoints, yielding the minimum possible endpoint difference 00. Two adjacent transitions (2≤42\le4 and 1≤21\le2) are nondecreasing; the remaining transition is not. Three such transitions are impossible under the endpoint condition for this multiset.