#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; k--; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (a[k] == 0) { cout << 0 << endl; exit(0); } ll r = a[k]; for (int i = k + 1; i < n; i++) { r += a[i]; if (a[i] < 2) break; } for (int i = k - 1; i >= 0; i--) { r += a[i]; if (a[i] < 2) break; } cout << r << endl; return 0; }