#K48207. Rearrange Array Based on Pivot
Rearrange Array Based on Pivot
Rearrange Array Based on Pivot
You are given an integer pivot and a list of integers. Your task is to rearrange the list such that all elements strictly less than the pivot appear before all elements greater than or equal to the pivot. The relative order of elements in each partition should remain the same as in the input.
In other words, if the input list is \(A = [a_1, a_2, \dots, a_n]\) and the pivot is \(p\), then the rearranged list should be \( [ \{ a_i | a_i < p \}, \{ a_i | a_i \ge p \} ] \).
Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line contains a single integer pivot \(p\).
- The second line contains a space-separated list of integers.
You may assume that the list contains at least one integer.
outputFormat
Print the rearranged list in a single line. The elements should be space-separated. There should be no extra spaces at the beginning or end of the output.
## sample5
1 8 3 7 5 6 4 9 2
1 3 4 2 8 7 5 6 9
</p>