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

#SP0000217. Dãy con có tổng nguyên tố (Primed Subsequence)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Dãy con có tổng nguyên tố (Primed Subsequence)

Primed Subsequence

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence a1,a2,…,ana_1,a_2,\ldots,a_n of nonnegative integers. A primed subsequence is a contiguous segment containing at least two elements whose sum is prime (a prime is an integer greater than 11 with exactly two positive divisors).

Find a valid segment of minimum length. If several segments have the same minimum length, choose the one with the earliest starting position. If no such segment exists, print the exact prescribed message. Preserve the original order of the chosen elements.

Input

The first line contains the integer nn. The second line contains nn nonnegative integers a1,a2,…,ana_1,a_2,\ldots,a_n in sequence order.

Output

If a valid segment exists, print one line beginning with the exact phrase Shortest primed subsequence is length x: (replace x by the segment length), followed by a space and the chosen elements separated by spaces. Otherwise, print exactly This sequence is anti-primed..

Subtasks

  • Subtask 1 (20 points): 1≤n≤251\le n\le25; 0≤ai<1040\le a_i<10^4 for all 1≤i≤n1\le i\le n.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000; 0≤ai<1040\le a_i<10^4 for all 1≤i≤n1\le i\le n.

  • Subtask 3 (50 points): 1≤n≤1041\le n\le10^4; 0≤ai<1040\le a_i<10^4 for all 1≤i≤n1\le i\le n.

Examples

Input

5
3 5 6 3 8

Output

Shortest primed subsequence is length 2: 5 6

Explanation

The sequence is 3,5,6,3,83,5,6,3,8. The adjacent pair sums, in order, are 3+5=83+5=8 (not prime), 5+6=115+6=11 (prime), 6+3=96+3=9 (not prime), and 3+8=113+8=11 (prime). Length 22 is the smallest permitted length. Among the two qualifying pairs, 5,65,6 starts earlier, at position 22 rather than position 44. Hence the displayed segment is 5,65,6.