#include #include #include using namespace atcoder; using namespace std; using ll = long long; using mint = modint998244353; void naive(vector A) { vector B; for (int i = 1;i < A.size();i++) B.push_back(A[i]); sort(B.begin(), B.end()); do { int d = 0; for (int i = 0;i < B.size() - 1;i++) d = max(d, abs(B[i + 1] - B[i])); for (auto v : B) cout << v << " "; cout << " D " << d << endl; }while (next_permutation(B.begin(), B.end())); } int main() { int N;cin >> N; int MA = 7; vector A(N + 1, MA + 100000); for (int i = 1;i <= N;i++) cin >> A[i]; sort(A.begin(), A.end(), greater()); mint ans = 0; vector now(N + 1, 0); for (int d = 1;d <= MA;d++) { vector dp(N + 1, 0); if (A[1] - A[2] <= d) { dp[1] = 2; } else { continue; } vector S(N + 1, 0); S[1] = 2; for (int i = 2;i < N;i++) { if (A[i] - A[i + 1] > d) { for (int k = 1;k <= N;k++) dp[k] = 0; break; } int ok = i + 1; int ng = 0; while (ok - ng > 1) { int m = (ok + ng) / 2; if (A[m] - A[i + 1] <= d) { ok = m; } else { ng = m; } } dp[i] = S[i - 1] - S[ok - 1]; S[i] = S[i - 1] + dp[i]; } for (int k = 1;k <= N;k++) ans += mint(d) * mint(dp[k] - now[k]); swap(now, dp); } cout << ans.val() << endl; }