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>
 
using namespace std;
 
const int maxn = 1e7 + 700;
 
 
int n,fre[maxn],p[220],ispr[maxn],even,odd,wrong;
vector <int> edge[220],v2;
 
bool fin(int u) {
    if (fre[u]==wrong) return false;
    fre[u]=wrong;
    for (int j=0;j<edge[u].size();j++) {
        int v=edge[u][j];
       // cout<<u<<" "<<v<<endl;
        if (p[v]==0 || fin(p[v])) {
            p[v]=u;
            return true;
        }
    }
    return false;
}
 
int main() {
  //  freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    ispr[1]=1;
    for (int i=2;i<maxn;i++)
        if (ispr[i]==0) {
            for (int j=i+i;j<maxn;j+=i) ispr[j]=1;
        }
    cin>>n;
    for (int i=1;i<=n;i++) {
        int x;
        cin>>x;
        fre[x]^=1;
        fre[x+1]^=1;
    }
    even=0; odd=0; wrong=2;
    for (int i=0;i<maxn;i++)
        if (fre[i]==1) {
            v2.push_back(i);
            if (i%2==0) even++;
            else odd++;
        }
    // for (int i=0;i<v2.size();i++) cout<<v2[i]<<" ";
   //  cout<<endl;
   // cout<<" " <<even<<" "<<odd<<endl;
    for (int i=0;i<v2.size();i++)
        for (int j=0;j<v2.size();j++)
            if (v2[i]%2==0 && v2[j]%2==1 && ispr[ abs(v2[j] - v2[i]) ]==0 && abs(v2[j] - v2[i])%2==1) {
                edge[i].push_back(j);
                edge[j].push_back(i);
            }
    int cnt=0;
    for (int i=0;i<v2.size();i++)
     if (p[i]==0) {
        wrong++;
        if (fin(i)) cnt++;
    }
    cout<< cnt + (even-cnt)/2 *2 + (odd-cnt)/2 * 2 + ((even-cnt)%2)*3;
}