#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
#define PI acos(-1)
using namespace std;
int main(){

  int i,j;
  int num[50001]={1,1};

  for(i=3;i<50001;i+=2){
    if(num[i]==1)
      continue;
    for(j=3*i;j<50001;j+=i*2)
      num[j]=1;
  }
  for(i=4;i<50001;i+=2)
    num[i]=1;

  int in;
  while(cin>>in){
    int co=0;
    loop(i,2,in){
      if(!(num[i]||num[in-i+1]))co++;
    }
    cout<<co<<endl;
  }

}