local mfl = math.floor local n = io.read("*n") local t = {} local max = 4471 local v = {} local inf = n + 1 for i = 1, max do v[i] = mfl(i * (i + 1) / 2) end for i = 1, 10000000 do t[i] = inf end local f = false for i = 1, max do if n == t[v[i]] then t[n] = 1 f = true break elseif v[i] < n then t[v[i]] = 1 end end local mmi = math.min while not f do for i = n - 1, 1, -1 do if t[i] ~= inf then for i_v = 1, max do local dst = i + v[i_v] if dst == n then f = true t[n] = t[i] + 1 break elseif dst < n then t[dst] = mmi(t[i] + 1, t[dst]) end end end if f then break end end end print(t[n])