Problem:
Score : 1200 points

Problem Statement

There are infinitely many cards, numbered 1, 2, 3, ...
Initially, Cards x_1, x_2, ..., x_N are face up, and the others are face down.

Snuke can perform the following operation repeatedly:

Select a prime p greater than or equal to 3. Then, select p consecutive cards and flip all of them.

Snuke's objective is to have all the cards face down.
Find the minimum number of operations required to achieve the objective.

Constraints

1 ≤ N ≤ 100

1 ≤ x_1 < x_2 < ... < x_N ≤ 10^7

Input

Input is given from Standard Input in the following format:

N
x_1 x_2 ... x_N

Output

Print the minimum number of operations required to achieve the objective.

Sample Input 1

2
4 5

Sample Output 1

2

Below is one way to achieve the objective in two operations:

Select p = 5 and flip Cards 1, 2, 3, 4 and 5.

Select p = 3 and flip Cards 1, 2 and 3.

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

3

Below is one way to achieve the objective in three operations:

Select p = 3 and flip Cards 1, 2 and 3.

Select p = 3 and flip Cards 4, 5 and 6.

Select p = 3 and flip Cards 7, 8 and 9.

Sample Input 3

2
1 10000000

Sample Output 3

4

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=1010;
struct gao{   int u,v,Next;   }Edge[MAXN<<1];
int n,Lo,Le,Seq[10000010],Odd[MAXN],Even[MAXN];
int Ans,Es,Ps,First[MAXN],Match[MAXN],Vis[MAXN];
inline int Read()
{   rg int a=0,c=1;   rg char b=getchar();
	while(b!='-'&&(b<'0'||b>'9'))b=getchar();
	if(b=='-')c=-1,b=getchar();
	while(b>='0'&&b<='9')a=a*10+b-48,b=getchar();
	return a*c;
}
inline void Link(rg int u,rg int v)
{   Edge[++Es]=(gao){u,v,First[u]},First[u]=Es;   }
inline int Abs(rg int A){   return A<0?-A:A;   }
inline bool Judge(rg int Num)
{   if(Num%2==0||Num<=2) return 0;
	for(rg int i=3,End=sqrt(Num);i<=End;i+=2)
		if(Num%i==0) return 0;
	return 1;
}
inline bool Couple(rg int Now,rg int Sign)
{   for(rg int i=First[Now];i!=-1;i=Edge[i].Next)
	{   rg int v=Edge[i].v;   if(Vis[v]==Sign) continue ;
		Vis[v]=Sign;
		if(!Match[v]||Couple(Match[v],Sign)) return Match[v]=Now,Match[Now]=v,1;
	}
	return 0;
}
int main()
{   scanf("%d",&n);
	memset(First,-1,sizeof(First));
	for(rg int i=1;i<=n;i++) Seq[Read()]=1;
	for(rg int i=1e7+1;i>=1;i--) Seq[i]=Seq[i]!=Seq[i-1];
	for(rg int i=1;i<=1e7+1;i++) if(Seq[i]) i%2?Odd[++Lo]=i:Even[++Le]=i;
	if((Lo+Le)%2) return puts("0");
	for(rg int i=1;i<=Lo;i++)
		for(rg int j=1;j<=Le;j++) if(Judge(Abs(Odd[i]-Even[j]))) Link(i,Lo+j),Link(Lo+j,i);
	for(rg int i=1;i<=Lo;i++) if(!Match[i]) Ps+=Couple(i,i);
	Ans=Ps+(Lo-Ps)/2*2+(Le-Ps)/2*2+((Lo-Ps)%2)*3,printf("%d\n",Ans);
}