import sequtils,math template `max=`*(x,y) = x = max(x,y) template `min=`*(x,y) = x = min(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() var maxN = 0 for p in primes: for i in maxN.countdown(2): if i > n or i + p > n : continue if dp[i] == 0 : continue dp[i+p] .max= dp[i] + 1 maxN .max= i + p maxN .min= n dp[p] .max= 1 maxN .max= p maxN .min= n if dp[n] == 0 : echo -1 else: echo dp[n]