#include<stdio.h>
#include<bitset>
int main()
{
	const int N=10001;
	std::bitset<N>p;
	p.set();
	int i,j,x,r;
	p[0]=p[1]=0;
	for(i=2;i<N/2;++i)if(p[i])for(j=i*2;j<N;j+=i)p[j]=0;
	while(scanf("%d",&x)>0)
	{
		for(r=i=0;i<x;++i)if(p[i+1]&&p[x-i])++r;
		printf("%d\n",r);
	}
	return 0;
}