CF680B.Bear and Finding Criminals

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn cities in Bearland, numbered 11 through nn . Cities are arranged in one long row. The distance between cities ii and jj is equal to ij|i-j| .

Limak is a police officer. He lives in a city aa . 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 aa . 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.

输入格式

The first line of the input contains two integers nn and aa ( 1<=a<=n<=1001<=a<=n<=100 ) — the number of cities and the index of city where Limak lives.

The second line contains nn integers t1,t2,...,tnt_{1},t_{2},...,t_{n} ( 0<=ti<=10<=t_{i}<=1 ). There are tit_{i} criminals in the ii -th city.

输出格式

Print the number of criminals Limak will catch.

输入输出样例

  • 输入#1

    6 3
    1 1 1 0 1 0
    

    输出#1

    3
    
  • 输入#2

    5 2
    0 0 0 1 0
    

    输出#2

    1
    

说明/提示

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

Using the BCD gives Limak the following information:

  • There is one criminal at distance 00 from the third city — Limak is sure that this criminal is exactly in the third city.
  • There is one criminal at distance 11 from the third city — Limak doesn't know if a criminal is in the second or fourth city.
  • There are two criminals at distance 22 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 11 , 33 and 55 , that is 33 criminals in total.

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

首页