#include <iostream>

using namespace std;

int isprime(int n, int k = 2)
{
    if(n == 1) { return 0; }
    
    if(n < k * k) { return 1; }
    
    if(n % k == 0) { return 0; }
    
    return isprime(n, k + 1);
}

int solve(int n)
{
    int count_ = 0;
    
    for(int i = 1; i <= n; i++)
    {
        count_ += isprime(i) * isprime(n + 1 - i);
    }
    
    return count_;
}

int main()
{
    int n;
    
    while(cin >> n)
    {
        cout << solve(n) << endl;
    }
    
    return 0;
}