#C13995. Categorize Numbers into Odd, Even, and Prime

    ID: 43594 Type: Default 1000ms 256MiB

Categorize Numbers into Odd, Even, and Prime

Categorize Numbers into Odd, Even, and Prime

You are given a list of n integers. Your task is to categorize these numbers into three groups:

  • Odd: All odd numbers (negative and positive) in the order of their first appearance (duplicates removed).
  • Even: All even numbers in the order of their first appearance (duplicates removed).
  • Prime: All numbers that are prime (a number is considered prime if it is greater than 1 and divisible only by 1 and itself) in the order of their first appearance (duplicates removed). Note that negative numbers are not considered prime.

Input is provided via standard input and output should be printed to standard output. The first line of input contains n, the number of elements. The second line contains n space-separated integers.

Output should consist of three lines:

  1. First line: all odd numbers separated by a single space. If there are no odd numbers, output an empty line.
  2. Second line: all even numbers separated by a single space. If there are no even numbers, output an empty line.
  3. Third line: all prime numbers separated by a single space. If there are no prime numbers, output an empty line.

Make sure that each category contains unique numbers preserving the order of their first occurrence.

inputFormat

The input is in two lines:

  • The first line contains a single integer n (1 ≤ n ≤ 105), the number of integers in the list.
  • The second line contains n space-separated integers.

Input is provided via standard input (stdin).

outputFormat

The output should consist of three lines printed to standard output (stdout):

  1. The first line contains the unique odd numbers (in order of first occurrence) separated by a space. Print an empty line if none.
  2. The second line contains the unique even numbers separated by a space. Print an empty line if none.
  3. The third line contains the unique prime numbers separated by a space. Print an empty line if none.
## sample
5
1 3 5 7 9
1 3 5 7 9

3 5 7

</p>