#K62697. Rearrange Array Based on Partition Value

    ID: 31589 Type: Default 1000ms 256MiB

Rearrange Array Based on Partition Value

Rearrange Array Based on Partition Value

Given an array of positive integers and an integer (X), rearrange the array such that all elements less than or equal to (X) appear before all elements greater than (X). The relative order of the elements in each partition must remain the same.

For example, if the array is [1, 4, 2, 10, 5, 3] and (X=4), the rearranged array should be [1, 4, 2, 3, 10, 5].

inputFormat

The input is given via standard input (stdin) with three lines.
The first line contains an integer (n), the size of the array.
The second line contains (n) positive integers separated by spaces.
The third line contains an integer (X), the partition value.

outputFormat

Output the rearranged array to standard output (stdout) as a sequence of integers separated by spaces.## sample

6
1 4 2 10 5 3
4
1 4 2 3 10 5