AT_abc423_c [ABC423C] Lock All Doors

Description

There are $ N + 1 $ rooms arranged in a line, numbered $ 0, 1, \ldots, N $ in order. Between the rooms, there are $ N $ doors numbered $ 1, 2, \ldots, N $ . Door $ i $ is between rooms $ i - 1 $ and $ i $ . For each door, a value $ L_i $ representing the lock state is given. When $ L_i = 0 $ , door $ i $ is unlocked, and when $ L_i = 1 $ , door $ i $ is locked. Takahashi is initially in room $ R $ , and can move between rooms $ i - 1 $ and $ i $ only when door $ i $ is unlocked. Also, he can perform a **switching operation** on door $ i $ only when he is in room $ i - 1 $ or room $ i $ . When a switching operation is performed on door $ i $ , if the door is unlocked, it becomes locked, and if it is locked, it becomes unlocked. Find the minimum number of switching operations needed to make all doors locked.

Input Format

The input is given from Standard Input in the following format: > $ N $ $ R $ $ L_1 $ $ L_2 $ $ \ldots $ $ L_N $

Output Format

Output the answer.

Explanation/Hint

### Sample Explanation 1 Takahashi can make all doors locked with six switching operations by acting as follows: - Move to room $ 2 $ . - Perform a switching operation on door $ 2 $ to lock door $ 2 $ . - Move to room $ 3 $ . - Perform a switching operation on door $ 4 $ to unlock door $ 4 $ . - Perform a switching operation on door $ 3 $ to lock door $ 3 $ . - Move to room $ 4 $ . - Perform a switching operation on door $ 4 $ to lock door $ 4 $ . - Move to room $ 5 $ . - Perform a switching operation on door $ 5 $ to lock door $ 5 $ . - Perform a switching operation on door $ 6 $ to lock door $ 6 $ . ### Constraints - $ 2 \leq N \leq 2 \times 10^5 $ - $ 0 \leq R \leq N $ - $ L_i \in \lbrace 0, 1 \rbrace $ - All input values are integers.