#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> &A, int B) {
int first=-1;
int second=A.size();
int flag=0;
int cnt=0;
for(int i=0;i<A.size();i++)
{
if(A[i]==1)
{
int f=i-B+1;
int g=i+B-1;
cout<<i<<" "<<f<<" "<<g<<endl;
if(flag==0)
{
first=f;
second=g;
cnt++;
flag=1;
}
else
{
if(second>=g)
{
continue;
}
else
{
cnt++;
second=g;
}
}
}
}
// cout<<first<<" "<<second<<endl;
if(first<=0 and second>=A.size()-1)
{
return cnt;
}
else
{
return -1;
}
}
int main()
{
vector<int>A={1,1,1,1};
cout<<solve(A,3);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBzb2x2ZSh2ZWN0b3I8aW50PiAmQSwgaW50IEIpIHsKICAgCiAgICAgICAgICAgaW50IGZpcnN0PS0xOwogICAgaW50IHNlY29uZD1BLnNpemUoKTsKICAgIGludCBmbGFnPTA7CiAgICBpbnQgY250PTA7CiAgICBmb3IoaW50IGk9MDtpPEEuc2l6ZSgpO2krKykKICAgIHsKICAgICAgICBpZihBW2ldPT0xKQogICAgICAgIHsgCiAgICAgICAgICAgIGludCBmPWktQisxOwogICAgICAgIGludCBnPWkrQi0xOwogICAgICAgICBjb3V0PDxpPDwiICI8PGY8PCIgIjw8Zzw8ZW5kbDsKICAgICAgICAKICAgICAgICAgICAgaWYoZmxhZz09MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZmlyc3Q9ZjsKICAgICAgICAgICBzZWNvbmQ9ZzsKICAgICAgICAgICBjbnQrKzsgCiAgICAgICAgICAgZmxhZz0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoc2Vjb25kPj1nKQogICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgfSAgCiAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgICAgICAgICAgIHNlY29uZD1nOwogICAgICAgICAgICAgICAgIH0KICAgICAgICAgIAogICAgICAgIAogICAgICAgICAgICAgfSAKICAgICAgICAKICAgICAgICAKICAgICAgCiAgICAgICAKICAgICAgICB9CiAgICAgICAKICAgIH0KICAgIC8vIGNvdXQ8PGZpcnN0PDwiICI8PHNlY29uZDw8ZW5kbDsKICAgIGlmKGZpcnN0PD0wIGFuZCBzZWNvbmQ+PUEuc2l6ZSgpLTEpCiAgICB7CiAgICAgICAgcmV0dXJuIGNudDsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICByZXR1cm4gLTE7CiAgICB9Cn0KaW50IG1haW4oKQp7Cgl2ZWN0b3I8aW50PkE9ezEsMSwxLDF9OwoJY291dDw8c29sdmUoQSwzKTsKfQo=