from collections import defaultdict n = int(input()) IsPrime = [True for _ in range(n + 1)] IsPrime[0] = IsPrime[1] = False Primes = [] for i in range(2, n + 1): if IsPrime[i]: Primes.append(i) for j in range(i * i, n + 1, i): IsPrime[j] = False C = defaultdict(lambda: -1) C[0] = 0 for p in Primes: NC = defaultdict(lambda: -1) N = C.keys() for i in N: NC[i] = max(NC[i], C[i]) if i + p <= n: NC[i + p] = max(NC[i + p], C[i] + 1) C = NC print(C[n])