#C8417. Rearrange Every N-th Element

    ID: 52397 Type: Default 1000ms 256MiB

Rearrange Every N-th Element

Rearrange Every N-th Element

Your task is to rearrange an array of integers such that every n-th element (considering the array positions as 1-indexed) is moved to the end of the array, while maintaining the relative order of all the other elements.

More formally, given an array \(A\) with length \(L\) and a positive integer \(n\), construct a new array by taking all elements that are not at positions \(n, 2n, 3n, \dots\) (in order) followed by the elements at those positions (in order). If \(n L\), you should output the original array without any changes.

The rearrangement can be expressed as follows:

\[ \text{result} = \text{non-nth elements} \| \text{nth elements} \]

where \(\|\) denotes the concatenation operation.

inputFormat

The input is provided via stdin and consists of two lines:

  • The first line contains a sequence of space-separated integers representing the array elements. This line may be empty, indicating an empty array.
  • The second line contains a single integer \(n\), which specifies the step for rearrangement.

outputFormat

Output the rearranged array as a sequence of space-separated integers on a single line to stdout. If the input array is empty, output an empty line.

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