-- extension section
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}
--{-# LANGUAGE Unsafe #-} --for large int
-- not supported extension
--{-# LANGUAGE Strict, StrictData #-}


module Main where

-- @@@@@@@@@@@@@@@@@--
-- import section   --
-- @@@@@@@@@@@@@@@@@--
--    import A.B.C( function name )  ...
-- or import A.B.C 

--
import           Prelude hiding(
  getLine,
  getContents,
  lines,
  words
  )

-- standard library
import           Control.Monad.ST
import           Control.Applicative
import           Data.Char


-- bytestring
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B


-- containers
import qualified Data.IntMap.Strict as M

-- deepseq


-- regex-posix


-- text
import           Data.Text.Lazy.IO as TIO
import           Data.Text.Lazy as T
import           Data.Text.Lazy.Read as TR

-- import Data.Text.IO as TIO
-- import Data.Text as T
-- import Data.Text.Read as TR



-- unordered-containers


-- vectors
import           Data.Vector.Unboxed as UV
import           Data.Vector.Unboxed.Mutable as MV


-- mtl


-- @@@@@@@@@@@@@@@@@--
-- main section     --
-- @@@@@@@@@@@@@@@@@--

main :: IO ()
main = do
  input <- getInput
  Prelude.putStr . show . getAnswer $ input 

-- main :: IO()
-- main = do
--   answer <- getInputandanser
--   putStr . show $ answer


-- @@@@@@@@@@@@@@@@@@@@@--
-- I/O DataType section --
-- @@@@@@@@@@@@@@@@@@@@@--
data Input = I (Int,Vector Int)
  deriving(Show)

type Answer = Int



-- @@@@@@@@@@@@@@@@@--
-- answerSection    --
-- @@@@@@@@@@@@@@@@@--
getInput :: IO Input
getInput = do
  n <- (!0) <$> intVectorFromLine 1
  v <- generateIntVectorFromLines n
  return (I (n,v))

getAnswer :: Input -> Answer 
getAnswer (I (n,v)) = M.foldl' f 0 $ go M.empty 0

  where go m n' | n' == (n-1) = M.alter ad (v!n') m
                | otherwise = go (M.alter ad (v!n') m) (n'+1)
          where ad Nothing = Just True
                ad (Just b) = Just $! not b
        f !a True =  a+1
        f !a False = a
-- getAnswer :: Input -> Answer 
-- getAnswer (I (n,v)) = UV.length $ UV.filter (== True)  $ runST $ do
--   mv <- MV.replicate (10^9::Int) False
--   go mv 0 
--   where go array n' | n' == (n-1) = do
--                         MV.modify array (not) (v!n' - 1)
--                         unsafeFreeze array                       
--                     | otherwise = do
--                         MV.modify array (not) (v!n' - 1)
--                         go array (n'+1) 



getInputAndAnser :: IO Answer
getInputAndAnser = undefined


-- @@@@@@@@@@@@@@@@@@@@@@@@@@--
-- question unique section    --
-- @@@@@@@@@@@@@@@@@@@@@@@@@@--





-- @@@@@@@@@@@@@@@@@--
-- util section     --
-- @@@@@@@@@@@@@@@@@--

-- standard Input Function
gLine :: IO Text
gLine = getLine

gContents :: IO Text
gContents = getContents

-- intVectorFromline 5  ("1 2 3 4 5") -> vector <1,2,3,4,5> 
intVectorFromLine ::Int -> IO ( Vector Int )
intVectorFromLine n = UV.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getLine

pairFromLine :: IO (Int,Int)
pairFromLine = do
  v <- intVectorFromLine 2
  return ( v ! 0, v ! 1)

intFromLine :: IO Int
intFromLine = do
  (! 0) <$> (intVectorFromLine 1) 
  
generatePairVectorFromLine :: Int -> IO ( Vector (Int, Int) )
generatePairVectorFromLine n = generateM n (const pairFromLine)

generateIntVectorFromLines :: Int -> IO (Vector Int)
generateIntVectorFromLines n = generateM n (const intFromLine )
