#K9171. Rearrange List by Pivot

    ID: 38036 Type: Default 1000ms 256MiB

Rearrange List by Pivot

Rearrange List by Pivot

You are given a list of integers and an integer pivot d. Your task is to rearrange the list such that all elements less than d appear before all elements greater than or equal to d, while keeping the original relative order within each partition.

Note: The input is read from standard input, and the output should be printed to standard output.

Example 1:
Input: 6 3 7 2 4 8 1 5
Output: 3 2 4 1 7 8

Example 2:
Input: 7 10 5 2 15 12 3 6 8
Output: 5 2 3 6 10 15 12

inputFormat

The first line contains an integer n denoting the number of elements in the list. The second line contains n space-separated integers representing the list. The third line contains the integer d which is used as the pivot.

outputFormat

Print the rearranged list as space-separated integers. The list should first include all numbers that are less than d (in the original order) followed by the numbers that are greater than or equal to d (also in the original order).

## sample
6
3 7 2 4 8 1
5
3 2 4 1 7 8