n=int(input()) a=list(map(int,input().split()))+[0] M=998244353 q=[(a[i],i) for i in range(n)] q.sort() w=[[0,0] for i in range(n)] p=[[] for i in range(n+1)] X=10**10 a[-1]=X ql=[-1] for i in range(n): while a[ql[-1]]a[i]: ql.pop() w[i][0]=ql[-1]+1 ql+=[i] qr=[n] for i in reversed(range(n)): while a[qr[-1]]>a[i]: qr.pop() w[i][1]=qr[-1]-1 qr+=[i] for i in range(n): v=a[i] l,r=w[i] p[i]+=[(l,i,v)] p[r+1]+=[(l,i,pow(v,M-2,M))] ans=0 B=448 st1=[1]*B*B st2=[B]*B lt=[1]*B for y in range(n): for l,r,v in p[y]: yl=l//B yr=r//B for i in range(yl*B,yl*B+B): st1[i]*=lt[yl] st1[i]%=M lt[yl]=1 for i in range(yr*B,yr*B+B): st1[i]*=lt[yr] st1[i]%=M lt[yr]=1 if yl==yr: for i in range(l,r+1): st2[yl]-=st1[i] st1[i]*=v st1[i]%=M st2[yl]+=st1[i] st2[yl]%=M else: for i in range(l,yl*B+B): st2[yl]-=st1[i] st1[i]*=v st1[i]%=M st2[yl]+=st1[i] st2[yl]%=M for i in range(yl+1,yr): st2[i]*=v st2[i]%=M lt[i]=v for i in range(yr*B,r+1): st2[yr]-=st1[i] st1[i]*=v st1[i]%=M st2[yr]+=st1[i] st2[yr]%=M g=0 l=0 r=y yl=l//B yr=r//B for i in range(yl*B,yl*B+B): st1[i]*=lt[yl] st1[i]%=M lt[yl]=1 for i in range(yr*B,yr*B+B): st1[i]*=lt[yr] st1[i]%=M lt[yr]=1 if yl==yr: g+=sum(st1[l:r+1]) else: g+=sum(st1[l:yl*B+B]) g+=sum(st2[yl+1:yr]) g+=sum(st1[yr*B:r+1]) ans+=g ans%=M print(ans)