#C5962. Move Value To End

    ID: 49669 Type: Default 1000ms 256MiB

Move Value To End

Move Value To End

Given an array of integers and a value val, your task is to move all occurrences of val to the end of the array while preserving the order of the other elements. The operation should be performed in-place.

For example, if you are given the array [3, 1, 2, 3, 4, 3] and val = 3, the resultant array should be [1, 2, 4, 3, 3, 3].

You are required to read the input from stdin and print the output to stdout.

The relation can be explained by the following idea: Let \(n\) be the length of the array, then the first part of the output is the subsequence of all elements \(x\) such that \(x \neq val\), and the remaining part contains exactly the count of \(val\). Formally, if count is the number of occurrences of val in the array, then the final array is

[ \text{result} = { x \in arr \mid x \neq val } \cup {\underbrace{val, val, \dots, val}_{\text{count times}}} ]

inputFormat

The first line contains an integer n which is the size of the array.

The second line contains n space-separated integers representing the elements of the array.

The third line contains an integer val which is the value to be moved to the end.

outputFormat

Output the modified array in one line with each integer separated by a single space.

## sample
6
3 1 2 3 4 3
3
1 2 4 3 3 3