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:f [3] [3,5..]
    where
      f (x:xs) ys = let (ps, qs) = span (< x^2) ys in
        ps ++ f (xs ++ ps) [z | z <- qs, mod z x /= 0]