#K44007. Filter Odd or Even Numbers

    ID: 27435 Type: Default 1000ms 256MiB

Filter Odd or Even Numbers

Filter Odd or Even Numbers

You are given a list of integers and an option string. Your task is to filter the list and output only the odd numbers if the option is odd or only the even numbers if the option is even. If the option is neither odd nor even, output an empty result.

Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). The filtered numbers must be printed in their original order, separated by a single space. If there are no numbers to output, print an empty line.

Input Format:

  • The first line contains an integer n representing the number of elements in the list.
  • The second line contains n space-separated integers.
  • The third line contains a string which is either odd or even (or some other value for invalid option).

Output Format:

  • Output the filtered list of integers separated by a space, according to the given option. If no integer meets the condition, output an empty line.

Example:

Input:
6
1 2 3 4 5 6
even

Output: 2 4 6

</p>

Constraints:

  • 1 ≤ n ≤ 10^5
  • Each integer in the list will be in the range of a 32-bit signed integer.

Mathematical Explanation:

Given an integer x, it is even if and only if \(x \mod 2 = 0\) and odd if \(x \mod 2 \neq 0\). The program should filter elements based on this condition.

inputFormat

The input consists of three lines:

  • First line: An integer n, the number of elements in the list.
  • Second line: n space-separated integers.
  • Third line: A string representing the option (either "odd" or "even").

outputFormat

Output a single line containing the filtered list of integers separated by a space. If no integers meet the condition, output an empty line.

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