cswork / OAOpen practice workspace

HSBCOA #1

Arrange Flower Sticks

Estimated EasyJudge-ready

Topics (AI-labelled)In-place Arrays

Sort the first K flower sticks (in input order) by length ascending, sort the remaining sticks by length descending, then concatenate the two parts. The 11 in the statement's example output does not match the input values; under the explicit rule it should be 5.

This site adds n and the value ranges, and fixes obvious typos in the example.

Input

The first line contains n (0≤n≤200000); the second line contains n integers; the third line contains K (0≤K≤n). Length values are 32-bit signed integers.

Output

Output the n lengths after concatenation according to the rule.

Example 1

Input:

8
17 7 5 10 46 23 16 8
3

Output:

5 7 17 46 23 16 10 8

Example 2

Input:

3
4 4 1
1

Output:

4 4 1

Example 3

Input:

11
14 1 1 20 26 5 18 30 4 3 29
8

Output:

1 1 5 14 18 20 26 30 29 4 3

Editorial

Loading solution…