import Data.Array.IO
import Data.List
import Data.Maybe
import Control.Monad

main = do
  _ <- getLine
  s <- return . (map read) . lines =<< getContents
  arr <- newArray (0,10000) Nothing :: IO (IOArray Int (Maybe Int))

  writeArray arr 0 (Just 1)
  forM_ s $ \x -> do
    forM_ (reverse [0..10000]) $ \i -> do
      r <- readArray arr i
      when (r /= Nothing) $ do
        writeArray arr (i+x) (Just 1)

  print =<< return . maximum . f =<< getElems arr

  where
    f xs = g $ catMaybes $ zipWith (\a b -> fmap (*b) a) xs [0..]
    g xs = filter (\x -> mod x 10 /= 0 || x == 0) xs
