#include #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair pll; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; K--; vector A(N); rep(i, N) { cin >> A[i]; } bool judge = (A[K] >= 3 ? 1 : 0); // right ll right = K, rtmp = 0; while (right < N) { if (A[right] >= 2) rtmp += A[right]; else if (A[right] == 1) { rtmp += A[right]; break; } else break; right++; } // left ll left = K, ltmp = 0; while (left > 0) { if (A[left] >= 2) ltmp += A[left]; else if (A[left] == 1) { ltmp += A[left]; break; } else break; left--; } if (judge && rtmp > 0 && ltmp > 0) { cout << rtmp + ltmp - A[K] << endl; } else if (judge) { cout << rtmp + ltmp << endl; } else cout << max(rtmp, ltmp) << endl; }