#include #include using namespace std; template constexpr T extended_euclidean(const T &n, const T &m, U &x, U &y) noexcept { if (m == 0) { x = 1, y = 0; return n; } T t = n / m, g = extended_euclidean(m, n - m * t, y, x); y -= x * t; return g; } template constexpr T inv(T n) noexcept { std::make_signed_t x, y; extended_euclidean(n, m, x, y); return x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); using ll = long long; ll n, cnt = 0; cin >> n; for (int a, i = 0; i < n; ++i) cin >> a, cnt += a; constexpr ll M = 998'244'353; cout << (min(cnt, n - cnt) * inv(n) % M + M) % M << '\n'; return 0; }