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

    stop
end program sample
  

