program nikkei20192qualb
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i
    integer(int64), allocatable:: d(:),cnt(:),ans
    integer(int64), parameter:: md = 998244353

    read*, n
    allocate(d(n))
    read*, d(:)
    if (d(1) /= 0) then
        print'(i0)', 0
        stop
    end if
    allocate(cnt(0:maxval(d)))
    cnt(:) = 0
    cnt(0)=1
    do i=2,n
        cnt(d(i))=cnt(d(i))+1
    end do

    if (cnt(0) > 1) then
        print'(i0)', 0
        stop
    end if

    if (minval(cnt) == 0) then
        print'(i0)', 0
        stop
    end if

    ans=1
    do i=1,size(cnt)-1
        ans = mod(ans*factorial(cnt(i-1),cnt(i),md),md)
    end do
    print'(i0)', ans


contains
    function factorial(a,b,md) result(ret)
        integer(int64):: a,b,md
        integer(int64):: aa,bb,ret
        aa = a
        bb = b
        ret = 1
        do while(bb > 0)
            if (mod(bb,2_8)/=0) ret=mod(ret*aa,md)
            aa=mod(aa*aa,md)
            bb=bb/2
        end do
    end function
    
end program nikkei20192qualb