import Data.List
import Data.Maybe
import Data.Ord
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readParams >>= mapM_ print . solve . tail

readParams :: IO [Int]
readParams = map b2int . B.words <$> B.getContents
  where b2int = fst . fromJust . B.readInt

solve :: [Int] -> [Int]
solve as = zipWith max ls rs
  where ls = init $ scanl max 0 as
        rs = tail $ scanr max 0 as
