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: Wrong Answer)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=205,L=1e7+5;
bool mark[L],prime[L];
namespace match
{
  const int N=205;
  int l[N],r[N],n,m;
  bool a[N][N],seen[N];
  bool findmatch(int i)
  {
    rep(j,0,m)
      {
	if(a[i][j] && !seen[j])
	  {
	    seen[j]=true;
	    if(r[j]<0 || findmatch(r[j]))
	      {
		l[i]=j; r[j]=i;
		return true;
	      }
	  }
      }
    return false;
  }
  int bipartitematch()
  {
    int cnt=0;
    rep(i,0,n) l[i]=-1;
    rep(i,0,m) r[i]=-1;
    rep(i,0,n)
      {
	rep(j,0,m) seen[j]=false;
	if(findmatch(i)) cnt++;
      }
    return cnt;
  }
};
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  memset(prime,true,sizeof(prime));
  prime[1]=false;
  rep(i,2,L)
    {
      if(!prime[i]) continue;
      for(int j=2*i;j<L;j+=i)
	prime[j]=false;
    }
  prime[2]=false;
  int n,x;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>x;
      mark[x]=true;
    }
  vi arr;
  rep(i,1,L-1)
    if((mark[i-1] && !mark[i])  || (!mark[i-1] && mark[i]))
      arr.pb(i);
  match::n=match::m=sz(arr);
  int odd=0,even=0;
  for(int x:arr)
    {
      if(x%2==0) even++;
      else odd++;
    }
  rep(i,0,sz(arr))
    rep(j,i+1,sz(arr))
    {
      if(prime[arr[j]-arr[i]]) match::a[i][j]=1;
      else match::a[i][j]=0;
    }
  int k=match::bipartitematch();
  int ans=k+((even-k)/2+(odd-k)/2)*2+((even-k)&1)*3;
  cout<<ans<<endl;
  return 0 ;
}