import Data.List
mo=10^9+7
main=do
 getLine
 d<-map read.words<$>getLine
 let c=f 0 0$sort d
 print$if head d/=0||head c/=1 then 0 else foldl1(\a b->a*b`mod`mo)$zipWith power c$tail c
power a n
 |n==0=1
 |even n=power(a*a`mod`mo)(div n 2)
 |odd n=a*(power a$n-1)`mod`mo
f i c[]=[c]
f i c(d:ds)
 |i==d=f i(c+1)ds
 |i/=d=c:f(i+1)0(d:ds)