import scala.io.Source

object Main extends App {
  var set = (1 to 10000).filter(x => isPrimeNumber(x)).toSet
  val in = Source.stdin.getLines
  for (line <- in) {
    val n = line.toInt
    val count1 = (1 to n / 2)
      .filter(x => set.contains(x))
      .filter(x => set.contains(n + 1 - x))
      .size
    val count2 =
      if (n % 2 == 1 && set.contains((n + 1) / 2)) 1
      else 0

    println(count1 * 2 + count2)
  }

  def isPrimeNumber(value: Int): Boolean = {
    if (value < 2) false
    else if (value == 2) true
    else if (value % 2 == 0) false
    else {
      val sqrt = Math.sqrt(value).toInt
      for (i <- 3 to sqrt by 2) {
        if (value % i == 0) {
          return false
        }
      }

      true
    }
  }
}

