#include<iostream>
#include<stdio.h>

using namespace std;

bool arr[10000];
long long listprime[10000];
int banyakprima = 0;

void sieve()
{
	for(int i = 3 ; i < 10000 ; i ++)
	{
		if(i%2 == 1)
		{
			arr[i] = true;
		}
		else
		arr[i] = false;
	}
	listprime[banyakprima] = 2;
	banyakprima++;
	arr[1] = false ; arr[0] = false ; arr[2] = true;
	for(int i = 3 ; i < 10000 ; i = i + 2)
	{
		if(arr[i])
		{
			listprime[banyakprima] = i;
			banyakprima++;
			for(long long j = i*i ; j < 10000 ; j = j + i )
			{
				arr[j] = false;
			}
		}
		
	}
}

int main()
{
	sieve();
	long long n , p ;
	while(cin>>n)
	{
		long long res = 1 ;
		long long tamp = n;
		long long hasil = 0;
		while(tamp != 1 && res != n)
		{
			if(arr[res] == true && arr[tamp] == true)
			{
				hasil++;
			}
			tamp--;
			res++;
		}
		cout<<hasil<<endl;
	}
}
