import qualified Data.IntMap.Lazy as IM
import Data.List
 
main = do
  getLine
  as <- zip [1..] . readInts <$> getLine
  print . foldr g 0 . IM.toList $ f as 
 
f [] = IM.empty
f ((k, v):as) = IM.insertWith (const succ) k 1 (f as)
 
g x (0, 1) = x
g x (_, 2) = x * 2 `div` 1000000007
g _ _ = 0

readInts :: String -> [Int]
readInts = map read . words