#C14304. Move the k-th Element to the Front

    ID: 43939 Type: Default 1000ms 256MiB

Move the k-th Element to the Front

Move the k-th Element to the Front

Given a list of integers and an index \(k\), move the element at the \(k\)-th position to the beginning of the list if \(0 \le k < n\), where \(n\) is the number of elements in the list. Otherwise, return the original list unchanged.

The input is read from standard input: the first line contains an integer \(n\) representing the number of elements, the second line contains \(n\) space-separated integers representing the list, and the third line contains an integer \(k\), the index of the element to move. The output should be printed to standard output as a single line containing the modified list with elements separated by a space.

inputFormat

The input consists of:

  • The first line with an integer \(n\): the number of elements in the list.
  • The second line with \(n\) space-separated integers.
  • The third line with an integer \(k\): the index of the element to be moved.

outputFormat

Output the modified list where, if \(k\) is a valid index (i.e. \(0 \le k < n\)), the \(k\)-th element is moved to the front. Otherwise, output the original list. The output should be a single line of space-separated integers.

## sample
5
10 20 30 40 50
2
30 10 20 40 50