#K88122. Taco Pattern
Taco Pattern
Taco Pattern
You are given an integer n and a list of elements. Your task is to output the list rearranged in a specific pattern: the first element, followed by the last element, the second element, the second last element, and so on. Formally, you need to create a sequence based on the following procedure:
For i = 0 to \(\lceil \frac{n+1}{2} \rceil - 1\):
- If i is a valid index of the list, output the element at index i.
- If n - i - 1 is a valid index and is not equal to i, output the element at index n - i - 1.
Note: The value of n may be larger than the number of provided elements. In such a case, only the available elements are used.
This problem tests your ability to manipulate array indices and handle edge cases. Good luck!
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer n, which represents the intended number of elements.
- The second line contains a sequence of space-separated strings representing the elements.
If the number of provided elements is less than n, only the given elements are considered.
outputFormat
Print to standard output (stdout) the rearranged elements in one line, separated by a single space.
## sample7
a b c d e f g
a g b f c e d