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) p=self.gindex(l,r) a=0 for i in p: 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 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 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)