# encoding: utf-8                                                            

require 'prime'

while n = gets and (not n.nil?)
  n = n.to_i
  ans = 0
  (1..n).each do |i|   
    ans += 1 if Prime.prime?(i) and Prime.prime?(n - i + 1)
  end
  p ans
end