primes = [false, false]
2.upto(10000){|x|
    prime = true
    2.upto(Math.sqrt(x)){|d| 
        if x % d == 0
            prime = false
            break
        end
    }
    primes[x] = prime
}

while line = gets
    n = line.to_i
    sum = 0
    1.upto(n){|i| sum += 1 if primes[i] && primes[n - i + 1]}
    puts sum
end

