#include #include #include using namespace std; template struct ModInt { using lint = long long; int val; constexpr ModInt() : val(0) {} constexpr ModInt &_setval(lint v) { val = (v >= mod ? v - mod : v); return *this; } constexpr ModInt(lint v) { _setval(v % mod + mod); } explicit operator bool() const { return val != 0; } constexpr ModInt operator+(const ModInt &x) const { return ModInt()._setval((lint)val + x.val); } constexpr ModInt operator-(const ModInt &x) const { return ModInt()._setval((lint)val - x.val + mod); } constexpr ModInt operator*(const ModInt &x) const { return ModInt()._setval((lint)val * x.val % mod); } constexpr ModInt operator/(const ModInt &x) const { return ModInt()._setval((lint)val * x.inv() % mod); } constexpr ModInt operator-() const { return ModInt()._setval(mod - val); } constexpr ModInt &operator+=(const ModInt &x) { return *this = *this + x; } constexpr ModInt &operator-=(const ModInt &x) { return *this = *this - x; } constexpr ModInt &operator*=(const ModInt &x) { return *this = *this * x; } constexpr ModInt &operator/=(const ModInt &x) { return *this = *this / x; } friend std::istream &operator>>(std::istream &is, ModInt &x) { lint t; is >> t; x = ModInt(t); return is; } constexpr lint power(lint n) const { lint ans = 1, tmp = this->val; while (n) { if (n & 1) ans = ans * tmp % mod; tmp = tmp * tmp % mod; n /= 2; } return ans; } constexpr lint inv() const { return this->power(mod - 2); } }; using mint = ModInt<998244353>; // Fast Walsh-Hadamard transform // Tutorials: // template void walsh_hadamard(std::vector& seq, F f) { const int n = seq.size(); for (int w = 1; w < n; w *= 2) { for (int i = 0; i < n; i += w * 2) { for (int j = 0; j < w; j++) { f(seq[i + j], seq[i + j + w]); } } } } auto zeta = [](mint& lo, mint& hi) { hi += lo; }; auto moebius = [](mint& lo, mint& hi) { hi -= lo; }; int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; vector trans(1 << N); for (auto &x : trans) { cin >> x; } mint Sinv = accumulate(trans.begin(), trans.end(), mint(0)).inv(); for (auto &x : trans) { x = -x * Sinv; } trans[0] += 1; walsh_hadamard(trans, zeta); vector dp(1 << N); dp[0] = 1; walsh_hadamard(dp, zeta); for (size_t i = 0; i < dp.size() - 1; i++) { dp[i] /= trans[i]; } walsh_hadamard(dp, moebius); cout << accumulate(dp.begin(), dp.end() - 1, mint(0)).val << '\n'; }