import math

r = 9999

sqrt = int(math.sqrt(r))

p = [1 for i in range(r)]

p[0] = 0

for i in range(sqrt):

    if p[i]:

        p[2*i+1::i+1] = [0 for j in range(2*i+1,r,i+1)]

prime = []

for i in range(r):

    if p[i]:

        prime.append(i)



while True:

    try:

        n = int(input())

        count = 0

        for i in prime:

            if i > n-1:

                break

            if p[i]*p[n-i-1] == 1:

                count += 1

        print(count)

    except:

        break
import math

r = 9999

sqrt = int(math.sqrt(r))

p = [1 for i in range(r)]

p[0] = 0

for i in range(sqrt):

    if p[i]:

        p[2*i+1::i+1] = [0 for j in range(2*i+1,r,i+1)]

prime = []

for i in range(r):

    if p[i]:

        prime.append(i)



while True:

    try:

        n = int(input())

        count = 0

        for i in prime:

            if i > n-1:

                break

            if p[n-i-1] == 1:

                count += 1

        print(count)

    except:

        break
import math

r = 9999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(sqrt):
    if p[i]:
        p[2 * i + 1 :: i + 1] = [0 for j in range(2 * i + 1, r, i + 1)]
prime = []
for i in range(r):
    if p[i]:
        prime.append(i)
while True:
    try:
        n = int(input())
        count = 0
        for i in prime:
            if i > n - 1:
                break
            if p[i] * p[n - i - 1] == 1:
                count += 1
        print(count)
    except:
        break

import math

r = 9999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(sqrt):
    if p[i]:
        p[2 * i + 1 :: i + 1] = [0 for j in range(2 * i + 1, r, i + 1)]
prime = []
for i in range(r):
    if p[i]:
        prime.append(i)
while True:
    try:
        n = int(input())
        count = 0
        for i in prime:
            if i > n - 1:
                break
            if p[n - i - 1] == 1:
                count += 1
        print(count)
    except:
        break

-            if p[i] * p[n - i - 1] == 1: +            if p[n - i - 1] == 1: