#define _CRT_SECURE_NO_WARNINGS #pragma comment (linker, "/STACK:526000000") #include "bits/stdc++.h" using namespace std; typedef string::const_iterator State; #define eps 1e-11L #define MAX_MOD 1000000007LL #define GYAKU 500000004LL #define MOD 998244353LL #define seg_size 262144 * 4LL #define pb push_back #define mp make_pair typedef long long ll; #define REP(a,b) for(long long (a) = 0;(a) < (b);++(a)) #define ALL(x) (x).begin(),(x).end() void init() { iostream::sync_with_stdio(false); cout << fixed << setprecision(20); } #define int ll void solve(){ int n, k; cin >> n >> k; k--; vector inputs(n); REP(i, n) { cin >> inputs[i]; } if (inputs[k] == 0) { cout << 0 << endl; return; } int base_ans = 0; int now = 0; int ans[2] = {}; for (int i = k; i >= 0; --i) { if (inputs[i] == 0)break; if (now == 0) { base_ans += inputs[i]; } else { ans[0] += inputs[i]; } if (inputs[i] == 1) { break; } } now = 0; for (int i = k; i < inputs.size(); ++i) { if (inputs[i] == 0)break; if (now == 0) { base_ans += inputs[i]; } else { ans[1] += inputs[i]; } if (inputs[i] == 1) { break; } } cout << base_ans-inputs[k]<< endl; } #undef int int main() { init(); solve(); }