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.


-----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]

Difficulty: EASY

Solutions:
def solve(arr, n, a):
	if a <= n // 2:
		gran = 2 * a - 1
		pt1 = arr[:gran]
		pt2 = arr[gran:]
		k = len(pt1)
		ans = 0
		for j in range(k):
			if pt1[j] == pt1[k - j - 1]:
				ans += pt1[j]
		ans += sum(pt2)
		return ans
	else:
		gran = 2 * (n - a) + 1
		pt1 = arr[:n - gran]
		pt2 = arr[n - gran:]
		k = len(pt2)
		ans = 0
		for j in range(k):
			if pt2[j] == pt2[k - j - 1]:
				ans += pt2[j]
		ans += sum(pt1)
		return ans
(n, a) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
print(solve(arr, n, a))


read = lambda : map(int, input().split())
(n, a) = read()
t = list(read())
ans = 0
for d in range(n):
	(i, j) = (a - d - 1, a + d - 1)
	if i == j:
		ans += t[i]
	elif i >= 0 and j < n and (t[i] == t[j]):
		ans += t[i] + t[j]
	elif i < 0 and j < n:
		ans += t[j]
	elif i >= 0 and j >= n:
		ans += t[i]
print(ans)


(N, index) = map(int, input().split())
arr = list(map(int, input().split()))
index -= 1
cnt = 0
if arr[index] == 1:
	cnt += 1
i = 1
while index - i >= 0 and index + i < N:
	if arr[index - i] == 1 and arr[index + i] == 1:
		cnt += 2
	i += 1
while index - i >= 0:
	if arr[index - i] == 1:
		cnt += 1
	i += 1
while index + i < N:
	if arr[index + i] == 1:
		cnt += 1
	i += 1
print(cnt)


(n, a) = map(int, input().split())
s = [int(i) for i in input().split()]
i = a - 1
t = 0
p = False
while not p:
	if s[i] == 1 and n == 1 and (a == 1):
		t = 1
		p = True
		break
	elif i == 0 or i == n - 1:
		t = s.count(1)
		p = True
		break
	else:
		if i != 0 or i != a - 1:
			if s[i] == 1:
				t = 1
			j = 1
			m = min(len(s[:i]), len(s[a:]))
			h = 0
			while j <= m:
				if s[i - j] == 1 and s[i + j] == 1:
					t = t + 2
					h += 1
				j += 1
			t = t + s[:i - m].count(1) + s[i + a:].count(1)
		p = True
		break
print(t)


import math
import sys
import collections

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
(n, pos) = mi()
d = li()
pos -= 1
t = min(pos, n - pos - 1)
i = 1
res = d[pos]
d[pos] = 0
while i <= t:
	print(pos - i, pos + i, file=sys.stderr)
	if d[pos - i] == d[pos + i] == 1:
		res += 2
	d[pos - i] = d[pos + i] = 0
	i += 1
print(res + d.count(1))


(n, a) = str(input()).split()
n = int(n)
a = int(a)
line = str(input()).split()
line = [int(it) for it in line]
num = line[a - 1]
for i in range(1, n):
	if a + i > n and a - i < 1:
		break
	elif a + i <= n and a - i >= 1:
		if line[a + i - 1] == 1 and line[a - i - 1] == 1:
			num += 2
	else:
		if a + i <= n:
			num += line[a + i - 1]
		if a - i >= 1:
			num += line[a - i - 1]
print(num)


input1 = [int(x) for x in input().split()]
CITY = input1[0]
NOW = input1[1]
CRIMINALS = {i + 1: int(x) for (i, x) in enumerate(input().split())}

def bcd(pos, distance):
	if distance == 0:
		return CRIMINALS[pos]
	else:
		ret = 0
		left = pos - distance
		right = pos + distance
		if left in CRIMINALS.keys():
			ret += CRIMINALS[left]
		if right in CRIMINALS.keys():
			ret += CRIMINALS[right]
		return ret
catch = 0
for dist in range(CITY):
	if dist == 0:
		catch += bcd(NOW, dist)
	else:
		left = NOW - dist
		right = NOW + dist
		info = bcd(NOW, dist)
		if left in CRIMINALS.keys() and right in CRIMINALS.keys():
			if info == 2:
				catch += 2
		elif left in CRIMINALS.keys() or right in CRIMINALS.keys():
			if info == 1:
				catch += 1
		else:
			break
print(catch)


(n, i) = list(map(int, input().split()))
lst = list(map(int, input().split()))
i -= 1
mp = {}
mp[0] = lst[i]
dis = 1
uniq = []
mx = max(n - i + 1, i + 1 - 0)
while dis < mx:
	if i + dis < n:
		mp[dis] = mp.get(dis, 0) + lst[dis + i]
	else:
		uniq.append(dis)
	if i - dis >= 0:
		mp[dis] = mp.get(dis, 0) + lst[i - dis]
	else:
		uniq.append(dis)
	dis += 1
res = mp[0]
del mp[0]
for (key, value) in mp.items():
	if key in uniq or value == 2:
		res += value
print(res)


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = 0
ukl = m - 1
ukr = m - 1
while ukl >= 0 or ukr < n:
	if ukl == ukr:
		if l[m - 1] == 1:
			ans += 1
	elif (ukl >= 0 and ukr < n) and l[ukl] == l[ukr] == 1:
		ans += 2
	elif ukl < 0 and l[ukr] == 1 or (l[ukl] == 1 and ukr >= n):
		ans += 1
	ukl -= 1
	ukr += 1
print(ans)


(n, c) = list(map(int, input().split()))
citys = list(map(int, input().split()))
aux = 1
total = 0
while True:
	if c + aux - 1 > n - 1:
		if c - aux - 1 < 0:
			break
		elif citys[c - aux - 1] == 1:
			total += 1
	elif c - aux - 1 < 0:
		if c + aux - 1 > n - 1:
			break
		elif citys[c + aux - 1] == 1:
			total += 1
	elif citys[c + aux - 1] == 1 and citys[c - aux - 1] == 1:
		total += 2
	if aux == n:
		break
	aux += 1
if citys[c - 1] == 1:
	total += 1
print(total)


import sys
(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a -= 1
cnt = 0
distance = min(a, n - 1 - a)
if arr[a] == 1:
	cnt = 1
left = arr[a - distance:a]
right = arr[a + 1:a + 1 + distance]
for i in range(distance):
	if left[i] == 1 and right[distance - i - 1] == 1:
		cnt += 2
cnt += arr[0:a - distance].count(1)
cnt += arr[a + 1 + distance:n].count(1)
print(cnt)


(a, b) = map(int, input().split())
b -= 1
c = list(map(int, input().split()))
count = c[b]
(x, y) = (-1, -1)
for i in range(1, a):
	if b + i < a:
		x = c[b + i]
	if b - i >= 0:
		y = c[b - i]
	if x == -1 and y in [0, 1]:
		count += y
	elif y == -1 and x in [0, 1]:
		count += x
	elif x in [0, 1] and y in [0, 1]:
		if x == y:
			count += x + y
	else:
		break
	(x, y) = (-1, -1)
print(count)


(x, y) = map(int, input().split())
count1 = 0
li = list(map(int, input().split()))
for i in range(1, x):
	p = False
	(a, b) = (0, 0)
	if y - 1 + i >= x and y - 1 - i < 0:
		break
	if y - 1 - i >= 0:
		a = li[y - 1 - i]
	else:
		p = True
	if y - 1 + i < x:
		b = li[y - 1 + i]
	else:
		p = True
	if a + b == 2:
		count1 += 2
	elif p == True and (a == 1 or b == 1):
		count1 += 1
count1 += li[y - 1]
print(count1)


(n, a) = map(int, input().split())
ti = list(map(int, input().split()))
num = a - 1
ans = ti[num]
for i in range(1, n):
	if num + i >= n and num - i < 0:
		break
	elif num + i >= n:
		ans += ti[num - i]
		continue
	elif num - i < 0:
		ans += ti[num + i]
		continue
	ans += ti[num + i] * ti[num - i] * 2
print(ans)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
crims = 0
if t[a] == 1:
	crims += 1
(down, up) = (a - 1, a + 1)
while down >= 0 or up < len(t):
	if down < 0 and t[up] == 1:
		crims += 1
	elif up >= len(t) and t[down] == 1:
		crims += 1
	elif down >= 0 and up < len(t) and (t[down] == 1) and (t[up] == 1):
		crims += 2
	down -= 1
	up += 1
print(crims)


(n, a) = map(int, input().split())
ar = list(map(int, input().split()))
curr = a - 1
ans = ar[curr]
left = curr - 1
right = curr + 1
while left >= 0 and right <= n - 1:
	if ar[left] + ar[right] == 2:
		ans += 2
	left -= 1
	right += 1
while left >= 0:
	ans += ar[left]
	left -= 1
while right <= n - 1:
	ans += ar[right]
	right += 1
print(ans)


(n, h) = map(int, input().split())
ls = list(map(int, input().split()))
firstRev = ls[:h - 1][::-1]
second = ls[h:]
ans = ls[h - 1]
ln = min(len(firstRev), len(second))
for i in range(ln):
	if firstRev[i] and second[i]:
		ans += 2
ans += sum(firstRev[ln:])
ans += sum(second[ln:])
print(ans)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
l = a - 1
r = a + 1
total = sum(t)
while l > -1 and r < n:
	total -= (t[l] + t[r]) % 2
	l -= 1
	r += 1
print(total)


(n, a) = map(int, input().split())
list = [int(i) for i in input().split()]
left = list[:a - 1]
right = list[a:]
sum = 0
if list[a - 1] == 1:
	sum += 1
n = min(len(left), len(right))
i = 0
while n > 0:
	if right[i] == 1 and left[-1 - i] == 1:
		sum += 2
	n -= 1
	i += 1
if len(left) == len(right):
	print(sum)
else:
	list = right if len(right) > len(left) else left
	if list == left:
		left = left[:len(left) - i]
		for i in left:
			if i == 1:
				sum += 1
	else:
		right = right[i:]
		for i in right:
			if i == 1:
				sum += 1
	print(sum)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().rstrip().split()))
a.insert(0, 0)
maxi = 0
count = 0
count1 = 0
myrange = max(n - k, k)
for i in range(1, myrange + 1):
	flag = 0
	count = 0
	if k + i <= n:
		flag += 1
		if a[k + i] == 1:
			count += 1
	if k - i > 0:
		flag += 1
		if a[k - i] == 1:
			count += 1
	if flag == 2 and count == 2:
		count1 += 2
	elif flag == 1 and count == 1:
		count1 += 1
	else:
		pass
if a[k] == 1:
	count1 += 1
print(count1)


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a_to_right = n - a
a_to_left = a - 1
shortesr_way_to_left = a_to_left < a_to_right
count = arr[a - 1]
if shortesr_way_to_left:
	for i in range(1, a_to_left + 1):
		if arr[a - 1 - i] + arr[a - 1 + i] == 2:
			count += 2
else:
	for i in range(1, a_to_right + 1):
		if arr[a - 1 + i] + arr[a - 1 - i] == 2:
			count += 2
if shortesr_way_to_left:
	for i in range(a + a_to_left, n):
		count += arr[i]
else:
	for i in range(0, a - 1 - a_to_right):
		count += arr[i]
print(count)


h = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
(l, r) = (h[1] - 1, h[1] - 1)
ans = c[h[1] - 1]
while True:
	(l, r) = (l - 1, r + 1)
	(lv, rv) = (1, 1)
	if l < 0 and r >= h[0]:
		break
	if l >= 0:
		lv = c[l]
	if r < h[0]:
		rv = c[r]
	if lv == 1 and rv == 1:
		if l >= 0 and r < h[0]:
			ans += 2
		else:
			ans += 1
print(ans)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
cur = 1
ans = 0
while True:
	if a - cur - 1 > -1:
		if a + cur - 1 < n:
			if t[a + cur - 1] > 0 and t[a - cur - 1] > 0:
				ans += t[a + cur - 1] + t[a - cur - 1]
		else:
			ans += t[a - cur - 1]
	elif a + cur - 1 < n:
		ans += t[a + cur - 1]
	else:
		break
	cur += 1
print(ans + t[a - 1])


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
m -= 1
k = min(n - m, m + 1)
l = 0 + (c[m] == 1)
for i in range(1, k):
	if c[m - i] == 1 and c[m + i] == 1:
		l += 2
if k - 1 == m:
	for i in range(m * 2 + 1, n):
		if c[i] == 1:
			l += 1
else:
	for i in range(0, m - k + 1):
		if c[i] == 1:
			l += 1
print(l)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
print(sum(t) - sum((t[i] + t[j] == 1 for (i, j) in zip(range(a - 2, -1, -1), range(a, n)))))


(n, p) = map(int, input().split())
A = list(map(int, input().split()))
an = 0
if A[p - 1] == 1:
	an += 1
l = p - 2
r = p
while l >= 0 or r < n:
	if l >= 0 and r < n and (A[l] == A[r]) and (A[l] == 1):
		an += 2
	elif r < n and A[r] == 1:
		if l < 0:
			an += 1
	elif l >= 0 and A[l] == 1:
		if r >= n:
			an += 1
	l -= 1
	r += 1
print(an)


(n, p) = map(int, input().split())
arr = list(map(int, input().split()))
p -= 1
i = p - 1
j = p + 1
res = 0
if arr[p]:
	res = 1
while i >= 0 and j < n:
	if arr[i] and arr[j]:
		res += 2
	i -= 1
	j += 1
while i >= 0:
	if arr[i]:
		res += 1
	i -= 1
while j < n:
	if arr[j]:
		res += 1
	j += 1
print(res)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
x = min(a - 1, n - a)
s = t[a - 1]
for i in range(1, x + 1):
	if t[a - 1 + i] == 1 and t[a - 1 - i] == 1:
		s += 2
if x == a - 1 and a - 1 != n - a:
	s += t[a + x:].count(1)
elif x == n - a and a - 1 != n - a:
	s += t[:a - x - 1].count(1)
print(s)


def exist(i, n, d, arr):
	ans = 0
	f = 0
	if d == 0:
		if arr[i] == 1:
			return 1
		else:
			return 0
	if i - d >= 0:
		ans = ans + 1
		if arr[i - d] == 1:
			f += 1
		else:
			return 0
	if i + d < n:
		ans = ans + 1
		if arr[i + d] == 1:
			f += 1
		else:
			return 0
	if f == ans:
		return f
	return 0
inf = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = 0
for i in range(100):
	ans = ans + exist(inf[1] - 1, inf[0], i, arr)
print(ans)


(n, a) = map(int, input().split())
arr = [int(x) for x in input().split()]
(x, y) = (a, a)
sum = 0
while True:
	if x == y:
		sum += arr[x - 1]
	elif x < 1:
		if y > n:
			break
		else:
			sum += arr[y - 1]
	elif y > n:
		sum += arr[x - 1]
	else:
		k = arr[x - 1] + arr[y - 1]
		if k == 2:
			sum += k
	x -= 1
	y += 1
print(sum)


(cities, location) = map(int, input().split())
criminals = list(map(int, input().split()))
distances = [0] * cities
for i in range(cities):
	if criminals[i] == 1:
		distances[abs(location - i - 1)] += 1
left_cities = cities - location
right_cities = location - 1
catch = 0
for current in range(cities):
	if current == 0:
		catch += distances[current]
	elif current <= left_cities and current <= right_cities:
		if distances[current] == 2:
			catch += 2
	else:
		catch += distances[current]
print(catch)


from collections import defaultdict, deque, Counter, OrderedDict
import sys
sys.setrecursionlimit(20000)

def main():
	(n, he) = map(int, input().split())
	he -= 1
	l = [int(i) for i in input().split()]
	ans = l[he]
	for i in range(1, 100):
		tor = he + i
		tol = he - i
		if tor < n and tol >= 0:
			if l[tor] == 1 and l[tol] == 1:
				ans += 2
		elif tor < n:
			if l[tor] == 1:
				ans += 1
		elif tol >= 0:
			if l[tol] == 1:
				ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, T) = map(int, input().split())
Q = list(map(int, input().split()))
B = min(T - 1, N - T)
Ans = Q[T - 1]
for i in range(B):
	if Q[T - 1 - i - 1] == Q[T + i] == 1:
		Ans += 2
Ans += sum(Q[:T - B - 1])
Ans += sum(Q[T + B:])
print(Ans)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
aps = 0
if t[a - 1] == 1:
	aps += 1
for d in range(1, max(n - a + 1, a)):
	if a - d > 0 and a + d <= n:
		if t[a - d - 1] == t[a + d - 1] == 1:
			aps += 2
	elif a - d <= 0:
		if t[a + d - 1] == 1:
			aps += 1
	elif a + d > n:
		if t[a - d - 1] == 1:
			aps += 1
print(aps)


[n, a] = list(map(int, input().split()))
t = list(map(int, input().split()))
a = a - 1
res = 0
for d in range(n):
	p = a - d
	q = a + d
	if d == 0:
		if t[p] == 1:
			res = res + 1
	elif p >= 0 and q < n:
		if t[p] == 1 and t[q] == 1:
			res = res + 2
	elif p >= 0 and q >= n:
		if t[p] == 1:
			res = res + 1
	elif p < 0 and q < n:
		if t[q] == 1:
			res = res + 1
print(res)


[n, a] = list(map(int, input().split()))
t = list(map(int, input().split()))
a -= 1
ans = t[a]
(before, after) = (a - 1, a + 1)
while before >= 0 and after < n:
	ans += 2 * int(t[before] == t[after] == 1)
	before -= 1
	after += 1
while before >= 0:
	ans += t[before]
	before -= 1
while after < n:
	ans += t[after]
	after += 1
print(ans)


(n, a) = list(map(int, input().split()))
a -= 1
t = list(map(int, input().split()))
d = 0
ans = 0
while a + d < len(t) or a - d >= 0:
	left = a - d
	right = a + d
	if d == 0 and t[a] == 1:
		ans += 1
	elif left >= 0 and t[left] == 1 and (right < len(t)) and (t[right] == 1):
		ans += 2
	elif left < 0 and right < len(t) and (t[right] == 1):
		ans += 1
	elif right >= len(t) and left >= 0 and (t[left] == 1):
		ans += 1
	d += 1
print(ans)


import sys
(n, a) = list(map(int, input().split()))
arr = list(map(int, input().split()))
(i, j) = (a - 1, a - 1)
c = 0
if arr[i]:
	c += 1
while i >= 0 or j < n:
	i -= 1
	j += 1
	if i >= 0 and j < n and (arr[i] == arr[j] == 1):
		c += 2
	elif i >= 0 and j >= n and arr[i]:
		c += 1
	elif i < 0 and j < n and arr[j]:
		c += 1
print(c)
sys.stdout.flush()


import sys
import bisect
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(n, a) = RI()
arr = RI()
a -= 1
cnt = 0
i = 0
while a - i >= 0 and a + i < n:
	if arr[a - i] == 1 and arr[a + i] == 1:
		if i == 0:
			cnt += 1
		else:
			cnt += 2
	else:
		cnt += 0
	i += 1
if a - i > 0:
	for j in range(a - i, -1, -1):
		if arr[j] == 1:
			cnt += 1
if a + i < n:
	for j in range(a + i, n):
		if arr[j] == 1:
			cnt += 1
print(cnt)


(n, k) = list(map(int, input().split()))
lst = list(map(int, input().split()))
(a, b) = (k - 2, k)
cnt = 0
if lst[k - 1] == 1:
	cnt += 1
while a >= 0 and b <= n - 1:
	if lst[a] + lst[b] == 2:
		cnt += 2
	a -= 1
	b += 1
if a >= 0:
	cnt += sum(lst[:a + 1])
cnt += sum(lst[b:])
print(cnt)


(m, n) = map(int, input().split())
n = n - 1
l = list(map(int, input().split()))
if m // 2 > n:
	k = n
	s = 0
	for i in range(1, k + 1):
		if l[n - i] == 1 and l[n + i] == 1:
			s = s + 2
	for j in range(n + k + 1, m):
		if l[j] == 1:
			s = s + 1
else:
	k = m - 1 - n
	s = 0
	for i in range(1, k + 1):
		if l[n - i] == 1 and l[n + i] == 1:
			s = s + 2
	for j in range(n - k):
		if l[j] == 1:
			s = s + 1
if l[n] == 1:
	print(s + 1)
else:
	print(s)


(n, a) = map(int, input().split())
l = [int(x) for x in input().split()]

def check(a, d):
	ans = 0
	if l[a] == 1:
		ans += 1
	for i in range(1, d + 1):
		if l[a + i] == 1 and l[a - i] == 1:
			ans += 2
	return ans
a = a - 1
sd = a
ed = n - 1 - a
ans = check(a, min(sd, ed))
if sd != ed:
	if sd < ed:
		for i in range(a + sd + 1, n):
			ans += l[i]
	else:
		for i in range(0, a - ed):
			ans += l[i]
print(ans)


(n, a) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
s = f = a - 1
counter = 0
while s > -1 and f < len(l):
	if l[s] == 1 and l[f] == 1:
		counter += 1 + int(s != f)
	s -= 1
	f += 1
while s > -1:
	if l[s] == 1:
		counter += 1
	s -= 1
while f < len(l):
	if l[f] == 1:
		counter += 1
	f += 1
print(counter)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
if a - 1 > n - a:
	l = l + [45] * (2 * a - n - 1)
else:
	l = [45] * (n - 2 * a + 1) + l
nn = len(l) // 2
for i in range(nn):
	if l[i] + l[len(l) - i - 1] == 2:
		ans += 2
	elif l[i] + l[len(l) - i - 1] == 46:
		ans += 1
ans += l[nn]
print(ans)


(numOfCities, pos) = [int(x) for x in input().split()]
criminals = [int(x) for x in input().split()]
CriminalsCought = 0
max_dist = pos - 1 if pos > numOfCities // 2 else numOfCities - pos
if criminals[pos - 1]:
	CriminalsCought += 1
for i in range(1, max_dist + 1):
	if pos - 1 - i < 0 or pos - 1 + i > numOfCities - 1:
		if pos > numOfCities // 2:
			CriminalsCought += criminals[pos - 1 - i]
		else:
			CriminalsCought += criminals[pos - 1 + i]
	elif criminals[pos - 1 + i] and criminals[pos - 1 - i]:
		CriminalsCought += 2
print(CriminalsCought)


(n, a) = map(int, input().split())
x = list(map(int, input().split()))
ans = 0
if n % 2 != 0 and a == n // 2 + 1:
	for i in range(n // 2 + 1):
		if x[a - 1 + i] == 1 and x[a - 1 - i] == 1:
			if i == 0:
				ans += 1
			else:
				ans += 2
else:
	for i in range(min(n - a + 1, a)):
		if x[a - 1 + i] == 1 and x[a - 1 - i] == 1:
			if i == 0:
				ans += 1
			else:
				ans += 2
	if a <= n // 2:
		for j in range(2 * a - 1, n):
			if x[j] == 1:
				ans += 1
	else:
		for j in range(n - ((n - a) * 2 + 1)):
			if x[j] == 1:
				ans += 1
print(ans)


alph = 'abcdefghijklmnopqrstuvwxyz'
(n, a) = map(int, input().split())
t = list(map(int, input().split()))
E = t[a - 1]
a -= 1
for i in range(1, max(a, n - a - 1) + 1):
	if a + i > n - 1:
		E += t[a - i]
	elif a - i < 0:
		E += t[a + i]
	else:
		E += 2 * t[a + i] * t[a - i]
print(E)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
M = t[a]
for i in range(1, n + 1):
	if 0 <= a - i < n and 0 <= a + i < n:
		if t[a - i] and t[a + i]:
			M += 2
	elif 0 <= a - i < n and t[a - i]:
		M += 1
	elif 0 <= a + i < n and t[a + i]:
		M += 1
print(M)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
l.insert(0, 0)
for i in range(1, n + 1):
	if l[i] != 0:
		d = i - k
		j = k - d
		if j < 1 or j > n or l[i] == l[j]:
			c += 1
print(c)


(n, m) = map(int, input().split())
a = [int(q) for q in input().split()]
m -= 1
k = a[m]
for i in range(1, m + 1):
	if m >= i:
		if m + i < n:
			if a[m - i] == a[m + i] == 1:
				k += 2
		else:
			k += a[m - i]
	else:
		k += a[m + i]
for i in range(2 * m + 1, n):
	k += a[i]
print(k)


cin = lambda : map(int, input().split())
(n, a) = cin()
a -= 1
l = list(cin())
res = 0
if l[a] == 1:
	res += 1
i = 1
while a - i >= 0 or a + i < n:
	sumpres = 0
	if a - i < 0:
		left = 1
	else:
		left = l[a - i]
		sumpres += 1
	if a + i >= n:
		right = 1
	else:
		right = l[a + i]
		sumpres += 1
	res += left * right * sumpres
	i += 1
print(res)


(n, a) = input().split()
mylist = input().split()
n = int(n)
a = int(a)
d1 = a - 1
d2 = n - a
d3 = abs(d1 - d2)
if d1 > d2:
	mylist += ['3'] * d3
else:
	mylist = ['3'] * d3 + mylist
counter = 0
if mylist[len(mylist) // 2] == '1':
	counter += 1
for i in range(len(mylist) // 2):
	if mylist[i] == mylist[-1 - i] == '1':
		counter += 2
	elif mylist[i] != '0' and mylist[-1 - i] != '0':
		counter += 1
print(counter)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
index = 1
count = 0
if x[m - 1] == 1:
	count += 1
while m + index - 1 < n and m - index - 1 >= 0:
	if x[m - 1 - index] == 1 and x[m + index - 1] == 1:
		count += 2
	index += 1
if m + index > n:
	while m - index > 0:
		if x[m - index - 1] == 1:
			count += 1
		index += 1
else:
	while m + index <= n:
		if x[m + index - 1] == 1:
			count += 1
		index += 1
print(count)


(a, b) = map(int, input().split())
cnt = 0
arr = list(map(int, input().split()))
t = sum(arr)
l = b - 2
r = b
while l >= 0 and r < a:
	t -= (arr[l] + arr[r]) % 2
	l -= 1
	r += 1
print(t)


import sys
input = sys.stdin.readline
(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0, 0)
ans = a[x]
for i in range(1, n + 1):
	if x - i > 0 and x + i < n + 1:
		if a[x - i] == 1 and a[x + i] == 1:
			ans += 2
	elif x - i > 0 and x + i >= n + 1:
		ans += a[x - i]
	elif x - i <= 0 and x + i < n + 1:
		ans += a[x + i]
print(ans)


(n, k) = list(map(int, input().split()))
s = 0
p = list(map(int, input().split()))
if k == 1 or k == n:
	print(p.count(1))
else:
	k -= 1
	y = 1
	for x in range(5555):
		if k - y >= 0 and k + y <= n - 1:
			if p[k - y] == 1 and p[k + y] == 1:
				s += 2
				y += 1
			else:
				y += 1
				pass
		else:
			break
	if p[k] == 1:
		s += 1
	if k - y == 0 and k + y == n - 1:
		print(s)
	elif k - y < 0:
		s += p[k + y:].count(1)
	elif k + y > n - 1:
		s += p[0:k - y + 1].count(1)
	print(s)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	(n, m) = map(int, input().split())
	m -= 1
	A = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		B = []
		if i == 0:
			B.append(A[m])
		else:
			if m - i >= 0:
				B.append(A[m - i])
			if m + i < n:
				B.append(A[m + i])
		if 0 not in B:
			ans += len(B)
	print(ans)
main()


(n, h) = map(int, input().split())
criminals = list(map(int, input().split()))
hasCriminal = []
noCriminal = []
caught = 0
for i in range(n):
	if criminals[i] != 0:
		hasCriminal.append(i)
	else:
		noCriminal.append(i)
distHasCriminal = []
distNoCriminal = []
for i in range(len(hasCriminal)):
	distHasCriminal.append(abs(hasCriminal[i] - (h - 1)))
for i in range(len(noCriminal)):
	distNoCriminal.append(abs(noCriminal[i] - (h - 1)))
for i in range(len(distHasCriminal)):
	if distHasCriminal[i] not in distNoCriminal:
		caught += criminals[hasCriminal[i]]
print(caught)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for _ in range(test_count):
	(n, a) = invr()
	t = inlt()
	t.insert(0, -1)
	d = max(a - 1, n - a)
	ans = 0
	if t[a] == 1:
		ans += 1
	for i in range(1, d + 1, 1):
		x = y = 0
		if a - i > 0:
			x += 1
			if t[a - i] == 1:
				y += 1
		if a + i <= n:
			x += 1
			if t[a + i] == 1:
				y += 1
		if x == y:
			ans += x
	print(ans)


def numberThieves(a, n, k):
	(i, j) = (k - 1, k - 1)
	tot = 0
	while i >= 0 and j < n:
		if a[i] == a[j] == 1:
			if i == j:
				tot += 1
			else:
				tot += 2
		i -= 1
		j += 1
	while i >= 0:
		if a[i] == 1:
			tot += 1
		i -= 1
	while j < n:
		if a[j] == 1:
			tot += 1
		j += 1
	return tot
li = list(map(int, input().split()))
arr = list(map(int, input().split()))
print(numberThieves(arr, li[0], li[1]))


info = input().split(' ')
n = int(info[0])
a = int(info[1]) - 1
tisinfo = map(int, input().split(' '))
tis = list(tisinfo)
criminals = 0
for i in range(0, n):
	duali = abs(i - a)
	if i > a:
		if a - duali < 0 and tis[i] == 1:
			criminals += 1
	elif i < a:
		if a + duali < n:
			if tis[i] == 1 and tis[a + duali] == 1:
				criminals += 2
		elif tis[i] == 1:
			criminals += 1
	elif tis[i] == 1:
		criminals += 1
print(str(criminals))


na = input().strip().split(' ')
n = int(na[0])
a = int(na[1])
c = input().strip().split(' ')
c = [int(ci) for ci in c]
i = a - 1
j = a - 1
count = 0
while i >= 0 and j <= n - 1:
	if i == j and c[i] == 1:
		count += 1
	elif c[i] == c[j] and c[i] == 1:
		count += 2
	i -= 1
	j += 1
if i >= 0:
	count += sum(c[:i + 1])
elif j <= n - 1:
	count += sum(c[j:])
print(count)


(n, a) = map(int, input().split())
a -= 1
summ = 0
t = list(map(int, input().split()))
for x in t:
	summ += x
l = a - 1
r = a + 1
while l >= 0 and r < n:
	summ -= (t[l] + t[r]) % 2
	l -= 1
	r += 1
print(summ)


(n, a) = map(int, input().split())
cities = list(map(int, input().split()))
a -= 1
criminals = 0
if cities[a] == 1:
	criminals += 1
right = a + 1
left = a - 1
while True:
	if right < n and left >= 0:
		if cities[right] == 1 and cities[left] == 1:
			criminals += 2
	else:
		if right >= n and left < 0:
			break
		if right < n and cities[right] == 1:
			criminals += 1
		elif left >= 0 and cities[left] == 1:
			criminals += 1
	right += 1
	left -= 1
print(criminals)


(n, a) = list(map(int, input().split()))
s = list(map(int, input().split()))
a -= 1
if s[a] == 1:
	ans = -1
else:
	ans = 0
for i in range(n):
	p1 = a - i
	p2 = a + i
	if p1 >= 0 and s[p1] == 1:
		c = 1
	else:
		c = 0
	if p2 < n and s[p2] == 1:
		c += 1
	if c == 2:
		ans += 2
	elif c == 1 and p1 < 0 or (c == 1 and p2 >= n):
		ans += 1
print(ans)


z = lambda : map(int, input().split())
(a, b) = z()
c = list(z())
i = j = b - 1
s = sum(c)
while i >= 0 and j < a:
	if c[i] + c[j] == 1:
		s -= 1
	i -= 1
	j += 1
print(s)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
cnt = [0 for i in range(101)]
crime = [0 for i in range(101)]
for i in range(1, n + 1):
	d = abs(a - i)
	cnt[d] += 1
	crime[d] += t[i - 1]
ans = 0
for i in range(101):
	if crime[i] == cnt[i]:
		ans += crime[i]
print(ans)


(n, a) = map(int, input().split())
m = list(map(int, input().split()))
cnt = m[a - 1]
for i in range(max(a, n - a)):
	c = None
	d = None
	if a - 2 - i >= 0:
		c = m[a - 2 - i]
	if a + i <= n - 1:
		d = m[a + i]
	if c != None and d != None:
		if c == d == 1:
			cnt += 2
	elif c == None and d != None:
		cnt += d
	elif d == None and c != None:
		cnt += c
print(cnt)


(n, a) = tuple(map(int, input().split()))
cities = list(map(int, input().split()))
criminals = 0
r = min(a - 1, n - a)
for i in range(a - r - 1, a - 1):
	if cities[i] == 1 and cities[2 * a - i - 2] == 1:
		criminals += 2
if cities[a - 1] == 1:
	criminals += 1
if a - r - 1 > 0:
	for i in range(0, a - r - 1):
		if cities[i] == 1:
			criminals += 1
else:
	for i in range(a + r, len(cities)):
		if cities[i] == 1:
			criminals += 1
print(criminals)


(n, a) = map(int, input().split())
arr = [int(x) for x in input().split()]
total = arr[a - 1]
a -= 1
i = 1
(foo, bar) = (0, 0)
while a - i >= 0 and a + i < n:
	foo = arr[a - i]
	bar = arr[a + i]
	if foo == bar == 1:
		total += 2
	i += 1
if a - i < 0:
	foo = sum(arr[a + i:])
else:
	foo = sum(arr[:a - i + 1])
print(total + foo)


(n, a) = map(int, input().split())
A = list(map(int, input().split()))
i = 1
cnt = A[a - 1]
while a - 1 - i >= 0 or a - 1 + i <= n - 1:
	x = a - 1 - i
	y = a - 1 + i
	if x >= 0 and y <= n - 1:
		if A[x] and A[y]:
			cnt += 2
	elif x >= 0:
		cnt += A[x]
	else:
		cnt += A[y]
	i += 1
print(cnt)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
sum = 0
left = a - 1
right = a + 1
if t[a] == 1:
	sum += 1
while left >= 0 or right < n:
	if left >= 0 and right < n and (t[left] == 1) and (t[right] == 1):
		sum += 2
	if left >= 0 and right >= n and (t[left] == 1):
		sum += 1
	if left < 0 and right < n and (t[right] == 1):
		sum += 1
	left -= 1
	right += 1
print(sum, flush=True)


(n, a) = map(int, input().split())
crim = list(map(int, input().split()))
ans = crim[a - 1]
for i in range(1, n):
	if a - 1 - i < 0 and a - 1 + i > n - 1:
		break
	if a - 1 - i < 0:
		ans += crim[a - 1 + i]
	elif a - 1 + i > n - 1:
		ans += crim[a - 1 - i]
	elif crim[a - 1 + i] == crim[a - 1 - i]:
		ans += 2 * crim[a - 1 + i]
print(ans)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [True] * n
ans = 0
ans += a[k - 1]
for i in range(min(k, n - k + 1)):
	(x, y) = (k - i - 1, k + i - 1)
	(b[x], b[y]) = (False, False)
for i in range(1, min(k, n - k + 1)):
	(x, y) = (a[k - i - 1], a[k + i - 1])
	if x == y:
		ans += x * 2
for i in range(n):
	if b[i]:
		ans += a[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
k -= 1

def get(i):
	if i < 0:
		return 0
	elif i >= n:
		return 0
	else:
		return a[i]

def gets(i):
	if k - i >= 0 and k + i < n:
		if get(k - i) == get(k + i):
			if get(k - i) == 0:
				return 0
			elif i == 0:
				return 1
			else:
				return 2
		else:
			return 0
	else:
		return get(k - i) or get(k + i)
i = 0
s = 0
while i < n:
	s += gets(i)
	i += 1
print(s)


(n, a) = list(map(int, input().split()))
x = list(map(int, input().split()))
a -= 1
result = x[a]
for i in range(1, n + 1):
	le = a - i
	rg = a + i
	le_i = le >= 0 and le < n
	rg_i = rg >= 0 and rg < n
	if not le_i and (not rg_i):
		break
	if le_i and (not rg_i):
		result += x[le]
	elif not le_i and rg_i:
		result += x[rg]
	elif x[le] == x[rg] == 1:
		result += 2
print(result)


import sys

def main(k, robbers):
	smaller = min(k, len(robbers) - k - 1)
	s = 0
	for (e, rob) in enumerate(robbers):
		if e == k:
			s += rob
		elif abs(k - e) > smaller:
			s += rob
	for i in range(k):
		if abs(k - i) <= smaller:
			if robbers[i] + robbers[k + abs(i - k)] > 1:
				s += 2
	print(s)
cases = []
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		(_, k) = map(int, line.strip().split())
	cases = list(map(int, line.strip().split()))
main(k - 1, cases)


(cityLength, limaksHouse) = map(int, input().split())
houses = input()
houses = houses.split(' ')
distance = 1
max = max(cityLength - limaksHouse, cityLength - (cityLength - limaksHouse) - 1)
crimes = 0
limaksHouse -= 1
if houses[limaksHouse] == '1':
	crimes += 1
while distance <= max:
	if limaksHouse - distance < 0:
		if houses[limaksHouse + distance] == '1':
			crimes += 1
	elif limaksHouse + distance >= len(houses):
		if houses[limaksHouse - distance] == '1':
			crimes += 1
	elif houses[limaksHouse + distance] == houses[limaksHouse - distance] and houses[limaksHouse - distance] == '1':
		crimes += 2
	distance += 1
print(crimes)


from sys import stdin

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def solve():
	(n, a) = ip()
	A = ip()
	a -= 1
	ans = 0
	if A[a] == 1:
		ans += 1
	(l, r) = (a - 1, a + 1)
	while l >= 0 or r < n:
		if l >= 0 and r < n:
			if A[l] == 1 and A[r] == 1:
				ans += 2
			l -= 1
			r += 1
		elif l < 0:
			if A[r] == 1:
				ans += 1
			r += 1
		else:
			if A[l] == 1:
				ans += 1
			l -= 1
	return ans
print(solve())


(n, a) = list(map(int, input().split(' ')))
(x, sum, i, j) = (list(map(int, input().split(' '))), 0, a - 2, a)
while i >= 0 or j < n:
	if i == -1:
		sum += x[j:].count(1)
		break
	if j == n:
		sum += x[:i + 1].count(1)
		break
	if x[i] == x[j] == 1:
		sum += 2
	(i, j) = (i - 1, j + 1)
print(sum if x[a - 1] == 0 else sum + 1)


(n, st) = map(int, input().split())
a = list(map(int, input().split())) + [0] * 100
cnt = 0
for i in range(100):
	if st - i - 1 >= 0 and st + i - 1 < n and (a[st - i - 1] == 1) and (a[st + i - 1] == 1):
		cnt += 2 - (i == 0)
	if st - i - 1 >= 0 and (not st + i - 1 < n) and (a[st - i - 1] == 1):
		cnt += 1
	if st - i - 1 < 0 and st + i - 1 < n and (a[st + i - 1] == 1):
		cnt += 1
print(cnt)


(n, a) = map(int, input().strip().split(' '))
li = list(map(int, input().strip().split(' ')))
t = 0
c = 0
a -= 1
while a + t < n or a - t >= 0:
	if a + t < n and a - t >= 0:
		if li[a + t] and li[a - t] and t:
			c += 2
		elif li[a + t] and li[a - t]:
			c += 1
	elif a + t < n and li[a + t]:
		c += 1
	elif a - t >= 0 and li[a - t]:
		c += 1
	t += 1
print(c)


(n, m) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
m -= 1
(left, right) = (m - 0 + 1, len(l) - m)
length = min(left, right)
(pos, count) = (1, 0)
while pos != length:
	if l[m - pos] == l[m + pos] and l[m - pos] == 1:
		count += 2
		(l[m + pos], l[m - pos]) = (0, 0)
	else:
		(l[m + pos], l[m - pos]) = (0, 0)
	pos += 1
if l[m] == 1:
	count += 1
	l[m] = 0
for i in l:
	if i == 1:
		count += 1
print(count)


(n, a) = map(int, input().split())
criminels = list(map(int, input().split()))
nbCriminels = 0
ville = a - 1
if criminels[ville] == 1:
	nbCriminels += 1
for distance in range(1, max(a, n - a + 1)):
	if n > ville + distance >= 0 and n > ville - distance >= 0:
		if criminels[ville + distance] + criminels[ville - distance] == 2:
			nbCriminels += 2
	elif ville + distance >= n and n > ville - distance >= 0:
		if criminels[ville - distance] == 1:
			nbCriminels += 1
	elif n > ville + distance >= 0 and ville - distance < 0:
		if criminels[ville + distance] == 1:
			nbCriminels += 1
print(nbCriminels)


def main():
	(n, a) = map(int, input().split())
	t = list(map(int, input().split()))
	count = 0
	for i in range(1, 101):
		if a - i > 0 and i + a <= n:
			if t[a - i - 1] == t[i + a - 1] and t[a + i - 1] == 1:
				count += 2
		elif i + a <= n and t[a + i - 1] == 1 and (a - i <= 0):
			count += 1
		elif a - i > 0 and t[a - i - 1] == 1 and (i + a > n):
			count += 1
		elif a - i <= 0 and i + a > n:
			break
	if t[a - 1] == 1:
		count += 1
	print(count)
main()


(n, a) = [int(i) for i in input().split()]
cities = [int(i) for i in input().split()]
a -= 1
count = 0
comeco = a
fim = a
while comeco >= 0 or fim < n:
	if comeco == fim == a:
		count += cities[a]
	elif comeco >= 0 and fim < n:
		if cities[comeco] == cities[fim]:
			count += 2 * cities[comeco]
	elif comeco >= 0:
		count += cities[comeco]
	elif fim < n:
		count += cities[fim]
	comeco -= 1
	fim += 1
print(count)


z = lambda : map(int, input().split())
(a, b) = z()
c = list(z())
i = j = b - 1
s = 0
while i >= 0 and j < a:
	if c[i] == c[j] == 1 and i == j == b - 1:
		s += 1
	elif c[i] == c[j] == 1:
		s += 2
	i -= 1
	j += 1
s += c[:i + 1].count(1) if i != -1 else 0
print(s + c[j:].count(1))


(n, a) = map(int, input().split())
l_c = list(map(int, input().split()))
a -= 1
t = 0
for i in range(n):
	d = abs(a - i)
	if a - d < 0 or a + d >= n:
		t += 1 if l_c[i] == 1 else 0
	elif a - d >= 0 and a + d < n:
		t += 1 if l_c[a - d] == l_c[a + d] == 1 else 0
print(t)


(n, a) = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
a -= 1
l = r = a
ans = 1 if q[a] else 0
while l - 1 >= 0 or r + 1 < n:
	if l - 1 >= 0:
		l -= 1
	if r + 1 < n:
		r += 1
	if q[l]:
		q[l] = 0
		tr = a + abs(l - a)
		if tr > n - 1:
			ans += 1
		elif tr < n and q[tr]:
			ans += 2
			q[tr] = 0
	if q[r]:
		q[r] = 0
		tl = a - abs(r - a)
		if tl < 0:
			ans += 1
		elif tl >= 0 and q[tl]:
			ans += 2
			q[tl] = 0
print(ans)


arr = list(map(int, input().split()))
n = arr[0]
a = arr[1]
a -= 1
ans = 0
arr = list(map(int, input().split()))
ans += arr[a]
i = 1
while a + i < n and a - i > -1:
	if arr[a + i] == arr[a - i] == 1:
		ans += 2
	i += 1
for j in range(a - i + 1):
	ans += arr[j]
for j in range(a + i, n):
	ans += arr[j]
print(ans)


(a, n) = map(int, input().split())
t = list(map(int, input().split()))
(i, j) = (n - 2, n)
ans = 1 if t[n - 1] == 1 else 0
while i >= 0 or j < a:
	if i >= 0 and j < a:
		if t[i] == t[j] == 1:
			ans += 2
	elif i < 0 and t[j] == 1:
		ans += 1
	elif j >= a and t[i] == 1:
		ans += 1
	i -= 1
	j += 1
print(ans)


(n, a) = list(map(int, input().split()))
c = list(map(int, input().split()))
res = c[a - 1]
for i in range(1, max(n - a + 1, a)):
	(l, r) = (a - 1 - i, a - 1 + i)
	if l >= 0 and r < n:
		if c[l] and c[r]:
			res += 2
	elif l >= 0:
		if c[l]:
			res += 1
	elif r < n:
		if c[r]:
			res += 1
print(res)


(n, a) = list(map(int, input().split()))
v = list(map(int, input().split()))
a -= 1
it = 0
cnt = 0
while a - it >= 0 and a + it < n:
	x = v[a - it] + v[a + it]
	if it == 0:
		if x == 2:
			cnt += 1
	elif x == 1:
		if it == 0:
			cnt += 1
	elif x == 2:
		cnt += 2
	it += 1
while a - it >= 0 or a + it < n:
	if a - it >= 0:
		cnt += v[a - it]
	if a + it < n:
		cnt += v[a + it]
	it += 1
print(cnt)


(a, n) = list(map(int, input().split()))
t = list(map(int, input().split()))
y = t[::-1]
c = 0
if len(t) == 1:
	print(sum(t))
else:
	for k in range(1, a):
		if 0 <= n - k - 1 <= a - 1 and 0 <= k + n - 1 <= a - 1:
			if t[n - k - 1] == 1 and t[k + n - 1] == 1:
				c += 2
		else:
			break
	if n > a - n:
		print(c + t[n - 1] + sum(t[:n - (a - n) - 1]))
	else:
		print(c + t[n - 1] + sum(t[2 * n - 1:]))


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(a - 1):
	if a + a - i - 2 >= n:
		ans += l[i]
	else:
		t = l[i] + l[a + a - i - 2]
		if t == 2:
			ans += 2
print(ans + l[a - 1] + sum(l[a + a - 1:]))


(n, a) = map(int, input().split())
(*aa,) = map(int, input().split())
ii = [1, -1][a <= int(n / 2)]
for i in range(a - 1, [-1, n][ii == 1], ii):
	if aa[i] == 0 or aa[2 * a - 2 - i] == 0:
		aa[i] = 0
		aa[2 * a - 2 - i] = 0
print(sum(aa))


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a -= 1
ans = 0
for i in range(n):
	if i == a:
		ans += arr[i]
	elif i < a:
		j = 2 * a - i
		if j >= n or arr[j] == 1:
			ans += arr[i]
	else:
		j = 2 * a - i
		if j < 0 or arr[j] == 1:
			ans += arr[i]
print(ans)


import sys
lines = sys.stdin.readlines()
(n, a) = map(int, lines[0].strip().split(' '))
nums = list(map(int, lines[1].strip().split(' ')))
res = 0
if nums[a - 1] == 1:
	res += 1
for i in range(1, min(a - 1, n - a) + 1):
	if nums[a - i - 1] == 1 and nums[a + i - 1] == 1:
		res += 2
if a * 2 - 1 < n:
	for i in range(a * 2, n + 1):
		if nums[i - 1] == 1:
			res += 1
elif a * 2 - 1 > n:
	for i in range(1, n - (n - a) * 2):
		if nums[i - 1] == 1:
			res += 1
print(res)


(n, ind) = list(map(int, input().split()))
arr = list(map(int, input().split()))
cnt = 0
ind -= 1
if arr[ind] == 1:
	cnt += 1
r = True
l = True
index = 1
while r or l:
	f = False
	s = False
	if ind - index < 0:
		l = False
	if ind + index >= n:
		r = False
	if r and l:
		if arr[ind + index] == 1 and arr[ind - index] == 1:
			f = True
			s = True
	if f and s:
		cnt += 2
	elif not r and l:
		if arr[ind - index] == 1:
			cnt += 1
	elif r and (not l):
		if arr[ind + index] == 1:
			cnt += 1
	if not l and (not r):
		break
	index += 1
print(cnt)


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a -= 1
cnt = arr[a]
for i in range(1, min(a + 1, n - a)):
	if arr[a - i] == arr[a + i] == 1:
		cnt += 2
if a + 1 > n - a:
	for i in range(a - (n - a) + 1):
		cnt += arr[i]
else:
	for i in range(2 * a + 1, n):
		cnt += arr[i]
print(cnt)


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a = a - 1
x = 0
i = 0
while a - i >= 0 or a + i < n:
	if a - i < 0 and arr[a + i] == 1:
		x += 1
	elif a + i >= n and arr[a - i] == 1:
		x += 1
	elif arr[a - i] == 1 and arr[a + i] == 1:
		if i == 0:
			x += 1
		else:
			x += 2
	i += 1
print(x)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1 or p == 1 or p == n:
	print(sum(a))
else:
	c = a[p - 1]
	k = p
	for i in range(1, min(p - 1, n - p) + 1):
		if a[p - i - 1] + a[p + i - 1] == 2:
			c = c + 2
		k = i
	print(c + sum(a[p + k:]) if p <= n // 2 else c + sum(a[:p - k - 1]))


(n, a) = (int(i) for i in input().split())
l = list(map(int, input().split()))
a -= 1
ans = 0
for d in range(n):
	if d == 0 and l[a] == 1:
		ans += 1
	elif a - d >= 0 and a + d < n and (l[a - d] == 1) and (l[a + d] == 1):
		ans += 2
	elif a - d < 0 and a + d < n and (l[a + d] == 1):
		ans += 1
	elif a - d >= 0 and a + d >= n and (l[a - d] == 1):
		ans += 1
print(ans)


(n, a) = [int(x) for x in input().split(' ')]
t = [0] + [int(x) for x in input().split(' ')]
m = min(n - a, a - 1)
res = 0
if t[a] == 1:
	res += 1
	t[a] = 0
for i in range(1, m + 1):
	s = t[a + i] + t[a - i]
	if s == 2:
		res += 2
	(t[a + i], t[a - i]) = (0, 0)
print(res + sum(t))


def main():
	(n, a) = map(int, input().split())
	a -= 1
	t = list(map(int, input().split()))
	ans = 0
	if t[a] == 1:
		ans = 1
	for i in range(1, 100):
		add = 0
		outrange = False
		x = a - i
		if 0 <= x < n:
			if t[x] == 1:
				add += 1
		else:
			outrange = True
		x = a + i
		if 0 <= x < n:
			if t[x] == 1:
				add += 1
		else:
			outrange = True
		if add == 2 or (add == 1 and outrange):
			ans += add
	print(ans)
main()


(n, a) = map(int, input().split())
t = [int(i) for i in input().split()]
a -= 1
k = 0
d = 0
if t[a] == 1:
	k += 1
while True:
	d += 1
	if a - d < 0 and a + d >= n:
		break
	if a - d < 0:
		if t[a + d] == 1:
			k += 1
		continue
	if a + d >= n:
		if t[a - d] == 1:
			k += 1
		continue
	if t[a + d] + t[a - d] == 2:
		k += 2
		continue
print(k)


(n, a) = map(int, input().split())
a -= 1
crim = list(map(int, input().split()))
i = 1
counter = crim[a]
while a - i >= 0 and a + i <= n - 1:
	if crim[a - i] == 1 and crim[a + i] == 1:
		counter += 2
	i += 1
while a - i >= 0:
	counter += crim[a - i]
	i += 1
while a + i <= n - 1:
	counter += crim[a + i]
	i += 1
print(counter)


from sys import stdin, stdout
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
(n, a) = gil()
t = gil()
i = j = a - 1
c = 0
while i >= 0 and j < n:
	s = t[i] + t[j]
	if s == 2:
		if i == j:
			c += 1
		else:
			c += 2
	i -= 1
	j += 1
if i >= 0:
	c += sum(t[:i + 1])
elif j < n:
	c += sum(t[j:])
print(c)


(n, a) = map(int, input().split())
l = [int(ele) for ele in input().split()]
if a == 1 or a == n:
	print(l.count(1))
	exit()
(n, a) = (n - 1, a - 1)
count = 0
if l[a] == 1:
	count += 1
	l[a] = 0
for i in range(1, min(n - a, a) + 1):
	if l[a + i] == 1 and l[a - i] == 1:
		count += 2
	(l[a + i], l[a - i]) = (0, 0)
count += l.count(1)
print(count)


(n, a) = map(int, input().split())
w = list(map(int, input().split()))
s = 0
a -= 1
for i in range(1, 150):
	k = 0
	l = 0
	if a - i > -1:
		l += 1
		if w[a - i] == 1:
			k += 1
	if a + i < n:
		l += 1
		if w[a + i] == 1:
			k += 1
	if k == l and k != 0:
		s += k
if w[a] == 1:
	s += 1
print(s)


(n, a) = [int(i) for i in input().split()]
crim = [int(j) for j in input().split()]
count = 0
a -= 1
if crim[a] == 1:
	count += 1
j = a - 1
k = a + 1
while j >= 0 and k < n:
	if crim[j] + crim[k] == 2:
		count += 2
	j -= 1
	k += 1
if j < 0 and k != n:
	while k < n:
		if crim[k] == 1:
			count += 1
		k += 1
elif j >= 0 and k == n:
	while j >= 0:
		if crim[j] == 1:
			count += 1
		j -= 1
print(count)


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a -= 1
l = a
r = a
ans = 0
while l >= 0 or r < n:
	if l < 0:
		if arr[r]:
			ans += 1
	elif r >= n:
		if arr[l]:
			ans += 1
	elif l == r and arr[l] == 1:
		ans += 1
	elif arr[l] == 1 and arr[r] == 1:
		ans += 2
	l -= 1
	r += 1
print(ans)


(n, a) = input().split()
n = int(n)
a = int(a)
arr = [int(x) for x in input().split()]
p = a - 1
cities = [0 for x in range(0, n)]
c = [0 for x in range(0, n)]
point1 = p - 1
point2 = p + 1
count = 0
cities[0] = 1
if arr[p] == 1:
	c[0] = 1
for i in range(1, n):
	if point1 >= 0 and point2 <= n - 1:
		if arr[point1] == 1 and arr[point2] == 1:
			c[i] = 2
		point1 -= 1
		point2 += 1
		cities[i] = 2
	elif point1 < 0 and point2 <= n - 1:
		cities[i] = 1
		if arr[point2] == 1:
			c[i] = 1
		point2 += 1
	elif point1 >= 0 and point2 > n - 1:
		cities[i] = 1
		if arr[point1] == 1:
			c[i] = 1
		point1 -= 1
for i in range(0, n):
	if c[i] == cities[i]:
		count += c[i]
print(count)


(n, a) = map(int, input().split())
m = [-1] + list(map(int, input().split()))
coun = 0
ans = 0
while True:
	if a + coun > n and a - coun < 1:
		break
	if coun == 0:
		if m[a] == 1:
			ans += 1
	else:
		check = 0
		if a + coun <= n:
			check = m[a + coun]
			if a - coun < 1:
				if check == 1:
					ans += 1
			else:
				check += m[a - coun]
				if check == 2:
					ans += 2
		else:
			ans += m[a - coun]
	coun += 1
print(ans)


(n, k) = map(int, input().split())
mas = [int(x) for x in input().split()]
k -= 1
u = max(k, n - k - 1)
u += 1
c = 0
for i in range(u):
	if i == 0:
		if mas[k]:
			c += 1
	elif k + i >= n:
		if k - i >= 0 and mas[k - i]:
			c += 1
	elif k - i < 0:
		if k + i < n and mas[k + i]:
			c += 1
	elif mas[k - i] and mas[k + i]:
		c += 2
print(c)


l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
if l == [2, 1] and l1 == [0, 1]:
	print(1)
else:
	k = l[1] - 1
	i = 1
	count = 0
	l = l[0] - 1
	if l1[k] == 1:
		count += 1
	while k - i != -1 or k + i != l + 1:
		if k - i < 0 or k + i > l:
			break
		if l1[k - i] == 1 and l1[k + i] == 1:
			count += 2
		i += 1
	if k - i > 0:
		count += l1[:k - i + 1].count(1)
	if k + i < l:
		count += l1[k + i:].count(1)
	print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	a = LI()
	m -= 1
	r = 0
	for i in range(n):
		if a[i] == 0:
			continue
		s = m - i
		t = m + s
		if s == 0 or (0 <= t < n and a[t] == 1) or (t < 0 or t >= n):
			r += 1
	return r
print(main())


(n, a) = map(int, input().split())
lis = list(map(int, input().split()))
police = a - 1
count = 0
i = police
j = police
while i >= 0 and j <= n - 1:
	if lis[i] == lis[j] == 1:
		count += 2
	i -= 1
	j += 1
while i >= 0:
	if lis[i] == 1:
		count += 1
	i -= 1
while j <= n - 1:
	if lis[j] == 1:
		count += 1
	j += 1
if lis[police] == 1:
	print(count - 1)
else:
	print(count)


def index_in_list(i, n):
	return 0 <= i < n
(n, a) = map(int, input().split())
l = list(map(int, input().split()))
d = max(a - 1, n - a)
cnt = 1 if l[a - 1] == 1 else 0
for i in range(1, d + 1):
	if index_in_list(a - 1 + i, n) and index_in_list(a - 1 - i, n) and (l[a - 1 + i] == l[a - 1 - i] == 1):
		cnt += 2
	elif index_in_list(a - 1 + i, n) and (not index_in_list(a - 1 - i, n)) and (l[a - 1 + i] == 1):
		cnt += 1
	elif index_in_list(a - 1 - i, n) and (not index_in_list(a - 1 + i, n)) and (l[a - 1 - i] == 1):
		cnt += 1
print(cnt)


def start():
	(n, a) = map(int, input().split())
	count = 0
	a -= 1
	arr = [int(item) for item in input().split()]
	i = a - 1
	j = a + 1
	if arr[a] == 1:
		count += 1
	while True:
		if i < 0 and j >= len(arr):
			break
		elif i >= 0 and j < len(arr):
			if arr[i] == 1 and arr[j] == 1:
				count += 2
			i = i - 1
			j = j + 1
		elif i < 0 and j < len(arr):
			if arr[j] == 1:
				count += 1
			j = j + 1
		elif j >= len(arr) and i >= 0:
			if arr[i] == 1:
				count += 1
			i = i - 1
	print(count)
start()


(n, a) = map(int, input().split())
b = list(map(int, input().split()))
(c, d) = (a - 2, a)
e = sum(b)
while c >= 0 and d < n:
	e -= (b[c] + b[d]) % 2
	c -= 1
	d += 1
print(e)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
s = []
l = 0
for i in range(n):
	if t[i] == 1:
		s.append(i + 1)
for i in range(1, n):
	if a - i in s and a + i in s:
		l += 2
	if a + i in s and a - i <= 0:
		l += 1
	if a - i in s and a + i >= n + 1:
		l += 1
print(l + int(t[a - 1] == 1))


(n, a) = map(int, input().split())
t = [int(i) for i in input().split()]
x = t[:a][::-1]
y = t[a - 1:]
if x[0]:
	k = 1
else:
	k = 0
for i in range(1, min(len(x), len(y))):
	if x[i] == 1 and y[i] == 1:
		k += 2
if len(x) > len(y):
	for i in range(len(y), len(x)):
		if x[i] == 1:
			k += 1
else:
	for i in range(len(x), len(y)):
		if y[i] == 1:
			k += 1
print(k)


(n, a) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
ss = sum(arr)
a -= 1
ans = 0
ss -= arr[a]
for i in range(1, a + 1):
	if a + i < n:
		if arr[a - i] + arr[a + i] == 2:
			ans += 2
		ss -= arr[a - i]
		ss -= arr[a + i]
ans += arr[a]
ans += ss
print(ans)


n = tuple(map(int, input().split(' ')))
x = tuple(map(int, input().split(' ')))
d = n[1] - 1
flag = 0
s = 0
for i in range(n[0]):
	if d - i >= 0 and d + i <= n[0] - 1:
		if x[d - i] == 1 and x[d + i] == 1:
			if i == 0:
				s += 1
			else:
				s += 2
	elif d - i >= 0:
		if x[d - i] == 1:
			s += 1
	elif d + i <= n[0] - 1:
		if x[d + i] == 1:
			s += 1
print(s)


[n, k] = list(map(int, input().split()))
t = list(map(int, input().split()))
k = k - 1
total_criminals = t[k]
for i in range(1, len(t)):
	cities = 0
	criminals = 0
	if k + i < len(t):
		criminals += t[k + i]
		cities += 1
	if k - i >= 0:
		criminals += t[k - i]
		cities += 1
	if criminals > 0 and criminals == cities:
		total_criminals += criminals
print(total_criminals)


(n, a) = map(int, input().split())
b = list(map(int, input().split()))
a = a - 1
c = []
d = []
e = []
g = 0
for i in range(n):
	c.append(abs(i - a))
for i in range(n):
	d.append([c[i], b[i]])
d.sort()
for i in range(len(d) - 1):
	if d[i] == d[i + 1]:
		d[i][1] = d[i][1] + d[i + 1][1]
		d[i + 1][1] = 0
for i in range(len(d)):
	if d[i][0] in e:
		continue
	else:
		e.append(d[i][0])
		g += d[i][1]
print(g)


s = 0
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
if l[m - 1] == 1:
	s += 1
for x in range(1, n):
	if m - x - 1 >= 0 and m - 1 + x < n:
		if l[m - 1 - x] == 1 and l[m - 1 + x] == 1:
			s += 2
	elif m - 1 + x < n and l[m - 1 + x] == 1 or (m - 1 - x >= 0 and l[m - 1 - x] == 1):
		s += 1
print(s)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	(n, k) = map(int, input().split())
	a = ain()
	ans = 0
	if a[k - 1] == 1:
		ans += 1
	item = 0
	for item in range(1, min(k - 1, n - k) + 1):
		if a[k + item - 1] == 1 and a[k - item - 1] == 1:
			ans += 2
	if k - 1 >= n // 2:
		ans += sum(a[:k - 1 - item])
	else:
		ans += sum(a[k + item:])
	print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
a -= 1
ans = sum(arr)
(lo, hi) = (a - 1, a + 1)
while lo >= 0 and hi < len(arr):
	ans -= (arr[lo] + arr[hi]) % 2
	lo -= 1
	hi += 1
print(ans)


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
tot = 0
if c[k - 1] == 1:
	tot += 1
pivot = k - 1
left_pointer = k - 1
right_pointer = k - 1
while left_pointer > 0 or right_pointer < n - 1:
	left_pointer -= 1
	right_pointer += 1
	if left_pointer >= 0 and right_pointer <= n - 1:
		if c[left_pointer] == c[right_pointer] and c[left_pointer] == 1:
			tot += 2
	elif left_pointer < 0 and right_pointer <= n - 1:
		if c[right_pointer] == 1:
			tot += 1
	elif left_pointer >= 0 and right_pointer >= n:
		if c[left_pointer] == 1:
			tot += 1
	else:
		break
print(tot)


(n, start) = map(int, input().split())
cities = list(map(int, input().split()))
start -= 1
i = j = start
ans = left = right = 0
while i >= 0 and j < n:
	if i == j:
		if cities[i]:
			ans += 1
	elif cities[i] and cities[j]:
		ans += 2
	i -= 1
	j += 1
if i > 0:
	ans += sum(cities[:i + 1])
if j < n:
	ans += sum(cities[j:])
print(ans)


(n, a) = map(int, input().split())
land = list(map(int, input().split()))
res = land[a - 1]
for o in range(1, min(a, n - a + 1)):
	if land[a - o - 1] == land[a + o - 1] == 1:
		res += land[a - o - 1] + land[a + o - 1]
if n - a > a - 1:
	for o in range(a * 2 - 1, n):
		res += land[o]
else:
	for o in range(0, a * 2 - n - 1):
		res += land[o]
print(res)


f = lambda : map(int, input().split())
(n, a) = f()
t = [0] + list(f())
ans = t[a]
for i in range(1, n):
	if a - i > 0 and a + i <= n:
		if t[a - i] == t[a + i]:
			ans += t[a - i] + t[a + i]
	elif a - i > 0:
		ans += t[a - i]
	elif a + i <= n:
		ans += t[a + i]
print(ans)


(n, a) = map(int, input().split())
a -= 1
t = list(map(int, input().split()))
ans = sum(t)
l = a - 1
r = a + 1
while l >= 0 and r < n:
	ans -= (t[l] + t[r]) % 2
	l -= 1
	r += 1
print(ans)


(n, a) = map(int, input().split())
a -= 1
t = list(map(int, input().split()))
r = t[a]
s = t[:a]
b = t[a + 1:]
b.reverse()
if len(s) > len(b):
	(b, s) = (s, b)
r += sum(b[:len(b) - len(s)])
b = b[len(b) - len(s):]
r += sum(map(lambda a, b: 2 * (a and b), b, s))
print(r)


import sys
(n, a) = map(int, input().split())
t = [0]
t += [int(x) for x in input().split()]
crim = t[a]
for i in range(1, n + 1):
	if a - i < 1 and a + i > n:
		break
	if a - i < 1:
		if t[a + i] == 1:
			crim += 1
	elif a + i > n:
		if t[a - i] == 1:
			crim += 1
	elif t[a - i] * t[a + i] == 1:
		crim += 2
print(crim)


def get(m, k, mp):
	i = m - k
	j = m + k
	if i < 0 and j < n:
		return mp[j]
	elif i >= 0 and j >= n:
		return mp[i]
	elif i >= 0 and j < n and (mp[i] ^ mp[j] == 0):
		return mp[i] + mp[j]
	else:
		return 0
(n, m) = map(int, input().split())
m -= 1
mp = list(map(int, input().split()))
i = m
j = m
ans = mp[m]
for k in range(1, 101):
	ans += get(m, k, mp)
print(ans)


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, k) = get_ints()
	arr = get_list()
	ans = 0
	for i in range(n):
		left = k - 1 - i
		right = k - 1 + i
		if left >= 0 and right <= n - 1:
			if arr[left] == 1 and arr[right] == 1:
				if left == right:
					ans += 1
					continue
				ans += 2
		elif left < 0 and right <= n - 1:
			if arr[right] == 1:
				ans += 1
		elif left >= 0 and right > n - 1:
			if arr[left] == 1:
				ans += 1
	print(ans)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
l = [100] + l
d = {}
for i in range(a, n + 1):
	d[i - a] = l[i]
for i in range(1, a):
	if a - i in d.keys():
		d[a - i] += l[i]
	else:
		d[a - i] = l[i]
p = 0
for i in d.keys():
	if i == 0:
		p += d[i]
	elif i <= min(n - a, a - 1):
		if d[i] == 2:
			p += 2
	else:
		p += d[i]
print(p)


arr1 = list(map(int, input().split()))

def proB(arr, k):
	k = k - 1
	ans = arr[k]
	temp1 = arr[:k]
	temp1 = temp1[::-1]
	temp2 = arr[k + 1:]
	(i, j) = (0, 0)
	while i < len(temp1) and j < len(temp2):
		if temp1[i] == 1 and temp2[j] == 1:
			ans += 2
		i += 1
		j += 1
	if temp1[i:] == []:
		ans += temp2[j:].count(1)
	else:
		ans += temp1[i:].count(1)
	return ans
(n, m) = (arr1[0], arr1[1])
for i in range(1):
	arr = list(map(int, input().split()))
	print(proB(arr, m))


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
p = a - 1
result = 0
for i in range(0, n):
	if t[i] == 1:
		distance = p - i
		if p + distance > n - 1 or p + distance < 0:
			result = result + 1
		elif t[p + distance] == 1:
			result = result + 1
print(result)


(n, a) = [int(x) for x in input().split()]
t = [1] + [int(x) for x in input().split()] + [1]
l = a - 1
r = a + 1
ans = t[a]
while l > 0 or r <= n:
	if t[l] == 1 and t[r] == 1:
		ans += 2
		if l == 0 or r == n + 1:
			ans -= 1
	if l > 0:
		l -= 1
	if r <= n:
		r += 1
print(ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
x = m - 1
c = 0
for i in range(n):
	if i == 0:
		if l[x] == 1:
			c += 1
	else:
		y = x - i
		z = x + i
		if y >= 0 and z <= n - 1:
			if l[y] == 1 and l[z] == 1:
				c += 2
		elif y >= 0 and z > n - 1:
			if l[y] == 1:
				c += 1
		elif y < 0 and z <= n - 1:
			if l[z] == 1:
				c += 1
		elif y < 0 and z > n - 1:
			break
print(c)


(n, a) = map(int, input().split())
city = list(map(int, input().split()))
no_criminals = 0
left = city[:a - 1]
right = city[a:]
if city[a - 1] == 1:
	no_criminals = 1
for (i, j) in zip(reversed(left), right):
	if i == 1 and j == 1:
		no_criminals += 2
if len(left) > len(right):
	for i in range(len(left) - len(right) - 1, -1, -1):
		if left[i] == 1:
			no_criminals += 1
else:
	for i in range(len(left), len(right)):
		if right[i] == 1:
			no_criminals += 1
print(no_criminals)


def mi():
	return map(int, input().split())
(n, cur) = mi()
a = list(mi())
i = 1
caught = 0
cur -= 1
if a[cur]:
	caught = 1
visited = [0] * n
visited[cur] = 1
while cur + i < n and cur - i >= 0:
	(visited[cur + i], visited[cur - i]) = (1, 1)
	if a[cur - i] and a[cur + i]:
		caught += 2
	i += 1
for i in range(n):
	if visited[i] == 0:
		if a[i]:
			caught += 1
print(caught)


(a, b) = input().split()
a = int(a)
b = int(b)
arr = [int(i) for i in input().split()]
i = b - 1
j = b - 1
count = 0
while 0 <= i <= b - 1 or b - 1 <= j <= a - 1:
	if 0 <= i <= b - 1 and b - 1 <= j <= a - 1:
		if arr[i] == 1 and arr[j] == 1:
			if i == j:
				count += 1
			else:
				count += 2
			i = i - 1
			j = j + 1
		else:
			i = i - 1
			j = j + 1
	elif i < 0 and j < a:
		if arr[j] == 1:
			count += 1
			j += 1
		else:
			j += 1
	elif arr[i] == 1:
		count += 1
		i = i - 1
	else:
		i = i - 1
print(count)


(n, a) = list(map(int, input().split()))
criminals = list(map(int, input().split()))
count = 0
start = a - 1
i = 0
while start + i < n or start - i >= 0:
	if start - i >= 0 and start + i < n:
		if start + i == start - i and criminals[start]:
			count += 1
		elif criminals[start - i] and criminals[start + i]:
			count += 2
	elif start - i >= 0 and criminals[start - i]:
		count += 1
	elif start + i < n and criminals[start + i]:
		count += 1
	i = i + 1
print(count)


(n, a) = map(int, input().split(' '))
cities = list(map(int, input().split(' ')))
a -= 1
a_post = a + 1
a_pre = a - 1
post_done = 0
pre_done = 0
cathed = 0
if a == 0 or a == n - 1:
	cathed = sum(cities)
else:
	cathed += cities[a]
	while True:
		if post_done == 0 and pre_done == 0:
			if cities[a_post] == 1 and cities[a_pre] == 1:
				cathed += 2
			if a_post + 1 != n:
				a_post += 1
			else:
				post_done = 1
			if a_pre - 1 != -1:
				a_pre -= 1
			else:
				pre_done = 1
		elif post_done == 1 and pre_done == 0:
			if a_pre == 0:
				cathed += cities[a_pre]
			else:
				cathed += sum(cities[:a_pre + 1])
			break
		elif pre_done == 1 and post_done == 0:
			if a_post == n - 1:
				cathed += cities[a_post]
			else:
				cathed += sum(cities[a_post:])
			break
		else:
			break
print(cathed)


def main():
	(n, a) = [int(t) for t in input().split()]
	arr = [int(t) for t in input().split()]
	a -= 1
	i = a - 1
	j = a + 1
	cnt = 1 if arr[a] == 1 else 0
	while i >= 0 and j <= len(arr) - 1:
		if arr[i] == arr[j] and arr[i] == 1:
			cnt += 2
		i -= 1
		j += 1
	while i >= 0:
		if arr[i] == 1:
			cnt += 1
		i -= 1
	while j <= len(arr) - 1:
		if arr[j] == 1:
			cnt += 1
		j += 1
	print(cnt)
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(i, j) = (k - 1, k - 1)
c = 0
while i >= 0 and j < n:
	if a[i] == 1 and a[j] == 1:
		if i != j:
			c += 2
		else:
			c += 1
	i -= 1
	j += 1
while i >= 0:
	if a[i] == 1:
		c += 1
	i -= 1
while j < n:
	if a[j] == 1:
		c += 1
	j += 1
print(c)


from sys import stdin

def find_increasing_substring(arr):
	ans = 1
	temp = 1
	aux = [1]
	for i in range(1, len(arr)):
		if arr[i] >= arr[i - 1]:
			aux.append(aux[-1] + 1)
		else:
			aux.append(1)
	return aux
(n, a) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
count = 0
a -= 1
if arr[a] == 1:
	count += 1
first = a - 1
second = a + 1
while first >= 0 and second < n:
	if arr[first] == 1 and arr[second] == 1:
		count += 2
	first -= 1
	second += 1
if first < 0 and second < n:
	while second < n:
		if arr[second] == 1:
			count += 1
		second += 1
elif first >= 0 and second == n:
	while first >= 0:
		if arr[first] == 1:
			count += 1
		first -= 1
print(count)


(n, a) = map(int, input().split())
t = [int(x) for x in input().split()]
a -= 1
i = a - 1
j = a + 1
criminals = 0 if t[a] == 0 else 1
while i >= 0 or j <= n - 1:
	if i >= 0 and j <= n - 1:
		if t[i] == t[j] == 1:
			criminals += 2
	elif i >= 0:
		if t[i] == 1:
			criminals += 1
	elif t[j] == 1:
		criminals += 1
	i -= 1
	j += 1
print(criminals)


(n, a) = map(int, input().split())
cc = list(map(int, input().split()))
a -= 1
tc = 0
if cc[a] == 1:
	tc += 1
l = a - 1
h = a + 1
while l >= 0 or h < n:
	if l >= 0 and h < n:
		if cc[l] == cc[h]:
			tc += cc[l] * 2
	elif l >= 0:
		tc += cc[l]
	elif h < n:
		tc += cc[h]
	l -= 1
	h += 1
print(tc)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
x -= 1
for i in range(n):
	if i == x:
		if a[i] == 1:
			cnt += 1
	elif i < x:
		r = x * 2 - i
		if r < n:
			if a[i] == 1 and a[r] == 1:
				cnt += 1
		elif a[i] == 1:
			cnt += 1
	else:
		l = x - (i - x)
		if l >= 0:
			if a[i] == 1 and a[l] == 1:
				cnt += 1
		elif a[i] == 1:
			cnt += 1
print(cnt)


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
M = 10 ** 9 + 7
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)
p = []

def permute(a, l, r):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans
import math

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def main():
	(n, a) = sep()
	t = lis()
	s = sum(t)
	b = a - 1
	l = b - 1
	r = b + 1
	while l >= 0 and r < n:
		s -= (t[l] + t[r]) % 2
		l -= 1
		r += 1
	print(s)
main()


(n, a) = map(int, input().strip().split())
array = list(map(int, input().strip().split()))
dist = max(n - a, a - 1)
answer = 0
for i in range(dist + 1):
	if a - i <= 0:
		if array[a + i - 1] == 1:
			answer += 1
	elif a + i > n:
		if array[a - i - 1] == 1:
			answer += 1
	elif array[a - i - 1] == 1 and array[a + i - 1] == 1:
		if i != 0:
			answer += 2
		else:
			answer += 1
print(answer)


c = input().split()
(n, a) = (int(c[0]), int(c[1]))
ch = input().split()
ch = [int(x) for x in ch]
D = {}
S = 0
if ch[a - 1] > 0:
	S = 1
for i in range(a, len(ch)):
	if ch[i] > 0:
		if abs(i - a + 1) not in D:
			D[abs(i - a + 1)] = ch[i]
		else:
			D[abs(i - a + 1)] += ch[i]
for i in range(a - 2, -1, -1):
	if ch[i] > 0:
		if abs(i - a + 1) not in D:
			D[abs(i - a + 1)] = ch[i]
		else:
			D[abs(i - a + 1)] += ch[i]
d = list(D.keys())
for i in range(len(d)):
	if D[d[i]] == 2:
		S += 2
	elif a - d[i] < 1 or a + d[i] > n:
		S += 1
print(S)


(n, p) = input().split()
(n, p) = [int(n), int(p)]
a = [int(i) for i in input().split()]
i = p - 1
if a[i] == 1:
	c = 1
else:
	c = 0
j = i - 1
k = i + 1
while j >= 0 or k < n:
	if j < 0 and k < n:
		if a[k] == 1:
			c += 1
	elif j >= 0 and k >= n:
		if a[j] == 1:
			c += 1
	elif j >= 0 and k < n:
		if a[j] == 1 and a[k] == 1:
			c += 2
	j -= 1
	k += 1
print(c)


(n, a) = map(int, input().split())
a -= 1
cts = list(map(int, input().split()))
d = 1
k = cts[a]
while True:
	(l_ind, r_ind) = (a - d, a + d)
	l_val = r_val = 0
	if l_ind < 0 and r_ind >= len(cts):
		break
	elif l_ind >= 0 and r_ind < len(cts):
		(l_val, r_val) = (cts[l_ind], cts[r_ind])
		if l_val + r_val == 2:
			k += 2
	elif l_ind >= 0:
		l_val = cts[l_ind]
		if l_val:
			k += 1
	else:
		r_val = cts[r_ind]
		if r_val:
			k += 1
	d += 1
print(k)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
sum = 0
q = a - 1
r = n - a
s = min(q, r)
if q < r:
	p = l[:a + a - 1]
else:
	p = l[-(r * 2 + 1):]
for num in range(s + 1):
	if p[num] == p[-(num + 1)] and p[num] == 1:
		sum += 2
if p == l[:a + a - 1]:
	sum += l[a + a - 1:].count(1)
else:
	sum += l[:-(r * 2 + 1)].count(1)
if l[a - 1] == 1:
	sum -= 1
print(sum)


ip = lambda : [int(i) for i in input().split()]
(n, a) = ip()
c = ip()
ans = 0
a -= 1
for i in range(n):
	cts = set()
	if a + i < n:
		cts.add(a + i)
	if a - i >= 0:
		cts.add(a - i)
	cr = 0
	for j in cts:
		cr += c[j]
	if cr == len(cts):
		ans += cr
print(ans)


(n, a) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
a -= 1
i = a
j = a
ans = [0] * n
while i >= 0 and j < n:
	if L[i] and L[j]:
		ans[i] = 1
		ans[j] = 1
	i -= 1
	j += 1
while i >= 0:
	if L[i]:
		ans[i] = 1
	i -= 1
while j < n:
	if L[j]:
		ans[j] = 1
	j += 1
print(sum(ans))


(n, k) = list(map(int, input().split()))
criminals = list(map(int, input().split()))
k -= 1
n -= 1
count = 0
for i in range(1, min(k, n - k) + 1):
	if criminals[k + i] and criminals[k - i]:
		count += 2
if k >= n - k:
	for i in range(k - (n - k) - 1, -1, -1):
		if criminals[i]:
			count += 1
else:
	for i in range(k + k + 1, n + 1):
		if criminals[i]:
			count += 1
if criminals[k]:
	print(count + 1)
else:
	print(count)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
k -= 1
s = 0
(i, j) = (k, k)
while i > -1 and j < n:
	if l[i] == l[j] == 1:
		s += 2
	i -= 1
	j += 1
if i == -1:
	while j < n:
		if l[j] == 1:
			s += 1
		j += 1
if j == n:
	while i > -1:
		if l[i] == 1:
			s += 1
		i -= 1
if l[k] == 1:
	s -= 1
print(s)


x = input().split()
y = int(x[0])
z = int(x[1])
k = list(map(int, input().split()))
c = 0
if k[z - 1] == 1:
	c += 1
i = z - 2
m = z
if y - z >= z:
	while i >= 0:
		if k[i] == k[m] and k[i] == 1:
			c += 2
		i -= 1
		m += 1
	while m < y:
		if k[m] == 1:
			c += 1
		m += 1
else:
	while m < y:
		if k[i] == k[m] and k[i] == 1:
			c += 2
		i -= 1
		m += 1
	while i >= 0:
		if k[i] == 1:
			c += 1
		i -= 1
print(c)


(n, a) = map(int, input().split())
criminals = list(map(int, input().split()))
res = 0
if criminals[a - 1] == 1:
	res += 1
prev_bcd = res
for i in range(1, n):
	left_limit = False
	if a - 1 - i >= 0:
		first = criminals[a - 1 - i]
	else:
		left_limit = True
		first = 0
	right_limit = False
	if a - 1 + i <= n - 1:
		second = criminals[a - 1 + i]
	else:
		right_limit = True
		second = 0
	bcd = first + second
	if bcd == 2:
		res += 2
	elif bcd == 1 and (left_limit or right_limit):
		res += 1
	prev_bcd = bcd
print(res)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
l.insert(0, 0)
sums = sum(l)
for i in range(1, n + 2, 1):
	if i < a and i <= n - a:
		if l[a + i] + l[a - i] == 1:
			sums -= 1
print(sums)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
yy = lambda : print('YES')
nn = lambda : print('NO')
from math import log10, log2, ceil, factorial as fac, gcd, inf

def f():
	(n, m) = ll()
	a = list(ll())
	m -= 1
	i = m - 1
	j = m + 1
	c = a[m]
	while i >= 0 and j < n:
		if a[i] == 1 and a[j] == 1:
			c += 2
		i -= 1
		j += 1
	while j < n:
		if a[j]:
			c += 1
		j += 1
	while i >= 0:
		if a[i]:
			c += 1
		i -= 1
	print(c)
f()


(n, t) = map(int, input().split())
a = list(map(int, input().split()))
t -= 1
kol = 0
if a[t] == 1:
	kol += 1
x = min(n - t - 1, t)
for i in range(1, x + 1):
	if a[t + i] and a[t - i]:
		kol += 2
for i in range(0, t - x):
	if a[i]:
		kol += 1
for i in range(t + x + 1, n):
	if a[i]:
		kol += 1
print(kol)


import sys

def findNumberOfCriminals(n, a, arr):
	criminalDict = {}
	for i in range(n):
		criminalDict[abs(i - a)] = criminalDict.get(abs(i - a), 0) + arr[i]
	criminal_count = 0
	for k in criminalDict:
		if a - k > -1 and a + k < n:
			if k != 0:
				if criminalDict[k] == 2:
					criminal_count += 2
				else:
					criminal_count += 0
			else:
				criminal_count += criminalDict[k]
		else:
			criminal_count += criminalDict[k]
	return criminal_count

def main():
	(n, a) = list((int(x) for x in sys.stdin.readline().strip().split()))
	arr = list((int(x) for x in sys.stdin.readline().strip().split()))
	print(findNumberOfCriminals(n, a - 1, arr))
main()


(a, b) = map(int, input().split())
n = list(map(int, input().split()))
i = 1
j = 1
count = 0
count = count + n[b - 1]
if b - 1 == 0:
	count = count + n[1:a].count(1)
	print(count)
elif b == a:
	count = count + n[0:a - 1].count(1)
	print(count)
else:
	i = b - 2
	j = b
	while i >= 0 and j <= a - 1:
		if n[i] == 1 and n[j] == 1:
			count = count + 2
		i = i - 1
		j = j + 1
	if i < 0 and j == a:
		print(count)
	elif i < 0 and j < a:
		count = count + n[j:a].count(1)
		print(count)
	else:
		count = count + n[0:i + 1].count(1)
		print(count)


(n, a) = [int(i) for i in input().split()]
a -= 1
t = [int(i) for i in input().split()]
count = 0
for i in range(1, max(a + 1, n - a + 1)):
	if a + i < n and a - i >= 0:
		if t[a - i] == 1 and t[a + i] == 1:
			count += 2
	elif a + i < n and t[a + i] == 1:
		count += 1
	elif a - i >= 0 and t[a - i] == 1:
		count += 1
print(count + t[a])


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a -= 1
count = 0
for i in range(n):
	if i < a and arr[i]:
		j = a + (a - i)
		if j < n:
			if arr[j]:
				count += 1
		else:
			count += 1
	elif i > a and arr[i]:
		j = a - (i - a)
		if j >= 0:
			if arr[j]:
				count += 1
		else:
			count += 1
	elif arr[i]:
		count += 1
print(count)


a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
n = a[0]
node = a[1]
6
leftHalf = b[:node - 1]
leftHalf = leftHalf[::-1]
rightHalf = b[node:]
minned = min(len(rightHalf), len(leftHalf))
count = 0
if b[node - 1] == 1:
	count += 1
for i in range(minned):
	if leftHalf[i] + rightHalf[i] == 2:
		count += 2
if len(rightHalf) < len(leftHalf):
	leftHalf = leftHalf[minned:]
	count = count + leftHalf.count(1)
else:
	rightHalf = rightHalf[minned:]
	count = count + rightHalf.count(1)
print(count)


from collections import defaultdict
(n, a) = map(int, input().split())
a -= 1
t = list(map(int, input().split()))
n_p = defaultdict(int)
n_c = defaultdict(int)
i = 0
while a + i < n or a - i >= 0:
	if a - i >= 0:
		n_c[i] += 1
		if t[a - i] == 1:
			n_p[i] += 1
	if a + i < n and i != 0:
		n_c[i] += 1
		if t[a + i] == 1:
			n_p[i] += 1
	i += 1
ans = 0
for d in n_p:
	if n_p[d] == n_c[d]:
		ans += n_c[d]
print(ans)


(n, a) = map(int, input().split())
if n == 1:
	print(int(input()))
else:
	l = list(map(int, input().split()))
	if a == 1 or a == n:
		print(l.count(1))
	else:
		c = 0
		i = a - 1
		if l[i] == 1:
			c += 1
		f = i - 1
		b = i + 1
		while 1:
			if l[f] == 1 and l[b] == 1:
				c = c + 2
			if i - f != b - i:
				if l[f] == 1 or l[b] == 1:
					c = c + 1
			if f == 0:
				if b == n - 1:
					break
			if f > 0:
				f = f - 1
			else:
				l[f] = 0
			if b < n - 1:
				b = b + 1
			else:
				l[b] = 0
		print(c)


__author__ = 'Utena'
(n, a) = map(int, input().split())
cities = [0] + list(map(int, input().split()))
p = [0] * n
c = [0] * n
for i in range(n):
	if i == 0:
		p[i] = 1
	elif i <= min(n - a, a - 1):
		p[i] = 2
	elif min(n - a, a - 1) < i <= max(n - a, a - 1):
		p[i] = 1
	else:
		p[i] = 0
for i in range(1, n + 1):
	c[abs(a - i)] += cities[i]
t = 0
for i in range(n):
	if c[i] == p[i]:
		t += c[i]
print(t)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
t = [0] + t
i = a + 1
j = a - 1
cri = t[a]
while True:
	if j == 0 and i == n + 1:
		break
	elif j > 0 and i <= n:
		if t[i] * t[j] == 1:
			cri += 2
		i += 1
		j -= 1
	elif j == 0 and i <= n:
		if t[i] == 1:
			cri += 1
		i += 1
	elif j > 0 and i > n:
		if t[j] == 1:
			cri += 1
		j -= 1
print(cri)


(n, a) = map(int, input().split())
a -= 1
t = [x for x in map(int, input().split())]
answer = 0
for i in range(n):
	if t[i]:
		distance = i - a
		j = a - distance
		if j < 0 or j >= n or t[i] == t[j]:
			answer += 1
print(answer)


(n, a) = map(int, input().split())
cities = list(map(int, input().split()))
final = 0
cities.insert(0, 0)
for i in range(1, n + 1):
	if cities[i]:
		d = i - a
		j = a - d
		final += j < 1 or j > n or cities[i] == cities[j]
print(final)


(n, a) = map(int, input().split())
a = a - 1
lis = list(map(int, input().split()))
ans = 0
if lis[a] == 1:
	ans += 1
for i in range(1, n):
	count = 0
	flag1 = 0
	flag2 = 0
	if a + i < n:
		count += lis[a + i]
		flag2 = 1
	if a - i > -1:
		count += lis[a - i]
		flag1 = 1
	if count == 2:
		ans += 2
	elif count == 1:
		if flag2 == 1 and flag1 == 1:
			pass
		elif flag2 == 1 or flag1 == 1:
			ans += 1
print(ans)


(n, a) = map(int, input().split())
data = list(map(int, input().split()))
a -= 1
ans = 0
for i in range(n):
	if i == 0:
		if data[a]:
			ans += 1
	else:
		if a + i > n - 1 and a - i > -1:
			if data[a - i]:
				ans += 1
		if a + i > n - 1 and a - i < 0:
			pass
		if a + i < n and a - i < 0:
			if data[a + i]:
				ans += 1
		(bool1, bool2) = (False, False)
		if a - i > -1 and a + i < n:
			bool1 = data[a + i] and 1
			bool2 = data[a - i] and 1
		if bool1 and bool2:
			ans += 2
print(ans)


(n, a) = map(int, input().split())
town = [int(i) for i in input().split()]
summ = 0
diapason = 0
side = 0
if n / 2 < a:
	diapason = n - a + 1
	side = 1
else:
	diapason = a
	side = -1
if a == n // 2 + 1:
	diapason = a
	side = 0
for i in range(1, diapason):
	if town[a - 1 - i] + town[a - 1 + i] == 2:
		summ += 2
if town[a - 1] == 1:
	summ += 1
if side == 0:
	summ = summ
elif side == 1:
	for i in range(0, a - diapason):
		if town[i] == 1:
			summ += 1
else:
	for i in range(a + diapason - 1, n):
		if town[i] == 1:
			summ += 1
print(summ)


V = input().split(' ')
n = int(V[0])
a = int(V[1]) - 1
Array = input().split(' ')
for j in range(len(Array)):
	Array[j] = int(Array[j])
i = 1
c = 0
f = 0
output = Array[a]
done = False
while not done:
	if a - i >= 0:
		c += Array[a - i]
		f += 1
	if a + i < len(Array):
		c += Array[a + i]
		f += 1
	if f == c:
		output += c
	if f == 0:
		done = True
	c = 0
	f = 0
	i += 1
print(output)


(n, a) = map(int, input().split())
x = [-1] * max(a - 1, n - a) + list(map(int, input().split())) + [-1] * max(a - 1, n - a)
c = 0
if x[a - 1 + max(a - 1, n - a)] == 1:
	c = 1
for i in range(1, max(a - 1, n - a) + 1):
	if x[i + a - 1 + max(a - 1, n - a)] + x[i + a - 1 - i * 2 + max(a - 1, n - a)] == 2:
		c += 2
	elif x[i + a - 1 + max(a - 1, n - a)] == -1 and x[i + a - 1 - i * 2 + max(a - 1, n - a)] != -1:
		c += x[i + a - 1 - i * 2 + max(a - 1, n - a)]
	elif x[i + a - 1 + max(a - 1, n - a)] != -1 and x[i + a - 1 - i * 2 + max(a - 1, n - a)] == -1:
		c += x[i + a - 1 + max(a - 1, n - a)]
print(c)


(n, a) = [int(i) for i in input().split()]
a -= 1
numbers = [int(i) for i in input().split()]
count = 0
for x in range(max(a, n - a) + 1):
	if a + x >= len(numbers) and a - x < 0:
		break
	if a + x >= len(numbers):
		count += numbers[a - x]
	elif a - x < 0:
		count += numbers[a + x]
	else:
		num1 = numbers[a + x]
		num2 = numbers[a - x]
		if num1 == num2 == 1:
			if a + x == a - x:
				count += 1
			else:
				count += 2
print(count)


(n, a) = map(int, input().split())
criminals = [int(i) for i in input().split()]
if n == 1 or n == 2:
	print(criminals.count(1))
else:
	if a - 1 < n - a:
		x = a - 1
		c1 = criminals[:2 * a - 1]
		c2 = criminals[2 * a - 1:]
	else:
		x = n - a
		c2 = criminals[:n - 2 * (n - a) - 1]
		c1 = criminals[n - 2 * (n - a) - 1:]
	ans = 0
	ans += c2.count(1)
	for i in range(x + 1):
		if c1[0 + i] == c1[len(c1) - 1 - i] and c1[0 + i] == 1:
			if x != i:
				ans += 2
			else:
				ans += 1
	print(ans)


def main():
	(n, a) = map(int, input().split())
	l = list(map(int, input().split())) + [0] * n
	print(sum(l) - sum((l[i] + l[j] == 1 for (i, j) in zip(range(a - 2, -1, -1), range(a, n)))))
main()


(n, a) = map(int, input().split())
l = [int(x) for x in input().split()]
count = 0
if a == 1 or a == n:
	for i in range(n):
		if l[i] == 1:
			count += 1
elif a - 1 < n - a:
	for i in range(1, a):
		if l[a - i - 1] == 1 and l[a + i - 1] == 1:
			count += 2
	for j in range(2 * a - 1, n):
		if l[j] == 1:
			count += 1
	if l[a - 1] == 1:
		count += 1
else:
	for i in range(1, n - a + 1):
		if l[a - i - 1] == 1 and l[a + i - 1] == 1:
			count += 2
	for j in range(2 * a - n - 1):
		if l[j] == 1:
			count += 1
	if l[a - 1] == 1:
		count += 1
print(count)


(n, a) = map(int, input().split())
criminals = list(map(int, input().split()))
i = j = a - 1
amount = 0
while i >= 0 and j < n:
	if criminals[i] == criminals[j] == 1:
		amount += 1 if i == j else 2
	i -= 1
	j += 1
while i >= 0:
	amount += criminals[i]
	i -= 1
while j < n:
	amount += criminals[j]
	j += 1
print(amount)


import math
n1 = input().split()
a = int(n1[1]) - 1
arr = input().split()
arr = map(int, arr)
arr = list(arr)
n = len(arr)
x = arr[:a]
x = len(x)
y = arr[a + 1:]
y = len(y)
if len(arr) == 1:
	res = sum(arr)
else:
	res = arr[a]
	if x > y:
		res += sum(arr[:a - y])
		arr = arr[a - y:]
		n = int(math.ceil(len(arr) / 2))
		a = int(math.ceil(len(arr) / 2) - 1)
	elif y > x:
		res += sum(arr[abs(a + x + 1):])
		arr = arr[:a + x + 1]
		n = int(math.ceil(len(arr) / 2))
		a = int(math.ceil(len(arr) / 2) - 1)
	else:
		n = int(math.ceil(len(arr) / 2))
	for i in range(1, n):
		if arr[a - i] + arr[a + i] == 2:
			res += 2
print(res)


(n, a) = list(map(int, input().split()))
l = list(map(int, input().split()))
c = 0
for i in range(1, n + 1):
	if l[i - 1]:
		dist = i - a
		j = a - dist
		if j < 1 or j > n or l[i - 1] == l[j - 1]:
			c += 1
print(c)


from sys import stdin, stdout

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(str(c))
(n, a) = get_ints()
t = get_array()
i = a - 1
j = a - 1
c = 0
while i >= 0 or j < n:
	if i == j and t[i] == 1:
		c += 1
	elif i >= 0 and j < n:
		if t[i] == 1 and t[j] == 1:
			c += 2
	elif i >= 0:
		if t[i] == 1:
			c += 1
	elif j < n and t[j] == 1:
		c += 1
	i -= 1
	j += 1
op(c)


(n, a) = map(int, input().split())
criminals = list(map(int, input().split()))
list1 = []
for i in range(n):
	list1.append([i + 1, abs(a - i - 1), criminals[i]])
list2 = []
for i in range(n):
	if list1[i][2] == 0:
		dis = list1[i][1]
		for j in range(n):
			if list1[j][1] == dis:
				if list1[i] not in list2:
					list2.append(list1[i])
				if list1[j] not in list2:
					list2.append(list1[j])
print(len(list1) - len(list2))


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
res = int(l[a - 1] == 1)
if a == 1:
	print(l.count(1))
	exit(0)
x = l[a - 2::-1]
y = l[a:]
while len(x) > 0 and len(y) > 0:
	if x[0] == 1 and y[0] == 1:
		res += 2
	x.pop(0)
	y.pop(0)
res = res + (x + y).count(1)
print(res)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
i = j = a - 1
s = sum(t)
while i >= 0 and j < n:
	if t[i] + t[j] == 1:
		s -= 1
	i -= 1
	j += 1
print(s)


def in_bounds(x, n):
	return 0 <= x < n
(n, a) = list(map(int, input().split()))
t = list(map(int, input().split()))
a -= 1
ans = t[a]
for d in range(1, n):
	l = a - d
	r = a + d
	if in_bounds(l, n) and in_bounds(r, n) and (t[l] == 1) and (t[r] == 1):
		ans += 2
	elif not in_bounds(l, n) and in_bounds(r, n) and (t[r] == 1):
		ans += 1
	elif in_bounds(l, n) and (not in_bounds(r, n)) and (t[l] == 1):
		ans += 1
print(ans)


b = input().split()
a = int(b[0])
b = int(b[1])
s = 0
c = input().split()
for i in range(a):
	c[i] = int(c[i])
if c[b - 1] == 1:
	s = s + 1
for i in range(1, a):
	if i + b <= a and b - i > 0:
		if c[i + b - 1] == 1 and c[b - i - 1] == 1:
			s = s + 2
	if i + b <= a and b - i <= 0:
		if c[i + b - 1] == 1:
			s = s + 1
	if i + b > a and b - i > 0:
		if c[b - i - 1] == 1:
			s = s + 1
print(s)


(n, a) = map(int, input().split())
a -= 1
cities = list(map(int, input().split()))
total = 0
for i in range(n):
	dist = abs(a - i)
	if dist == 0 and cities[a] == 1:
		total += 1
	elif a + dist <= n - 1 and a - dist >= 0:
		if cities[a + dist] == 1 and cities[a - dist] == 1:
			total += 2
			cities[a + dist] = 0
			cities[a - dist] = 0
	elif a - dist < 0 and cities[a + dist] == 1:
		total += 1
	elif a + dist >= n and cities[a - dist] == 1:
		total += 1
print(total)


(n, m) = map(int, input().split())
cnt = 0
li = list(map(int, input().split()))
p = m - 1
if li[p] == 1:
	cnt += 1
q = max(m - 1, n - m)
for i in range(1, q + 1):
	if p + i <= n - 1 and p - i >= 0:
		if li[p + i] + li[p - i] == 2:
			cnt += 2
	elif p + i > n - 1 and p - i >= 0:
		if li[p - i] == 1:
			cnt += 1
	elif p + i <= n - 1 and p - i < 0:
		if li[p + i] == 1:
			cnt += 1
print(cnt)


(n, a) = map(int, input().split())
criminals = list(map(int, input().split()))
caught = 0
if criminals[a - 1] == 1:
	caught += 1
item = 0
for item in range(1, min(a - 1, n - a) + 1):
	if criminals[a + item - 1] == 1 and criminals[a - item - 1] == 1:
		caught += 2
if a - 1 >= n // 2:
	caught += sum(criminals[:a - item - 1])
else:
	caught += sum(criminals[a + item:])
print(caught)


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
arr.insert(0, 0)
cnt = 0
cnt += arr[a]
k = 1
while a - k >= 1 and a + k <= n:
	if arr[a - k] ^ arr[a + k] == 0:
		cnt += arr[a - k] + arr[a + k]
	k += 1
while a - k >= 1:
	cnt += arr[a - k]
	k += 1
while a + k <= n:
	cnt += arr[a + k]
	k += 1
print(cnt)


from collections import defaultdict
(n, a) = map(int, input().split())
A = list(map(int, input().split()))
(ans, i) = (sum(A), 1)
while a - 1 - i >= 0 and a - 1 + i <= n - 1:
	if A[a - 1 - i] != A[a - 1 + i]:
		ans -= 1
	i += 1
print(ans)


def bcd(n, a, t):
	left = a - 1
	right = a - 1
	count = 0
	while left >= 0 or right <= len(t) - 1:
		if left >= 0 and right <= len(t) - 1:
			if t[left] == 1 and t[right] == 1:
				if left != right:
					count += 2
				if left == right:
					count += 1
			left = left - 1
			right = right + 1
		elif left >= 0 and right > len(t) - 1:
			if t[left] == 1:
				count += 1
			left = left - 1
		elif left < 0 and right <= len(t) - 1:
			if t[right] == 1:
				count += 1
			right = right + 1
		else:
			break
	print(count)
n = list(map(int, input('').split()))
t = list(map(int, input('').split()))
bcd(n[0], n[1], t)


(n, a) = map(int, input().split())
array = list(map(int, input().split()))
max1 = max(n - a, a - 1)
counter = 0
for i in range(max1 + 1):
	if i:
		if a + i - 1 <= n - 1:
			if a - i - 1 >= 0:
				if array[a + i - 1] + array[a - i - 1] == 2:
					counter += 2
			else:
				counter += array[a + i - 1]
		else:
			counter += array[a - i - 1]
	else:
		counter += array[a - 1]
print(counter)


(n, a) = tuple(map(int, input().split()))
thieves = list(map(int, input().split()))
i = 1
a -= 1
count = 0
if thieves[a] == 1:
	count += 1
while a - i >= 0:
	if a + i < n and thieves[a + i] + thieves[a - i] == 2:
		count += 1
	elif a + i >= n and thieves[a - i] == 1:
		count += 1
	i += 1
i = 1
while a + i < n:
	if a - i >= 0 and thieves[a + i] + thieves[a - i] == 2:
		count += 1
	elif a - i < 0 and thieves[a + i] == 1:
		count += 1
	i += 1
print(count)


def BCD(num_cities, my_loc, criminals):
	my_loc -= 1
	list1 = criminals[:my_loc]
	list2 = criminals[my_loc + 1:]
	found = int(criminals[my_loc])
	if len(list1) >= len(list2):
		for (i, j) in zip(list1[len(list1) - len(list2):], list2[::-1]):
			if i == j:
				found += 2 * int(i)
		for i in range(len(list1) - len(list2)):
			found += int(list1[i])
		return found
	else:
		for (i, j) in zip(list1, list2[:len(list1)][::-1]):
			if i == j:
				found += 2 * int(i)
		for i in range(len(list1), len(list2)):
			found += int(list2[i])
		return found
(n, a) = input().split()
b = input().split()
print(BCD(n, int(a), b))


z = list(map(int, input().split()))
x = list(map(int, input().split()))
te = []
for i in range(z[1] - 1, z[0]):
	if x[i] == 1:
		te.append(abs(z[1] - 1 - i))
for i in range(z[1] - 1):
	if x[i] == 1:
		te.append(abs(z[1] - 1 - i))
c = 0
for i in te:
	if z[1] - 1 - i > -1 and z[1] - 1 + i < z[0]:
		if x[z[1] - 1 + i] == 1 and x[z[1] - 1 - i] == 1:
			c += 1
	elif z[1] - 1 - i < 0 or z[1] - 1 + i > z[0] - 1:
		c += 1
print(c)


(n, a) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ans = 0
if l[a - 1] == 1:
	ans = ans + 1
k = min(a - 1, n - a)
al = l[a - 1 - k:a - 1]
bl = l[a:a + k]
gl = l[:a - 1 - k] + l[a + k:]
ans = ans + gl.count(1)
al.reverse()
for i in range(k):
	if (al[i] + bl[i]) % 2 == 0:
		ans = ans + (al[i] + bl[i])
print(ans)


(n, a) = [int(i) for i in input().split()]
a -= 1
t = [int(i) for i in input().split()]
ans = 0
for i in range(n):
	if t[i]:
		inv = 2 * a - i
		if inv < 0 or inv >= n or t[inv]:
			ans += 1
print(ans)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
i = a
j = a
r = 0
l = len(t)
if t[a - 1] > 0:
	r -= 1
while True:
	c = 0
	c1 = 0
	if i <= l:
		c += 1
		if t[i - 1] > 0:
			c1 += 1
	if j > 0:
		c += 1
		if t[j - 1] > 0:
			c1 += 1
	if c == 2 and c1 == 2:
		r += 2
	elif c == 1 and c1 == 1:
		r += 1
	i += 1
	j -= 1
	if i > l and j < 0:
		break
print(r)


(n, a) = list(map(int, input().strip().split()))
T = list(map(int, input().strip().split()))
limak_i = a - 1
criminals = 0

def bcd(d):
	if d == 0:
		return (1, T[limak_i])
	(li, ri) = (limak_i - d, limak_i + d)
	neighbors = []
	if li >= 0:
		neighbors.append(T[li])
	if ri < n:
		neighbors.append(T[ri])
	return (len(neighbors), sum(neighbors))
for d in range(n):
	(num, count) = bcd(d)
	if num == 1:
		criminals += count
	elif count == 2:
		criminals += count
print(criminals)


(N, a) = map(int, input().split())
a -= 1
T = list(map(int, input().split()))
now = 0
ans = 0
while a - now >= 0 or a + now < N:
	if now == 0:
		if T[a] == 1:
			ans += 1
		now += 1
		continue
	tmp = 0
	if a - now >= 0:
		tmp += T[a - now]
	if a + now < N:
		tmp += T[a + now]
	if tmp == 2:
		ans += 2
	elif tmp == 1:
		if a - now < 0 or a + now >= N:
			ans += 1
	now += 1
print(ans)


(a, n) = map(int, input().split())
dataLine = input()
data = dataLine.split()
for i in range(a):
	data[i] = int(data[i])
ans = 0
for i in range(max(a - n + 1, n)):
	if n - 1 - i >= 0 and n - 1 + i < a and (data[n - 1 - i] == 1) and (data[n - 1 + i] == 1):
		if i == 0:
			ans += 1
		else:
			ans += 2
	elif n - 1 - i < 0 and data[n - 1 + i] == 1:
		ans += 1
	elif n - 1 + i >= a and data[n - 1 - i] == 1:
		ans += 1
print(ans)


([n, a], c) = (map(int, input().split()), [0] + list(map(int, input().split())))
ans = 0
for d in range(max(a, n - a + 1)):
	directions = found = 0
	if a - d > 0:
		directions += 1
		found += c[a - d]
	if a + d <= n and d:
		directions += 1
		found += c[a + d]
	ans += (directions == found) * found
print(ans)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
catch = 0
if l[a - 1]:
	catch += 1
i = a - 2
j = a
while True:
	if i == -1 or j == n:
		break
	if l[i] + l[j] == 2:
		catch += 2
	i -= 1
	j += 1
if n % 2 == 1 and a == n // 2 + 1:
	print(catch)
else:
	if i == -1:
		for i in range(j, n):
			if l[i]:
				catch += 1
	else:
		for i in range(i, -1, -1):
			if l[i]:
				catch += 1
	print(catch)


(size, pos) = map(int, input().split())
array = list(map(int, input().split()))
counter = 0
for i in range(size):
	if i == 0:
		if array[pos - 1 - i] == 1:
			counter += 1
	elif pos - 1 - i >= 0 and pos - 1 + i < size:
		if array[pos - 1 - i] == 1 and array[pos - 1 + i] == 1:
			counter += 2
		else:
			continue
	elif pos - 1 - i >= 0:
		if array[pos - 1 - i] == 1:
			counter += 1
	elif pos - 1 + i < size:
		if array[pos - 1 + i] == 1:
			counter += 1
print(counter)


import math
(n, a) = map(int, input().split())
b = list(map(int, input().split()))
c = 0
if b[a - 1] == 1:
	c += 1
if a <= math.ceil(n / 2):
	for i in range(1, a):
		if b[a - 1 - i] == 1 and b[a - 1 + i] == 1:
			c += 2
	j = 2 * (a - 1) + 1
	c1 = b[j:].count(1)
	print(c + c1)
else:
	for i in range(1, n - a + 1):
		if b[a - 1 - i] == 1 and b[a - 1 + i] == 1:
			c += 2
	j = 2 * a - 2 - n
	c1 = b[0:j + 1].count(1)
	print(c + c1)


from itertools import zip_longest
(n, a) = map(int, input().split())
c = (*map(int, input().split()),)
(x, y, counter) = (reversed(c[:a - 1]), c[a:], 0)
for (i, j) in zip_longest(x, y, fillvalue=-1):
	if i == j and j == 1:
		counter += 2
	elif min(i, j) == -1 and max(i, j) == 1:
		counter += 1
print(counter + c[a - 1])


(n, a) = map(int, input().split())
A = list(map(int, input().split()))
i = a - 1
j = a - 1
ans = 0
while i >= 0 and j < n:
	if A[i] == 1 and A[j] == 1 and (j == i):
		ans += 1
		i -= 1
		j += 1
		continue
	if A[i] == 1 and A[j] == 1:
		ans += 2
	i -= 1
	j += 1
while i >= 0:
	ans += A[i]
	i -= 1
while j < n:
	ans += A[j]
	j += 1
print(ans)


(n, m) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = 0
m -= 1
if a[m] == 1:
	c += 1
l = min(m + 1, n - m)
for d in range(1, l):
	if (a[m - d] + a[m + d]) % 2 == 0:
		c += a[m - d] + a[m + d]
for i in range(m - l + 1):
	c += a[i]
for i in range(m + l, n):
	c += a[i]
print(c)


k = list(map(int, input().split()))
n = k[0]
a = k[1]
s = list(map(int, input().split()))
s2 = s[0:a]
s2 = s2[::-1]
s3 = s[a - 1:]
count = 0
if s2[0] == 1 and s3[0] == 1:
	count = 1
for i in range(1, min(len(s2), len(s3))):
	if s2[i] == 1 and s3[i] == 1:
		count += 2
extra = []
if len(s2) > len(s3):
	extra = s2[len(s3):]
if len(s2) < len(s3):
	extra = s3[len(s2):]
count += extra.count(1)
print(count)


(n, a) = map(int, input().split(' '))
li = list(map(int, input().split(' ', n)[:n]))
(l, r) = (a - 1, a - 1)
co = 0
if li[l]:
	co += 1
l -= 1
r += 1
while l >= 0 and r < n:
	if li[l] & li[r]:
		co += 2
	l -= 1
	r += 1
while l >= 0:
	if li[l]:
		co += 1
	l -= 1
while r < n:
	if li[r]:
		co += 1
	r += 1
print(co)


(n, place) = map(int, input().split())
place = place - 1
cities = list(map(int, input().split()))
for i in range(1, n):
	if place - i < 0 or place + i >= n:
		break
	if cities[place + i] & cities[place - i] == 1:
		cities[place + i] = 2
		cities[place - i] = 0
	else:
		cities[place + i] = 0
		cities[place - i] = 0
print(sum(cities))


lt = list(input().split())
(n, k) = (int(lt[0]), int(lt[1]))
lt = list(input().split())
q = 0
if lt[k - 1] == '1':
	q = 1
(i, j) = (k - 2, k)
while i > -1 and j < n:
	if lt[i] == '1' and lt[j] == '1':
		q += 2
	i -= 1
	j += 1
if i == -1:
	for i in range(j, n):
		if lt[i] == '1':
			q += 1
elif j == n:
	for j in range(0, i + 1):
		if lt[j] == '1':
			q += 1
print(q)


(n, a) = list(map(int, input().split(' ')))
li = list(map(int, input().split(' ')))
li1 = li[:a - 1]
li2 = li[a:]
li1.reverse()
i = 0
j = 0
ans = 0
if li[a - 1] == 1:
	ans += 1
while i < len(li1) or j < len(li2):
	if i < len(li1) and j < len(li2):
		if li1[i] == 1 and li2[j] == 1:
			ans += 2
	elif i < len(li1) and j >= len(li2):
		if li1[i] == 1:
			ans += 1
	elif li2[j] == 1:
		ans += 1
	i += 1
	j += 1
print(ans)


(n, a) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
max_d = max(a - 1, n - a)
d = 0
criminals = 0
while d <= max_d:
	i = a - d - 1
	j = a + d - 1
	left = t[i] if i >= 0 else -1
	right = t[j] if j < n else -1
	if left == right == 1:
		criminals += 1 if i == j else 2
	elif left == 1 and right == -1 or (left == -1 and right == 1):
		criminals += 1
	d += 1
print(criminals)


(n, a) = map(int, input().split())
a -= 1
t = list(map(int, input().split()))
t1 = t[:a]
t2 = t[a + 1:n]
ans = t[a]
for i in range(1, min(len(t2), len(t1)) + 1):
	ans += (t[a - i] == t[a + i] == 1) * 2
if len(t2) > len(t1):
	for i in range(len(t1) * 2 + 1, n):
		ans += t[i]
elif len(t1) > len(t2):
	for i in range(len(t1) - len(t2)):
		ans += t1[i]
print(ans)


in1 = input()
in2 = input()
s = in1.split()
s = [int(i) for i in s]
a = [int(i) for i in in2.split()]
s[1] = s[1] - 1
summ = a[s[1]]
i = s[1] - 1
j = s[1] + 1
while i >= 0 and j < s[0]:
	if a[i] == 1 and a[j] == 1:
		summ = summ + 2
	i = i - 1
	j = j + 1
while i >= 0:
	if a[i] == 1:
		summ = summ + 1
	i = i - 1
while j < s[0]:
	if a[j] == 1:
		summ = summ + 1
	j = j + 1
print(summ)


I = lambda : list(map(int, input().split()))
(n, a) = I()
t = I()
a -= 1
k = t[a]
for i in range(1, 100):
	l = a - i
	r = a + i
	if l >= 0 and r < n:
		k += 2 * (t[l] and t[r])
	elif l >= 0:
		k += t[l]
	elif r < n:
		k += t[r]
print(k)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
s = 0
i = a - 2
j = a
while i >= 0 and j < n:
	if t[i] == 1 and t[j] == 1:
		s = s + 2
	i = i - 1
	j = j + 1
if i == -1:
	for z in range(j, n):
		if t[z] == 1:
			s = s + 1
if j == n:
	for z in range(i, -1, -1):
		if t[z] == 1:
			s = s + 1
s = s + t[a - 1]
print(s)


(n, a) = map(int, input().split())
data = list(map(int, input().split()))
data1 = data[:a - 1][::-1]
data2 = data[a:]
res = sum((2 * v1 * v2 for (v1, v2) in zip(data1, data2)))
if len(data1) < len(data2):
	res += sum(data2[len(data1):])
else:
	res += sum(data1[len(data2):])
res += data[a - 1]
print(res)


(n, a) = map(int, input().split())
ns = list(map(int, input().split()))
a -= 1
if a < n // 2:
	l = ns[:a]
	r = ns[a + 1:a + 1 + len(l)]
	m = ns[a + 1 + len(l):]
else:
	r = ns[a + 1:]
	l = ns[a - len(r):a]
	m = ns[:a - len(r)]
r.reverse()
x = sum((2 for i in range(len(l)) if l[i] == r[i] == 1))
print(x + ns[a] + sum(m))


(n, a) = input().split(' ')
n = int(n)
a = int(a) - 1
L = input().split(' ')
L = list(map(int, L))
s = 0
if L[a] == 1:
	s += 1
if a >= n // 2:
	L.reverse()
	a = n - a - 1
for i in range(a):
	if L[i] == 1 and L[i] == L[2 * a - i]:
		s += 2
for i in range(2 * a + 1, n):
	if L[i] == 1:
		s += 1
print(s)


(n, a) = map(int, input().split())
numbers_list = map(int, input().split())
criminals_city = []
for num in numbers_list:
	criminals_city.append(num)

def count_criminals(criminals_city):
	count = 0
	if len(criminals_city) == 1:
		if criminals_city[0]:
			print(1)
		else:
			print(0)
		return
	if criminals_city[a - 1] == 1:
		count += 1
	min_val = min(n - a, a - 1)
	val_n = n
	left_val = a - 1
	for i in range(1, min_val + 1):
		if criminals_city[a - 1 - i] == 1 and criminals_city[a - 1 + i] == 1:
			count += 2
		left_val = a - 1 - i
	if left_val != 0:
		for i in range(left_val):
			if criminals_city[i] == 1:
				count += 1
	for i in range(a + min_val, n):
		if criminals_city[i] == 1:
			count += 1
	print(count)
count_criminals(criminals_city)


(n, a) = map(int, input().split())
s1 = list(map(int, input().split()))
dist = []
for i in range(n):
	dist.append([i + 1, abs(a - i - 1), s1[i]])
dist1 = []
for i in range(n):
	if dist[i][2] == 0:
		p = dist[i][1]
		for j in range(n):
			if dist[j][1] == p:
				if dist[i] not in dist1:
					dist1.append(dist[i])
				if dist[j] not in dist1:
					dist1.append(dist[j])
print(len(dist) - len(dist1))


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
d = [0] * n
for i in range(n):
	if t[i] == 1:
		d[abs(i - a)] += 1
res = 0
i1 = i2 = a
for i in range(n):
	if d[i] == 2:
		res += 2
	elif d[i] == 1 and (i1 < 0 or i2 >= n or i1 == i2):
		res += 1
	i1 -= 1
	i2 += 1
print(res)


(numbers, initial) = map(int, input().split())
initial -= 1
count = 0
setI = list(map(int, input().split()))
setA = setI[:initial][::-1]
setB = setI[initial + 1:]
if setI[initial] == 1:
	count += 1
if len(setA) > len(setB):
	for i in range(len(setA) - len(setB)):
		setB.append(3)
	for i in range(len(setA)):
		if setA[i] == 1 and setB[i] == 1:
			count += 2
		elif setA[i] == 1 and setB[i] == 3:
			count += 1
elif len(setB) > len(setA):
	for i in range(len(setB) - len(setA)):
		setA.append(3)
	for i in range(len(setB)):
		if setB[i] == 1 and setA[i] == 1:
			count += 2
		elif setB[i] == 1 and setA[i] == 3:
			count += 1
else:
	for i in range(len(setA)):
		if setA[i] == 1 and setB[i] == 1:
			count += 2
print(count)


(number, place) = [int(i) for i in input().split()]
place -= 1
cities = [int(i) for i in input().split()]
criminals = 0
for i in range(number):
	if place - i >= 0 and place + i < number:
		if cities[place - i] == 1 and cities[place + i] == 1:
			criminals += 2
	elif place - i >= 0:
		if cities[place - i] == 1:
			criminals += 1
	elif place + i < number:
		if cities[place + i] == 1:
			criminals += 1
if cities[place] == 1:
	criminals -= 1
print(criminals)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
ans = sum(l)
x = min(a - 1, n - a)
for i in range(1, x + 1):
	if l[a - i - 1] + l[a + i - 1] == 1:
		ans -= 1
print(ans)


s = input()
k = s.split()
n = int(k[0])
se = int(k[1]) - 1
c = input()
cities = c.split(' ')
t = 0
i = 1
if cities[se] == '1':
	t += 1
while i < n:
	if se + i < n and se - i >= 0:
		if cities[se + i] == cities[se - i] == '1':
			t += 2
	elif se + i < n and cities[se + i] == '1':
		t += 1
	elif se - i >= 0 and cities[se - i] == '1':
		t += 1
	i += 1
print(t)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
a -= 1
ans = 0
for i in range(n):
	if a - i < 0 or a + i >= n:
		break
	if l[a - i] == 1 and l[a + i] == 1:
		if i == 0:
			ans += 1
		else:
			ans += 2
	l[a - i] = 0
	l[a + i] = 0
ans += l.count(1)
print(ans)


(n, a) = input().split()
n = int(n)
a = int(a) - 1
t = [int(i) for i in input().split()]
l = a - 1
r = a + 1
count = 0
if t[a]:
	count += 1
while l >= 0 and r < n:
	if t[l] + t[r] == 2:
		count += 2
	l -= 1
	r += 1
while l >= 0:
	if t[l]:
		count += 1
	l -= 1
while r < n:
	if t[r]:
		count += 1
	r += 1
print(count)


(n, a) = map(int, input().split())
lst = [int(x) for x in input().split()]
lstind = []
left = a - 1
right = n - a
stepl = a - 1
stepr = a - 1
if lst[a - 1] == 1:
	crimes = 1
else:
	crimes = 0
for i in range(n):
	stepl -= 1
	stepr += 1
	lstind.append([stepl, stepr])
for i in lstind:
	if i[0] < 0 or i[0] >= n:
		if i[1] < 0 or i[1] >= n:
			continue
		elif lst[i[1]] == 1:
			crimes += 1
	elif i[1] < 0 or i[1] >= n:
		if i[0] < 0 or i[0] >= n:
			continue
		elif lst[i[0]] == 1:
			crimes += 1
	elif lst[i[0]] == 1 and lst[i[1]] == 1:
		crimes += 2
print(crimes)


(n, a) = list(map(int, input().split()))
arr = list(map(int, input().split()))
a -= 1
leftPtr = a - 1
rightPtr = a + 1
count = arr[a]
while leftPtr >= 0 or rightPtr < n:
	leftval = -1
	rightval = -1
	if leftPtr >= 0:
		leftval = arr[leftPtr]
	if rightPtr < n:
		rightval = arr[rightPtr]
	if leftval == rightval:
		count += leftval + rightval
	elif leftval == -1 and rightval != -1:
		count += rightval
	elif rightval == -1 and leftval != -1:
		count += leftval
	leftPtr -= 1
	rightPtr += 1
print(count)


from collections import defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
(n, k) = M()
a = LI()
d = defaultdict(int)
k -= 1
c = 0
ans = 0
while k + c < n and k - c >= 0:
	if a[k + c] == a[k - c]:
		if c == 0:
			ans += a[k + c]
		else:
			ans += a[k + c] * 2
	c += 1
for i in range(0, k - c + 1):
	if a[i] == 1:
		ans += 1
for i in range(k + c, n):
	if a[i] == 1:
		ans += 1
print(ans)


(n, index) = map(int, input().split())
cities = list(map(int, input().split()))
index = index - 1
(left, right) = (index - 1, index + 1)
count = 1 if cities[index] == 1 else 0
while right < len(cities) or left >= 0:
	if left < 0 and right < len(cities):
		if cities[right] == 1:
			(count, right) = (count + 1, right + 1)
			continue
	if right >= len(cities) and left >= 0:
		if cities[left] == 1:
			(count, left) = (count + 1, left - 1)
			continue
	if cities[left] == 1 and cities[right] == 1:
		count = count + 2
	(right, left) = (right + 1, left - 1)
print(count)


import math
(n, a) = [int(j) for j in input().split()]
s = [int(j) for j in input().split()]
ans = 0
if n >= a + a - 1:
	r = a + a - 1
else:
	r = n - a + 1 + n - a + 1 - 1
if a > (n + 1) // 2:
	ans = sum(s[:n - r])
	s = s[n - r:]
else:
	ans = sum(s[r:])
	s = s[:r]
for i in range((len(s) + 1) // 2):
	if s[i] == s[len(s) - 1 - i]:
		ans += s[i] + s[len(s) - 1 - i]
		if i == len(s) - 1 - i:
			ans -= s[i]
print(ans)


def read_input():
	(n, a) = map(int, input().split(' '))
	c = list(map(int, input().split(' ')))
	return (a - 1, c)

def calc_caught_criminals(a, c):
	n = len(c)
	i_left = i_right = a
	sum = c[a]
	i_left -= 1
	i_right += 1
	while i_left >= 0 or i_right < n:
		if i_left >= 0 and i_right < n:
			sum += 2 * (c[i_left] == c[i_right] == 1)
		elif i_left >= 0:
			if c[i_left] == 1:
				sum += 1
		elif c[i_right] == 1:
			sum += 1
		i_left -= 1
		i_right += 1
	return sum
print(calc_caught_criminals(*read_input()))


(n, a) = list(map(int, input().split()))
criminals = list(map(int, input().split()))
if a == 1 or a == n:
	c = 0
	for i in range(n):
		if criminals[i] == 1:
			c += 1
	print(c)
else:
	a = a - 1
	m = min(a, n - 1 - a)
	if abs(a - m) == 0:
		start = 0
		end = a + m
		c = 0
		s = end
		while start <= end:
			if criminals[start] == 1 and criminals[end] == 1:
				c = c + 2
			start = start + 1
			end = end - 1
		if s + 1 < n:
			for i in range(s + 1, n):
				if criminals[i] == 1:
					c += 1
		if criminals[a] == 1:
			print(c - 1)
		else:
			print(c)
	elif a + m == n - 1:
		start = abs(a - m)
		end = n - 1
		c = 0
		e = start
		while start <= end:
			if criminals[start] == 1 and criminals[end] == 1:
				c = c + 2
			start = start + 1
			end = end - 1
		for i in range(0, e):
			if criminals[i] == 1:
				c += 1
		if criminals[a] == 1:
			print(c - 1)
		else:
			print(c)


(n, l) = [int(n) for n in input().split()]
l -= 1
criminals = [int(n) for n in input().split()]
caught = criminals[l]
i = 1
while True:
	left = None if l - i < 0 else criminals[l - i]
	right = None if l + i >= len(criminals) else criminals[l + i]
	if left == right == None:
		break
	if left == None and right == 1:
		caught += 1
	if right == None and left == 1:
		caught += 1
	if left == right == 1:
		caught += 2
	i += 1
print(caught)


(n, a) = map(int, input().split())
criminals = [-1] + list(map(int, input().split())) + [-1]
catch = 0
left = a - 1
right = a + 1
while left > 0 and right < n + 1:
	if criminals[left] > 0 and criminals[right] > 0:
		catch = catch + criminals[left] + criminals[right]
	left -= 1
	right += 1
if left == 0:
	while right < n + 1:
		catch += criminals[right]
		right += 1
if right == n + 1:
	while left > 0:
		catch += criminals[left]
		left -= 1
if criminals[a] > 0:
	catch += criminals[a]
print(catch)


(n, a) = map(int, input().split())
b = []
t = list(map(int, input().split()))
for i in range(n):
	if t[i] == 1:
		b.append(abs(i + 1 - a))
r = 0
for j in b:
	if b.count(j) == 2:
		r += 1
	elif b.count(j) == 1 and (a - 1 - j < 0 or a - 1 + j > n - 1):
		r += 1
	elif j == 0:
		r += 1
print(r)


data = input().split(' ')
(n, a) = (int(data[0]), int(data[1]))
a -= 1
cities = input().split(' ')
left = cities[:a]
right = cities[a + 1:]
right.reverse()
criminals = 0
if cities[a] == '1':
	criminals += 1
while len(left) > 0 and len(right) > 0:
	(a, b) = (left.pop(), right.pop())
	if a == '1' and b == '1':
		criminals += 2
for i in range(len(left)):
	if left[i] == '1':
		criminals += 1
for i in range(len(right)):
	if right[i] == '1':
		criminals += 1
print(criminals)


def solve():
	(n, a) = map(int, input().split())
	t = list(map(int, input().split()))
	z = 0
	i = a - 2
	j = a
	if t[a - 1] == 1:
		z += 1
	if n == 2:
		print(t.count(1))
	else:
		while i >= 0 and j < n:
			if t[i] == 1 and t[j] == 1:
				z += 2
			i -= 1
			j += 1
		if not i == 0:
			z = z + t[:i + 1].count(1)
		if not j == n - 1:
			z = z + t[j:].count(1)
		print(z)
	return
try:
	solve()
except:
	pass


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
ans = sum(arr)
l = r = a - 1
while l >= 0 and r < n:
	if arr[l] + arr[r] == 1:
		ans -= 1
	l -= 1
	r += 1
print(ans)


1

def main():
	(n, a) = map(int, input().split())
	a -= 1
	arr = list(map(int, input().split()))
	ans = 0
	for d in range(1, 150):
		b1 = a + d < len(arr)
		c1 = b1 and arr[a + d] == 1
		b2 = a - d >= 0
		c2 = b2 and arr[a - d] == 1
		if b1 and b2:
			ans += 2 * int(c1 and c2)
		else:
			ans += int(c1) + int(c2)
	ans += arr[a]
	print(ans)
main()


(n, a) = map(int, input().split())
tl = list(map(int, input().split()))
l = a - 2
r = a
res = tl[a - 1]
while l >= 0 or r < n:
	if l >= 0 and r < n and (tl[l] == tl[r] == 1):
		res += 2
	elif l < 0 and tl[r] == 1 or (r >= n and tl[l] == 1):
		res += 1
	l -= 1
	r += 1
print(res)


def main():
	[n, a] = [int(_) for _ in input().split()]
	criminals = input().split()
	a -= 1
	distance = min(a, n - 1 - a)
	catched_criminals_count = 0
	for i in range(1, distance + 1):
		if criminals[a - i] == '1' == criminals[a + i]:
			catched_criminals_count += 2
	if criminals[a] == '1':
		catched_criminals_count += 1
	if a < n - 1 - a:
		catched_criminals_count += sum((criminals[i] == '1' for i in range(2 * a + 1, n)))
	elif a > n - 1 - a:
		catched_criminals_count += sum((criminals[i] == '1' for i in range(0, 2 * a + 1 - n)))
	print(catched_criminals_count)
main()


(n, a) = map(int, input().split())
a -= 1
l = list(map(int, input().split()))
ans = 0
for i in range(n):
	if l[i] == 1 and (not 0 <= a * 2 - i < n or l[a * 2 - i] == 1):
		ans += 1
print(ans)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
l.insert(0, 0)
s = sum(l)
i = 1
while i < a and i <= n - a:
	if l[a + i] + l[a - i] == 1:
		s -= 1
	i += 1
print(s)


(n, a) = map(int, input().split())
t = (*map(int, input().split()),)
max_distance = max(a, len(t) - a + 1)
a -= 1
count = 0
if t[a] == 1:
	count = 1
for d in range(1, max_distance):
	if a - d >= 0 and a + d < len(t):
		if t[a - d] and t[a + d]:
			count += 2
	elif a - d >= 0:
		if t[a - d]:
			count += 1
	elif a + d < len(t):
		if t[a + d]:
			count += 1
print(count)


(n, a) = list(map(int, input().split()))
t = list(map(int, input().split()))
a -= 1
r = t[a]
for i in range(1, n):
	if a - i >= 0:
		if a + i < n:
			if t[a - i] == t[a + i]:
				r += 2 * t[a - i]
		else:
			r += t[a - i]
	elif a + i < n:
		r += t[a + i]
print(r)


(n, l) = (int(i) for i in input().split())
n_criminals = [int(i) for i in input().split()]
total = 0
for i in range(101):
	cities = set([l + i, l - i])
	cities = {c for c in cities if c > 0 and c <= n}
	criminals = sum((n_criminals[c - 1] for c in cities))
	if criminals == len(cities):
		total += criminals
print(total)


(number_of_houses, location) = list(map(int, input().split()))
houses = list(map(int, input().split()))
index_left = location - 1
index_right = location - 1
counter = 0
if houses[index_left] == 1 and houses[index_right] == 1:
	counter += 1
index_left -= 1
index_right += 1
while index_left >= 0 and index_right < number_of_houses:
	if houses[index_left] == 1 and houses[index_right] == 1:
		counter += 2
	index_left -= 1
	index_right += 1
while index_right < number_of_houses:
	if houses[index_right] == 1:
		counter += 1
	index_right += 1
while index_left >= 0:
	if houses[index_left] == 1:
		counter += 1
	index_left -= 1
print(counter)


def indices(c_ind, arr):
	cout = 0
	l_ind = c_ind - 1
	r_ind = c_ind + 1
	if arr[c_ind] == 1:
		cout += 1
	while l_ind >= 0 and r_ind < n:
		if arr[l_ind] == 1 and arr[r_ind] == 1:
			cout += 2
		l_ind -= 1
		r_ind += 1
	while l_ind >= 0:
		if arr[l_ind] == 1:
			cout += 1
		l_ind -= 1
	while r_ind < n:
		if arr[r_ind] == 1:
			cout += 1
		r_ind += 1
	return cout
(n, ind) = map(int, input().split())
height = list(map(int, input().split()))
print(indices(ind - 1, height))


(n, a) = [int(i) for i in input().split()]
criminals = [int(i) for i in input().split()]
left = a - 2
right = a
count = 0
if criminals[a - 1] == 1:
	count += 1
while right < len(criminals) and left >= 0:
	if criminals[left] == 1 and criminals[right] == 1:
		count += 2
	left -= 1
	right += 1
if right < len(criminals):
	for i in range(right, len(criminals)):
		count += criminals[i]
if left > 0:
	for i in range(0, left + 1):
		count += criminals[i]
print(count)


N = list(map(int, input().split()))
X = list(map(int, input().split()))
SUM = 0
SUM += 1 if X[N[1] - 1] == 1 else 0
i = N[1] - 2
j = N[1]
while i != -1 or j != len(X):
	C = 0
	if i == -1:
		SUM += X[j:].count(1)
		break
	if j == len(X):
		SUM += X[:i + 1].count(1)
		break
	C = 1 if X[i] == 1 else 0
	SUM += 2 if X[j] == 1 and C == 1 else 0
	i -= 1
	j += 1
print(SUM)


def solve():
	(n, a) = map(int, input().split())
	criminals = list(map(int, input().split()))
	m = max(n - a, a) + 1
	distances = [0] * m
	if criminals[a - 1]:
		distances[0] += 1
	j = a - 2
	while j >= 0:
		distances[a - j - 1] += criminals[j]
		j -= 1
	j = a
	while j < n:
		distances[j - a + 1] += criminals[j]
		j += 1
	ans = 0
	if distances[0] > 0:
		ans += 1
	for (d, dist) in enumerate(distances):
		cond1 = dist >= 2
		cond2 = dist >= 1 and (a - 1 - d < 0 or a + d > n)
		if cond1:
			ans += 2
		elif cond2:
			ans += 1
	print(ans)
solve()


(n, a) = map(int, input().split())
l1 = list(map(int, input().split()))
r = 0
r1 = 0
for i in range(a - 1):
	k = 0
	if l1[a - i - 2] == 1:
		r = r + 1
		k = 1
	if k == 1 and a + i < n and (l1[a + i] == 1):
		r = r + 1
	if a + i < n and l1[a + i] == 0 and (k == 1):
		r = r - 1
for i in range(1, n - a + 1):
	k = 0
	if l1[a + i - 1] == 1:
		r1 = r1 + 1
		k = 1
	if a - i - 1 >= 0 and l1[a - i - 1] == 1 and (k == 1):
		r1 = r1 + 1
	if a - i - 1 >= 0 and l1[a - i - 1] == 0 and (k == 1):
		r1 = r1 - 1
if l1[a - 1] == 1:
	r = r + 1
	r1 = r1 + 1
print(max(r, r1))


[n, s] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s -= 1
i = s - 1
j = s + 1
c = a[s]
while True:
	if i >= 0:
		if j < n:
			if a[i] == 1 and a[j] == 1:
				c += 2
			i -= 1
			j += 1
		else:
			if a[i] == 1:
				c += 1
			i -= 1
	elif j < n:
		if a[j] == 1:
			c += 1
		j += 1
	else:
		break
print(c)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 10 ** 9 + 7
T = 1
for _ in range(T):
	(n, a) = list(map(int, stdin.readline().split()))
	t = list(map(int, stdin.readline().split()))
	s = a - 1
	e = a - 1
	flag = True
	ans = 0
	while flag:
		if s >= 0 and e < n:
			if t[s] == 1 and t[e] == 1:
				if s == e:
					ans += 1
				else:
					ans += 2
		elif s < 0:
			if t[e] == 1:
				ans += 1
		elif e >= n:
			if t[s] == 1:
				ans += 1
		s -= 1
		e += 1
		if s < 0 and e >= n:
			flag = False
	print(ans)


[n, m] = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
(r, m) = (0, m - 1)
for i in range(n):
	if c[i] != 0 and (m == i or i > 2 * m or i < 2 * m - (n - 1) or (c[i] == c[2 * m - i])):
		r += c[i]
print(r)


n = list(map(int, input().split(' ')))
li = list(map(int, input().split(' ')))
count = 0
if li[n[1] - 1] == 1:
	count = count + 1
i = 1
while n[1] - 1 + i < n[0]:
	if n[1] - 1 - i >= 0 and n[1] - 1 + i < n[0]:
		if li[n[1] - 1 - i] == 1 and li[n[1] - 1 + i] == 1:
			count = count + 2
	else:
		break
	i = i + 1
if n[1] - 1 - i >= 0:
	while n[1] - 1 - i >= 0:
		if li[n[1] - 1 - i] == 1:
			count = count + 1
		i = i + 1
else:
	while n[1] - 1 + i < n[0]:
		if li[n[1] - 1 + i] == 1:
			count = count + 1
		i = i + 1
print(count)


(n, a) = map(int, input().split())
b = list(map(int, input().split()))

def fn(a, b):
	ans = 0
	t = a - 1
	if b[t] == 1:
		ans += 1
	i = 1
	while t - i >= 0 or t + i <= n - 1:
		if t - i < 0:
			temp1 = 1
			temp2 = b[t + i]
			if temp1 == 1 and temp2 == 1:
				ans += 1
		elif t + i > n - 1:
			temp2 = 1
			temp1 = b[t - i]
			if temp1 == 1 and temp2 == 1:
				ans += 1
		else:
			temp1 = b[t - i]
			temp2 = b[t + i]
			if temp1 == 1 and temp2 == 1:
				ans += 2
		i += 1
	return ans
print(fn(a, b))


(n, p) = map(int, input().split())
p -= 1
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
	if a[i] == 1:
		if i < p:
			if p + p - i < n and a[p + p - i] == 1:
				cnt += 2
				a[i] = a[p + p - i] = 0
			elif p + p - i >= n:
				cnt += 1
		elif i == p:
			cnt += 1
		elif i > 2 * p:
			cnt += 1
print(cnt)


(n, a) = map(int, input().split())
criminals = [None] + list(map(int, input().split()))
caught = 0
for i in range(max(a - 1, n - a) + 1):
	if i == 0:
		if criminals[a] == 1:
			caught += 1
	elif a - i < 1:
		if criminals[a + i] == 1:
			caught += 1
	elif a + i > n:
		if criminals[a - i] == 1:
			caught += 1
	elif criminals[a + i] == 1 and criminals[a - i] == 1:
		caught += 2
print(caught)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
p = 0
k = 0
for i in range(m - 1, n):
	if l[i] == 1:
		if m - p - 1 < 0:
			k = k + 1
		elif l[m - p - 1] == 1:
			k = k + 1
	p = p + 1
p = 0
for i in range(m - 1, -1, -1):
	if i == m - 1 and l[m - 1] == 1:
		k = k - 1
	if l[i] == 1:
		if m + p > n:
			k = k + 1
		elif l[m + p - 1] == 1:
			k = k + 1
	p = p + 1
print(k)


(n, a) = input().split()
n = int(n)
a = int(a) - 1
d = input().split()
d = [int(i) for i in d]
count = 0
for i in range(a + 1):
	if i == 0:
		if d[a] == 1:
			count += 1
	else:
		r = a + i
		l = a - i
		if r < n and l >= 0:
			if d[r] == 1 and d[l] == 1:
				count += 2
		elif l < 0:
			if d[r] == 1:
				count += 1
		elif d[l] == 1:
			count += 1
for i in range(2 * a + 1, n):
	if d[i] == 1:
		count += 1
print(count)


(n, a) = map(int, input().split())
x = input().split()
ans = 0
if a > n // 2:
	x = x[::-1]
	a = n - a + 1
for i in range(a - 1, n):
	if x[i] == '1' and i + 1 < 2 * a:
		if x[a - (i + 1 - a) - 1] == '1':
			ans += 2
	elif x[i] == '1':
		ans += 1
print(ans - int(x[a - 1]))


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
k -= 1
count = 0
if lst[k] == 1:
	count += 1
for i in range(k):
	if lst[i] == 0:
		continue
	if lst[i] == 1:
		if k + k - i > i and k + k - i < n:
			if lst[k + k - i] == 1:
				count += 2
		else:
			count += 1
b = 1 + k * 2
for i in range(b, n):
	if lst[i] == 1:
		count += 1
print(count)


(n, a) = list(map(int, input().split()))
a -= 1
c = list(map(int, input().split()))
ans = 0
for i in range(n):
	if c[i]:
		j = 2 * a - i
		if j not in range(n) or c[j] == 1:
			ans += 1
print(ans)


R = lambda : map(int, input().split())
(n, m) = R()
l = list(R())
h = l.count(1)
g = min(n - m, m)
for i in range(g):
	if m - 2 - i >= 0 and m + i < n and (l[m - 2 - i] != l[m + i]):
		h -= 1
print(h)


(n, a) = list(map(int, input().split()))
l = list(map(int, input().split()))
a -= 1
counter = 0
if l[a] == 1:
	counter += 1
i = 1
while a + i < n or a - i >= 0:
	if a + i < n and a - i >= 0:
		if l[a + i] == 1 and l[a - i] == 1:
			counter += 2
	if a + i < n and a - i < 0:
		if l[a + i] == 1:
			counter += 1
	if a - i >= 0 and a + i >= n:
		if l[a - i] == 1:
			counter += 1
	i += 1
print(counter)


(n, a) = input().split()
n = int(n)
a = int(a)
arr = [int(x) for x in input().split()]
count = 0
p = a - 1
point1 = p - 1
point2 = p + 1
if arr[p] == 1:
	count += 1
for i in range(0, len(arr)):
	if point1 >= 0 and point2 <= n - 1:
		if arr[point1] == 1 and arr[point2] == 1:
			count += 2
		point1 -= 1
		point2 += 1
	elif point1 < 0 and point2 <= n - 1:
		if arr[point2] == 1:
			count += 1
		point2 += 1
	elif point1 >= 0 and point2 > n - 1:
		if arr[point1] == 1:
			count += 1
		point1 -= 1
	else:
		break
print(count)


(Nciudad, Plimak) = map(int, input().split())
Aciudad = list(map(int, input().split()))
contR = Aciudad[Plimak - 1]
i = Plimak - 2
c = Plimak
while i >= 0 and c < Nciudad:
	if Aciudad[i] == 1 and Aciudad[c] == 1:
		contR += 2
	i -= 1
	c += 1
if i == -1:
	for k in range(c, Nciudad):
		contR += Aciudad[k]
else:
	for k in range(0, i + 1):
		contR += Aciudad[k]
print(contR)


gi = lambda : list(map(int, input().split()))
(n, a) = gi()
l = gi()
ans = sum(l)
k = 1
while a - k > 0 and a + k <= n:
	if l[a - k - 1] != l[a + k - 1]:
		ans -= 1
	k += 1
print(ans)


from sys import stdin, stdout

def read_int_from_line():
	return list(map(int, input().split()))

def solve():
	(n, a) = read_int_from_line()
	a -= 1
	t = read_int_from_line()
	count = t[a]
	for i in range(1, n):
		i1 = a - i
		i2 = a + i
		target = []
		if i1 >= 0:
			target.append(i1)
		if i2 < n:
			target.append(i2)
		criminals = 0
		for city in target:
			criminals += t[city]
		if criminals == len(target):
			count += criminals
	print(count)

def main():
	solve()
main()


(n, a) = map(int, input().split())
s = input()
m = [int(x) for x in s.split()]
c = 0
if m[a - 1] == 1:
	c += 1
i = a - 2
j = a
while i > -1 or j < n:
	if i > -1:
		if m[i] == 1:
			if j < n:
				if m[j] == 1:
					c += 2
			else:
				c += 1
	elif j < n:
		if m[j] == 1:
			c += 1
	i -= 1
	j += 1
print(c)


(n, current) = map(int, input().split())
cities = list(map(int, input().split()))
current = current - 1
prevv = current - 1
nextt = current + 1
if prevv < 0 or nextt > n - 1:
	print(sum(cities))
else:
	res = 0
	if cities[current]:
		res += 1
	while prevv >= 0 or nextt <= n - 1:
		if nextt > n - 1:
			res += sum(cities[:prevv + 1])
			break
		if prevv < 0:
			res += sum(cities[nextt:])
			break
		if cities[prevv] == 1 and cities[nextt] == 1:
			res += 2
		prevv -= 1
		nextt += 1
	print(res)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
t1 = t[0:a]
t2 = t[a + 1:n]
i = 0
ans = 0
if t[a] == 1:
	ans += 1
f = 0
while True:
	if a - i <= 0 and a + i >= n - 1:
		break
	elif a - i <= 0:
		f = 1
		break
	elif a + i >= n - 1:
		f = 2
		break
	if t1[a - i - 1] == t2[i] == 1:
		ans += 2
	i += 1
if f == 1:
	ans += sum(t2[i:len(t2)])
elif f == 2:
	ans += sum(t1[0:len(t1) - i])
print(ans)


(n, a) = map(int, input().split())
criminals = list(map(int, input().split()))
a -= 1
caught_criminals = 0
bcd_count = 0
max_distance_away = max(a - 0, len(criminals) - a)
while bcd_count <= max_distance_away:
	l_index = a - bcd_count
	left = criminals[l_index] if l_index >= 0 else None
	r_index = a + bcd_count
	right = criminals[r_index] if r_index < len(criminals) else None
	valid_cities = 0
	valid_criminals = 0
	if left is not None:
		valid_cities += 1
		valid_criminals += left
	if right is not None and r_index != l_index:
		valid_cities += 1
		valid_criminals += right
	if valid_cities == 2 and valid_criminals == 2:
		caught_criminals += 2
	elif valid_cities == 1 and valid_criminals == 1:
		caught_criminals += 1
	bcd_count += 1
print(caught_criminals)


def criminal_city():
	cities = input().split()
	criminals = input().split()
	cities[1] = int(cities[1]) - 1
	cities.append(int(cities[1]))
	if cities[1] == 0:
		output = 0
		for i in range(len(criminals)):
			if int(criminals[i]) == 1:
				output += 1
		print(output)
		return
	else:
		output = 0
		distance = 0
		left = right = True
		if int(criminals[cities[1]]) == 1:
			output += 1
		while left or right:
			distance += 1
			detector = 0
			if cities[1] - 1 < 0:
				left = False
			elif int(criminals[cities[1] - 1]) == 1:
				detector += 1
			if cities[2] + 1 >= len(criminals):
				right = False
			elif int(criminals[cities[2] + 1]) == 1:
				detector += 1
			cities[1] -= 1
			cities[2] += 1
			if detector != 0:
				if detector == 2 and left and right:
					output += 2
				elif detector == 1 and left and (not right):
					output += 1
				elif detector == 1 and (not left) and right:
					output += 1
		print(output)
		return
criminal_city()


(n, a) = map(int, input().split())
(a, t, v) = (a - 1, input().split(), 0)
for (i, ti) in enumerate(t):
	if ti == '1':
		j = 2 * a - i
		if j not in range(n) or t[j] == '1':
			v += 1
print(v)


read = lambda f: [f(i) for i in input().split(sep=' ')]
na = read(int)
a = na[1] - 1
n = na[0]
values = read(lambda i: bool(int(i)))
summ = 0
if values[a]:
	summ += 1
for i in range(n):
	if i < a:
		if 2 * a - i < n:
			if values[i] and values[2 * a - i]:
				summ += 2
		elif values[i]:
			summ += 1
	elif i > 2 * a:
		if values[i]:
			summ += 1
print(summ)


def main():
	(N, A) = [int(i) for i in input().split()]
	city = [-1] + [int(i) for i in input().split()] + [-1]
	(i, j) = (A, A)
	qtd = 0
	if city[A] == 1:
		qtd += 1
	i -= 1
	j += 1
	while city[i] != -1 and city[j] != -1:
		if city[i] + city[j] == 2:
			qtd += 2
		i -= 1
		j += 1
	if city[i] == -1:
		while city[j] != -1:
			if city[j] == 1:
				qtd += 1
			j += 1
	elif city[j] == -1:
		while city[i] != -1:
			if city[i] == 1:
				qtd += 1
			i -= 1
	print(qtd)
main()


(n, k) = map(int, input().split())
w = list(map(int, input().split()))
c = 0
k -= 1
if w[k] == 1:
	c += 1
l = k - 1
r = k + 1
while l >= 0 or r < n:
	if l < 0:
		l = -1
	if r >= n:
		r = -1
	if l == -1 and r != -1:
		if w[r] == 1:
			c += 1
		r += 1
	elif l != -1 and r == -1:
		if w[l] == 1:
			c += 1
		l -= 1
	elif l != -1 and r != -1:
		if w[l] == w[r] == 1:
			c += 2
		l -= 1
		r += 1
	else:
		break
print(c)


def fun(n, a, arr):
	if n <= 2:
		return sum(arr)
	count = arr[a]
	i = 1
	while a - i > -1 and a + i < n:
		if arr[a - i] and arr[a + i]:
			count += 2
		i += 1
	if a + i < n:
		count += sum(arr[a + i:])
	if a - i > -1:
		count += sum(arr[:a - i + 1])
	return count
(n, a) = list(map(lambda x: int(x), input().split()))
arr = list(map(lambda x: int(x), input().split()))
print(fun(n, a - 1, arr))


(n, a) = map(int, input().split())
c = list(map(int, input().split()))
t = c[a - 1]
c[a - 1] = 0
for x in range(1, min(a, n - a + 1)):
	if c[a - 1 - x] == c[a - 1 + x] == 1:
		t += 2
	(c[a - 1 - x], c[a - 1 + x]) = (0, 0)
for y in c:
	if y == 1:
		t += 1
print(t)


(n, a) = map(int, input().split())
ar = list(map(int, input().split()))
a = a - 1
c = ar[a]
if n == 1:
	print(ar[0])
	exit(0)
b = min(n - a, a + 1)
for i in range(1, b):
	c += (ar[a - i] & ar[a + i]) << 1
for i in range(a - b + 1):
	c += ar[i]
for i in range(a + b, n):
	c += ar[i]
print(c)


(n, a) = [int(i) for i in input().split()]
t = input().split()
a -= 1
d = [0] * n
c = [0] * n
for i in range(n):
	if a + i < n:
		if t[a + i] == '1':
			d[i] += 1
		c[i] += 1
	if a - i >= 0 and a - i != a:
		if t[a - i] == '1':
			d[i] += 1
		c[i] += 1
cc = 0
for i in range(n):
	if d[i] > 0 and c[i] == d[i]:
		cc += d[i]
print(cc)


(n, a) = list(map(int, input().split()))
crims = list(map(int, input().split()))
a -= 1
count = crims[a]
for pivot in range(1, n):
	if a - pivot < 0 and a + pivot >= n:
		break
	if a - pivot < 0:
		count += crims[a + pivot]
	elif a + pivot >= n:
		count += crims[a - pivot]
	elif crims[a + pivot] == 1 and crims[a - pivot] == 1:
		count += 2
print(count)


(n, p) = list(map(int, input().strip().split(' ')))
l = list(map(int, input().strip().split(' ')))
p -= 1
sum = l[p]
i = j = p
i -= 1
j += 1
while not (i < 0 and j >= n):
	if i < 0:
		sum += l[j]
		j += 1
	elif j >= n:
		sum += l[i]
		i -= 1
	elif l[i] == l[j] and l[i] == 1:
		sum += 2
		i -= 1
		j += 1
	else:
		i -= 1
		j += 1
print(sum)


(n, a) = map(int, input().split())
t = [int(x) for x in input().split()]
i = 0
count = 0
while 1:
	if a - i - 1 >= 0 and a + i - 1 <= n - 1:
		if t[a - i - 1] == 1 and t[a + i - 1] == 1:
			if i == 0:
				count += 1
			else:
				count += 2
		i += 1
	elif a - i - 1 >= 0 and a + i - 1 > n - 1:
		if t[a - i - 1] == 1:
			count += 1
		i += 1
	elif a - i - 1 < 0 and a + i - 1 <= n - 1:
		if t[a + i - 1] == 1:
			count += 1
		i += 1
	else:
		break
print(count)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
k -= 1
res = arr[k]
for i in range(1, n):
	if k - i >= 0 and k + i < n:
		res += arr[k - i] + arr[k + i] if arr[k - i] == arr[k + i] else 0
	elif k - i >= 0:
		res += arr[k - i]
	elif k + i < n:
		res += arr[k + i]
	else:
		break
print(res)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	(n, a) = map(int, input().split())
	t = list(map(int, input().split()))
	dis = max(n - a, a - 1)
	a = a - 1
	ans = 1 if t[a] == 1 else 0
	for d in range(1, dis + 1):
		if a - d >= 0 and a + d < n:
			if t[a - d] == 1 and t[a + d] == 1:
				ans += 2
		else:
			if a - d < 0 and t[a + d] == 1:
				ans += 1
			if a + d >= n and t[a - d] == 1:
				ans += 1
	print(ans)
main()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
i = k - 1
l = i
h = i
c = 0
while l >= 0 and h < n:
	if l == i and h == i and (arr[i] == 1):
		c += 1
	elif arr[l] == 1 and arr[h] == 1:
		c += 2
	l -= 1
	h += 1
while l >= 0:
	if arr[l] == 1:
		c += 1
	l -= 1
while h < n:
	if arr[h] == 1:
		c += 1
	h += 1
print(c)


(n, a) = map(int, input().strip().split())
a -= 1
arr = list(map(int, input().strip().split()))
left = a - 1
right = a + 1
count = 1 if arr[a] == 1 else 0
while left >= 0 and right < n:
	if arr[left] == arr[right] == 1:
		count += 2
	left -= 1
	right += 1
while left >= 0:
	count += arr[left]
	left -= 1
while right < n:
	count += arr[right]
	right += 1
print(count)


Limak = int(input().split(' ')[1])
cities = [int(city) for city in input().split(' ')]
if len(cities) - Limak > Limak - 1:
	a = len(cities) - Limak
else:
	a = Limak - 1
criminals = 0
criminals += cities[Limak - 1]
for number in range(a + 1)[1:]:
	first_num = 1
	second_num = 1
	changed1 = False
	changed2 = False
	if Limak - number > 0:
		first_num = cities[Limak - number - 1]
		changed1 = True
	if Limak + number <= len(cities):
		second_num = cities[Limak + number - 1]
		changed2 = True
	if second_num == 1 and first_num == 1:
		if changed1 == True and changed2 == True:
			criminals += 2
		else:
			criminals += 1
print(criminals)


(n, a) = [int(x) for x in input().split()]
l = list(map(int, input().split()))
l1 = l[0:a - 1]
l2 = l[a:]
num = 0
if a - 1 >= n - a:
	for i in range(0, n - a):
		if l1[-i - 1] == 1 and l2[i] == 1:
			num += 2
	l3 = l[0:2 * a - n - 1]
	s = sum(l3)
	num += s
else:
	for i in range(0, a - 1):
		if l1[-i - 1] == 1 and l2[i] == 1:
			num += 2
	l3 = l[2 * a - 1:]
	s = sum(l3)
	num += s
num += l[a - 1]
print(num)


def main():
	(n, a) = map(int, input().split())
	a -= 1
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if arr[i]:
			distance = a - i
			j = a + distance
			if j < 0 or j >= n or i == j or (arr[i] == arr[j]):
				ans += 1
	print(ans)
main()


(n, a) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
a -= 1
answer = 0
if arr[a]:
	answer += 1
for i in range(1, n):
	left_index = a - i
	right_index = a + i
	if left_index >= 0 and right_index < n:
		if arr[left_index] and arr[right_index]:
			answer += 2
	else:
		if left_index < 0 and right_index < n and (arr[right_index] == 1):
			answer += 1
		if right_index >= n and left_index >= 0 and (arr[left_index] == 1):
			answer += 1
print(answer)


a = input().split()
n = int(a[1]) - 1
m = int(a[0]) - int(a[1])
b = input().split()
l1 = []
l2 = []
for i in range(n):
	l1.append(int(b[i]))
c = 0
if b[n] == '1':
	c = c + 1
for i in range(m):
	l2.append(int(b[i + n + 1]))
l1.reverse()
x = min(n, m)
for i in range(x):
	if l1[i] == 1 and l2[i] == 1:
		c = c + 2
if n > x:
	for i in range(x, n):
		if l1[i] == 1:
			c = c + 1
else:
	for i in range(x, m):
		if l2[i] == 1:
			c = c + 1
print(c)


(a, n) = map(int, input().split())
x = [int(q) for q in input().split()]
i = n - 2
j = n
c = 0
if x[n - 1] == 1:
	c = 1
if x[n - 1] == 0:
	c = 0
while i >= 0 and j <= a - 1:
	if x[i] == x[j] == 1:
		c += 2
	i -= 1
	j += 1
if i < 0:
	c += x[j:].count(1)
if j > a - 1:
	c += x[:i + 1].count(1)
print(c)


(n, a) = map(int, input().split())
list_1 = input().split()
catch = 0
m = max(n - a, a - 1)
if n - a == a - 1:
	list_2 = [int(y) for y in list_1]
if n - a > a - 1:
	list_2 = [10 for x in range(m - a + 1)] + [int(y) for y in list_1]
if n - a < a - 1:
	list_2 = [int(y) for y in list_1] + [10 for x in range(m - n + a)]
if len(list_2) % 2 == 1:
	if list_2[(len(list_2) - 1) // 2] == 1:
		catch += 1
for i in range(m):
	if list_2[i] + list_2[len(list_2) - i - 1] == 11:
		catch += 1
	if list_2[i] + list_2[len(list_2) - i - 1] == 2:
		catch += 2
print(catch)


def solution(n, a, l):
	a = a - 1
	ans = 0
	for i in range(n):
		if i == 0:
			ans += 1 if l[a] == 1 else 0
			continue
		before = a - i
		after = a + i
		if before < 0 and after >= n:
			continue
		if before < 0 and after < n:
			ans += 1 if l[after] == 1 else 0
			continue
		if before >= 0 and after >= n:
			ans += 1 if l[before] == 1 else 0
			continue
		ans += 2 if l[before] == 1 and l[after] == 1 else 0
	return ans
(n, a) = [int(x) for x in input().split(' ')]
l = [int(x) for x in input().split(' ')]
print(solution(n, a, l))


(n, a1) = map(int, input().split())
a = list(map(int, input().split()))
i = j = a1 - 1
count = 0
if a[i] == 1:
	count += 1
i -= 1
j += 1
while i >= 0 and j < len(a):
	if a[i] == 1 and a[j] == 1:
		count += 2
	i -= 1
	j += 1
while j < len(a):
	if a[j] == 1:
		count += 1
	j += 1
while i >= 0:
	if a[i] == 1:
		count += 1
	i -= 1
print(count)


def police(arr, ind):
	ans = 1 if arr[ind - 1] == 1 else 0
	left = ind - 1
	right = ind + 1
	while True:
		if left - 1 < 0 and right - 1 >= len(arr):
			break
		if right - 1 >= len(arr) and arr[left - 1] == 1:
			ans += 1
		elif left - 1 < 0 and arr[right - 1] == 1:
			ans += 1
		elif arr[left - 1] == 1 and arr[right - 1] == 1:
			ans += 2
		left -= 1
		right += 1
	return ans
(n, ind) = list(map(int, input().rstrip().split()))
ar = list(map(int, input().rstrip().split()))
print(police(ar, ind))


(n, k) = tuple(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
i = j = k - 1
ans = 0
while i >= 0 or j < n:
	if i < 0 and j < n:
		if a[j] == 1:
			ans += 1
	elif i >= 0 and j >= n:
		if a[i] == 1:
			ans += 1
	elif a[i] == 1 and a[j] == 1:
		ans += 2
	i -= 1
	j += 1
if a[k - 1] == 1:
	ans -= 1
print(ans)


(n, city) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a = [-3] * 100 + a + [-3] * 100
summ = 0
city += 99
for i in range(1, n):
	if a[city - i] == 1 and a[city + i] == 1:
		summ += 2
	elif a[city - i] + a[city + i] == -2:
		summ += 1
if a[city] == 1:
	summ += 1
print(summ)


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]
(n, a) = inp()
t = arr_inp()
(c, c1, ans) = (a - 1, a + 1, t[a - 1])
while c > 0 and c1 <= n:
	ans += (t[c - 1] and t[c1 - 1]) * 2
	c1 += 1
	c -= 1
if c1 == c:
	print(ans)
elif c == 0:
	print(ans + sum(t[c1 - 1:]))
else:
	print(ans + sum(t[:c]))


import sys
(n, a) = map(int, sys.stdin.readline().split())
tn = list(map(int, sys.stdin.readline().split()))
ans = 0
if tn[a - 1] is 1:
	ans = 1
dis = 1
while True:
	if a - dis < 1 and a + dis > n:
		break
	elif a - dis < 1:
		if tn[a + dis - 1] is 1:
			ans += 1
	elif a + dis > n:
		if tn[a - dis - 1] is 1:
			ans += 1
	elif tn[a - dis - 1] is 1 and tn[a + dis - 1] is 1:
		ans += 2
	dis += 1
print(ans)


(n, k) = map(int, input().split())
k -= 1
ip = list(map(int, input().split()))
count = 0
for i in range(max(k + 1, n - k)):
	if k - i < 0:
		count += ip[k + i]
	elif k + i > n - 1:
		count += ip[k - i]
	elif i == 0:
		count += ip[k]
	elif ip[k - i] == 1 and ip[k + i] == 1:
		count += 2
print(count)


(n, curr) = map(int, input().split())
curr -= 1
a = list(map(int, input().split()))
if len(a) - curr - 1 < curr:
	sub = a[curr - (len(a) - curr - 1):]
	rest = a[:curr - (len(a) - curr - 1)]
elif len(a) - curr - 1 > curr:
	sub = a[:2 * curr + 1]
	rest = a[2 * curr + 1:]
else:
	sub = a
	rest = []
mid = len(sub) // 2
left = sub[:mid]
right = sub[mid + 1:][::-1]
summ = 0
for i in range(len(left)):
	if left[i] == 1 and left[i] == right[i]:
		summ += 2
print(summ + a[curr] + sum(rest))


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
d -= 1
low = 0
high = n - 1
ans = 0
dist = max(abs(d - low), abs(d - high))
while dist > 0:
	if d - dist >= 0 and d + dist <= n - 1:
		if a[d - dist] == 1 and a[d + dist] == 1:
			ans += 2
	elif d - dist >= 0:
		if a[d - dist] == 1:
			ans += 1
	elif d + dist <= n - 1:
		if a[d + dist] == 1:
			ans += 1
	dist -= 1
if a[d] == 1:
	print(ans + 1)
else:
	print(ans)


class CodeforcesTask680BSolution:

	def __init__(self):
		self.result = ''
		self.n_a = []
		self.cities = []

	def read_input(self):
		self.n_a = [int(x) for x in input().split(' ')]
		self.cities = [int(x) for x in input().split(' ')]

	def process_task(self):
		catch_cnt = 0
		p = self.n_a[1]
		r = 0
		while p + r <= self.n_a[0] or p - r >= 1:
			if p + r <= self.n_a[0] and p - r >= 1:
				if self.cities[p + r - 1] == self.cities[p - r - 1]:
					if p + r - 1 == p - r - 1:
						catch_cnt += 1 * self.cities[p + r - 1]
					else:
						catch_cnt += 2 * self.cities[p + r - 1]
			elif p + r <= self.n_a[0]:
				if self.cities[p + r - 1]:
					catch_cnt += 1
			elif p - r >= 1:
				if self.cities[p - r - 1]:
					catch_cnt += 1
			r += 1
		self.result = str(catch_cnt)

	def get_result(self):
		return self.result
Solution = CodeforcesTask680BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
numbers = [int(x) for x in input().split()]
pos = m - 1
i = 0
summ = sum(numbers)
while i <= pos and i < n - pos:
	if numbers[pos + i] + numbers[pos - i] == 1:
		summ -= 1
	i += 1
print(summ)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def solve(a, k):
	count = 0
	if len(a) - k > k - 1:
		left = False
		right = True
	elif k - 1 > len(a) - k:
		left = True
		right = False
	else:
		left = False
		right = False
	min_dist = min(len(a) - k, k - 1)
	if a[k - 1] == 1:
		count += 1
	for i in range(1, min_dist + 1):
		if (a[k - i - 1] == 1) & (a[k + i - 1] == 1):
			count += 2
	if left:
		for i in range(k - min_dist - 1):
			if a[i] == 1:
				count += 1
	if right:
		for i in range(k + min_dist, len(a)):
			if a[i] == 1:
				count += 1
	return count
(n, k) = to_list(input())
a = to_list(input())
print(solve(a, k))


(n, a) = list(map(int, input().split()))
t = list(map(int, input().split()))
S = t.count(1)
for i in range(min(a, n - a + 1)):
	if t[a - 1 - i] * t[a - 1 + i] != 1 and (t[a - 1 - i] == 1 or t[a - 1 + i] == 1):
		S -= 1
print(S)


(n, a) = [int(j) for j in input().split()]
t = [int(j) for j in input().split()]
d = 1
a -= 1
c = 0
if t[a]:
	c = 1
while True:
	p = a - d
	q = a + d
	if p >= 0 or q < n:
		if p >= 0 and q < n:
			if t[p] and t[q]:
				c += 2
		elif p < 0 and q < n:
			if t[q]:
				c += 1
		elif p >= 0 and q >= n:
			if t[p]:
				c += 1
	else:
		break
	d += 1
print(c)


import sys

def main():
	(n, a) = [int(tok) for tok in sys.stdin.readline().split()]
	a -= 1
	ncrims = [int(tok) for tok in sys.stdin.readline().split()]
	nbefore = a
	nafter = n - nbefore - 1
	res = ncrims[a]
	if nbefore > nafter:
		res += sum(ncrims[0:nbefore - nafter])
	if nafter > nbefore:
		res += sum(ncrims[a + nbefore + 1:])
	d = min(nbefore, nafter)
	for i in range(1, d + 1):
		if ncrims[a - i] == 1 and ncrims[a + i] == 1:
			res += 2
	print(res)
main()


def inRange(cur, n):
	if cur < 0 or cur >= n:
		return False
	return True
(n, x) = map(int, input().split())
city = [i for i in map(int, input().split())]
x = x - 1
ans = city[x]
dis = 1
while inRange(x - dis, n) or inRange(x + dis, n):
	if not inRange(x - dis, n):
		ans += city[x + dis]
	if not inRange(x + dis, n):
		ans += city[x - dis]
	if inRange(x - dis, n) and inRange(x + dis, n):
		if city[x - dis] == city[x + dis]:
			ans += city[x - dis] * 2
	dis = dis + 1
print(ans)


(n, k) = list(map(int, input().split()))
lst = list(map(int, input().split()))
a = k - 1
b = n - k
mi = min(a, b)
count = 0
k -= 1
if lst[k] == 1:
	count += 1
for i in range(mi + 1):
	if lst[k - i] == 1 and lst[k + i] == 1 and (i > 0):
		count += 2
if a < b:
	temp = lst[k + mi + 1:]
	count += temp.count(1)
else:
	temp = lst[:k - mi]
	count += temp.count(1)
print(count)


from itertools import compress
(n, a) = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
d = [abs(i - a) for i in range(1, n + 1)]
if n == 1 and t[0] == 1:
	print(1)
else:
	cnt = 0
	for i in range(max(d) + 1):
		mask = [j == i for j in d]
		if sum(mask) == 1:
			cnt += t[mask.index(True)]
		elif all([i == 1 for i in compress(t, [j == i for j in d])]):
			cnt += 2
	print(cnt)


(nb_city, city) = [int(x) for x in input().split()]
cities = [int(x) for x in input().split()]
city -= 1
l = city - 1
r = city + 1
ans = sum(cities)
while l >= 0 and r < nb_city:
	ans -= cities[l] ^ cities[r]
	l -= 1
	r += 1
print(ans)


(n, a) = [int(x) for x in input().split()]
cities = [int(x) for x in input().split()]
res = 0
a -= 1
for i in range(a):
	if 2 * a - i < n:
		if cities[i] == 1 and cities[i] == cities[2 * a - i]:
			res += 2
	elif cities[i] == 1:
		res += 1
for i in range(2 * a + 1, n):
	if cities[i] == 1:
		res += 1
if cities[a] == 1:
	res += 1
print(res)


import pdb

def solve():
	(m, n) = map(int, input().split())
	criminals = list(map(int, input().split()))
	l = n - 1
	r = n - 1
	acc = 0
	while l >= 0 or r < len(criminals):
		if l == r:
			acc += criminals[l]
		elif l >= 0 and r < len(criminals):
			if criminals[l] == criminals[r]:
				acc += 2 * criminals[l]
		elif l >= 0:
			acc += criminals[l]
		elif r < len(criminals):
			acc += criminals[r]
		l -= 1
		r += 1
	print(acc)
solve()


(n, a) = map(int, input().split())
criminals = list(map(int, input().split()))
current = a - 1
distance = 1
sum = 0
if criminals[current] == 1:
	sum = 1
while current + distance < n or current - distance >= 0:
	if current + distance >= n:
		if criminals[current - distance] == 1:
			sum += 1
	elif current - distance < 0:
		if criminals[current + distance] == 1:
			sum += 1
	elif criminals[current - distance] == 1 and criminals[current + distance] == 1:
		sum += 2
	distance += 1
print(str(sum))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
m -= 1
y = []
x = [0] * (n + 1)
d = {}
for i in range(n):
	r = abs(i - m)
	y.append(r)
	if r not in d:
		d[r] = l[i]
	else:
		d[r] += l[i]
cnt = 0
for i in d.keys():
	if d[i] == 2:
		cnt += d[i]
	elif i == 0:
		cnt += d[i]
	elif y.count(i) == 1:
		cnt += d[i]
print(cnt)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
city = 1 if l[a - 1] == 1 else 0
distance = 1
a -= 1
while a - distance >= 0 or a + distance < n:
	c = 0
	if a - distance >= 0:
		if l[a - distance] == 1:
			c += 1
	else:
		c += 1
	if a + distance < n:
		if l[a + distance] == 1:
			c += 1
	else:
		c += 1
	if c == 2 and a - distance >= 0 and (a + distance < n):
		city += 2
	elif c == 2:
		city += 1
	distance += 1
print(city)


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
x = k - 1
count = 0
for i in range(n):
	if i == 0:
		if ar[x] == 1:
			count += 1
	else:
		l = x - i
		r = x + i
		if l >= 0 and r <= n - 1:
			if ar[l] == 1 and ar[r] == 1:
				count += 2
		elif l >= 0 and r > n - 1:
			if ar[l] == 1:
				count += 1
		elif l < 0 and r <= n - 1:
			if ar[r] == 1:
				count += 1
		elif l < 0 and r > n - 1:
			break
print(count)


(n, a) = map(int, input().split())
a -= 1
t = list(map(int, input().split()))
ans = t[a]
for d in range(1, n):
	if a >= d and a + d < n and t[a - d] and t[a + d]:
		ans += 2
	elif a < d and a + d < n and t[a + d]:
		ans += 1
	elif a >= d and a + d >= n and t[a - d]:
		ans += 1
print(ans)


(n, a) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
a -= 1
ans = arr[a]
i = a - 1
j = a + 1
while i >= 0 and j < n:
	ans += 2 if arr[i] and arr[j] else 0
	i -= 1
	j += 1
while i >= 0:
	ans += arr[i]
	i -= 1
while j < n:
	ans += arr[j]
	j += 1
print(ans)


(n, a) = list(map(int, input().split(' ')))
(b, s, i, j) = (list(map(int, input().split(' '))), 0, a - 2, a)
while i >= 0 or j < n:
	if j == n:
		s += b[:i + 1].count(1)
		break
	if i == -1:
		s += b[j:].count(1)
		break
	if b[i] == b[j] == 1:
		s += 2
	(i, j) = (i - 1, j + 1)
print(s + 1 if b[a - 1] != 0 else s)


a = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
c = 0
for i in range(a[0]):
	if i - (a[1] - 1) <= 0:
		if n[i]:
			if a[1] - 1 + abs(a[1] - 1 - i) not in range(a[1] - 1, len(n)):
				c += 1
			elif n[a[1] - 1 + abs(a[1] - 1 - i)]:
				c += 1
	elif n[i]:
		if a[1] - 1 - abs(a[1] - 1 - i) not in range(a[1] - 1):
			c += 1
		elif n[a[1] - 1 - abs(a[1] - 1 - i)]:
			c += 1
print(c)


count_info = list(map(int, input().split(' ')))
city_crime = list(map(int, input().split(' ')))
value = 0
for i in range(0, count_info[1] - 1):
	if city_crime[i] == 1:
		if (count_info[1] - 1) * 2 - i > count_info[0] - 1:
			value += 1
		elif city_crime[(count_info[1] - 1) * 2 - i] == city_crime[i]:
			value += 2
if count_info[0] > (count_info[1] - 1) * 2 + 1:
	for i in range((count_info[1] - 1) * 2 + 1, count_info[0]):
		if city_crime[i] == 1:
			value += 1
if city_crime[count_info[1] - 1] == 1:
	print(value + 1)
else:
	print(value)


f = lambda x: int(x) - 1
(n, c) = map(f, input().split())
arr = list(map(int, input().split()))
res = arr[c]
for l in range(n):
	l += 1
	(ge, le) = (-1, -1)
	if c + l <= n:
		ge = arr[c + l]
	if c - l >= 0:
		le = arr[c - l]
	if ge > -1 and le > -1:
		res += 2 if ge + le > 1 else 0
	else:
		res += ge if ge > -1 else 0
		res += le if le > -1 else 0
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k <= n // 2:
	b = a[:k + k - 1]
	c = a[k + k - 1:]
else:
	b = a[k - (n - k) - 1:]
	c = a[:k - (n - k) - 1]
ans = 0
for i in range(len(b) // 2):
	if b[i] and b[len(b) - i - 1]:
		ans += 2
if b[len(b) // 2]:
	ans += 1
print(ans + sum(c))


(n, a) = map(int, input().split())
a -= 1
b = [1] * n + [*map(int, input().split())] + [1] * n
print(sum((b[n + a - abs(a - x)] * b[n + a + abs(a - x)] for x in range(n))))


(n, a) = map(int, input().split())
a -= 1
arr = [int(i) for i in input().split()]
ans = 0
for i in range(len(arr)):
	if arr[i] == 1:
		val = i - a
		if val == 0:
			ans += 1
		elif val < 0:
			val *= -1
			if a + val > len(arr) - 1:
				ans += 1
			elif arr[a + val] == 1:
				ans += 2
			else:
				pass
		else:
			val *= -1
			if a + val < 0:
				ans += 1
print(ans)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
(n, a) = R()
ol = L()
cnt = 0
for i in range(n):
	if i > 0 and a - i >= 1 and (a + i <= n):
		cnt += 2 * (ol[a - i - 1] + ol[a + i - 1] == 2)
	if i > 0 and a - i < 1 and (a + i <= n):
		cnt += ol[a + i - 1] == 1
	if i > 0 and a - i >= 1 and (a + i > n):
		cnt += ol[a - i - 1] == 1
	if i == 0 and ol[a - 1] == 1:
		cnt += 1
print(cnt)


(n, p) = map(int, input().split())
l = list(map(int, input().split()))
valid = [x for x in range(n)]
c = l[p - 1]
for d in range(1, max(p - 1, n - p) + 1):
	(left, right) = (p - d - 1, p + d - 1)
	res_left = l[left] if left in valid else None
	res_right = l[right] if right in valid else None
	if res_left is None and res_right is None:
		continue
	elif res_left is None:
		c += res_right
	elif res_right is None:
		c += res_left
	if res_left == 1 and res_right == 1:
		c += 2
print(c)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
lp = []
for i in range(n):
	lp.append(abs(i - a + 1))
total = 0
for i in range(max(lp) + 1):
	co = []
	for j in range(n):
		if lp[j] == i:
			co.append(l[j])
			if len(co) == 2:
				break
	if sum(co) == 2:
		total += 2
	else:
		total += min(co)
print(total)


list1 = list(map(int, input().split()))
numeroCiudades = int(list1[0])
ciudadVive = int(list1[1])
ciudades = list(map(int, input().split()))
derecha = []
izquierda = []
ciudadVive -= 1
total = 0
if ciudadVive == 0:
	pos = 0
	while pos <= len(ciudades) - 1:
		if ciudades[pos] == 1:
			total += 1
		pos += 1
elif ciudadVive == len(ciudades) - 1:
	pos = len(ciudades) - 1
	while pos > -1:
		if ciudades[pos] == 1:
			total += 1
		pos -= 1
else:
	for i in range(0, ciudadVive):
		izquierda.append(ciudades[i])
	i += 1
	if ciudades[i] == 1:
		total += 1
	for k in range(i + 1, len(ciudades)):
		if len(izquierda) > 0:
			if ciudades[k] == izquierda.pop() and ciudades[k] != 0:
				total += 2
		elif ciudades[k] == 1:
			total += 1
	while len(izquierda) != 0:
		if izquierda.pop() == 1:
			total += 1
print(total)


(n, a) = map(int, input().split())
a -= 1
t = [int(x) for x in input().split()]
ans = 0
for x in range(n):
	if t[x] == 1:
		diff = abs(a - x)
		if a - diff >= 0 and a + diff < n and (diff > 0):
			if t[a - diff] == 1 and t[a + diff] == 1:
				ans += 2
				t[a - diff] = 0
				t[a + diff] = 0
		else:
			ans += 1
print(ans)


(n, m) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
j = 0
m = m - 1
nd = 0
while m - j >= 0 or m + j < n:
	a = None
	b = None
	if m - j >= 0:
		a = lst[m - j]
	if m + j < n:
		b = lst[m + j]
	if (a == 1 and b == 1) and j == 0:
		nd = nd + 1
	elif a == 1 and b == 1:
		nd += 2
	elif a == None and b == 1 or (a == 1 and b == None):
		nd += 1
	j += 1
print(nd)


(n, m) = map(int, input().split())
mat = list(map(int, input().split()))
step = min(n - m, m - 1)
start = m - step - 1
end = m + step
lefts = mat[start:m - 1][::-1]
rights = mat[m:end]
res = mat[m - 1]
if start == 0:
	res += sum(mat[end:])
else:
	res += sum(mat[:start])
for i in range(len(lefts)):
	res += lefts[i] and rights[i] * 2
print(res)


from math import ceil
x = list(map(int, input().split(' ')))
y = list(map(int, input().split(' ')))
d = x[1]
st = []
for i in range(len(y)):
	if y[i] == 1:
		st.append(list((abs(d - (i + 1)), 1)))
counter = 0
r = min(x[0] - x[1], x[1] - 1) + 1
for i in range(len(st)):
	if st[i][0] in range(0, r) and st.count(st[i]) > 1 or st[i][0] == 0:
		counter += 1
	elif st[i][0] not in range(0, r):
		counter += 1
print(counter)


(n, a) = list(map(int, input().split()))
c = list(map(int, input().split()))
a -= 1
ap = min(n - a - 1, a)
pre = c[a - ap:a + ap + 1]
print(sum(c) - sum(pre) + sum([pre[i] and pre[len(pre) - i - 1] for i in range(len(pre))]))


(n, a) = map(int, input().split())
c = list(map(int, input().split()))
ans = c[a - 1]
for i in range(1, min(a, abs(n - a) + 1)):
	ans += (c[a - 1 - i] & c[a - 1 + i]) * 2
if a == (n + 1) / 2:
	print(ans)
elif a < (n + 1) / 2:
	ans += sum(c[2 * a - 1:])
	print(ans)
else:
	ans += sum(c[:2 * a - n - 1])
	print(ans)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
a = a - 1
if l[a] == 1:
	t = 1
else:
	t = 0
j = a + 1
k = a - 1
for i in range(n):
	if j < n and k >= 0:
		if l[j] == 1 and l[k] == 1:
			t += 2
	elif j > n - 1 and k >= 0:
		if l[k] == 1:
			t += 1
	elif j < n and k < 0:
		if l[j] == 1:
			t += 1
	j += 1
	k -= 1
print(t)


(n, k) = map(int, input().split())
v = [int(x) for x in input().split()]
k -= 1
ans = v[k]
for d in range(1, max(n - k, k + 1)):
	ans += ((v[k - d] if k - d >= 0 else 1) + (v[k + d] if k + d < n else 1) == 2) * ((k - d >= 0) + (k + d < n))
print(ans)


(n, a) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
a = a - 1
(i, j) = (a - 1, a + 1)
criminals = 0
if t[a] == 1:
	criminals = 1
while i > -1 and j < n:
	if t[i] == 1 and t[j] == 1:
		criminals += 2
	i -= 1
	j += 1
while i > -1:
	if t[i] == 1:
		criminals += 1
	i -= 1
while j < n:
	if t[j] == 1:
		criminals += 1
	j += 1
print(criminals)


import sys
import math
input = sys.stdin.readline

def solve():
	(n, a) = map(int, input().strip().split())
	A = list(map(int, input().strip().split()))
	i = a - 2
	j = a
	ans = A[a - 1]
	while i >= 0 and j < n:
		if A[i] and A[j]:
			ans += 2
		i -= 1
		j += 1
	while i >= 0:
		if A[i]:
			ans += 1
		i -= 1
	while j < n:
		if A[j]:
			ans += 1
		j += 1
	print(ans)
solve()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
m -= 1
for i in range(n):
	if a[i] == 0:
		x = abs(m - i)
		if i > m and m - x >= 0:
			try:
				a[m - x] = 0
			except:
				l = 0
		elif i < m:
			try:
				a[m + x] = 0
			except:
				l = 0
print(sum(a))


(n, i) = map(int, input().split())
i -= 1
cities = list(map(int, input().split()))
longest = max(n - 1 - i, i)
criminals_caught = 0
if cities[i]:
	criminals_caught += 1
for d in range(1, longest + 1):
	if i - d >= 0:
		s = cities[i - d] == 1
	else:
		s = 'Out'
	if i + d < n:
		h = cities[i + d] == 1
	else:
		h = 'Out'
	if s == True and h == True:
		criminals_caught += 2
	elif s == True and h == 'Out':
		criminals_caught += 1
	elif h == True and s == 'Out':
		criminals_caught += 1
print(criminals_caught)


(n, a) = map(int, input().split())
l = list(map(int, input().split()))
if n % 2 != 0:
	middle = n // 2 + 1
else:
	middle = n // 2
answer = 0
for i in range(n):
	if i == 0:
		if l[a - 1] == 1:
			answer += 1
		continue
	left = a - 1 - i
	right = a - 1 + i
	if left >= 0:
		if right < n:
			if l[left] == l[right] and l[left] == 1:
				answer += 2
		elif l[left] == 1:
			answer += 1
	elif right < n:
		if l[right] and l[right] == 1:
			answer += 1
	else:
		break
print(answer)


from itertools import zip_longest
f = lambda : map(int, input().split())
(n, m) = f()
c = 0
l = list(f())
if m == 1:
	print(sum(l))
else:
	for (i, j) in zip_longest(l[m - 2::-1], l[m:], fillvalue='-'):
		if i == 1 and j == 1:
			c += 2
		elif i == '-':
			c += j
		elif j == '-':
			c += i
	print(c + l[m - 1])


(n, a) = map(int, input().split())
arr = list(map(int, input().split()))
a = a - 1
j = 1
count = arr[a]
front = 0
back = 0
while 1:
	k = a - j
	k1 = a + j
	if k < 0 and k1 >= n:
		break
	if k < 0:
		front = k1
		break
	if k1 >= n:
		back = k
		break
	if arr[k] == 1 and arr[k1] == 1:
		count += 2
	j += 1
if front != 0:
	for i in range(front, n):
		count += arr[i]
elif back != 0:
	for i in range(back + 1):
		count += arr[i]
print(count)


(n, p) = map(int, input().split())
p -= 1
a = list(map(int, input().split()))
res = a[p]
for i in range(1, len(a)):
	if p - i < 0 and p + i >= len(a):
		break
	if p - i < 0:
		res += a[p + i]
	elif p + i >= len(a):
		res += a[p - i]
	elif a[p + i] + a[p - i] == 2:
		res += 2
print(res)


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
left = n - 1
right = n - 1
if n == 1 and m == 1:
	print(l[0])
else:
	while 1:
		if left == -1 and right == 10000:
			break
		if left > 0:
			left = left - 1
		else:
			left = -1
		if right < m - 1:
			right = right + 1
		else:
			right = 10000
		if left >= 0 and right <= m - 1:
			if l[left] == 1 and l[right] == 1:
				c = c + 2
		elif left >= 0 and right == 10000:
			if l[left] == 1:
				c = c + 1
		elif left == -1 and right <= m - 1:
			if l[right] == 1:
				c = c + 1
	if l[n - 1] == 1:
		c = c + 1
	print(c)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
fr = bk = a - 1
counter = 0
while fr >= 0 and bk <= len(t) - 1:
	if t[fr] + t[bk] == 2:
		if fr == bk:
			counter += 1
		else:
			counter += 2
	fr -= 1
	bk += 1
counter += sum(t[0:fr + 1])
counter += sum(t[bk:])
print(counter)


(n, here) = map(int, input().split())
x = input().split(' ')
crime = 0
ins = []
out = []
if x[here - 1] > '0':
	crime += 1
for i in range(len(x)):
	if here > n / 2:
		if i < here - (n - here) - 1:
			out.append(int(x[i]))
		else:
			ins.append(x[i])
	elif i > (here - 1) * 2:
		out.append(int(x[i]))
	else:
		ins.append(x[i])
crime += sum(out)
meio = int((len(ins) - 1) / 2) + 1
for j in range(1, meio):
	r = meio - 1 + j
	l = meio - 1 - j
	if ins[r] > '0' and ins[l] > '0':
		crime += 2
print(crime)


(n, a) = map(int, input().split())
a -= 1
criminals = list(map(int, input().split()))
sureCriminals = 0
for (left, right) in zip(criminals[a::-1], criminals[a:]):
	if left and right:
		sureCriminals += 2
nearestEdgeDist = min(a, n - a - 1)
sureCriminals += sum(criminals[:a - nearestEdgeDist]) + sum(criminals[a + nearestEdgeDist + 1:])
if criminals[a]:
	sureCriminals -= 1
print(sureCriminals)


(n, a) = map(int, input().split())
t = list(map(int, input().split()))
a -= 1
i = 1
c = 0
if t[a] == 1:
	c += 1
while a - i >= 0 or a + i < n:
	if a - i >= 0 and a + i < n:
		if t[a - i] == 1 and t[a + i] == 1:
			c += 2
	elif a - i >= 0 or a + i < n:
		k = 0
		if a - i >= 0 and t[a - i] == 1:
			k += 1
		if a + i < n and t[a + i] == 1:
			k += 1
		c += k
	i += 1
print(c)


import math, sys, re, itertools, pprint
(ri, rai) = (lambda : int(input()), lambda : list(map(int, input().split())))
(n, a) = rai()
a -= 1
t = rai()
res = 0
for j in range(n):
	if a - j < 0 and a + j >= n:
		break
	if a - j < 0:
		res += t[a + j]
	elif a + j >= n:
		res += t[a - j]
	else:
		tt = t[a + j] & t[a - j]
		res += tt if j == 0 else 2 * tt
print(res)


(n, a) = list(map(int, input().split()))
c = list(map(int, input().split()))
a = a - 1
i = 1
b = 1 if c[a] else 0
while a - i >= 0 or a + i < n:
	if a - i >= 0:
		if c[a - i]:
			if a + i >= n:
				b += 1
			elif c[a + i]:
				b += 2
		i += 1
		continue
	if a + i < n:
		if c[a + i]:
			if a - i < 0:
				b += 1
			elif c[a - i]:
				b += 2
		i += 1
		continue
print(b)


def catch_criminals(size, home, locations):
	result = 0
	for (idx, loc) in enumerate(locations):
		coord = idx + 1
		if loc == 1:
			if coord == home:
				result = result + 1
			elif 2 * home - coord - 1 < 0 or 2 * home - coord > size:
				result = result + 1
			elif locations[2 * home - coord - 1] == 1:
				result = result + 1
	print(result)
home = list(map(int, input().split(' ')))
locations = list(map(int, input().split(' ')))
catch_criminals(home[0], home[1], locations)


[n, k] = list(map(int, input().split()))
criminals = list(map(int, input().split()))
count = 0
left = k - 1
right = n - k
side = None
symm = None
uncount = 0
if left > right:
	side = 'left has extra'
	symm = n - k
	uncount = criminals[0:2 * k - 1 - n].count(1)
else:
	side = 'right has extra'
	symm = k - 1
	uncount = criminals[2 * k - 1:n].count(1)
for i in range(symm):
	off = criminals[k - 2 - i]
	leg = criminals[k + i]
	if leg + off == 0:
		count += 0
	elif leg + off == 1:
		count += 0
	elif leg + off == 2:
		count += 2
if criminals[k - 1] == 1:
	print(count + uncount + 1)
else:
	print(count + uncount)


(n, a) = map(int, input().split())
cities = list(map(int, input().split()))
total_criminals = len([x for x in cities if x == 1])
for d in range(min(a, n - (a - 1))):
	if cities[a - 1 - d] != cities[a - 1 + d]:
		total_criminals -= 1
print(total_criminals)


L = int(input().split()[1]) - 1
c = [int(i) for i in input().split()]
result = 0
if c[L] == 1:
	result = 1
for i in range(0, len(c)):
	d = abs(L - i)
	if c[i] == 1:
		if L < i:
			if L - d < 0 and d != 0:
				result += 1
			elif L - d >= 0:
				if c[L - d] == 1 and d != 0:
					result += 1
		elif L > i:
			if L + d >= len(c) and d != 0:
				result += 1
			elif L + d < len(c):
				if c[L + d] == 1 and d != 0:
					result += 1
print(result)


pos = list(map(int, list(input().split())))[1]
pos = pos - 1
arr = list(map(int, list(input().split())))
j = pos - 1
k = pos + 1
count = 0
if arr[pos] == 1:
	count = 1
while j >= 0 and k < len(arr):
	if arr[j] == arr[k] == 1:
		count += 2
	j = j - 1
	k = k + 1
while j >= 0:
	if arr[j] == 1:
		count += 1
	j = j - 1
while k < len(arr):
	if arr[k] == 1:
		count += 1
	k = k + 1
print(count)


(n, a) = map(int, input().split())
ar = list(map(int, input().split()))
a = a - 1
b = min(a + 1, n - a)
count = 0
count += ar[a]
for i in range(1, b):
	l = a - i
	r = a + i
	if ar[l] + ar[r] == 2:
		count += 2
if a < n - a:
	for i in range(a + 1, n - a):
		count += ar[a + i]
if a > n - a:
	b = n - a - 1
	count += sum(ar[0:a - b])
print(count)