#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; constexpr ll mod007 = 1000000007; constexpr ll mod998 = 998244353; ll N, A[100000], res; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; // A[i] %= mod998; } sort(A, A + N); for (int i = 0; i < N; i++) { res += A[i] * (N - 1); int l = i; int r = N; while (l + 1 != r) { int m = (l + r) / 2; if (A[i] + A[m] < mod998) { l = m; } else { r = m; } } res -= mod998 * (N - r); } cout << res << endl; }