#include using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define reps(i, n) for (int i = 0; i <= (int)(n); i++) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define rreps(i, x) for (int i = (int)(x); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back typedef long long ll; typedef pair P; const int inf = INT_MAX; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } vector isprime() { int MAX = 20010; vector is_prime(MAX, 1), p; is_prime[0] = 0; is_prime[1] = 0; for (int i = 2; i < MAX; i++) { if (!is_prime[i]) continue; is_prime[i] = i; p.pb(i); for (int j = i*2; j < MAX; j += i) is_prime[j] = 0; } return p; } int dp[20010]; int main() { cin.tie(0); ios::sync_with_stdio(false); vector primes = isprime(); int N; cin >> N; fill(dp, dp+N, -1); dp[0] = 0; for (auto p : primes) rreps(i, N) { if (p + i <= N && dp[i] != -1) { chmax(dp[p+i], dp[i] + 1); } } cout << dp[N] << endl; return 0; }