#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, k; scanf("%d %d", &n, &k); vector a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int s = k - 1; if (a[s] == 0) { puts("0"); return 0; } if (a[s] == 1) { ll left = 0, right = 0; for (int i = s - 1; i >= 0; i--) { if (a[i] == 0) break; if (a[i] == 1) { left++; break; } left += a[i]; } for (int i = s + 1; i < n; i++) { if (a[i] == 0) break; if (a[i] == 1) { right++; break; } right += a[i]; } printf("%d\n", a[s] + max(left, right)); } else { ll left = 0, right = 0; for (int i = s - 1; i >= 0; i--) { if (a[i] == 0) break; if (a[i] == 1) { left++; break; } left += a[i]; } for (int i = s + 1; i < n; i++) { if (a[i] == 0) break; if (a[i] == 1) { right++; break; } right += a[i]; } printf("%d\n", a[s] + left + right); } return 0; /* おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!! */ }