#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define inf 1e18 #define mod 998244353 using namespace std; typedef long long llint; typedef long long ll; typedef pair P; ll n; ll a[2505], b[2505]; ll dp[2505], sum[2505]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; rep(i, 1, n) cin >> a[i]; ll dmax = 0; rep(i, 1, n-1) chmax(dmax, a[i+1]-a[i]); rep(i, dmax, 2500){ rep(j, 1, n) dp[j] = 0; rep(j, 1, n-1){ ll p = lower_bound(a+1, a+n+1, a[j+1]-i) - a; dp[j] = sum[j-1] - sum[p-1] + 1, dp[j] %= mod; sum[j] = sum[j-1] + dp[j], sum[j] %= mod; } b[i] = dp[n-1]*2%mod; } ll ans = 0; rep(i, 1, 2500) ans += (b[i]-b[i-1]+mod)%mod * i % mod, ans %= mod; cout << ans << endl; return 0; }