#C12649. Pairwise Swap

    ID: 42099 Type: Default 1000ms 256MiB

Pairwise Swap

Pairwise Swap

Given a list of elements, your task is to swap each pair of adjacent elements. If the list contains an odd number of elements, the last element remains in its original position.

Formally, if the input list is \( a_1, a_2, \dots, a_n \), then for every \( i \) such that \(1 \le i \le \lfloor\frac{n}{2}\rfloor\), swap \( a_{2i-1} \) with \( a_{2i} \). If \(n\) is odd, \(a_n\) is not swapped.

The program should read input from standard input and write the result to standard output.

Example:

  • Input: 4\n1 2 3 4 → Output: 2 1 4 3
  • Input: 5\n1 2 3 4 5 → Output: 2 1 4 3 5

inputFormat

The input is given via standard input and has the following format:

  1. The first line contains an integer \( n \) indicating the number of elements in the list. \( n \) can be zero.
  2. If \( n > 0 \), the second line contains \( n \) elements separated by a single space. Elements may be strings or integers.

outputFormat

Output the list after performing the pairwise swaps. The elements should be outputted in order, separated by a single space. If the list is empty, output nothing.

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