Codeforces Round 356 (Div. 2)
B
Bear and Finding Criminals
Codeforces
1000
原题
← AC →
翻译中…

There are $*n*$ cities in Bearland, numbered $1$ through $*n*$. Cities are arranged in one long row. The distance between cities $*i*$ and $*j*$ is equal to $|*i* - *j*|$.

翻译中…

Limak is a police officer. He lives in a city $*a*$. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.

翻译中…

Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city $*a*$. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.

翻译中…

You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*a*$ ($1 ≤ *a* ≤ *n* ≤ 100$) — the number of cities and the index of city where Limak lives.

翻译中…

The second line contains $*n*$ integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ ($0 ≤ *t*_{*i*} ≤ 1$). There are $*t*_{*i*}$ criminals in the $*i*$-th city.

翻译中…

Output

翻译中…

Print the number of criminals Limak will catch.

翻译中…

Note

翻译中…

In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.

翻译中…

image

翻译中…

Using the BCD gives Limak the following information:

翻译中…
  • There is one criminal at distance $0$ from the third city — Limak is sure that this criminal is exactly in the third city.
  • There is one criminal at distance $1$ from the third city — Limak doesn't know if a criminal is in the second or fourth city.
  • There are two criminals at distance $2$ from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city.
  • There are zero criminals for every greater distance.
翻译中…

So, Limak will catch criminals in cities $1$, $3$ and $5$, that is $3$ criminals in total.

翻译中…

In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance $2$ from Limak's city. There is only one city at distance $2$ so Limak is sure where a criminal is.

翻译中…

image

翻译中…

样例

Input #1
6 3
1 1 1 0 1 0
Output #1
3
InputCopy OutputCopy
Input #2
5 2
0 0 0 1 0
Output #2
1
InputCopy OutputCopy
题目信息
题号
680B
时间限制
2 s
内存限制
256 MB
标签
构造
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。