#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 last; last.fill(-1); std::vector> pos(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < L; ++j) { if ((a[i] >> j) & 1) { last[j] = i; } else if (last[j] >= 0) { pos[i].push_back(last[j]); } } std::sort(pos[i].begin(), pos[i].end()); pos[i].erase(std::unique(pos[i].begin(), pos[i].end()), pos[i].end()); pos[i].push_back(i); } std::vector pd { 0, 1 }; for (int i = 1; i < n; ++i) { const int psiz = pos[i - 1].size(), siz = pos[i].size(); std::vector dp(siz + 1); for (int k = 0, j = 0; k < siz; ++k) { while (j < psiz and pos[i - 1][j] <= pos[i][k]) ++j; dp[k + 1] = dp[k] + pd[j]; } pd.swap(dp); } std::cout << pd.back().val() << std::endl; return 0; }