PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000135. Tập con có tổng từng cặp nguyên tố (Simple Subset)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tập con có tổng từng cặp nguyên tố (Simple Subset)

Simple Subset

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array aa of nn positive integers; equal values are allowed. Choose a subsequence (not necessarily contiguous) such that the sum of every pair of elements at distinct chosen positions is prime.

Maximize the number of selected elements. Equal values at different positions count as distinct elements. Any maximum-size valid subsequence may be printed.

Input

The first line contains nn. The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print the maximum size mm on the first line. Print the mm selected elements separated by spaces on the next line, in any order.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; 1≤ai≤301\le a_i\le 30 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤1501\le n\le 150; 1≤ai≤10001\le a_i\le 1000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le 1000; 1≤ai≤1061\le a_i\le 10^6 for every 1≤i≤n1\le i\le n.

Examples

Input

3
2 1 1

Output

3
1 1 2

Explanation

The input has three elements 2,1,12,1,1. Taking all three works: 1+1=21+1=2 is prime, and both remaining pairwise sums equal 1+2=31+2=3, also prime. There are only three input positions, so the optimum size is 3, represented by 1 1 2.