func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int two(int n) { return 1 << n; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   int dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0};   const int md = 1000000007;   int dcmp(double a, double b) {     return fabs(a - b) <= 1e-9 ? 0 : (a > b) ? 1 : -1;   }   int arr[1009], tmp[1009] = {0};   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, r, sum = 0;     cin >> n >> r;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];       sum += arr[i];       if (arr[i] == 1) {         for (int j = i - r + 1; j <= i + r - 1; ++j) {           if (j >= 1 && j <= n) tmp[j]++;         }       }     }     int cnt = 0;     for (int i = 1; i <= n; ++i) {       if (tmp[i] < 1) return cout << -1, 0;     }     for (int i = 1; i <= n; ++i) {       bool ok = false;       if (arr[i] == 1) {         for (int j = i - r + 1; j <= i + r - 1; ++j) {           if (j >= 1 && j <= n)             if (tmp[j] == 1) {               ok = true;               break;             }         }         if (!ok) {           cnt++;           for (int j = i - r + 1; j <= i + r - 1; ++j) {             if (j >= 1 && j <= n) tmp[j]--;           }         }       }     }     cout << sum - cnt;   }   