#include // #include using namespace std; // using namespace atcoder; #define rep2(i,m,n) for (int i = (m); i < (n); ++i) #define rep(i,n) rep2(i,0,n) typedef long long int ll; typedef long double ld; typedef pair P; template struct V : vector { using vector::vector; }; V() -> V; V(size_t) -> V; template V(size_t, T) -> V; template vector make_vec(size_t n, T a) { return vector(n, a); } template auto make_vec(size_t n, Ts... ts) { return vector(n, make_vec(ts...)); } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1<<30; const ll LINF = 1LL<<61; // const ll MOD = 1000000007; const ll MOD = 998244353; // using mint = modint1000000007; int MAX = 3000; int main() { int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; sort(a.begin(), a.end()); vector as(n); for(int i=n-1; i>1; i--) as[i-2] = abs(a[i] - a[i-1]); for(int i=n-1; i>0; i--) chmax(as[i-1], as[i]); cout << as << endl; // i番目までみた, 最後に使ったのがj, スコアの総和 auto dp = make_vec(n+1, n+1, 0LL); auto done = make_vec(n+1, MAX, false); auto rec = [&](auto self, int x, int y) -> ll { if(done[x][y]) return dp[x][y]; if(x <= 0) return dp[x][y]; for(int j = y-1; j >= 0; j--) { if(x > 0)dp[x][y] = (dp[x][y] + self(self, x-1, j) + max(abs(a[x-1]-a[j]), as[x-1])) % MOD; } done[x][y] = true; return dp[x][y] % MOD; }; ll ans = 0; rep(i,n+1) ans = (ans + rec(rec, n, i) % MOD); cout << ans << endl; // rep(i,n+1) cout << dp[i] << endl; return 0; }