let iota ?(init=0) ?(step=1) n =
  let rec iota i n acc =
    if n = 0 then List.rev acc
    else iota (i + step) (pred n) (i :: acc) in
  iota init n []

let is_prime n =
  if n < 2 then false
  else if n mod 2 = 0 && n <> 2 then false
  else
    let rec is_prime d =
      if d * d > n then true
      else if n mod d = 0 then false
      else is_prime (d + 2) in
    is_prime 3

let rec solve () =
  try
    let n = int_of_string @@ read_line () in
    let xs = iota ~init:1 n in
    let pairs = List.combine xs @@ List.rev xs in
    print_endline @@ string_of_int
    @@ List.fold_left
         (fun s (a, b) -> if is_prime a && is_prime b then s + 1 else s)
         0
         pairs;
    solve ()
  with End_of_file -> ()

let () = solve ()