import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean[] isNotPrime = new boolean[n * 3]; for (int i = 2; i <= Math.sqrt(n * 3); i++) { if (!isNotPrime[i]) { for (int j = 2; i * j < n * 3; j++) { isNotPrime[i * j] = true; } } } ArrayList primes = new ArrayList<>(); for (int i = 3; i < n * 3; i++) { if (!isNotPrime[i]) { primes.add(i); } } int[] counts = new int[n * 3]; counts[8]++; int max = 8; long ans = 0; for (int i = 2; primes.get(i) <= n; i++) { for (int j = i + 1; j < primes.size() && primes.get(j) - primes.get(i) <= max; j++) { ans += counts[primes.get(j) - primes.get(i)]; } for (int j = 0; j < i; j++) { counts[primes.get(i) + primes.get(j)]++; } max = primes.get(i) + primes.get(i - 1); } System.out.println(ans); } }