#include <bits/stdc++.h>
using namespace std;
int cycleMod(int num, int cycle) {
  if (num < 0) {
    return ((num % cycle) + cycle) % cycle;
  }
  return num % cycle;
}
int dvsCnt(int num, int subset) { return num / subset; }
long long fact(int n) {
  long long res = 1;
  for (int i = 1; i <= n; i++) {
    res *= i;
  }
  return res;
}
long combinations(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
string sumBigInts(string smaller, string bigger) {
  int smallsz = smaller.size(), bigsz = bigger.size(), singleSum, carry = 0;
  stringstream tmp;
  string res = "";
  for (int i = bigsz - 1, j = smallsz - 1; i >= 0; i--, j--) {
    if (j < 0) {
      if (carry > 0) {
        tmp << ((bigger[i] - '0') + carry) << res;
        tmp >> res;
        tmp.clear();
        carry = 0;
      } else {
        res = bigger[i] + res;
      }
      continue;
    }
    singleSum = (smaller[j] - '0') + (bigger[i] - '0') + carry;
    carry = singleSum / 10;
    res = (char)((singleSum % 10) + '0') + res;
  }
  int zeros = 0;
  for (int i = 0; i < res.size(); i++) {
    if (res[i] == '0')
      zeros++;
    else
      break;
  }
  res = res.substr(zeros);
  return res;
}
string multiplyBigInts(string x, string y) {
  int singleProd, carry = 0;
  int xsz = x.size(), ysz = y.size();
  int bigSz, smallsz;
  string bigger, smaller, res = "", finalRes = "";
  if (xsz > ysz) {
    bigger = x, smaller = y;
    bigSz = xsz, smallsz = ysz;
  } else {
    bigger = y, smaller = x;
    bigSz = ysz, smallsz = xsz;
  }
  for (int j = smallsz - 1; j >= 0; j--) {
    for (int i = bigSz - 1; i >= 0; i--) {
      singleProd = (bigger[i] - '0') * (smaller[j] - '0') + carry;
      carry = singleProd / 10;
      res = (char)((singleProd % 10) + '0') + res;
    }
    res = (char)(carry + '0') + res;
    for (int z = j; z < smallsz - 1; z++) {
      res += '0';
    }
    finalRes = finalRes.size() > res.size() ? sumBigInts(res, finalRes)
                                            : sumBigInts(finalRes, res);
    res = "";
    carry = 0;
  }
  return finalRes == "" ? "0" : finalRes;
}
set<int> primeFactors(int n) {
  set<int> primes;
  vector<int> res;
  while (n % 2 == 0) {
    primes.insert(2);
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      primes.insert(i);
      n = n / i;
    }
  }
  if (n > 2) {
    primes.insert(n);
  }
  return primes;
}
vector<int> customPrimeFactors(vector<int> groupOfNumbers) {
  set<int> primes, tmp;
  vector<int> res;
  for (int i = 0; i < groupOfNumbers.size(); i++) {
    tmp = primeFactors(groupOfNumbers[i]);
    cout << groupOfNumbers[i] << " : ";
    for (std::set<int>::iterator it = tmp.begin(); it != tmp.end(); ++it) {
      primes.insert(*it);
      cout << *it << " ";
    }
    cout << endl;
  }
  for (std::set<int>::iterator it = primes.begin(); it != primes.end(); ++it) {
    res.push_back(*it);
  }
  return res;
}
long long orginalSet[5];
int getMonths(int m, bool isLeap) {
  if (m == 1) return 0;
  if (m == 2) return 31;
  int bef8 = m > 7 ? 8 : m;
  int aft8 = m > 7 ? m - 7 : 0;
  int cons = bef8 / 2;
  int resBefore8 =
      (bef8 % 2 != 0 ? cons : cons - 1) * 30 + cons * 31 - (isLeap ? 1 : 2);
  if (m > 8) {
    cons = aft8 / 2;
    resBefore8 += (aft8 % 2 != 0 ? cons : cons - 1) * 30 + cons * 31;
  }
  return resBefore8;
}
bool canPreciselyDetermined(vector<int> d1, vector<int> d2) {
  bool isLeap1 = d1[2] % 400 == 0 || (d1[2] % 4 == 0 && d1[2] % 100 != 0);
  bool isLeap2 = d2[2] % 400 == 0 || (d2[2] % 4 == 0 && d2[2] % 100 != 0);
  bool isLeapBef1 = (d1[2] - 1) % 400 == 0 ||
                    ((d1[2] - 1) % 4 == 0 && (d1[2] - 1) % 100 != 0);
  bool isLeapBef2 = (d2[2] - 1) % 400 == 0 ||
                    ((d2[2] - 1) % 4 == 0 && (d2[2] - 1) % 100 != 0);
  isLeapBef2 = d2[2] > d1[2] && isLeapBef1 || isLeapBef2;
  int m1 = getMonths(d1[1], isLeap1);
  int m2 = getMonths(d2[1], isLeap2);
  long long date1 = d1[0] + m1 + ((d1[2] - 1) * 365 + (isLeapBef1 ? 1 : 0));
  long long date2 = d2[0] + m2 + ((d2[2] - 1) * 365 + (isLeapBef2 ? 1 : 0));
  return (date2 - date1 == 1);
}
map<string, int> goals;
int r1, r2, c1, c2, d1, d2;
int res[2][2];
int repets[10];
bool tryOpen() {
  memset(repets, 0, sizeof(repets));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      repets[res[i][j]]++;
    }
  }
  bool noRepeats = true;
  for (int i = 1; i < 10; i++) {
    if (repets[i] > 1) {
      noRepeats = false;
      break;
    }
  }
  return noRepeats && (res[0][0] + res[0][1] == r1) &&
         (res[1][0] + res[1][1] == r2) && (res[0][0] + res[1][0] == c1) &&
         (res[0][1] + res[1][1] == c2) && (res[0][0] + res[1][1] == d1) &&
         (res[1][0] + res[0][1] == d2);
}
long long n, c;
vector<long long> stulls;
long long largestMin = 9999999999;
bool checkMinDis(long long mnDis, long long c) {
  c--;
  int lastPos = 0;
  for (int i = 1; i < n && c; i++) {
    if (stulls[i] - stulls[lastPos] >= mnDis) {
      c--;
      lastPos = i;
    }
  }
  return c == 0;
}
void max_heapify(std::vector<long long>& arr, int i, int size_) {
  int largest, l = (2 * i) + 1, r = l + 1;
  if (l < size_ && arr[l] > arr[i])
    largest = l;
  else
    largest = i;
  if (r < size_ && arr[r] > arr[largest]) largest = r;
  if (largest != i) {
    std::swap(arr[i], arr[largest]);
    max_heapify(arr, largest, size_);
  }
}
void build_max_heap(std::vector<long long>& arr) {
  for (int i = (arr.size() / 2); i >= 0; i--) max_heapify(arr, i, arr.size());
}
void heap_sort(std::vector<long long>& arr) {
  build_max_heap(arr);
  int sz = arr.size();
  for (int i = arr.size() - 1; i > 0; i--) {
    std::swap(arr[0], arr[i]);
    sz--;
    max_heapify(arr, 0, sz);
  }
}
vector<int> nums;
int sz;
bool visited[1001];
int getCoveredSections(int dex, int prev) {
  if (dex < 0 || dex >= sz || nums[dex] > prev || visited[dex]) {
    return 0;
  }
  visited[dex] = true;
  int res = 1 + getCoveredSections(dex + 1, nums[dex]) +
            getCoveredSections(dex - 1, nums[dex]);
  visited[dex] = false;
  return res;
}
int main() {
  int n, init;
  cin >> n >> init;
  sz = n;
  int odds = 0;
  nums.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> nums[i];
  }
  int res = 0;
  for (int i = 0; init + i <= n || init - i >= 0; i++) {
    bool leftCondiciton = (init - i < 1 || nums[init - i] == 1);
    bool rightCondiciton = (init + i > n || nums[init + i] == 1);
    bool finalCond =
        (leftCondiciton && rightCondiciton && !(init - i < 1 && init + i > n));
    res += finalCond && (init - i >= 1 && init + i <= n && i != 0) ? 2
           : finalCond                                             ? 1
                                                                   : 0;
  }
  cout << res;
  return 0;
}

### Prompt

Create a solution in Cpp for the following problem:

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 t1, t2, ..., tn (0 ≤ ti ≤ 1). There are ti criminals in the i-th city.

Output

Print the number of criminals Limak will catch.

Examples

Input

6 3
1 1 1 0 1 0


Output

3


Input

5 2
0 0 0 1 0


Output

1

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>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int cycleMod(int num, int cycle) {
  if (num < 0) {
    return ((num % cycle) + cycle) % cycle;
  }
  return num % cycle;
}
int dvsCnt(int num, int subset) { return num / subset; }
long long fact(int n) {
  long long res = 1;
  for (int i = 1; i <= n; i++) {
    res *= i;
  }
  return res;
}
long combinations(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
string sumBigInts(string smaller, string bigger) {
  int smallsz = smaller.size(), bigsz = bigger.size(), singleSum, carry = 0;
  stringstream tmp;
  string res = "";
  for (int i = bigsz - 1, j = smallsz - 1; i >= 0; i--, j--) {
    if (j < 0) {
      if (carry > 0) {
        tmp << ((bigger[i] - '0') + carry) << res;
        tmp >> res;
        tmp.clear();
        carry = 0;
      } else {
        res = bigger[i] + res;
      }
      continue;
    }
    singleSum = (smaller[j] - '0') + (bigger[i] - '0') + carry;
    carry = singleSum / 10;
    res = (char)((singleSum % 10) + '0') + res;
  }
  int zeros = 0;
  for (int i = 0; i < res.size(); i++) {
    if (res[i] == '0')
      zeros++;
    else
      break;
  }
  res = res.substr(zeros);
  return res;
}
string multiplyBigInts(string x, string y) {
  int singleProd, carry = 0;
  int xsz = x.size(), ysz = y.size();
  int bigSz, smallsz;
  string bigger, smaller, res = "", finalRes = "";
  if (xsz > ysz) {
    bigger = x, smaller = y;
    bigSz = xsz, smallsz = ysz;
  } else {
    bigger = y, smaller = x;
    bigSz = ysz, smallsz = xsz;
  }
  for (int j = smallsz - 1; j >= 0; j--) {
    for (int i = bigSz - 1; i >= 0; i--) {
      singleProd = (bigger[i] - '0') * (smaller[j] - '0') + carry;
      carry = singleProd / 10;
      res = (char)((singleProd % 10) + '0') + res;
    }
    res = (char)(carry + '0') + res;
    for (int z = j; z < smallsz - 1; z++) {
      res += '0';
    }
    finalRes = finalRes.size() > res.size() ? sumBigInts(res, finalRes)
                                            : sumBigInts(finalRes, res);
    res = "";
    carry = 0;
  }
  return finalRes == "" ? "0" : finalRes;
}
set<int> primeFactors(int n) {
  set<int> primes;
  vector<int> res;
  while (n % 2 == 0) {
    primes.insert(2);
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      primes.insert(i);
      n = n / i;
    }
  }
  if (n > 2) {
    primes.insert(n);
  }
  return primes;
}
vector<int> customPrimeFactors(vector<int> groupOfNumbers) {
  set<int> primes, tmp;
  vector<int> res;
  for (int i = 0; i < groupOfNumbers.size(); i++) {
    tmp = primeFactors(groupOfNumbers[i]);
    cout << groupOfNumbers[i] << " : ";
    for (std::set<int>::iterator it = tmp.begin(); it != tmp.end(); ++it) {
      primes.insert(*it);
      cout << *it << " ";
    }
    cout << endl;
  }
  for (std::set<int>::iterator it = primes.begin(); it != primes.end(); ++it) {
    res.push_back(*it);
  }
  return res;
}
long long orginalSet[5];
int getMonths(int m, bool isLeap) {
  if (m == 1) return 0;
  if (m == 2) return 31;
  int bef8 = m > 7 ? 8 : m;
  int aft8 = m > 7 ? m - 7 : 0;
  int cons = bef8 / 2;
  int resBefore8 =
      (bef8 % 2 != 0 ? cons : cons - 1) * 30 + cons * 31 - (isLeap ? 1 : 2);
  if (m > 8) {
    cons = aft8 / 2;
    resBefore8 += (aft8 % 2 != 0 ? cons : cons - 1) * 30 + cons * 31;
  }
  return resBefore8;
}
bool canPreciselyDetermined(vector<int> d1, vector<int> d2) {
  bool isLeap1 = d1[2] % 400 == 0 || (d1[2] % 4 == 0 && d1[2] % 100 != 0);
  bool isLeap2 = d2[2] % 400 == 0 || (d2[2] % 4 == 0 && d2[2] % 100 != 0);
  bool isLeapBef1 = (d1[2] - 1) % 400 == 0 ||
                    ((d1[2] - 1) % 4 == 0 && (d1[2] - 1) % 100 != 0);
  bool isLeapBef2 = (d2[2] - 1) % 400 == 0 ||
                    ((d2[2] - 1) % 4 == 0 && (d2[2] - 1) % 100 != 0);
  isLeapBef2 = d2[2] > d1[2] && isLeapBef1 || isLeapBef2;
  int m1 = getMonths(d1[1], isLeap1);
  int m2 = getMonths(d2[1], isLeap2);
  long long date1 = d1[0] + m1 + ((d1[2] - 1) * 365 + (isLeapBef1 ? 1 : 0));
  long long date2 = d2[0] + m2 + ((d2[2] - 1) * 365 + (isLeapBef2 ? 1 : 0));
  return (date2 - date1 == 1);
}
map<string, int> goals;
int r1, r2, c1, c2, d1, d2;
int res[2][2];
int repets[10];
bool tryOpen() {
  memset(repets, 0, sizeof(repets));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      repets[res[i][j]]++;
    }
  }
  bool noRepeats = true;
  for (int i = 1; i < 10; i++) {
    if (repets[i] > 1) {
      noRepeats = false;
      break;
    }
  }
  return noRepeats && (res[0][0] + res[0][1] == r1) &&
         (res[1][0] + res[1][1] == r2) && (res[0][0] + res[1][0] == c1) &&
         (res[0][1] + res[1][1] == c2) && (res[0][0] + res[1][1] == d1) &&
         (res[1][0] + res[0][1] == d2);
}
long long n, c;
vector<long long> stulls;
long long largestMin = 9999999999;
bool checkMinDis(long long mnDis, long long c) {
  c--;
  int lastPos = 0;
  for (int i = 1; i < n && c; i++) {
    if (stulls[i] - stulls[lastPos] >= mnDis) {
      c--;
      lastPos = i;
    }
  }
  return c == 0;
}
void max_heapify(std::vector<long long>& arr, int i, int size_) {
  int largest, l = (2 * i) + 1, r = l + 1;
  if (l < size_ && arr[l] > arr[i])
    largest = l;
  else
    largest = i;
  if (r < size_ && arr[r] > arr[largest]) largest = r;
  if (largest != i) {
    std::swap(arr[i], arr[largest]);
    max_heapify(arr, largest, size_);
  }
}
void build_max_heap(std::vector<long long>& arr) {
  for (int i = (arr.size() / 2); i >= 0; i--) max_heapify(arr, i, arr.size());
}
void heap_sort(std::vector<long long>& arr) {
  build_max_heap(arr);
  int sz = arr.size();
  for (int i = arr.size() - 1; i > 0; i--) {
    std::swap(arr[0], arr[i]);
    sz--;
    max_heapify(arr, 0, sz);
  }
}
vector<int> nums;
int sz;
bool visited[1001];
int getCoveredSections(int dex, int prev) {
  if (dex < 0 || dex >= sz || nums[dex] > prev || visited[dex]) {
    return 0;
  }
  visited[dex] = true;
  int res = 1 + getCoveredSections(dex + 1, nums[dex]) +
            getCoveredSections(dex - 1, nums[dex]);
  visited[dex] = false;
  return res;
}
int main() {
  int n, init;
  cin >> n >> init;
  sz = n;
  int odds = 0;
  nums.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> nums[i];
  }
  int res = 0;
  for (int i = 0; init + i <= n || init - i >= 0; i++) {
    bool leftCondiciton = (init - i < 1 || nums[init - i] == 1);
    bool rightCondiciton = (init + i > n || nums[init + i] == 1);
    bool finalCond =
        (leftCondiciton && rightCondiciton && !(init - i < 1 && init + i > n));
    res += finalCond && (init - i >= 1 && init + i <= n && i != 0) ? 2
           : finalCond                                             ? 1
                                                                   : 0;
  }
  cout << res;
  return 0;
}

```