import Control.Applicative
import Control.Monad
import Data.List

main = do
  n <- readLn
  ls <- zip [1..] $ map read . words <$> getLine
  let
    (ans,als) = solve ls
    in print ans
       mapM print als

solve :: [(Int,Int)] -> (Int,[Int])
solve ls = let
  bs = [x | x <- ls , odd (fst x) , snd x >= 0 ]
  cs = [x | x <- ls , even (fst x) , snd x >= 0 ]
  sumb = sum $ map snd bs
  sumc = sum $ map snd cs 
  in if bs == cs then maximum $ map snd ls
    else if sumb <= sumc
      then (sumb, (removels bs))
      else (sumc, (removels cs))
      
removels :: [(Int,Int)] -> [Int]
removels ls = let
  nums = map snd ls
  ds = take (length nums) [1..] \\ nums
  in zipWith (-) [0,1..] ds