#C13614. Every N-th Element
Every N-th Element
Every N-th Element
Given a list of integers and an integer \(n\), return a new list that contains every \(n\)-th element of the original list. The list is considered 1-indexed, meaning the first element is at position 1.
If \(n \le 0\) or if there is no valid \(n\)-th element in the list, the output should be an empty list.
inputFormat
The input is read from standard input (stdin) and consists of three parts:
- An integer \(m\) on the first line representing the number of elements in the list.
- If \(m > 0\), a second line containing \(m\) space-separated integers.
- A third line containing an integer \(n\), the interval at which elements should be selected.
outputFormat
Print the elements that are at every \(n\)-th position from the list, separated by a space, to standard output (stdout). If there are no such elements, output an empty line.
## sample10
1 2 3 4 5 6 7 8 9 10
3
3 6 9