#include #include #include using namespace std; #define MOD 998244353 int main() { int N; while (cin >> N) { vector v(N); for (auto& x : v) cin >> x; int64_t ret = 0; vector ands{(1LL<<61)-1}; for (int i = N-1; i >= 0; i--) { int64_t x = ands.back() & v[i]; if (x != ands.back()) { if (x == 0) break; ands.push_back(x); } if (i == 0) ret += MOD-N; // Ignore single-break solutions. } for (auto a : ands) { vector> cur{{a, 1}}, next; for (int i = 0; i < N; i++) { next.clear(); int64_t sum = 0; for (auto [x, cnt] : cur) { int64_t y = x & v[i]; if (y == 0) continue; cnt %= MOD; sum += cnt; if (next.empty() || y != next.back().first) next.emplace_back(y, 0); next.back().second += cnt; } int64_t y = (1LL<<61)-1; if (next.empty() || y != next.back().first) next.emplace_back(y, 0); next.back().second += sum; cur.swap(next); } for (auto const& [x, cnt] : cur) if (x == a) ret += cnt; } cout << ret%MOD << endl; } }