{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Char8 as C
import Data.Maybe
import Data.Vector.Unboxed ((!))
import qualified Data.Vector.Unboxed as V

main = sol <$> readLn <*> get >>= put

get = V.unfoldr (C.readInt . C.dropWhile (<'0')) <$> C.getLine

put = mapM_ (putStrLn . show)

sol n v = f <$> [1..n+1]
  where
  h = V.unsafeAccumulate_ (+) (V.replicate (n+1) 0) v (V.replicate (n+1) 1) :: V.Vector Int
  d = fromJust $ V.elemIndex 2 h
  i = V.elemIndices d v
  m = n-(V.last i-V.head i)
  f k
    | k==1      = n
    | k==n+1    = 1
    | k-1<=m    = (chs (n+1) k-chs m (k-1)) `mod` p
    | otherwise = chs (n+1) k
  chs i j = (fac!i) `prd` (ifac!j) `prd` (ifac!(i-j))
  nat = V.enumFromN 1 (n+1)
  fac = V.scanl' prd 1 nat
  bnd = inv $ fac!(n+1)
  ifac = V.scanr' prd bnd nat

inv 1 = 1
inv a = pwr a (p-2)

pwr :: Int -> Int -> Int
pwr !a !n
  | n == 0    = 1
  | odd n     = prd a r
  | otherwise = r
  where
  q = pwr a (n `div` 2)
  r = prd q q

prd = flip flip p . (mod .) . (*)

p = 10^9+7 :: Int