#include "oriand.h"

long long oriand(int n, int k, std::vector<long long> a)
{
    long long mask = (1ll << k) - 1;

    long long ans = 0;
    for (int l = 0; l < n; l++)
    {
        int m = l;
        long long left = 0;
        for (; m < n; m++)
        {
            left |= a[m];

            if (left == mask) break;
        }

        int r = m + 1;
        long long right = mask;
        for (; r < n; r++)
        {
            right &= a[r];

            if (right == 0) break;
        }

        ans += std::max(n - r, 0);
    }

    return ans;
}
