{-# LANGUAGE BangPatterns #-}
import qualified Data.IntMap as IM

main :: IO ()
main = do
  n <- readLn
  print $ solve n

solve :: Int -> Int
solve n = sum [ m | m <- pred <$> divisors n, m > 0, let (q, r) = n `divMod` m, q == r ]

divisors :: Int -> [Int]
divisors = go [1] . factorize
  where
    go !xs !mp = case IM.minViewWithKey mp of
      Nothing            -> xs
      Just ((k, v), mp') -> go xs' mp'
        where
          xs' = (*) <$> xs <*> [ k ^ i | i <- [0..v] ]

factorize :: Int -> IM.IntMap Int
factorize = go 2 IM.empty
  where
    go !k !mp !n
      | k > n     = mp
      | r == 0    = go k mp1 q
      | otherwise = go (k + 1) mp n
      where
        (q, r) = n `divMod` k
        mp1    = IM.insertWith (+) k 1 mp
