#P5771. Anti-Prime Subsequence

    ID: 18999 Type: Default 1000ms 256MiB

Anti-Prime Subsequence

Anti-Prime Subsequence

For a sequence \(X = \{x_1,x_2,\dots,x_L\}\) with \(L \ge 2\), we call it an anti-prime sequence if for any \(1 \le i < j \le L\), the sum \(x_i + x_j\) is not a prime number. Given a sequence \(A = \{a_1,a_2,\dots,a_N\}\) of length \(N\), your task is to select a subsequence (not necessarily contiguous) with the maximum number of elements such that the chosen subsequence is an anti-prime sequence.

Note: The number 1 is a special case. Recall that \(1\) is not a prime number, but note that \(1+1=2\) which is prime. Hence, you can include at most one occurrence of \(1\) in your subsequence if there are other odd numbers in it.

inputFormat

The first line contains an integer \(N\) (the length of sequence \(A\)).

The second line contains \(N\) space-separated integers \(a_1, a_2, \dots, a_N\).

outputFormat

On the first line, output the size of the maximum anti-prime subsequence.

On the second line, output the elements of the chosen subsequence separated by a space. If there are multiple answers, print any of them.

sample

4
1 2 3 4
2

2 4

</p>