#K70272. Move Specified Element to the End

    ID: 33272 Type: Default 1000ms 256MiB

Move Specified Element to the End

Move Specified Element to the End

Given an array of integers and a specified integer (X), rearrange the array such that all occurrences of (X) are moved to the end while preserving the relative order of the other elements. The rearrangement should be performed in-place without using extra space for another array. Note that the relative order of the non-(X) elements must remain unchanged, and all elements equal to (X) should appear after them. The array can be empty or contain only the integer (X).

inputFormat

The input is read from standard input (stdin). The first line contains two space-separated integers, (N) (the number of elements in the array) and (X) (the integer to be moved). The second line contains (N) space-separated integers representing the array elements.

outputFormat

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

8 2
1 2 3 4 5 2 3 2
1 3 4 5 3 2 2 2