import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  ns <- map read . lines <$> getContents :: IO [Int]
  mapM_ (print . solve) ns

solve :: Int -> Int
solve n = 2 * go [1..(n+1) `div` 2]
  where
    go [] = 0
    go (x:xs) = (if isPrime x && isPrime (n+1 - x)
                   then 1
                   else 0) + go xs

isPrime :: Int -> Bool
isPrime n  = n `elem` (takeWhile (<= n) primes)

primes = 2 : 3 : filter f [5..]
  where
    f n = all (\i -> n `mod` i /= 0) (takeWhile (\i -> i * i <= n) primes)