import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.ArrayList; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); DifferentSumOfPrime solver = new DifferentSumOfPrime(); solver.solve(1, in, out); out.close(); } static class DifferentSumOfPrime { public void solve(int testNumber, Scanner in, PrintWriter out) { // 2万なのでN^2くらいは通りそうだけど… int n = in.nextInt(); ArrayList primes = Prime.eratosthenes(n); int[] dp = new int[n + 1]; // dp[i] = i を異なる素数の和で表した時の最大個数 Arrays.fill(dp, -1); for (Integer p : primes) { for (int i = n; i > p; i--) { if (dp[i - p] > 0) { dp[i] = Math.max(dp[i], dp[i - p] + 1); } } dp[p] = Math.max(dp[p], 1); // out.println(Arrays.toString(dp)); } out.println(dp[n]); } } static class Prime { public static ArrayList eratosthenes(int n) { // n以下の素数をすべて列挙する(計算量は O(N log(log N))) // ただし10^5が耐用限界っぽい感じはする ArrayList res = new ArrayList<>(); ArrayList primes = new ArrayList<>(); for (int i = 2; i <= n; i++) { res.add(i); } while (res.size() > 0) { primes.add(res.get(0)); res.removeIf(a -> a % res.get(0) == 0); } return primes; } } }