import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    cs <- VU.replicateM n $ do
            c <- getInt
            return $ c - 1
    let result = VU.create $ do
            vec <- VUM.replicate n (1 :: Int)
            color <- VUM.replicate 200001 (-1 :: Int)

            forM_ [0,1] $ \i -> do
                VUM.write color (cs VU.! i) i

            forM_ [2..n-1] $ \i -> do
                let ci = cs VU.! i
                j <- VUM.read color ci
                xj <- if j == -1 || j == i-1
                      then return 0
                      else VUM.read vec j
                xp <- VUM.read vec (i-1)
                VUM.write vec i $ (xj + xp) `mod` 1000000007
                VUM.write color ci i
            
            return vec
    print $ result VU.! (n-1)