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 <iostream>
#include <vector>
#include <algorithm>
#include <time.h>
#include <random>
#include <fstream>
#include <set>

using namespace std;

const int N = 1e7 + 2;

int n;

int c[N];
int p[N];
int a[200];

vector<int> graph[400];

int paired[400];
int marked[400];

int TryKuhn(int v)
{
    if (marked[v]) return 0;
    marked[v] = 1;
    for (auto u : graph[v])
    {
        if (paired[u] == -1 || TryKuhn(paired[u]))
        {
            paired[u] = v;
            return 1;
        }
    }
    return 0;
}

int G()
{
    int res = 0;
    fill(paired, paired + 400, -1);
    for (int i = 0; i < n; i++)
    {
        fill(marked, marked + 400, 0);
        if (TryKuhn(i))
            res++;
    }
    return res;
}

signed main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for (int i = 2; i < N; i++)
    {
        if (p[i] == 0)
        {
            for (int j = 2; j * i < N; j++) p[i * j] = 1;
        }
    }
    p[2] = 1;
    p[1] = 1;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        c[x] = 1;
    }
    n = 0;
    for (int i = 0; i + 1 < N; i++)
    {
        if (c[i] != c[i + 1])
        {
            a[n] = i;
            n++;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (a[i] % 2 == 0 && a[j] % 2 == 1)
            {
                if (1 || !p[abs(a[i] - a[j])])
                {
                    graph[i].push_back(200 + j);
                    graph[200 + j].push_back(i);
                }
            }
        }
    }
    /*for (int i = 0; i < 400; i++)
    {
        for (auto u : graph[i])
        {
            cout << i << " " << u << endl;
        }
    }*/
    int c0 = 0, c1 = 0, c2 = G();
    for (int i = 0; i < n; i++)
    {
        if (a[i] % 2 == 0) c0++;
        else c1++;
    }
    int ans = c2 + ((c0 - c2) / 2) * 2 + ((c1 - c2) / 2) * 2 + ((c1 - c0) % 2) * 3;
    cout << ans;
}