import qualified Data.IntMap.Lazy as M

apply :: Int -> (a -> a) -> a -> a
apply n f x = (iterate f x) !! n

main = interact $ unlines . map (show . lagrangeFST . read) . init . lines

lagrangeFST' n = M.findWithDefault 0 n (apply 4 dp (M.singleton 0 0))
 where 
  dp m = M.unionsWith (+) (m : map memo ds)
   where
    memo d = M.map (const 1) $ M.mapKeys (min (n+1) . (+d)) m
    ds = takeWhile (<=n) (map (^2) [1..])

lagrangeFST n = search 1 n (reverse (takeWhile (<=n) (map (^2) [1..])))
 where
  search _ 0 _ = 1
  search _ _ [] = 0
  search i x dds@(d:ds)
   | i>4 || x<=0 = 0
   | otherwise = search (i+1) (x-d) (dropWhile (> (x-d)) dds) + search i x ds