#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i> N >> K; K--; vector A(N); rep(i, N) cin >> A[i]; if (A[K] == 0) { cout << "0\n"; return 0; } ll l = 0, r = 0; for (int i = K - 1; i >= 0; i--) { if (A[i] < 2) { l += A[i]; break; } l += A[i]; } for (int i = K + 1; i < N; i++) { if (A[i] < 2) { r += A[i]; break; } r += A[i]; } if (A[K] == 1) { if (l > r) cout << l + A[K] << endl; else cout << r + A[K] << endl; return 0; } cout << l + A[K] + r << endl; }