The problem about the chest (Hard)
Chest named Vova, like all the other chests, dreams of becoming a real safe for his owner. To do this, he wants to make an unusual combination lock. Who wants to open will be given a square matrix with N×N size, filled with random numbers. These numbers need to be made prime by using only two operations:
increase the number by 2
decrease the number by 1
Recall that a number is called prime if it is greater than one and has no divisors other than one and itself.
In response, the lock will be necessary to introduce the minimum number of operations that must be performed in order to transform the matrix to the desired form.
Input
The first line contains the size of the matrix n (1 ≤ n ≤ 50). Each of the next n lines contains n integers. This is matrix generated by the lock. To tell you the truth, elements are not entirely random. It is known that each element is non-negative and not greater than 10^18.
Output
Number, after which the lock will open.