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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] X = new int[N];
        for(int i=0;i<N;i++){
            X[i] = int.Parse(str[i]);
        }
        List<int> Diff = new List<int>();
        Diff.Add(X[0]);
        Diff.Add(X[N-1]+1);
        for(int i=1;i<N;i++){
            if(X[i] != X[i-1] + 1){
                Diff.Add(X[i]);
            }
        }
        for(int i=0;i<N-1;i++){
            if(X[i] + 1 != X[i+1]){
                Diff.Add(X[i]+1);
            }
        }
        int[] diff = Diff.ToArray();
        int o = 0;
        int e = 0;
        for(int i=0;i<diff.Length;i++){
            if(diff[i] % 2 == 0){
                e++;
            }
            else{
                o++;
            }
        }
        int[] Odd = new int[o];
        int[] Even = new int[e];
        o = 0;
        e = 0;
        for(int i=0;i<diff.Length;i++){
            if(diff[i] % 2 == 0){
                Even[e] = diff[i];
                e++;
            }
            else{
                Odd[o] = diff[i];
                o++;
            }
        }
        List<int> f = new List<int>();
        List<int> t = new List<int>();
        List<long> capa = new List<long>();
        int S = 0;
        int Ef = 1;
        int Of = e+1;
        int T = o+e+1;
        for(int i=0;i<e;i++){
            f.Add(S);
            t.Add(Ef+i);
            capa.Add(1);
        }
        for(int i=0;i<0;i++){
            f.Add(Of+i);
            t.Add(T);
            capa.Add(1);
        }
        Generateprimenumber G = new Generateprimenumber(10000);
        for(int i=0;i<e;i++){
            for(int j=0;j<o;j++){
                if(G.Prime(Math.Max(Even[i]-Odd[j],Odd[j]-Even[i]))){
                    f.Add(Ef+i);
                    t.Add(Of+j);
                    capa.Add(1);
                }
            }
        }
        MaxFlow Flow = new MaxFlow(f.ToArray(),t.ToArray(),capa.ToArray(),o+e+2,0,o+e+1);
        int flow = (int)Flow.flow;
        int count = diff.Length - flow;
        if(e % 2 != flow % 2){
            count++;
        }
        sb.Append(count+"\n");
    }
}
class Edge{
    public Vertex to;
    public long capacity;
    public Edge rev;
    public Edge(Vertex v,long c){
        to = v;
        capacity = c;
    }
}
class Vertex{
    public bool finished;
    public List<Edge> edges;
    public void AddEdge(Edge e){
        edges.Add(e);
    }
    public Vertex(){
        edges = new List<Edge>();
        finished = false;
    }
}
class MaxFlow{
    Vertex[] point;
    Vertex S;
    Vertex G;
    public long flow;
    int E;
    const long INF = 1000000000000000;
    public MaxFlow(int[] f,int[] t,long[] capacity,int n,int s,int g){
        point = new Vertex[n];
        for(int i=0;i<n;i++){
            point[i] = new Vertex();
        }
        E = f.Length;
        for(int i=0;i<E;i++){
            point[f[i]].AddEdge(new Edge(point[t[i]],capacity[i]));
            point[t[i]].AddEdge(new Edge(point[f[i]],0));
            point[f[i]].edges[point[f[i]].edges.Count-1].rev = point[t[i]].edges[point[t[i]].edges.Count-1];
            point[t[i]].edges[point[t[i]].edges.Count-1].rev = point[f[i]].edges[point[f[i]].edges.Count-1];
        }
        S = point[s];
        G = point[g];
        flow = 0;
        while(true){
            long fl = dfs(S,INF);
            flow += fl;
            if(fl == 0){
                break;
            }
            for(int i=0;i<n;i++){
                point[i].finished = false;
            }
        }
    }
    long dfs(Vertex v,long f){
        v.finished = true;
        if(v == G){
            return f;
        }
        for(int i=0;i<v.edges.Count;i++){
            Edge e = v.edges[i];
            if(!e.to.finished && e.capacity > 0){
                long d = dfs(e.to,Math.Min(f,e.capacity));
                if(d > 0){
                    e.capacity -= d;
                    e.rev.capacity += d;
                    return d;
                }
            }
        }
        return 0;
    }
}
class Generateprimenumber{
    public int[] p;
    public int length;
    public Generateprimenumber(int n){
        bool[] a = new bool[n+1];
        List<int> pp = new List<int>();
        int j = 2;
        for(int i=0;i<n+1;i++){
            a[i] = true;
        }
        while(j<=n){
            if(a[j]){
                pp.Add(j);
                for(int i=j;(long)i*(long)j<=n;i++){
                    a[i*j] = false;
                }
            }
            j++;
        }
        length = pp.Count;
        p = pp.ToArray();
    }
    public bool Prime(int x){
        for(int i=0;i<length;i++){
            if(p[i] == x){
                return true;
            }
            else if(x % p[i] == 0){
                return false;
            }
            else if(p[i]*p[i] > x){
                break;
            }
        }
        return true;
    }
}