#include <algorithm>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

constexpr int MOD = 998244353;

/**
 * And Circle
 *
 * Main idea: brute force the partition that a[0] is in, then use a dynamic
 * programming algorithm for the rest of the circle This looks O(n^3): there's
 * potentially n^2 partitions a[0] can be part of, then the remaining DP takes
 * O(n).
 *
 * Insight: If all the values are unique, the maximum size of a partition is
 * log(a_i). This is because each new value turns off at least one bit.
 * Therefore, compress unique values, solve, and handle the duplicates
 * separately.
 *
 * If you have a valid partitioning, you can add an extra barrier between two
 * equal values and still have a valid partition. Therefore, just count the
 * number of valid partitions which do not have barriers between equal adjacent
 * elements and then multiply by a constant to handle the extra values.
 *
 * A straightforward implementation is O(n log^2 a_i). This can be improved to
 * O(n log a_i) by implementing the inner DP in O(n), but this shouldn't be
 * necessary.
 */
int main() {
    vector<int64_t> a;

    // extra = 2^k where k is the number of adjacent duplicates
    int extra = 1;
    int64_t total_and = (1LL << 62) - 1;
    {
        int n;
        cin >> n;

        for (int i = 0; i < n; ++i) {
            int64_t x;
            cin >> x;

            total_and &= x;
            if (!a.empty() && a.back() == x) {
                extra = (2 * extra) % MOD;
            } else {
                a.push_back(x);
            }
        }
    }

    while (a.size() > 1 && a[0] == a.back()) {
        extra = (2 * extra) % MOD;
        a.pop_back();
    }

    int n = a.size();

    int ans = total_and > 0 ? 1 : 0;

    int64_t left_val = a[0];
    // This loop looks O(n), but can actually only run O(log a_i) times.
    for (size_t l = n; l > 0; --l) {
        if (l < n) {
            left_val &= a[l];
        }
        if (left_val == 0) {
            break;
        }

        // dp[i] = number of ways to partition [i, l)
        vector<int> dp(l + 1, 0);
        dp[l] = 1;
        for (int i = l - 1; i > 0; --i) {
            int64_t val = a[i];

            // Also only O(log a_i) times
            for (int j = i; j < l; ++j) {
                val &= a[j];
                if (val == 0) {
                    break;
                }

                dp[i] += dp[j + 1];
                if (dp[i] >= MOD)
                    dp[i] -= MOD;
            }
        }

        int64_t val = left_val;
        for (int r = 0; r < l; ++r) {
            val &= a[r];
            if (val == 0) {
                break;
            }

            // Don't forget about the duplicates!
            ans += 1LL * dp[r + 1] * extra % MOD;
            if (ans >= MOD)
                ans -= MOD;
        }
    }

    cout << ans << '\n';

    return 0;
}
