#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++)
    {
        for (int r = l + 1; r < n; r++)
        {
            bool valid = false;
            for (int m = l; m < r; m++)
            {
                long long left = 0;
                for (int i = l; i <= m; i++)
                {
                    left |= a[i];
                }
                long long right = mask;
                for (int i = m + 1; i <= r; i++)
                {
                    right &= a[i];
                }
                if (left == mask && right == 0)
                {
                    valid = true;
                    break;
                }
            }
            if (valid) ans++;
        }
    }

    return ans;
}
