#include #include using namespace std; int n, k, i, j; int main(){ cin >> n >> k; int p, q; int a[n]; int ans = 0; int tmp = 0, tmpa = 0, tmpb = 0; for(i = 0; i < n; i++){cin >> a[i];} if(a[k - 1] == 0){ cout << 0 << endl; return 0; } if(a[k - 1] == 1) tmp = 1; p = 0, q = n - 1; for(i = 0; i < n; i++){ if(i < k - 1){ if(a[i] == 0) p = i + 1; if(a[i] == 1) p = i; }else if(i > k - 1){ if(a[i] == 0) q = i - 1; if(a[i] == 1) q = i; } } for(i = p; i < q + 1; i++){ if(tmp == 0) ans += a[i]; else{ if(i < k) tmpa += a[i]; if(i > k) tmpb += a[i]; } } if(tmp == 1) ans = max(tmpa, tmpb); cout << ans << endl; return 0; }