#include using namespace std; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define popcount __builtin_popcount #define next __next #define prev __prev #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template using MaxHeap = priority_queue; template using MinHeap = priority_queue, greater>; template vector vect(int len, T elem) { return vector(len, elem); } // ----------------- Input ------------------- template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second; } template istream &operator>>(istream &is, vector &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ',' << p.second; } template ostream &operator<<(ostream &os, const vector &v) { for (const T &e : v) os << e << " "; return os; } template ostream &operator<<(ostream &os, const deque &d) { for (const T &e : d) os << e << " "; return os; } template ostream &operator<<(ostream &os, const set &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template ostream &operator<<(ostream &os, const map &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template void dump_tuple(ostream &os, const TupleTy t, std::index_sequence) { (..., (os << (I == 0 ? "" : ",") << std::get(t))); } template ostream &operator<<(ostream &os, const tuple &t) { os << "("; dump_tuple(os, t, std::make_index_sequence()); return os << ")"; } void dump_str_rec(ostringstream &) {} template void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward(tail)...); } template string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------------ ACL -------------------- #include constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; using mint = atcoder::static_modint; ostream &operator<<(ostream &os, const mint &v) { return os << v.val(); } // ------------ End of template -------------- #define endl "\n" using ll = long long; using pii = pair; const bool multitest = false; int nCk(int n, int k) { assert(n >= 1 && k >= 0 && k <= n); while (n > 0) { int nb = (n & 1), kb = (k & 1); n >>= 1; k >>= 1; if (nb < kb) return 0; } return 1; } void solve() { int N; cin >> N; vector B(N); cin >> B; auto dp = vect(N + 1, vect(2, mint(0))); dp[0][0] = mint(1); for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { if (B[i] == -1 || B[i] == k) { dp[i + 1][(j + k * nCk(N - 1, i)) % 2] += dp[i][j]; } } } } cout << dp[N][1] << endl; return; } int main() { fastio(); if (!multitest) { solve(); } else { cerr << "[Warning] Multi testcase mode on" << endl; int t; cin >> t; while (t--) solve(); } return 0; }