program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,ans
    integer(8)::a,b,c,d,y(100010)
    integer(8),allocatable::x(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    y(:)=0
    m=0
    if(x(1)/=0)then
        write(*,*)0
        stop
    end if
    do i=1,n
        a=x(i)
        y(a)=y(a)+1
        if(a>m)then
            m=a
        end if
    end do
    ans=1
    do i=1,m-1
        if(y(i)==0)then
            write(*,*)0
            stop
        end if
        ans=mod(ans*y(i)**y(i+1),998244353)
    end do
    write(*,*)ans

    stop
end program sample
  

