#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 minR = n;

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

            if (left != mask) continue;

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

                if (right == 0)
                {
                    minR = std::min(minR, r);
                    break;
                }
            }
        }

        ans += n - minR;
    }

    return ans;
}
