We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this:


1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1


Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime.



Input

Input contains several test cases. Each test case consists of an integer N in one line.

Output

For each line of input, output P .

Example

Input

1
4
7
51


Output

0
2
2
6
#include <iostream>
#include <vector>
using namespace std;
const int SIZE = 10000;
int main (int argc, char *argv[]) {
	// make sieve
	vector<bool> sieve(SIZE,true);
	sieve[0] = false; sieve[1] = false;
	for(int i = 2; i < SIZE; ++i) {
		if (sieve[i]) {
			for(int j = i+i; j < SIZE; j+=i) {
				sieve[j] = false;
			}
		}
	}
	// count p
	int N;
	while (cin >> N) {
		vector<int> inc(N), dec(N);
		for (int i=0;i<N;i++) {
			inc[i] = i+1;
			dec[i] = N-i;
		}
		int count = 0;
		for(int i = 0; i < N; ++i) {
			if (sieve[inc[i]] && sieve[dec[i]]) count++;
		}
		cout << count << endl;
	}
	return 0;
}