import sequtils,math template `max=`*(x,y) = x = max(x,y) proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord proc getIsPrimes(n:int) :seq[bool] = # [0...n] O(n loglog n) result = newSeqWith(n+1,true) result[0] = false result[1] = false for i in 2..n.float.sqrt.int : if not result[i]: continue for j in countup(i*2,n,i): result[j] = false proc getPrimes(n:int):seq[int] = # [2,3,5,...n] let isPrimes = getIsPrimes(n) result = @[] for i,p in isPrimes: if p : result &= i const primes = getPrimes(20010) var dp: array[20010,int] let n = scan() for p in primes: for i in (n-p).countdown(2): if dp[i] == 0 : continue dp[i+p] .max= dp[i] + 1 dp[p] .max= 1 if dp[n] == 0 : echo -1 else: echo dp[n]