#include<iostream>
#include<cstring>
using namespace std;

bool d[10001];
int n;

int main(){

  memset(d,true,sizeof(d));
  d[0] = d[1] = false;
  for(int i=2;i*i<10001;i++){
    if(d[i] == true){
      for(int j=i+i;j<10001;j+=i) d[j] = false;
    }
  }

  while(cin >> n){

    int cnt = 0;
    for(int i=1;i<=n;i++){
      if(d[i] == true && d[n-(i-1)] == true) cnt++;
    }

    cout << cnt << endl;

  }
}