• + 0 comments

    Haskell

    module Main where
    
    solve :: [Int] -> Maybe Int
    solve bs = go bs 0
      where
        go [] acc = Just acc
        go [x] acc = if even x then Just acc else Nothing
        go (x : y : xs) acc
            | even x = go (y : xs) acc
            | otherwise = go (y + 1 : xs) (acc + 2)
    
    main :: IO ()
    main = do
        n <- readLn :: IO Int
        bs <- map read . words <$> getLine :: IO [Int]
        case solve bs of
            Just acc -> print acc
            Nothing -> putStrLn "NO"