M=998244353 class LazySegTree: def __init__(self,n): self.tl=1 while self.tl0: if l%2==1: break l//=2 while r>0: if r%2==0: break r//=2 p=[] while l>0: p+=[l] l//=2 while r>0: p+=[r] r//=2 while len(p)>0: y=p.pop() if y*20: if l%2==1: break l//=2 while r>0: if r%2==0: break r//=2 l//=2 r//=2 while l>0: self.st[l]=self.op(self.st[l*2],self.st[l*2+1]) l//=2 while r>0: self.st[r]=self.op(self.st[r*2],self.st[r*2+1]) r//=2 return def prod(self,l,r): self.propa(l,r) a=0 for i in self.gindex(l,r): a=self.op(a,self.st[i]) return a n=int(input()) a=list(map(int,input().split()))+[0] w=[[0,0] for i in range(n)] p=[[] for i in range(n+1)] X=10**10 a[-1]=X q=[-1] for i in range(n): while (a[q[-1]],q[-1])<(a[i],i): q.pop() w[i][0]=q[-1]+1 q+=[i] q=[n] for i in reversed(range(n)): while (a[q[-1]],q[-1])<(a[i],i): q.pop() w[i][1]=q[-1]-1 q+=[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))] a[-1]=-X q=[-1] for i in range(n): while (a[q[-1]],q[-1])>(a[i],i): q.pop() w[i][0]=q[-1]+1 q+=[i] q=[n] for i in reversed(range(n)): while (a[q[-1]],q[-1])>(a[i],i): q.pop() w[i][1]=q[-1]-1 q+=[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 st=LazySegTree(n) for y in range(n): for l,r,v in p[y]: st.apply(l,r,v) l=0 r=y ans+=st.prod(l,r) ans%=M print(ans)