-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
 
main = getContents >>= print . solve . map read . tail . words

solve cards = ans where
    f (r, a) v = (odd w, a + (div w 2) + k)  where
        (k, w) = if r && v > 0 then (1, v - 1) else (0, v)
    (_, ans) = foldl f (False, 0) cards 