N=int(input()) A=list(map(int,input().split())) v,w=1,1 MOD=998244353 for i in range(N-1): a,b=A[i:i+2] v=v*w%MOD w=min(a,b) print(v*w%MOD)