Problem: Ikshu and his prime matrix

Ikshu is in love with prime numbers. He has a matrix of size N X N and wants atleast 5 prime numbers in that matrix arranged like a cross as shown in figure. Let us call this matrix "new year matrix"
X   X   X   X    X
If matrix is not a "new year matrix" he can alter it with the operation as described below:

1) Choose an element from the matrix.

2)  Increment the value at the element by K assuring that value of
   element does not exceed 10000.

Above operation can be applied any number of times.

Example :

Let matrix be:
2 2 3
4 5 6
7 8 9
and k be 1

He can perform 2 operations on (3,3) to get a cross centered at (2,2) with prime numbers = [2,3,5,7,11]

constraints:
1 ≤ N ≤ 1000
1 ≤ K ≤ 5
1 ≤ any element of matrix ≤10000

Input:
First line on input contains two integer N and K which is the size of the matrix, followed by N X N matrix.
N is the size of the matrix
and K is the value which is allowed to be add to any element of matrix.

Output: 
First line of output contains "yes" if such cross is possible else it contains "no".
If answer is possible, second line contains the minimum number of operations and third line contains the co-ordinate of center of cross(assuming indexing to be 1-based)
If many such answers are possible, print the one with minimum row index, if many answers are possible with same minimum row index print the one with minimum col index

SAMPLE INPUT
3 1
2 2 3
4 5 6
7 8 9

SAMPLE OUTPUT
yes
2 
2 2

Solution (in PYTHON):

Solution:
sieve={i:0 for i in range(2,100000)}
for i in range(2,100000):
    if sieve[i]==0:
        for j in range(2,1+99999/i):
            sieve[i*j]=1
n,k=map(int,raw_input().split())
if k==1:
    cur=2
    pre=[0]
    for i in range(1,10001):
        if i<=cur:
            pre.append(cur-i)
        else:
            cur+=1
            while sieve[cur]==1:
                cur+=1
            pre.append(cur-i)
elif k==2:
    cur=3
    pre=[0]*10001
    for i in range(1,10001,2):
        if i<=cur:
            pre[i]=(cur-i)/2
        else:
            cur+=2
            while sieve[cur]==1:
                cur+=2
            pre[i]=(cur-i)/2
    for i in range(4,10001,2):
        pre[i]=-1
elif k==3:
    cur=2
    pre=[0]*10001
    for i in range(2,10001,3):
        if i<=cur:
            pre[i]=(cur-i)/3
        else:
            cur+=3
            while sieve[cur]==1:
                cur+=3
            pre[i]=(cur-i)/3
    cur=7
    for i in range(1,10001,3):
        if i<=cur:
            pre[i]=(cur-i)/3
        else:
            cur+=3
            while sieve[cur]==1:
                cur+=3
            pre[i]=(cur-i)/3
    for i in range(6,10001,3):
        pre[i]=-1
elif k==4:
    cur=5
    pre=[0]*10001
    for i in range(1,10001,4):
        if i<=cur:
            pre[i]=(cur-i)/4
        else:
            cur+=4
            while sieve[cur]==1:
                cur+=4
            pre[i]=(cur-i)/4
    cur=7
    for i in range(3,10001,4):
        if i<=cur:
            pre[i]=(cur-i)/4
        else:
            cur+=4
            while sieve[cur]==1:
                cur+=4
            pre[i]=(cur-i)/4
    for i in range(4,10001,2):
        pre[i]=-1
else:
    cur=11
    pre=[0]*10001
    for i in range(1,10001,5):
        if i<=cur:
            pre[i]=(cur-i)/5
        else:
            cur+=5
            while sieve[cur]==1:
                cur+=5
            pre[i]=(cur-i)/5
    cur=7
    for i in range(2,10001,5):
        if i<=cur:
            pre[i]=(cur-i)/5
        else:
            cur+=5
            while sieve[cur]==1:
                cur+=5
            pre[i]=(cur-i)/5
    cur=13
    for i in range(3,10001,5):
        if i<=cur:
            pre[i]=(cur-i)/5
        else:
            cur+=5
            while sieve[cur]==1:
                cur+=5
            pre[i]=(cur-i)/5
    cur=19
    for i in range(4,10001,5):
        if i<=cur:
            pre[i]=(cur-i)/5
        else:
            cur+=5
            while sieve[cur]==1:
                cur+=5
            pre[i]=(cur-i)/5
    for i in range(10,10001,5):
        pre[i]=-1
grid=[]
for _ in range(n):
    grid.append(map(int,raw_input().split()))
ans=10**9
ansr=0
ansc=0
for r in range(1,n-1):
    for c in range(1,n-1):
        if min(pre[grid[r][c]],pre[grid[r-1][c-1]],pre[grid[r-1][c+1]],pre[grid[r+1][c-1]],pre[grid[r+1][c+1]])!=-1:
            com=pre[grid[r][c]]+pre[grid[r-1][c-1]]+pre[grid[r-1][c+1]]+pre[grid[r+1][c-1]]+pre[grid[r+1][c+1]]
            if com<ans:
                ans=com
                ansr=r+1
                ansc=c+1
if ans==10**9:
    print 'no'
else:
    print 'yes'
    print ans
    print ansr,ansc