import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) M=2500 cnt=[0]*M mod=998244353 for d in range(M-1,-1,-1): if any(A[i+1]-A[i]>d for i in range(N-1)): break dp=[0]*(N+1) r=N dp[N-1]=1 for l in range(N-3,-1,-1): while A[r-1]-A[l]>d: r-=1 dp[l+1]=(dp[l+2]+dp[l+2]-dp[r])%mod cnt[d]=dp[1]*2%mod for i in range(M-1,0,-1): cnt[i]-=cnt[i-1] cnt[i]%=mod ans=sum(d*cnt[d]%mod for d in range(M))%mod print(ans)