atcoder#ARC080D. [ARC080F] Prime Flip

[ARC080F] Prime Flip

Score : 12001200 points

Problem Statement

There are infinitely many cards, numbered 11, 22, 33, ...... Initially, Cards x1x_1, x2x_2, ......, xNx_N are face up, and the others are face down.

Snuke can perform the following operation repeatedly:

  • Select a prime pp greater than or equal to 33. Then, select pp 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

  • 1N1001 \leq N \leq 100
  • 1x1<x2<...<xN1071 \leq x_1 < x_2 < ... < x_N \leq 10^7

Input

Input is given from Standard Input in the following format:

NN

x1x_1 x2x_2 ...... xNx_N

Output

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

2
4 5
2

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

  • Select p=5p = 5 and flip Cards 11, 22, 33, 44 and 55.
  • Select p=3p = 3 and flip Cards 11, 22 and 33.
9
1 2 3 4 5 6 7 8 9
3

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

  • Select p=3p = 3 and flip Cards 11, 22 and 33.
  • Select p=3p = 3 and flip Cards 44, 55 and 66.
  • Select p=3p = 3 and flip Cards 77, 88 and 99.
2
1 10000000
4