#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1000000;

int next0[MAXN];
int next1[MAXN];

void precalc(const vector<long long>& v) {
    int zero = v.size();
    int one = v.size();
    for (int i = v.size()-1; i >= 0; i--) {
        if (v[i] == 0) zero = i;
        else one = i;
        next0[i] = zero;
        next1[i] = one;
    }
}

long long oriand(int n, int k, vector<long long> v) {
    precalc(v);

    long long ans = 0;
    for (int l = 0; l < v.size(); l++) {
        int m = next1[l];
        if (m+1 >= n) continue;
        int r = next0[m+1];

        ans += (v.size()-r);
    }
    return ans;
}
