#K40742. Array Rearrangement: Move Specified Element to End
Array Rearrangement: Move Specified Element to End
Array Rearrangement: Move Specified Element to End
Given an array of integers and a specified value (v), rearrange the array so that all occurrences of (v) are moved to the end, while the relative order of the other elements is maintained.
Formally, if the initial array is (A = [a_1, a_2, \dots, a_n]), then after the transformation, it should become ([\text{all } a_i \neq v \text{ in original order}, \underbrace{v, v, \dots, v}_{\text{all occurrences of } v}]).
inputFormat
Input is read from standard input (stdin). The first line contains an integer (n) (the number of elements in the array). The second line contains (n) space-separated integers representing the array. The third line contains an integer (v), the value that needs to be moved to the end.
outputFormat
Output the rearranged array to standard output (stdout) as a sequence of space-separated integers on one line.## sample
7
4 2 4 0 3 4 5
4
2 0 3 5 4 4 4