#ifndef CLASS_MODINT #define CLASS_MODINT #include template class modint { private: std::uint32_t n; public: modint() : n(0) {}; modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {}; static constexpr std::uint32_t get_mod() { return mod; } std::uint32_t get() const { return n; } bool operator==(const modint& m) const { return n == m.n; } bool operator!=(const modint& m) const { return n != m.n; } modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; } modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; } modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; } modint operator+(const modint& m) const { return modint(*this) += m; } modint operator-(const modint& m) const { return modint(*this) -= m; } modint operator*(const modint& m) const { return modint(*this) *= m; } modint inv() const { return (*this).pow(mod - 2); } modint pow(std::uint64_t b) const { modint ans = 1, m = modint(*this); while (b) { if (b & 1) ans *= m; m *= m; b >>= 1; } return ans; } }; #endif // CLASS_MODINT #include #include using namespace std; using mint = modint<998244353>; int main() { const int Z = 999630629; int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } mint answer = 0; for (int i = 0; i < N; i++) { answer += A[i]; } answer *= mint(2).pow(N - 1); int sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } if (sum >= Z) { int rem = sum - Z; vector fact(rem + 1); fact[0] = 1; for (int i = 1; i <= rem; i++) { fact[i] = fact[i - 1] * i; } vector factinv(rem + 1); for (int i = 0; i <= rem; i++) { factinv[i] = fact[i].inv(); } auto comb = [&](int x, int y) { return fact[x] * factinv[y] * factinv[x - y]; }; vector cnt(rem + 1); for (int i = 0; i < N; i++) { if (A[i] <= rem) { cnt[A[i]] += 1; } } vector dp(rem + 1); dp[0] = 1; for (int i = 1; i <= rem; i++) { if (cnt[i] >= 1) { for (int j = rem; j >= 0; j--) { for (int k = 1; k <= cnt[i] && k * i <= j; k++) { dp[j] += dp[j - k * i] * comb(cnt[i], k); } } } } for (int i = 0; i <= rem; i++) { answer -= dp[i] * Z; } } cout << answer.get() << endl; return 0; }