Problem:
Pair of Primes

We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing
order and decreasing order like this:

1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1

Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both
numbers in the pairs are prime.

Input

Input contains several test cases. Each test case consists of an integer N in
one line.

Output

For each line of input, output P .

Sample Input

1
4
7
51

Output for the Sample Input

0
2
2
6

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var s=Console.ReadLine();
			if(s==null)break;
			var d=int.Parse(s);
			Sol mySol = new Sol(d);
			Console.WriteLine(mySol.Ans);
		}
	}
}

class Sol{
	int ans;
	public int Ans{
		get{return ans;}
		set{this.ans=value;}
	}
	public Sol(int d){
		int[,] Arr=new int[2,d+1];
		for(int i=0;i<=d;i++)Arr[0,i]=0;
		Arr[0,1]=1;
		for(int i=2;i<=d;i++){
			if(Arr[0,i]==0){
				int k;
				for(k=2;k*i<=d;k++)Arr[0,k*i]=1;
			}
		}
		for(int i=1;i<=d;i++){
			Arr[1,d-i+1]=Arr[0,i];
		}
		int cnt=0;
		for(int i=1;i<=d;i++){
			if(Arr[0,i]==0 && Arr[1,i]==0)cnt++;
		}
		ans=cnt;
	}
}