#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int N, M;     cin >> N >> M;     vector<int> arr(N + 2);     arr[0] = 1;     for (int i = 0; i < N; ++i) cin >> arr[i + 1];     arr[N + 1] = 1;     int q = M, w = M;     int r = 0;     while (q > 0 || w < N + 1) {       int s = arr[q] + arr[w];       if (s == 2) r += s - (q == 0) - (w == N + 1) - (w == q);       if (q > 0) q--;       if (w < N + 1) w++;     }     cout << r << endl;     return 0;   }   