#include #include #include #include #include using mint = atcoder::modint998244353; constexpr int L = 30; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector a(n); for (auto &&e : a) std::cin >> e; std::array, L> pos{}; std::vector> pre(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < L; ++j) { if ((a[i] >> j) & 1) { pos[j].push_back(i); } else if (pos[j].size()) { pre[i].push_back(pos[j].back()); } } std::sort(pre[i].begin(), pre[i].end()); pre[i].erase(std::unique(pre[i].begin(), pre[i].end()), pre[i].end()); pre[i].push_back(i); } std::vector> dp(n); dp[0].push_back(1); for (int i = 1; i < n; ++i) { int j = 0; mint sum = 0; for (int k = 0; k < int(pre[i].size()); ++k) { while (j < int(pre[i - 1].size()) and pre[i - 1][j] <= pre[i][k]) { sum += dp[i - 1][j++]; } dp[i].push_back(sum); } } mint ans = std::accumulate(dp[n - 1].begin(), dp[n - 1].end(), mint(0)); std::cout << ans.val() << std::endl; return 0; }