N=int(input()) A=list(map(int,input().split())) sum=sum(A) if sum==0 or sum==N: print(0) exit(0) MOD=998244353 cnt=0 for i in range(N): if A[i]==0 and A[(i+1)%N]==1:cnt+=1 ans=cnt*pow(N,-1,MOD)%MOD print(ans)