Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down.

There is a cursor pointing at some symbol of the string. Suppose that cursor is at position i (1 ≤ i ≤ n, the string uses 1-based indexing) now. Left and right arrow keys are used to move cursor around the string. The string is cyclic, that means that when Nam presses left arrow key, the cursor will move to position i - 1 if i > 1 or to the end of the string (i. e. position n) otherwise. The same holds when he presses the right arrow key (if i = n, the cursor appears at the beginning of the string).

When Nam presses up arrow key, the letter which the text cursor is pointing to will change to the next letter in English alphabet (assuming that alphabet is also cyclic, i. e. after 'z' follows 'a'). The same holds when he presses the down arrow key.

Initially, the text cursor is at position p. 

Because Nam has a lot homework to do, he wants to complete this as fast as possible. Can you help him by calculating the minimum number of arrow keys presses to make the string to be a palindrome?


-----Input-----

The first line contains two space-separated integers n (1 ≤ n ≤ 10^5) and p (1 ≤ p ≤ n), the length of Nam's string and the initial position of the text cursor.

The next line contains n lowercase characters of Nam's string.


-----Output-----

Print the minimum number of presses needed to change string into a palindrome.


-----Examples-----
Input
8 3
aeabcaez

Output
6



-----Note-----

A string is a palindrome if it reads the same forward or reversed.

In the sample test, initial Nam's string is: $\text{aeabcaez}$ (cursor position is shown bold).

In optimal solution, Nam may do 6 following steps:[Image]

The result, $\text{zeaccaez}$, is now a palindrome.

Difficulty: MEDIUM_HARD
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(n, p) = map(int, input().split())
p -= 1
s = input()
if p >= n // 2:
	p = n - 1 - p
l = 0
r = n // 2 - 1
while l < n // 2 and s[l] == s[n - 1 - l]:
	l += 1
while r >= 0 and s[r] == s[n - 1 - r]:
	r -= 1
(ans, ch) = (0, 0)
for i in range(l, r + 1):
	temp = abs(ord(s[i]) - ord(s[n - 1 - i]))
	ch += min(temp, 26 - temp)
if l < r:
	ans += min(abs(p - r), abs(p - l)) + abs(r - l) + ch
elif l == r:
	if ch:
		ans += abs(p - l) + ch
print(ans)


def change(a, b):
	(a, b) = (ord(a) - 96, ord(b) - 96)
	(a, b) = (max(a, b), min(a, b))
	return min(a - b, 26 + b - a)

def mini(arr, p):
	if len(arr) == 0:
		return 0
	if arr[-1] <= p:
		return p - arr[0]
	if arr[0] >= p:
		return arr[-1] - p
	return min(arr[-1] - p, p - arr[0]) + (arr[-1] - arr[0])

def func(s, p):
	mid = (len(s) + 1) / 2
	if p > mid:
		p = mid - (p - mid)
	mid = int(len(s) / 2)
	steps = 0
	mis = []
	for i in range(mid):
		if s[i] != s[len(s) - 1 - i]:
			steps += change(s[i], s[len(s) - 1 - i])
			mis.append(i + 1)
	steps = steps + mini(mis, p)
	return steps
l = list(map(int, input().split()))
pos = l[1]
s = input()
ans = func(s, pos)
print(int(ans))


(n, p) = map(int, input().split())
from sys import stdin
s = stdin.readline().rstrip('\n')
l = [0] * n
for i in range(n // 2):
	if s[i] != s[n - 1 - i]:
		a = abs(ord(s[i]) - ord(s[n - 1 - i]))
		b = ord(s[i]) - 97 + 1 + 122 - ord(s[n - 1 - i])
		c = ord(s[n - 1 - i]) - 97 + 1 + 122 - ord(s[i])
		l[i] = l[n - 1 - i] = min(a, b, c)
c = 0
for i in range(n // 2):
	c += l[i]
p = p - 1
if p >= n // 2:
	p = n - 1 - p
if c != 0:
	a = 0
	for i in range(n // 2 - 1, p, -1):
		if l[i] != 0:
			a = i - p
			break
	b = 2 * a
	d = 0
	for i in range(p):
		if l[i] != 0:
			d = p - i
			break
	b += d
	a += 2 * d
	print(min(a, b) + c)
else:
	print(0)


(n, p) = map(int, input().split())
p -= 1
if p >= n // 2:
	p = n - 1 - p
s = input()
d = [abs(ord(s[i]) - ord(s[n - 1 - i])) for i in range(n // 2)]
d = [min(x, 26 - x) for x in d]
(first, last) = (-1, -1)
for i in range(len(d)):
	if d[i] > 0:
		if first == -1:
			first = i
		last = i
a = 0 if first == -1 else min(abs(p - first), abs(p - last)) + (last - first) + sum(d)
print(a)


(n, p) = list(map(int, input().split()))
string = input()
(n, p) = (n - 1, p - 1)
if p > n // 2:
	p = n - p
ans = 0
(left, right) = (-1, -1)
for i in range(n // 2 + 1):
	(ch, corresponding) = (string[i], string[n - i])
	if ch != corresponding:
		if left == -1:
			left = i
		else:
			right = i
		t = abs(ord(ch) - ord(corresponding))
		t = min(t, 26 - t)
		ans += t
if left != -1 and right != -1:
	ans += right - left
mn = float('inf')
if left != -1:
	mn = min(mn, abs(p - left))
if right != -1:
	mn = min(mn, abs(right - p))
if mn != float('inf'):
	ans += mn
print(ans)


(n, p) = map(int, input().split())
temp = list(input())
check = []
if p > n // 2:
	p = n + 1 - p
cnt = 0
for i in range(n // 2):
	if temp[i] != temp[n - 1 - i]:
		check += [i + 1]
		a = min(abs(ord(temp[i]) - ord(temp[n - 1 - i])), 26 - abs(ord(temp[i]) - ord(temp[n - 1 - i])))
		cnt += a
if len(check) == 0:
	print(0)
else:
	if p <= check[0]:
		cnt += check[-1] - p
	elif p >= check[-1]:
		cnt += p - check[0]
	else:
		cnt += min(p - check[0], check[-1] - p) + min(abs(check[0] - check[-1]), n - abs(check[0] - check[-1]))
	print(cnt)


for _ in range(1):
	(n, p) = [int(i) for i in input().split()]
	if n - p < p - 1:
		p = 1 + n - p
	p -= 1
	s = input()
	to_go = int(n / 2) - 1
	i = 0
	j = n - 1
	l = []
	while i <= to_go:
		if s[i] != s[j]:
			l.append(i)
		i += 1
		j -= 1
	if len(l) == 0:
		print(0)
		continue
	elif len(l) == 1:
		ind = l[0]
		a = ord(s[ind])
		b = ord(s[n - 1 - ind])
		print(abs(p - l[0]) + min(abs(a - b), 26 - abs(a - b)))
		continue
	e1 = l[0]
	e2 = l[-1]
	ans = 0
	if p == e1 or p == e2:
		e1 -= p
		e2 -= p
		ans += abs(e1 + e2)
	elif p < e1:
		ans += e2 - p
	elif p > e2:
		ans += p - e1
	elif p > e1 and p < e2:
		d1 = e2 - p
		d2 = p - e1
		m = min(d1, d2)
		ans += 2 * m
		if d1 == m:
			ans += d2
		else:
			ans += d1
	for i in l:
		i1 = n - 1 - i
		x = abs(ord(s[i]) - ord(s[i1]))
		ans += min(x, 26 - x)
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

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

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, p) = mp()
s = inp()
p = min(p, n + 1 - p)
p -= 1
r = (n - 1) // 2
l = 0
while l != p and s[l] == s[n - 1 - l]:
	l += 1
while r != p and s[r] == s[n - 1 - r]:
	r -= 1
c = 0
for i in range(n // 2):
	x = abs(ord(s[i]) - ord(s[n - 1 - i]))
	c += min(x, 26 - x)
l = abs(p - l)
r = abs(p - r)
print(min(l, r) * 2 + max(l, r) + c)


(n, p) = map(int, input().split())
p -= 1
st = input().strip()
l = 0
h = n // 2 - 1
if p > h:
	p = n - 1 - p
inside = False
ans = 0
i = 0
H = -1
while i <= h:
	if st[i] != st[n - 1 - i]:
		if not inside:
			l = i
			inside = True
		H = i
	ans += min(abs(ord(st[i]) - ord(st[n - 1 - i])), abs(ord('z') - ord('a') + 1 - abs(ord(st[i]) - ord(st[n - 1 - i]))))
	i += 1
h = H
if h == -1:
	print('0')
	exit(0)
ans += h - l
ans += min(abs(l - p), abs(p - h))
print(ans)


from math import ceil
(n, p) = map(int, input().split())
(s, ans, be, en) = (input(), 0, 0, ceil(n / 2))
if p > n // 2:
	(be, en) = (n // 2, n)
(c1, c2, flag) = (0, 0, 0)
for i in range(p - 1, be - 1, -1):
	x1 = abs(ord(s[i]) - ord(s[n - i - 1]))
	if x1:
		flag = c1
	ans += min(x1, 26 - x1)
	c1 += 1
c1 = flag
flag = 0
for i in range(p, en):
	c2 += 1
	x = abs(ord(s[i]) - ord(s[n - i - 1]))
	if x:
		flag = c2
	ans += min(x, 26 - x)
c2 = flag
print(ans + 2 * min(c1, c2) + max(c1, c2))


def piche_se(n, p, s):
	s = [i for i in s]
	sol = 0
	if 1 == 1:
		if n % 2 == 0:
			if p < n // 2:
				tota = n // 2
				last = -1
			else:
				tota = n
				last = n // 2 - 1
		elif p <= n // 2:
			tota = n // 2 + 1
			last = -1
		else:
			tota = n
			last = n // 2
		temp = 0
		prev = p
		soty = prev
		if abs(p - tota) > abs(p - last):
			for i in range(soty, last, -1):
				if s[i] != s[n - i - 1]:
					sol += abs(i - prev)
					sol += min((ord(s[i]) - ord(s[n - i - 1])) % 26, (ord(s[n - i - 1]) - ord(s[i])) % 26)
					prev = i
					s[n - i - 1] = s[i]
			soty = prev
			for i in range(soty, tota):
				if s[i] != s[n - i - 1]:
					sol += abs(i - prev)
					sol += min((ord(s[i]) - ord(s[n - i - 1])) % 26, (ord(s[n - i - 1]) - ord(s[i])) % 26)
					prev = i
					s[n - i - 1] = s[i]
			return sol
		for i in range(p, tota):
			if s[i] != s[n - i - 1]:
				sol += abs(i - prev)
				sol += min((ord(s[i]) - ord(s[n - i - 1])) % 26, (ord(s[n - i - 1]) - ord(s[i])) % 26)
				prev = i
				s[n - i - 1] = s[i]
		soty = prev
		for i in range(soty, last, -1):
			if s[i] != s[n - i - 1]:
				sol += abs(i - prev)
				sol += min((ord(s[i]) - ord(s[n - i - 1])) % 26, (ord(s[n - i - 1]) - ord(s[i])) % 26)
				prev = i
				s[n - i - 1] = s[i]
		return sol
(n, p) = list(map(int, input().split()))
s = input().rstrip()
print(piche_se(n, p - 1, s))


def main():
	s = 'abcdefghijklmnopqrstuvwxyz'
	d = {(a, b): min((ord(a) - ord(b)) % 26, (ord(b) - ord(a)) % 26) for a in s for b in s}
	(n, m) = map(int, input().split())
	(s, res, n, m) = (input(), 0, n - 1, min(m - 1, n - m))
	idx = [i for (i, a) in zip(range((n + 1) // 2), s) if a != s[n - i]]
	print(sum((d[s[i], s[n - i]] for i in idx)) + min(abs(m - idx[0]), abs(m - idx[-1])) + idx[-1] - idx[0] if idx else 0)
main()


(n, p) = map(int, input().split())
p = min(p, n + 1 - p)
p -= 1
s = input()
ans = 0
t = []
for i in range(n // 2):
	if s[i] != s[-i - 1]:
		ans += min(abs(ord(s[i]) - ord(s[-i - 1])), 26 - abs(ord(s[i]) - ord(s[-i - 1])))
		t.append(i)
if not t:
	ans = 0
elif t[0] >= p:
	ans += t[-1] - p
elif t[-1] <= p:
	ans += p - t[0]
else:
	m = min(p - t[0] + t[-1] - t[0], t[-1] - p + t[-1] - t[0])
	ans += m
print(ans)


(n, p) = map(int, input().split())
s = input()
ans = 0
p -= 1
if n % 2 == 1 and p == n // 2 and (n != 1):
	p -= 1
	ans += 1
cnt = 0
for i in range(n):
	if n - 1 - i <= i:
		break
	if s[i] != s[n - 1 - i]:
		cnt += 1
if p >= n // 2 and n != 1:
	h = ''
	for i in range(n - 1, -1, -1):
		h += s[i]
	s = h
	p = n - 1 - p
r = 0
l = 0
rr = 0
ll = 0
for i in range(p):
	if s[i] != s[n - 1 - i]:
		ans += min(26 - abs(ord(s[i]) - ord(s[n - 1 - i])), abs(ord(s[i]) - ord(s[n - 1 - i])))
		r += 1
		rr = max(rr, p - i)
for i in range(p + 1, n // 2):
	if s[i] != s[n - 1 - i]:
		ans += min(26 - abs(ord(s[i]) - ord(s[n - 1 - i])), abs(ord(s[i]) - ord(s[n - 1 - i])))
		l += 1
		ll = max(ll, i - p)
ans += min(26 - abs(ord(s[p]) - ord(s[n - 1 - p])), abs(ord(s[p]) - ord(s[n - 1 - p])))
ans += ll + rr + min(ll, rr)
print(ans)


from string import ascii_lowercase

def solve(n: int, p: int, s: str) -> int:
	if s == s[::-1]:
		return 0

	def get_dist(src: str, dsc: str) -> int:
		(src_idx, dsc_idx) = (ascii_lowercase.index(src), ascii_lowercase.index(dsc))
		if src_idx > dsc_idx:
			(src_idx, dsc_idx) = (dsc_idx, src_idx)
		return min(dsc_idx - src_idx, src_idx + 26 - dsc_idx)
	p -= 1
	is_palindromic = [False] * n
	up_down_cost = 0
	for i in range((n + 1) // 2):
		if s[i] == s[n - i - 1]:
			is_palindromic[i] = is_palindromic[n - i - 1] = True
		else:
			up_down_cost += get_dist(s[i], s[n - i - 1])
	idx_of_not_palindromic = list((i for i in range(n) if not is_palindromic[i]))
	if p < n // 2:
		idx_of_not_palindromic = list((_ for _ in idx_of_not_palindromic if _ < (n + 1) // 2))
	else:
		idx_of_not_palindromic = list((_ for _ in idx_of_not_palindromic if _ >= (n + 1) // 2))
	move_cost_candidates = []
	(min_idx, max_idx) = (min(idx_of_not_palindromic), max(idx_of_not_palindromic))
	if p < min_idx:
		move_cost_candidates.append(max_idx - p)
	if p > max_idx:
		move_cost_candidates.append(p - min_idx)
	move_cost_candidates.append(p + n - 1 - min_idx)
	move_cost_candidates.append(max_idx - min_idx + min(abs(p - max_idx), abs(p - min_idx)))
	move_cost_candidates.append(n - 1 - p + max_idx)
	return up_down_cost + min(move_cost_candidates)
(n, p) = map(int, input().split())
s = input()
print(solve(n, p, s))


(n, p) = list(map(int, input().split()))
string = input()

def calc_delta(s):

	def get_min_shift(i):
		ord_diff = abs(ord(s[i]) - ord(s[n - i - 1]))
		return min(ord_diff, 26 - ord_diff)
	return {i: get_min_shift(i) for i in range((n + 1) // 2)}

def palindrome(s):
	deltas = calc_delta(s)
	offset_indices = list(filter(lambda i: deltas[i] > 0, deltas.keys()))
	if not offset_indices:
		return 0
	alpha_delta = sum(deltas.values())
	mindex = min(offset_indices)
	maxdex = max(offset_indices)
	sindex = min(p - 1, n - p)
	if mindex == maxdex or maxdex <= sindex:
		travel_delta = abs(sindex - mindex)
		return travel_delta + alpha_delta
	if mindex >= sindex:
		return maxdex - sindex + alpha_delta
	min_delta = min(maxdex - sindex, sindex - mindex)
	max_delta = max(maxdex - sindex, sindex - mindex)
	travel_delta = 2 * min_delta + max_delta
	return travel_delta + alpha_delta
print(palindrome(string))


from sys import stdin

def solve(tc):
	(n, p) = map(int, stdin.readline().split())
	n -= 1
	p -= 1
	s = stdin.readline()
	half = n // 2
	lo = 0
	hi = n
	if p <= half:
		hi = half - 1 if n % 2 == 0 else half
	else:
		lo = half + 1
	while lo < hi and s[lo] == s[n - lo]:
		lo += 1
	while lo < hi and s[hi] == s[n - hi]:
		hi -= 1
	if lo == hi and s[lo] == s[n - lo]:
		print(0)
		return
	cnt = hi - lo
	if p < lo:
		cnt += lo - p
	elif p > hi:
		cnt += p - hi
	else:
		cnt += min(p - lo, hi - p)
	for i in range(lo, hi + 1):
		fwd = ord(s[i]) - ord(s[n - i])
		if fwd < 0:
			fwd += 26
		rev = ord(s[n - i]) - ord(s[i])
		if rev < 0:
			rev += 26
		cnt += min(fwd, rev)
	print(cnt)
	pass
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


(n, p) = map(int, input().split())
text = input()
p -= 1
if p >= len(text) // 2:
	text = text[-1::-1]
	p = len(text) - p - 1
maxr = p
minl = p
for i in range(p, len(text) // 2):
	if text[i] != text[-i - 1]:
		maxr = i
flag = 0
for i in range(p, -1, -1):
	if text[i] != text[-i - 1]:
		minl = i
ans = 0
a = maxr - p + maxr - minl
b = p - minl + maxr - minl
ans += min(a, b)
for i in range(0, len(text) // 2):
	ans += min((ord(text[-i - 1]) - ord(text[i])) % 26, (ord(text[i]) - ord(text[-i - 1])) % 26)
print(ans)


def solve(n, p, s):
	if p >= n // 2:
		p = n + 1 - p
	to_be_changed = [i for i in range(n // 2) if s[i] != s[n - i - 1]]
	if not to_be_changed:
		return 0
	tmp = [min((ord(s[i]) - ord(s[n - i - 1])) % 26, -(ord(s[i]) - ord(s[n - i - 1])) % 26) for i in to_be_changed]
	up_down_cost = sum(tmp)
	right_left_cost = to_be_changed[-1] - to_be_changed[0] + min(abs(p - 1 - to_be_changed[0]), abs(p - 1 - to_be_changed[-1]))
	return up_down_cost + right_left_cost

def test():
	assert solve(8, 3, 'aeabcaez')
(n, p) = map(int, input().split())
s = input()
print(solve(n, p, s))


(n, p) = map(int, input().split())
s = input()
(main, m) = ('abcdefghijklmnopqrstuvwxyz', dict())
for i in range(26):
	m[main[i]] = i
p = min(p - 1, n - p)
(b, a, ans, f, ff) = (-1, -1, 0, True, True)
for i in range(n // 2):
	if s[i] != s[n - 1 - i]:
		ans += min(abs(m[s[i]] - m[s[n - i - 1]]), 26 - abs(m[s[i]] - m[s[n - i - 1]]))
		if i < p and ff:
			b = i
			ff = False
		if i > p:
			a = i
if b != -1 and a != -1:
	ans += abs(a - b) + min(p - b, a - p)
if b == -1 or a == -1:
	if b == -1 and a == -1:
		ans = ans
	else:
		ans += abs(p - max(a, b))
print(ans)


(n, p) = map(int, input().split())
ans = [0] * n
if p > (n + 1) // 2:
	p = ~(p - 1) % n + 1
s = input()
for i in range(n // 2):
	ans[i] = min((ord(s[i]) - ord(s[~i])) % 26, (ord(s[~i]) - ord(s[i])) % 26)
fz = 0
while fz < n and ans[fz] == 0:
	fz += 1
lz = n // 2 - 1
while lz >= 0 and ans[lz] == 0:
	lz -= 1
lz = n // 2 - 1 - lz
if fz == n:
	exit(print(0))
gl = max(0, p - 1 - fz)
gr = max(0, n // 2 - p - lz)
print(sum(ans) + min(gl * 2 + gr, gr * 2 + gl))


import sys

def dbg(*args):
	print('D:', *args, file=sys.stderr)
(n, p) = map(int, input().split())
s = input()
if s == s[::-1]:
	print('0')
else:
	sz = len(s)
	if p > sz // 2:
		p = sz - p
	else:
		p -= 1
	(l, r) = (0, sz // 2 - 1)
	while s[l] == s[-l - 1]:
		l += 1
	while s[r] == s[-r - 1]:
		r -= 1
	dbg(l, r, p)
	sum = r - l
	sum += min(abs(p - l), abs(r - p))
	for i in range(l, r + 1):
		a1 = ord(s[i])
		a2 = ord(s[-i - 1])
		if a1 > a2:
			(a1, a2) = (a2, a1)
		sum += min(a2 - a1, a1 + 26 - a2)
	print(sum)


(n, p) = [int(i) for i in input().split()]
str = input()
p -= 1
if p != n / 2 and p == n // 2:
	press = 0
	for i in range(p + 1, n):
		press += 1
		if str[i] != str[n - i - 1]:
			s = min(ord(str[i]), ord(str[n - i - 1]))
			g = max(ord(str[i]), ord(str[n - i - 1]))
			press += min(g - s, 122 - g + s - 96)
	print(press)
	exit()
lL = 0
rL = n
if p < n // 2:
	rL = n // 2
else:
	lL = n // 2
	if n % 2 == 1:
		lL += 1
(l, r) = (p, p)
press = 0
for i in range(lL, rL):
	if str[i] != str[n - i - 1]:
		l = min(l, i)
		r = max(r, i)
		s = min(ord(str[i]), ord(str[n - i - 1]))
		g = max(ord(str[i]), ord(str[n - i - 1]))
		press += min(g - s, 122 - g + s - 96)
press += 2 * min(p - l, r - p) + max(p - l, r - p)
print(press)


def calc(c1, c2):
	x = abs(ord(c1) - ord(c2))
	return min(x, 26 - x)
(a, b) = map(int, input().split(' '))
strx = input()
if a % 2 == 0:
	if b > a // 2:
		b = a + 1 - b
	left = strx[:a // 2]
	right = strx[a // 2:]
	right = right[::-1]
	dist = [calc(left[i], right[i]) for i in range(a // 2)]
	indx = b - 1
	rightpt = b - 1
	leftpt = b - 1
	for i in range(a // 2):
		if dist[i] != 0:
			leftpt = i
			break
	dist.reverse()
	for i in range(a // 2):
		if dist[i] != 0:
			rightpt = a // 2 - 1 - i
			break
	sumlr = rightpt - leftpt + min(abs(leftpt - indx), abs(rightpt - indx))
	print(sum(dist) + sumlr)
else:
	if b > a // 2 + 1:
		b = a + 1 - b
	left = strx[:a // 2]
	right = strx[a // 2:][1:]
	right = right[::-1]
	dist = [calc(left[i], right[i]) for i in range(a // 2)]
	indx = b - 1
	rightpt = b - 1
	leftpt = b - 1
	for i in range(a // 2):
		if dist[i] != 0:
			leftpt = i
			break
	dist.reverse()
	for i in range(a // 2):
		if dist[i] != 0:
			rightpt = a // 2 - 1 - i
			break
	sumlr = rightpt - leftpt + min(abs(leftpt - indx), abs(rightpt - indx))
	print(sum(dist) + sumlr)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
from fractions import *

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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 value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
s = input()
l = 0
r = len(s) - 1
ans = 0
left = []
right = []
while l < r:
	ans += min(abs(ord(s[l]) - ord(s[r])), 26 - abs(ord(s[l]) - ord(s[r])))
	if s[l] != s[r]:
		left.append(l)
		right.append(r)
	l += 1
	r -= 1
f = 0
if n % 2 == 1 and k == n // 2:
	f = 2
	if k - left[0] < right[0] - k:
		f = 1
if f == 1 or (k < ceil(n / 2) and ans != 0):
	k -= 1
	ans += abs(left[-1] - left[0])
	ans += min(abs(k - left[0]), abs(k - left[-1]))
elif f == 2 or (k >= ceil(n / 2) and ans != 0):
	a = right
	k -= 1
	ans += abs(right[-1] - right[0])
	ans += min(abs(k - right[0]), abs(k - right[-1]))
print(ans)


def getUnpaired(s):
	unpaired = set()
	for i in range(0, n // 2):
		if s[i] != s[n - i - 1]:
			unpaired.add(i)
	return unpaired

def getDist(c1, c2):
	dist1 = abs(ord(c1) - ord(c2))
	dist2 = abs(ord(c1) + 26 - ord(c2))
	dist3 = abs(ord(c2) + 26 - ord(c1))
	return min(dist1, dist2, dist3)

def tryLR(p, s, unpaired):
	done = set()
	moves = 0
	try:
		(l, r) = (min(unpaired), max(unpaired))
	except:
		return 0
	while p >= l:
		if p in unpaired and p not in done:
			moves += getDist(s[p], s[len(s) - p - 1])
			done.add(p)
		if p == l:
			break
		p -= 1
		moves += 1
	while p <= r:
		if p in unpaired and p not in done:
			moves += getDist(s[p], s[len(s) - p - 1])
			done.add(p)
		if p == r:
			break
		p += 1
		moves += 1
	return moves

def tryRL(p, s, unpaired):
	done = set()
	moves = 0
	try:
		(l, r) = (min(unpaired), max(unpaired))
	except:
		return 0
	while p <= r:
		if p in unpaired and p not in done:
			moves += getDist(s[p], s[len(s) - p - 1])
			done.add(p)
		if p == r:
			break
		p += 1
		moves += 1
	while p >= l:
		if p in unpaired and p not in done:
			moves += getDist(s[p], s[len(s) - p - 1])
			done.add(p)
		if p == l:
			break
		p -= 1
		moves += 1
	return moves
(n, p) = (int(x) for x in input().split())
s = input()
p -= 1
if p >= n // 2:
	p = n - p - 1
unpaired = getUnpaired(s)
print(min(tryLR(p, s, unpaired), tryRL(p, s, unpaired)))


input_ = list(map(int, input().split()))
(n, p) = (input_[0], input_[1])
pal_ = list(input())
pal_ = [ord(letter) - 96 for letter in pal_]
diff_ = 0
dist_ = 0
p_down = p - 1 <= int(n / 2) - 1
if n % 2 == 0:
	bad_ = list()
	for i in range(int(n / 2)):
		if pal_[int(n / 2) - 1 - i] != pal_[int(n / 2) + i]:
			if p_down:
				bad_.append(int(n / 2) - 1 - i)
			else:
				bad_.append(int(n / 2) + i)
			max_pal = max(pal_[int(n / 2) - 1 - i], pal_[int(n / 2) + i])
			min_pal = min(pal_[int(n / 2) - 1 - i], pal_[int(n / 2) + i])
			diff_ += min(max_pal - min_pal, 26 - max_pal + min_pal)
else:
	bad_ = list()
	for i in range(int(n / 2) + 1):
		if pal_[int(n / 2) - i] != pal_[int(n / 2) + i]:
			if p_down:
				bad_.append(int(n / 2) - i)
			else:
				bad_.append(int(n / 2) + i)
			max_pal = max(pal_[int(n / 2) - i], pal_[int(n / 2) + i])
			min_pal = min(pal_[int(n / 2) - i], pal_[int(n / 2) + i])
			diff_ += min(max_pal - min_pal, 26 - max_pal + min_pal)
if len(bad_) == 0:
	print(0)
else:
	if p_down:
		min_ = bad_[-1]
		max_ = bad_[0]
		if p - 1 >= max_:
			dist_ = p - 1 - min_
		elif p - 1 <= min_:
			dist_ = max_ - p + 1
		else:
			(dist_1, dist_2) = (p - 1 - min_, max_ - p + 1)
			dist_ = 2 * min(dist_1, dist_2) + max(dist_1, dist_2)
	else:
		min_ = bad_[0]
		max_ = bad_[-1]
		if p - 1 <= min_:
			dist_ = max_ - p + 1
		elif p - 1 >= max_:
			dist_ = p - 1 - min_
		else:
			(dist_1, dist_2) = (p - 1 - min_, max_ - p + 1)
			dist_ = 2 * min(dist_1, dist_2) + max(dist_1, dist_2)
	print(dist_ + diff_)


s = input()
p = int(s.split()[1])
s = input()
n = int(len(s))
a = []
if p > n // 2:
	p = n - p + 1
sum = 0
if n == 1:
	print('0')
	quit()
for i in range(n // 2):
	j = int(n - i - 1)
	q = abs(ord(s[j]) - ord(s[i]))
	a.append(min(q, 26 - q))
	sum += a[i]
i = 0
while (a[i] == 0) & (i < p - 1):
	i += 1
if i == p - 1:
	i = 0
else:
	i = p - i - 1
j = n // 2 - 1
while (a[j] == 0) & (j > p - 1):
	j -= 1
if j == p - 1:
	j = 0
else:
	j = j - p + 1
sum += min(i, j) * 2 + max(i, j)
print(str(sum))


(n, p) = map(int, input().split())
s = list(input())
p -= 1
d = [0] * (n // 2 + 1)
for i in range(n // 2):
	x = ord(s[i]) - ord(s[n - i - 1])
	d[i] = min(abs(x), 26 - abs(x))
if p >= n // 2:
	p = n - 1 - p
if sum(d) == 0:
	print(0)
	exit()
(i, j) = (0, n // 2)
while d[i] == 0:
	i += 1
while d[j] == 0:
	j -= 1
if i > p:
	i = p
if j < p:
	j = p
print(sum(d) + min(p - 2 * i + j, 2 * j - i - p))


ad = ord('z') - ord('a') + 1

def mc(a, b):
	pd = abs(ord(a) - ord(b))
	return min(pd, ad - pd)

def fd(v, r):
	for c in r:
		if not v[c]:
			return c

def mp(s, n, p):
	cl = n // 2
	v = [s[c] == s[-(c + 1)] for c in range(cl)]
	rv = range(cl)
	if p >= cl:
		p = n - p - 1
	return (fd(v, rv), fd(v, rv[::-1]), p)

def d(s, n, p):
	(l, r, p) = mp(s, n, p)
	if l == None:
		return 0
	t = 0
	for c in range(l, r + 1):
		t += mc(s[c], s[-(c + 1)])
	(lp, rp) = (abs(p - l), abs(r - p))
	if l < p < r:
		if lp > rp:
			(lp, rp) = (rp, lp)
		t += 2 * lp + rp
	else:
		t += r - l + min(lp, rp)
	return t
(n, p) = [int(c) for c in input().split()]
s = input()
print(d(s, n, p - 1))


I = lambda : list(map(int, input().split()))

def ge(x):
	return ord(x) - 97
(n, k) = I()
s = input()
x = 0
ind = []
k -= 1
for i in range(n // 2):
	p = min((ge(s[i]) - ge(s[n - i - 1])) % 26, (ge(s[n - i - 1]) - ge(s[i])) % 26)
	if p != 0:
		ind.append(i if k < n // 2 else n - i - 1)
	x += p
if ind != []:
	x += min(abs(k - ind[-1]) + abs(ind[-1] - ind[0]), abs(k - ind[0]) + abs(ind[-1] - ind[0]))
print(x)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, input().split()))

def fn(ch1, ch2):
	m1 = (ord(ch1) - ord(ch2) + 26) % 26
	m2 = (ord(ch2) - ord(ch1) + 26) % 26
	return min(m1, m2, 26 - m1, 26 - m2)
for _ in range(1):
	(n, p) = lst()
	s = input()
	hf = (n - 1) // 2
	p -= 1
	if p > hf:
		p = n - p - 1
	p1 = ans = 0
	while p1 < p and s[p1] == s[n - p1 - 1]:
		p1 += 1
	p2 = hf
	while p2 > p and s[p2] == s[n - p2 - 1]:
		p2 -= 1
	for i in range(p1, p2 + 1):
		ans += fn(s[i], s[n - i - 1])
	ans += min(2 * abs(p - p1) + abs(p - p2), abs(p - p1) + 2 * abs(p - p2))
	print(ans)


(n, k) = map(int, input().split())
s = input()
k -= 1
k = min(k, n - k - 1)
a = -1
b = 0
ans = 0
l = 0
for i in range(n // 2):
	j = abs(ord(s[i]) - ord(s[n - 1 - i]))
	j = min(j, 26 - j)
	if j > 0 and a == -1:
		a = i
	if j > 0:
		b = i
	l += j
a = min(a, n - a - 1)
b = min(b, n - b - 1)
if l == 0:
	print(0)
else:
	if (k - a) * (k - b) > 0:
		ans = max(abs(k - a), abs(k - b))
	else:
		ans = abs(k - a) + abs(k - b) + min(abs(k - a), abs(k - b))
	print(ans + l)


(n, p) = map(int, input().split())
ans = [0] * n
if p > (n + 1) // 2:
	p = ~(p - 1) % n + 1
s = input()
for i in range(n // 2):
	ans[i] = min((ord(s[i]) - ord(s[~i])) % 26, (ord(s[~i]) - ord(s[i])) % 26)
(fz, lz) = (0, n // 2 - 1)
while fz < n and ans[fz] == 0:
	fz += 1
while lz >= 0 and ans[lz] == 0:
	lz -= 1
l = max(0, p - 1 - fz)
r = max(0, n // 2 - p - n // 2 + 1 + lz)
print(sum(ans) + min(l * 2 + r, r * 2 + l))


(n, p) = map(int, input().split())
p -= 1
string_orig = input()
if p >= (n + 1) // 2:
	string_orig = string_orig[::-1]
	p = n - p - 1
steps_rl = 0
string = list(string_orig)
pos = p
for i in range(p, (n + 1) // 2):
	(c1, c2) = (string[i], string[n - i - 1])
	if c1 != c2:
		diff = abs(ord(c1) - ord(c2))
		steps_rl += min(diff, 26 - diff) + i - pos
		string[i] = string[n - i - 1]
		pos = i
cur = pos
for i in range(cur, -1, -1):
	(c1, c2) = (string[i], string[n - i - 1])
	if c1 != c2:
		diff = abs(ord(c1) - ord(c2))
		steps_rl += min(diff, 26 - diff) + pos - i
		string[i] = string[n - i - 1]
		pos = i
string = list(string_orig)
steps_lr = 0
pos = p
cur = pos
for i in range(cur, -1, -1):
	(c1, c2) = (string[i], string[n - i - 1])
	if c1 != c2:
		diff = abs(ord(c1) - ord(c2))
		steps_lr += min(diff, 26 - diff) + pos - i
		string[i] = string[n - i - 1]
		pos = i
for i in range(p, (n + 1) // 2):
	(c1, c2) = (string[i], string[n - i - 1])
	if c1 != c2:
		diff = abs(ord(c1) - ord(c2))
		steps_lr += min(diff, 26 - diff) + i - pos
		string[i] = string[n - i - 1]
		pos = i
print(min(steps_rl, steps_lr))


(n, p) = map(int, input().split())
s = input()
mid = int(n / 2)
alphabets = ''.join([chr(i) for i in range(97, 123)]) * 2

def min_diff(alp1, alp2, alphabets=alphabets):
	(alp1, alp2) = (min(alp1, alp2), max(alp1, alp2))
	return min(abs(alphabets.find(alp1) - alphabets.find(alp2)), abs(alphabets.find(alp2) - alphabets.replace(alp1, '0', 1).find(alp1)))
p = 1 + n - p if p > mid else p
i = 0
diff = []
steps = 0
while i <= mid - 1:
	temp = min_diff(s[i], s[n - 1 - i])
	diff.append(1 if temp > 0 else 0)
	steps += temp
	i += 1
l_l = diff[:p - 1]
l_r = diff[p:]
if sum(l_l) == 0 and sum(l_r) == 0:
	pass
elif sum(l_l) == 0:
	steps = steps + len(l_r)
elif sum(l_r) == 0:
	steps = steps + len(l_l)
else:
	l_l_index = len(l_l) - l_l.index(1)
	l_r_index = len(l_r) - l_r[::-1].index(1)
	steps = steps + 2 * min(l_l_index, l_r_index) + max((l_l_index, l_r_index))
print(0 if n == 1 else steps + 1 if p == int(n / 2) + 1 else steps)


(n, pos) = (int(x) for x in input('').split())
s = input('')

def dis(a, b):
	a = ord(a)
	b = ord(b)
	return min(abs(a - b), abs(a + 26 - b), abs(b + 26 - a))
d = [dis(s[i], s[len(s) - i - 1]) for i in range((len(s) + 1) // 2)]
pos -= 1
if pos >= (len(s) + 1) // 2:
	pos = len(s) - pos - 1
for (rightmost, v) in enumerate(reversed(d)):
	if v != 0:
		rightmost = len(d) - rightmost - 1
		break
for (leftmost, v) in enumerate(d):
	if v != 0:
		break
ans = min(abs(rightmost - pos) + rightmost - leftmost, abs(pos - leftmost) + rightmost - leftmost) + sum(d)
if sum(d) == 0:
	print(0)
else:
	print(ans)


def cost(a, b):
	return min(abs(ord(b) - ord(a)), 26 - abs(ord(b) - ord(a)))

def pal(x, n):
	return n - x - 1
(n, pt) = map(int, input().split())
pt -= 1
s = input()
if pt >= n // 2:
	s = s[::-1]
	pt = pal(pt, n)
cos = [cost(s[i], s[pal(i, n)]) for i in range(n)]
start = -1
end = -1
for i in range(n):
	if cos[i]:
		start = i
		break
for i in range(int(n // 2) - 1, -1, -1):
	if cos[i]:
		end = i
		break
turn = sum(cos[:int(n // 2)])
walk = 0
if start != -1:
	if pt <= start:
		walk = end - pt
	elif pt > start and pt < end:
		walk = min(end - pt + end - pt + pt - start, pt - start + pt - start + end - pt)
	else:
		walk = pt - start
print(walk + turn)


import math
(content_length, current_position) = map(int, input().split())
middle_position = math.ceil(content_length / 2)
text = input()
answer = 0
first_need_change = -1
last_need_change = -1
for index in range(middle_position):
	left_char = text[index]
	right_char = text[content_length - index - 1]
	if left_char != right_char:
		left_value = ord(left_char)
		right_value = ord(right_char)
		answer += min(abs(left_value - right_value), abs(26 - abs(left_value - right_value)))
		if first_need_change == -1:
			first_need_change = index + 1
		else:
			last_need_change = index + 1
move_count = 0
if current_position > middle_position:
	current_position = content_length - current_position + 1
near_position = min(abs(first_need_change - current_position), abs(last_need_change - current_position))
far_position = max(abs(first_need_change - current_position), abs(last_need_change - current_position))
if last_need_change != -1:
	if first_need_change >= current_position and last_need_change >= current_position or (first_need_change <= current_position and last_need_change <= current_position):
		move_count += near_position + (far_position - near_position)
	else:
		move_count += near_position + abs(first_need_change - last_need_change)
elif first_need_change != -1:
	move_count = abs(first_need_change - current_position)
answer += move_count
print(answer)


(n, p) = map(int, input().split())
s = input()
cr = []
if n % 2 == 0:
	if p > n // 2:
		p = n - p + 1
	else:
		p = p
elif p > n // 2 + 1:
	p = n - p + 1
else:
	p = p
for i in range(n // 2):
	if s[i] != s[n - 1 - i]:
		cr.append(i)
count = 0
if len(cr) == 0:
	pass
elif p - 1 > cr[-1]:
	count = count + p - 1 - cr[0]
elif p - 1 < cr[0]:
	count = count + cr[-1] - p + 1
elif abs(cr[0] - p + 1) < abs(cr[-1] - p + 1):
	count = count + 2 * abs(cr[0] - p + 1) + abs(cr[-1] - p + 1)
elif abs(cr[0] - p + 1) == abs(cr[-1] - p + 1):
	count = count + abs(cr[0] - p + 1)
else:
	count = count + 2 * abs(cr[-1] - p + 1) + abs(cr[0] - p + 1)
for i in cr:
	if abs(ord(s[i]) - ord(s[n - 1 - i])) <= 26 - abs(ord(s[i]) - ord(s[n - 1 - i])):
		count = count + abs(ord(s[i]) - ord(s[n - 1 - i]))
	else:
		count = count + 26 - abs(ord(s[i]) - ord(s[n - 1 - i]))
print(count)


(n, p) = map(int, input().split())
p -= 1
s = input()
arr = [(lambda x, y: min(abs(x - y), 26 - abs(y - x)))(ord(s[i]), ord(s[n - i - 1])) for i in range(n // 2)]
p = min(p, n - p - 1)
(f, l) = (0, len(arr) - 1)
for a in arr:
	if a != 0:
		break
	else:
		f += 1
for a in reversed(arr):
	if a != 0:
		break
	else:
		l -= 1
print(sum(arr) + l - f + min(abs(p - l), abs(p - f)) if sum(arr) > 0 else 0)


lis = 'abcdefghijklmnopqrstuvwxyz'

def dis(a, b):
	aa = lis.index(a)
	bb = lis.index(b)
	m = 27
	m1 = 27
	ans = 100
	for i in range(26):
		if aa < i:
			m = min(i - aa, 26 - i + aa)
		else:
			m = min(aa - i, 26 - aa + i)
		if bb < i:
			m1 = min(i - bb, 26 - i + bb)
		else:
			m1 = min(bb - i, 26 - bb + i)
		ans = min(ans, m + m1)
	return ans
(n, p) = map(int, input().split())
s = input()
if n == 1 and p == 1:
	print(0)
	exit()
ans = 0
for i in range(n // 2):
	ans += dis(s[i], s[n - i - 1])
i = 0
j = n // 2 - 1
if p > n // 2:
	p = n - p
else:
	p -= 1
while i < min(p, n // 2) and s[i] == s[n - i - 1]:
	i += 1
while p < j and s[j] == s[n - j - 1]:
	j -= 1
ans += min(p - i, j - p) + j - i
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, p) = map(int, input().split())
	s = input()
	(maxi, mini) = (-1, -1)
	ans = 0
	flag = 0
	if p > n // 2:
		p = n - p + 1
	for i in range(n // 2):
		if s[i] != s[n - i - 1]:
			if not flag:
				mini = i + 1
				flag = 1
			maxi = i + 1
			ans += min(abs(ord(s[i]) - ord(s[n - i - 1])), 26 - abs(ord(s[i]) - ord(s[n - i - 1])))
	if maxi != -1:
		ans += min(abs(maxi - p), abs(p - mini))
		ans += maxi - mini
	print(ans)
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')
main()


(n, p) = map(int, input().split())
p -= 1
s = input()
ans = 0
idx = 0
pos = []
while idx < n // 2:
	if s[idx] != s[n - 1 - idx]:
		diff = abs(ord(s[idx]) - ord(s[n - 1 - idx]))
		ans += min(diff, 26 - diff)
		if p >= n // 2:
			pos.append(n - 1 - idx)
		else:
			pos.append(idx)
	idx += 1
pos.sort()
if ans == 0:
	print(0)
elif len(pos) == 1:
	ans += abs(p - pos[0])
	print(ans)
else:
	if abs(p - pos[0]) < abs(p - pos[-1]):
		ans += abs(p - pos[0]) + (pos[-1] - pos[0])
	else:
		ans += abs(p - pos[-1]) + (pos[-1] - pos[0])
	print(ans)


ALPHA = ord('z') - ord('a') + 1

def is_problem(s):
	return [int(s[i] != s[-i - 1]) for i in range(len(s))]

def count_problems(s):
	return sum(is_problem(s))

def change(a, b):
	return min(abs(a - b), ALPHA - abs(a - b))

def solve(p, s):
	if p >= len(s) // 2:
		s = list(reversed(s))
		p = len(s) - p - 1
	ss = is_problem(s)
	first_problem = p
	last_problem = p
	answer = 0
	for (i, sss) in enumerate(ss[:len(s) // 2]):
		if sss:
			first_problem = min(i, first_problem)
			last_problem = max(i, last_problem)
			answer += change(s[i], s[-i - 1])
	answer += min(p - first_problem, last_problem - p) + (last_problem - first_problem)
	return answer

def main():
	(n, p) = map(int, input().split())
	p -= 1
	s = list(map(ord, input()))
	print(solve(p, s))
assert 1 == change(ord('z'), ord('a'))
assert 1 == change(ord('b'), ord('c'))
assert 1 == solve(5, list(map(ord, 'abcdefdcba')))
assert 6 == solve(2, list(map(ord, 'aeabcaez')))
main()


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, p) = map(int, input().split())
s = input()
summ = 0
min1 = -1
max1 = -1
flag = 0
for i in range(n // 2):
	if s[i] != s[n - i - 1]:
		if flag == 0:
			min1 = i + 1
			flag = 1
		max1 = i + 1
		s1 = abs(ord(s[i]) - ord(s[n - i - 1]))
		s2 = 26 - s1
		summ += min(s1, s2)
if p > n // 2:
	p = n + 1 - p
if max1 != -1:
	summ += min(abs(max1 - p), abs(p - min1))
	summ += max1 - min1
print(summ)


(n, p) = [int(i) for i in input().split()]
p -= 1
p = min(p, n - p - 1)
s = input()
ans = 0
m1 = None
m2 = 0
for i in range(n):
	if n - i - 1 < i:
		break
	if s[i] != s[-i - 1]:
		if m1 is None:
			m1 = i
		m2 = max(m2, i)
	ans += min(abs(ord(s[i]) - ord(s[-i - 1])), 26 - abs(ord(s[i]) - ord(s[-i - 1])))
if m1 is None:
	print(0)
	exit(0)
if m2 <= p:
	x = p - m1
elif m1 >= p:
	x = m2 - p
else:
	x = min(2 * (m2 - p) + p - m1, 2 * (p - m1) + m2 - p)
print(ans + x)


import sys
from math import sqrt
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
(n, p) = map(int, input().split())
line = input().rstrip('\n')
if p > int(len(line) / 2):
	line = line[::-1]
	p = n - p + 1
l = n
r = -1
for i in range(0, int(n / 2)):
	if line[i] != line[n - 1 - i]:
		l = min(l, i)
		r = max(r, i)
res = 0
if l == n and r == -1:
	res = 0
else:
	for i in range(l, r + 1):
		case1 = abs(ord(line[n - 1 - i]) - ord(line[i]))
		case2 = 26 - case1
		num = min(case1, case2)
		res += num
	res += min(abs(p - 1 - l), abs(p - 1 - r)) + r - l
print(res)


def main():
	from sys import stdin, stdout
	(n, o) = list(map(int, stdin.readline().split()))
	string = stdin.readline().strip()
	if n & 1:
		s1 = string[:n // 2]
		s2 = string[n // 2 + 1:]
		rev = s2[::-1]
		minim = 0
		indexlist = []
		for i in range(n // 2):
			k = abs(ord(s1[i]) - ord(rev[i]))
			minim += min(k, 26 - k)
			if k:
				indexlist.append(i)
		if o > n // 2:
			o = n - o
		else:
			o -= 1
		if len(indexlist):
			indexlist += [o]
			for i in range(len(indexlist)):
				indexlist[i] = indexlist[i] - o
			minia = min(indexlist)
			maxia = max(indexlist)
			minim += min(abs(minia), abs(maxia)) * 2 + max(abs(minia), abs(maxia))
		stdout.write(str(minim))
	else:
		s1 = string[:n // 2]
		s2 = string[n // 2:]
		rev = s2[::-1]
		minim = 0
		indexlist = []
		for i in range(n // 2):
			k = abs(ord(s1[i]) - ord(rev[i]))
			minim += min(k, 26 - k)
			if k:
				indexlist.append(i)
		if o > n // 2:
			o = n - o
		else:
			o -= 1
		if len(indexlist):
			indexlist += [o]
			for i in range(len(indexlist)):
				indexlist[i] = indexlist[i] - o
			minia = min(indexlist)
			maxia = max(indexlist)
			minim += min(abs(minia), abs(maxia)) * 2 + max(abs(minia), abs(maxia))
		stdout.write(str(minim))

def __starting_point():
	main()
__starting_point()


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

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

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

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	(n, k) = IP()
	k = k - 1
	s = input()
	mov = 0
	li = [0] * n
	if k < n // 2:
		for i in range(n // 2):
			if s[i] != s[n - i - 1]:
				(x, y) = (ord(s[i]), ord(s[n - i - 1]))
				li[i] = min(abs(max(x, y) - min(x, y)), abs(min(x, y) + 26 - max(x, y)))
	else:
		s = s[::-1]
		for i in range(n // 2):
			if s[i] != s[n - i - 1]:
				(x, y) = (ord(s[i]), ord(s[n - i - 1]))
				li[i] = min(abs(max(x, y) - min(x, y)), abs(min(x, y) + 26 - max(x, y)))
		k = n - 1 - k
	last = -1
	act = 0
	for i in range(k, -1, -1):
		if li[i] != 0:
			last = i
	if last != -1:
		for i in range(k, last - 1, -1):
			if li[i] != 0:
				act += li[i]
	last1 = -1
	act1 = 0
	for i in range(k + 1, n // 2):
		if li[i] != 0:
			last1 = i
	if last1 != -1:
		for i in range(k + 1, last1 + 1):
			if li[i] != 0:
				act1 += li[i]
		if last == -1:
			print(act1 + (last1 - k))
			return
	elif last != -1:
		print(act + (k - last))
		return
	else:
		print(0)
		return
	print(min(act + abs((k - last) * 2) + abs(last1 - k) + act1, act1 + abs((last1 - k) * 2) + act + abs(k - last)))
solve()


(n, p) = map(int, input().split())
s = [ord(c) for c in input()]
ans = 0
left = right = -1
for i in range(n // 2):
	diff = abs(s[i] - s[n - i - 1])
	ans += min(diff, 26 - diff)
	if s[i] != s[n - i - 1]:
		if left == -1:
			left = i
		right = i
if left == -1:
	print(0)
else:
	p -= 1
	n -= 1
	if p > n // 2:
		p = n - p
	ans += min(abs(p - left), abs(right - p))
	ans += right - left
	print(ans)


import math
(n, p) = [int(i) for i in input().split()]
word = [char for char in input()]
flag = True
psum = 0
s = 'abcdefghijklmnopqrstuvwxyz'
if p > n / 2:
	p = n + 1 - p
for i in range(1, math.floor(n / 2 + 1)):
	op = abs(s.find(word[i - 1]) - s.find(word[n - i]))
	if op:
		if flag:
			fir = i
			flag = False
		psum += min(op, 26 - op)
		las = i
if psum == 0:
	print('0')
elif fir >= p:
	print(las - p + psum)
elif las <= p:
	print(p - fir + psum)
else:
	print(min(2 * (p - fir) + las - p, 2 * (las - p) + p - fir) + psum)


from string import ascii_lowercase
from itertools import takewhile, dropwhile
(n, pos) = map(int, input().split())
m = {i: v for (v, i) in zip(range(1, 26 + 1), list(ascii_lowercase))}
s = list(map(lambda x: m[x], list(input())))
mid = [n // 2 + 1] if n % 2 == 1 else [n // 2, n // 2 + 1]
mid.extend([1, n])
pans = []
for i in range(n // 2):
	temp = abs(s[i] - s[i * -1 - 1])
	pans.append(min(abs(26 - temp), temp))
new_pos = pos if pos <= n // 2 else n - pos + 1
new_pos -= 1
mans = list(filter(lambda x: x[1] != 0, enumerate(pans)))
(pos_left, pos_right) = (min(new_pos, min(mans, default=(new_pos, 0))[0]), max(max(mans, default=(new_pos, 0))[0], new_pos))
(mn, mx) = sorted([new_pos - pos_left, pos_right - new_pos])
ans = mn * 2 + mx
print(sum(pans) + ans)


(n, p) = [int(x) for x in input().split()]
l = list(input())
flag = 0
if p > n // 2:
	flag = 1
ans = 0
p -= 1
ff = p
ffm = p
for i in range(n):
	if i > n - i - 1:
		break
	x = ord(l[i]) - 97
	y = ord(l[n - i - 1]) - 97
	if x != y:
		ans += min(abs(x - y), 26 - max(x, y) + min(x, y))
		if abs(p - i) < abs(p - (n - i - 1)):
			temp = i
		else:
			temp = n - i - 1
		ff = max(ff, temp)
		ffm = min(ffm, temp)
x = abs(p - ff)
y = abs(p - ffm)
res = min(x, y) * 2 + max(x, y)
print(ans + res)


import os
import sys
from io import BytesIO, IOBase
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')
from collections import Counter
import math
(n, pos) = map(int, input().split())
s = input()
anss = 0
f = 0
for i in range(n // 2):
	if s[i] != s[n - i - 1]:
		f = 1
		v1 = min(s[i], s[n - i - 1])
		v2 = max(s[i], s[n - i - 1])
		anss += min(ord(v2) - ord(v1), ord('z') - ord(v2) + 1 + ord(v1) - ord('a'))
if f == 0:
	print(0)
	exit()
if pos > n // 2:
	pos = n - pos + 1
ma = 0
mi = n
for i in range(n // 2):
	if s[i] != s[n - i - 1]:
		ma = max(ma, i)
		mi = min(mi, i)
if ma >= pos - 1 and mi <= pos - 1:
	print(min(2 * (ma - pos + 1) + pos - 1 - mi, 2 * (pos - 1 - mi) + ma - pos + 1) + anss)
elif ma <= pos - 1:
	print(pos - 1 - mi + anss)
else:
	print(ma - pos + 1 + anss)


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque

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

def mdata():
	return map(int, data().split())
(n, p) = mdata()
s = data()
p = min(p - 1, n - p)
ind1 = p
ind2 = p
k = 0
for i in range(n // 2):
	t = abs(ord(s[i]) - ord(s[n - 1 - i]))
	if t != 0:
		k += min(t, 26 - t)
		if i < ind2:
			ind2 = i
		elif i > ind1:
			ind1 = i
k += 2 * min(ind1 - p, p - ind2) + max(ind1 - p, p - ind2)
print(k)


(n, p) = map(int, input().split(' '))
s = list(input())
change = 0
leftchange = set()
rightchange = set()
p -= 1
for x in range(n // 2):
	if s[x] != s[n - x - 1]:
		leftchange.add(x)
		rightchange.add(n - x - 1)
	change += min(abs(ord(s[x]) - ord(s[n - x - 1])), ord(s[x]) + ord('z') - ord(s[n - x - 1]) - ord('a') + 1, ord('z') - ord(s[x]) + ord(s[n - x - 1]) - ord('a') + 1)
if len(leftchange) == 0:
	print(0)
elif p <= n // 2 - 1:
	if max(leftchange) <= p:
		print(p - min(leftchange) + change)
	elif min(leftchange) >= p:
		print(max(leftchange) - p + change)
	else:
		print(min(max(leftchange) - p + max(leftchange) - min(leftchange), p - min(leftchange) + max(leftchange) - min(leftchange)) + change)
elif max(rightchange) <= p:
	print(p - min(rightchange) + change)
elif min(rightchange) >= p:
	print(max(rightchange) - p + change)
else:
	print(min(max(rightchange) - p + max(rightchange) - min(rightchange), p - min(rightchange) + max(rightchange) - min(rightchange)) + change)


(n, p) = map(int, input().split())
l = list(input())
flag = 0
min1 = max1 = -1
sum = 0
for i in range(n // 2):
	if l[i] != l[n - 1 - i]:
		if flag == 0:
			min1 = i + 1
			flag = 1
		max1 = i + 1
		s1 = abs(ord(l[i]) - ord(l[n - 1 - i]))
		s2 = 26 - s1
		sum += min(s1, s2)
if p > n // 2:
	p = n + 1 - p
if max1 != -1:
	sum += min(abs(max1 - p), abs(p - min1))
	sum += max1 - min1
print(sum)


import math
(n, p) = map(int, input().split(' '))
S = input()
p = min(p - 1, n - p)
s1 = S[0:int(n / 2)]
s2 = S[-int(n / 2):]
s2 = s2[::-1]
if s1 == s2:
	print(0)
	return
l = int(n / 2)
r = 0
ans = 0
for i in range(0, int(n / 2)):
	if s1[i] != s2[i]:
		if i < l:
			l = i
		if i > r:
			r = i
		ans += int(min(abs(ord(s1[i]) - ord(s2[i])), abs(abs(ord(s1[i]) - ord(s2[i])) - 26)))
ans += int(abs(r - l) + min(abs(r - p), abs(l - p)))
print(ans)


(n, p) = map(int, input().split())
ans = 0
s = input()
for i in range(n // 2):
	a = []
	a.append(s[i])
	a.append(s[n - 1 - i])
	a.sort()
	ans += min(ord(a[1]) - ord(a[0]), ord('z') - ord(a[1]) + 1 + ord(a[0]) - ord('a'))
p -= 1
n -= 1
mid = n // 2
if p > mid:
	p = n - p
st = 0
e = mid
while s[st] == s[n - st] and st < n:
	st += 1
while s[e] == s[n - e] and e > 0:
	e -= 1
if st > e:
	print(0)
else:
	ans += min(abs(p - st), abs(e - p))
	ans += e - st
	print(ans)


(n, p) = list(map(int, input().split()))
l = input()
i = 0
j = n - 1
pos = []
ans = 0
while i <= j:
	if l[i] != l[j]:
		if abs(p - i) < abs(p - j):
			pos.append(i + 1)
		else:
			pos.append(j + 1)
		x = max(ord(l[i]), ord(l[j]))
		y = min(ord(l[i]), ord(l[j]))
		ans = ans + min(abs(x - y), abs(x - y - 26))
	i = i + 1
	j = j - 1
if len(pos) == 0:
	print(ans)
else:
	pmin = min(pos)
	pmax = max(pos)
	if pmin <= p and pmax <= p or (pmin >= p and pmax >= p):
		d = max(abs(p - pmin), abs(p - pmax))
		ans = ans + d
	else:
		d2 = min(abs(p - pmin), abs(p - pmax))
		d1 = max(abs(p - pmax), abs(p - pmin))
		ans = ans + 2 * d2 + d1
	print(ans)


(n, x) = map(int, input().split())
s = input()
a = [0] * (n // 2)
if n % 2 == 0:
	s1 = s[:n // 2]
	s2 = s[n // 2:]
else:
	s1 = s[:n // 2]
	s2 = s[n // 2 + 1:]
s2 = s2[::-1]
if s1 == s2:
	print(0)
	exit()
for i in range(n // 2):
	c = abs(ord(s1[i]) - ord(s2[i]))
	a[i] = min(26 - c, c)
ans = sum(a)
l = r = -1
if x > n // 2:
	x = abs(x - n)
else:
	x -= 1
for i in range(x):
	if a[i] != 0:
		l = i
		break
for i in range(x, n // 2):
	if a[i] != 0:
		r = i
if l == -1:
	ans += abs(x - r)
elif r == -1:
	ans += abs(x - l)
elif r != -1 and l != -1:
	ans += min(abs(x - r), abs(x - l))
	ans += abs(r - l)
print(ans)


(n, p) = map(int, input().strip().split())
arr = input()
lis = []
flag = 0
mins = -1
maxs = -1
f = 0
sums = 0
for x in range(n // 2):
	if arr[x] != arr[-(x + 1)]:
		if f == 0:
			mins = x
			f = 1
		if maxs < x:
			maxs = x
		if abs(ord(arr[x]) - ord(arr[-(x + 1)])) <= 13:
			sums += abs(ord(arr[x]) - ord(arr[-(x + 1)]))
		else:
			sums += 26 - abs(ord(arr[x]) - ord(arr[-(x + 1)]))
if n % 2 == 1:
	if p > n // 2 + 1:
		p = n - p + 1
elif p > n // 2:
	p = n - p + 1
if mins == -1:
	print('0')
else:
	if mins < p - 1 < maxs:
		sums += abs(maxs - mins) + min(abs(p - 1 - maxs), abs(p - 1 - mins))
	elif p - 1 <= mins:
		sums += abs(maxs - (p - 1))
	elif p - 1 >= maxs:
		sums += abs(p - 1 - mins)
	print(sums)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = input()
a = n // 2
ans = []
for i in range(0, a):
	ans.append(min(abs(ord(s[i]) - ord(s[n - i - 1])), 26 - abs(ord(s[i]) - ord(s[n - i - 1]))))
x = sum(ans)
if m > a:
	m = n + 1 - m
g1 = 0
g2 = a - 1
d = 0
for i in range(0, a):
	if ans[i] != 0:
		g1 = i
		d = 1
		break
for i in range(0, a):
	if ans[a - i - 1] != 0:
		g2 = a - i - 1
		d = 1
		break
g1 += 1
g2 += 1
if g1 == 1 and g2 == a and (d == 0):
	pass
elif m >= g2:
	x += m - g1
elif m <= g1:
	x += g2 - m
else:
	x += g2 - g1 + min(m - g1, g2 - m)
print(x)


(n, pos) = map(int, input().split())
s = input()
c = 0
indxi = []
indxj = []
if n > 1:
	i = 0
	j = n - 1
	while i < n // 2 and j >= n // 2:
		if s[i] != s[j]:
			indxi.append(i)
			indxj.append(j)
			c += min(abs(ord(s[i]) - ord(s[j])), abs(abs(ord(s[i]) - ord(s[j])) - 26))
		i += 1
		j -= 1
	if pos - 1 >= n // 2:
		if len(indxj) == 1:
			if indxj[0] != pos - 1:
				c += abs(indxj[0] - (pos - 1))
		elif len(indxj) > 1:
			minj = min(abs(min(indxj) - (pos - 1)), abs(max(indxj) - (pos - 1)))
			maxj = max(abs(min(indxj) - (pos - 1)), abs(max(indxj) - (pos - 1)))
			if min(indxj) < pos - 1 and pos - 1 < max(indxj):
				c += 2 * minj + maxj
			elif pos - 1 == min(indxj) or pos - 1 == max(indxj):
				c += abs(min(indxj) - max(indxj))
			elif pos - 1 > max(indxj):
				c += abs(pos - 1 - min(indxj))
			else:
				c += abs(pos - 1 - max(indxj))
	elif len(indxi) == 1:
		if indxi[0] != pos - 1:
			c += abs(indxi[0] - (pos - 1))
	elif len(indxi) > 1:
		mini = min(abs(min(indxi) - (pos - 1)), abs(max(indxi) - (pos - 1)))
		maxi = max(abs(min(indxi) - (pos - 1)), abs(max(indxi) - (pos - 1)))
		if min(indxi) < pos - 1 and pos - 1 < max(indxi):
			c += 2 * mini + maxi
		elif pos - 1 == min(indxi) or pos - 1 == max(indxi):
			c += abs(min(indxi) - max(indxi))
		elif pos - 1 > max(indxi):
			c += abs(pos - 1 - min(indxi))
		else:
			c += abs(pos - 1 - max(indxi))
	print(c)
else:
	print(0)


(n, p) = list(map(int, input().split()))
a = input()
if p > n // 2:
	a = a[::-1]
	p = n - p
else:
	p = p - 1
ans = 0
lo = hi = p
i = p
while i >= 0:
	if a[i] != a[n - i - 1]:
		lo = i
		mx = max(ord(a[i]) - ord('a') + 1, ord(a[n - i - 1]) - ord('a') + 1)
		mi = min(ord(a[i]) - ord('a') + 1, ord(a[n - i - 1]) - ord('a') + 1)
		ans += min(mx - mi, 26 - mx + mi)
	i -= 1
i = p + 1
while i < n // 2:
	if a[i] != a[n - i - 1]:
		hi = i
		mx = max(ord(a[i]) - ord('a') + 1, ord(a[n - i - 1]) - ord('a') + 1)
		mi = min(ord(a[i]) - ord('a') + 1, ord(a[n - i - 1]) - ord('a') + 1)
		ans += min(mx - mi, 26 - mx + mi)
	i += 1
xx = max(abs(lo - p), abs(hi - p))
yy = min(abs(lo - p), abs(hi - p))
ans += xx + 2 * yy
print(ans)


(n, p) = map(int, input().split())
p = p - 1
a = input()
fn = 0
ln = n // 2
sum_val = 0
allzero = True
flag = True
for i in range(n // 2):
	diff = abs(ord(a[i]) - ord(a[n - i - 1]))
	val = min(diff, 26 - diff)
	sum_val += val
	if val == 0 and flag:
		fn += 1
	else:
		flag = False
	if val != 0:
		ln = i
		allzero = False
if p >= n // 2:
	p = n - p - 1
if allzero:
	print(0)
elif p > ln:
	print(sum_val + p - fn)
elif p < fn:
	print(sum_val + ln - p)
else:
	print(sum_val + min(ln - p, p - fn) + ln - fn)


(n, c) = map(int, input().split())
s = input()
ans = 0
first = n - 1
last = 0
for i in range(n // 2):
	if s[i] != s[n - i - 1]:
		first = min(first, i)
		last = max(last, i)
		a = ord(s[i]) - 97
		b = ord(s[n - i - 1]) - 97
		change = min(a, b) + 26 - max(a, b)
		ans += min(abs(b - a), change)
if c == n // 2:
	ans += n // 2 - first
elif c < n // 2:
	c -= 1
	a = c - min(c, first)
	b = max(c, last) - c
	ans += a + b + min(a, b)
else:
	c = n - c
	a = c - min(c, first)
	b = max(c, last) - c
	ans += a + b + min(a, b)
print(max(0, ans))


(n, p) = map(int, input().split())
p -= 1
if p >= n // 2:
	p = n - 1 - p
chars = input()
tmp = [abs(ord(chars[i]) - ord(chars[n - 1 - i])) for i in range(n // 2)]
tmp = [min(x, 26 - x) for x in tmp]
(val1, val2) = (-1, -1)
for i in range(len(tmp)):
	if tmp[i] > 0:
		if val1 == -1:
			val1 = i
		val2 = i
a = 0 if val1 == -1 else min(abs(p - val1), abs(p - val2)) + (val2 - val1) + sum(tmp)
print(a)


import sys
from math import log2, floor, ceil, sqrt, gcd
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 = 1000000007

def solve(a, b):
	a = ord(a)
	b = ord(b)
	return min(abs(a - b), 26 - abs(a - b))
(n, k) = Ri()
k -= 1
st = ri()
ans = 0
if k > ceil(n / 2) - 1:
	st = st[::-1]
	k = n - 1 - k
if k < n // 2:
	endr = k
	summr = 0
	for i in range(k, ceil(n / 2)):
		if st[i] != st[n - i - 1]:
			summr += solve(st[i], st[n - i - 1])
			endr = i
	endl = k
	summl = 0
	for i in range(k - 1, -1, -1):
		if st[i] != st[n - i - 1]:
			summl += solve(st[i], st[n - i - 1])
			endl = i
	if endr == -1 and endl == -1:
		ans = 0
	elif endr == -1:
		ans = summl + k - endl
	elif endl == -1:
		ans = summr + endr - k
	else:
		ans = min(summr + summl + (endr - k) + endr - endl, summr + summl + (k - endl) + endr - endl)
print(ans)


(n, s) = [int(i) for i in input().split()]
st = input()
mid = n // 2
if s > mid:
	s = n - s
else:
	s -= 1
diff = 0
lis = []
for i in range(mid):
	if st[i] != st[n - 1 - i]:
		t1 = ord(st[i]) - 97
		t2 = ord(st[n - 1 - i]) - 97
		test1 = t2 - t1
		if test1 < 0:
			test1 += 26
		test2 = t1 - t2
		if test2 < 0:
			test2 += 26
		diff += min(test1, test2)
		lis.append(i)
before = []
after = []
for i in lis:
	if i < s:
		before.append(i)
	elif i > s:
		after.append(i)
mi = ma = -1
if len(before) > 0:
	mi = min(before)
if len(after) > 0:
	ma = max(after)
if mi == -1 or ma == -1:
	m = max(mi, ma)
	if m != -1:
		diff += abs(s - m)
else:
	d1 = s - mi
	d2 = ma - s
	if d2 <= d1:
		diff += 2 * d2 + d1
	else:
		diff += 2 * d1 + d2
print(diff)


(n, p) = map(int, input().split())
s = input().rstrip()
p = min(p, n - p + 1)
Count = 0
M = l = r = X = p
for i in range(0, n // 2):
	C = min(abs(ord(s[i]) - ord(s[-i - 1])), abs(ord('z') - max(ord(s[i]), ord(s[-i - 1])) + min(ord(s[i]), ord(s[-i - 1])) - ord('a') + 1) % 26)
	if C > 0:
		if i + 1 < p:
			if M == p:
				M = i + 1
			l = i + 1
		elif i + 1 > p and r == p:
			r = i + 1
		X = i + 1
	Count += C
print(Count + min(abs(X - p) + X - M, X + p - M * 2))


import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf

def getInt():
	return int(sys.stdin.readline().rstrip())

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	sys.stdout.write()
	pass

def getMirrorChar(string, curpos):
	finalPos = len(string) - 1
	palPos = finalPos - curpos
	return palPos
ASCIICONV = 97

def calcChange(a, b):
	x = ord(a) - ASCIICONV
	y = ord(b) - ASCIICONV
	return min((x - y) % 26, (y - x) % 26)

def solve(size, initPos, k):
	initPos -= 1
	ans = []
	moves = 0
	string = [i for i in k]
	if initPos >= size // 2:
		initPos = getMirrorChar(string, initPos)
	curPos = initPos
	lastSwitch = initPos
	while curPos < size // 2:
		otherChar = getMirrorChar(string, curPos)
		if string[curPos] != string[otherChar]:
			moves += calcChange(string[curPos], string[otherChar]) + abs(curPos - lastSwitch)
			string[otherChar] = string[curPos]
			lastSwitch = curPos
		curPos += 1
	while curPos > -1:
		otherChar = getMirrorChar(string, curPos)
		if string[curPos] != string[otherChar]:
			moves += calcChange(string[curPos], string[otherChar]) + abs(curPos - lastSwitch)
			string[otherChar] = string[curPos]
			lastSwitch = curPos
		curPos -= 1
	ans.append(moves)
	moves = 0
	curPos = initPos
	lastSwitch = initPos
	string = [i for i in k]
	while curPos > -1:
		otherChar = getMirrorChar(string, curPos)
		if string[curPos] != string[otherChar]:
			moves += calcChange(string[curPos], string[otherChar]) + abs(curPos - lastSwitch)
			string[otherChar] = string[curPos]
			lastSwitch = curPos
		curPos -= 1
	curPos = initPos
	while curPos < size // 2:
		otherChar = getMirrorChar(string, curPos)
		if string[curPos] != string[otherChar]:
			moves += calcChange(string[curPos], string[otherChar]) + abs(curPos - lastSwitch)
			string[otherChar] = string[curPos]
			lastSwitch = curPos
		curPos += 1
	ans.append(moves)
	return min(ans)

def readinput():
	(size, initPos) = getInts()
	k = [i for i in getString()]
	print(solve(size, initPos, k))
readinput()


(n, p) = map(int, input().split())
w = list(input())
d = []
done = []
for i in range(n // 2):
	if w[i] != w[-i - 1]:
		temp = int(abs(ord(w[i]) - ord(w[-i - 1])))
		d.append(min(temp, 26 - temp))
		done.append(i)
if p <= n // 2:
	p -= 1
else:
	p = n - p
if len(done) == 0:
	print(0)
else:
	a = min(done)
	b = max(done)
	ans = sum(d)
	ans += min(abs(p - a), abs(b - p)) + (b - a)
	print(ans)


(n, p) = map(int, input().split())
s = input()
p = n - p if p > n // 2 else p - 1
(left, right, steps) = (n // 2, -1, 0)
for i in range(n // 2):
	x = abs(ord(s[i]) - ord(s[-i - 1]))
	steps += min(x, 26 - x)
	if x != 0:
		left = min(left, i)
		right = max(right, i)
if steps:
	print(steps + right - left + min(abs(p - left), abs(right - p)))
else:
	print(0)


import math

def min_dist(c1, c2):
	g = abs(ord(c1) - ord(c2))
	return min(g, 26 - g)
(length, p) = [int(k) for k in input().split()]
s = str(input())
s = ' ' + s
mid = int(len(s) / 2)
if p > mid:
	p = len(s) - p
diff = [0] * (length + 1)
for i in range(1, mid + 1):
	if s[i] != s[length - i + 1]:
		diff[i] = 1
		diff[length - i + 1] = 1
left = 0
right = 0
for i in range(1, p):
	if diff[i] == 1:
		left = p - i
		break
g = mid
if length % 2 == 1:
	g = g - 1
for i in range(g, p, -1):
	if diff[i] == 1:
		right = i - p
		break
if left >= right:
	horizontal = 2 * right + left
else:
	horizontal = 2 * left + right
vertical = 0
for i in range(1, mid + 1):
	if diff[i] == 1:
		vertical += min_dist(s[i], s[length - i + 1])
print(horizontal + vertical)


import sys

def find_cost(a, b):
	ch = 'abcdefghijklmnopqrstuvwxyz'
	min_cost = sys.maxsize
	(a, b) = (min(a, b), max(a, b))
	c = ch.index(b) - ch.index(a)
	d = 25 - ch.index(b) + (ch.index(a) - 0) + 1
	return int(min(c, d))
(n, k) = map(int, input().split())
st = input()
mid = (n + 1) // 2
(s, e) = (int(), int())
ans = 0
if k <= mid:
	(s, e) = (1, mid)
	if n % 2:
		e -= 1
		if k == mid:
			k -= 1
			ans += 1
else:
	(s, e) = (mid + 1, n)
j = 0
if s == 1:
	j = n
elif n % 2:
	j = s - 2
else:
	j = s - 1
cost = [0] * (n + 5)
s = int(s)
e = int(e)
for i in range(int(s), int(e + 1)):
	cost[i] = find_cost(st[i - 1], st[-i])
if sum(cost) == 0:
	print(0)
	exit(0)
(f, l) = (0, 0)
(ff, ll) = (k, k)
for i in range(k, e + 1):
	if cost[i] != 0:
		ll = i
for i in range(s, k + 1):
	if cost[i] != 0:
		ff = i
		break
cst = sum(cost[ff:ll + 1]) + ll - ff + min(k - ff, ll - k)
ans += cst
print(ans)


from collections import Counter
import itertools
from functools import lru_cache
import sys
import math

def helper():
	pass

def cyclicDistance(ax, bx):
	(a, b) = (ord(ax) - ord('a'), ord(bx) - ord('a'))
	if a > b:
		(a, b) = (b, a)
	return min(b - a, a + (26 - b % 26))

def solve():
	(n, p) = map(int, input().split(' '))
	p -= 1
	s = input()
	(lfal, rfal) = ([], [])
	if not (p >= 0 and p <= n // 2):
		p = n - 1 - p
	(fs, fw) = (0, 0)
	if n % 2 == 0 and p == n // 2:
		p -= 1
	for i in range(p, n // 2):
		if s[i] != s[n - 1 - i]:
			fs += cyclicDistance(s[i], s[n - 1 - i])
			fw = i - p
	(bs, bw) = (0, 0)
	for i in range(p, -1, -1):
		if s[i] != s[n - 1 - i]:
			bs += cyclicDistance(s[i], s[n - 1 - i])
			bw = p - i
	ans = bs + fs - cyclicDistance(s[p], s[n - 1 - p]) + 2 * min(fw, bw) + max(fw, bw)
	print(ans)
t = 1
for _ in range(t):
	solve()


(n, p) = input().split()
n = int(n)
p = int(p)
s = input()
p -= 1
c = 0
p = min(p, n - 1 - p)
l = p
r = p
for i in range(p - 1, -1, -1):
	if s[i] != s[n - i - 1]:
		l = i
		c += min(abs(ord(s[i]) - ord(s[n - i - 1])), abs(26 - abs(ord(s[i]) - ord(s[n - i - 1]))))
for i in range(p, int(n / 2)):
	if s[i] != s[n - i - 1]:
		r = i
		c += min(abs(ord(s[i]) - ord(s[n - i - 1])), abs(26 - abs(ord(s[i]) - ord(s[n - i - 1]))))
l = p - l
r = r - p
c += 2 * min(l, r) + max(l, r)
print(c)


(n, pos) = map(int, input().split())
pos -= 1
s = input().rstrip()
cost = [0] * n
(left, right) = ([], [])
for i in range(n // 2):
	cost[i] = abs(ord(s[i]) - ord(s[n - i - 1]))
	cost[i] = min(cost[i], abs(26 - cost[i]))
	cost[n - i - 1] = cost[i]
	if cost[i]:
		left.append(i)
		right.append(n - i - 1)
if pos > n // 2:
	pos = n - pos - 1
if not left:
	print(0)
	exit()
if left[0] >= pos:
	ret = left[-1] - pos
elif left[-1] <= pos:
	ret = pos - left[0]
else:
	ret = min(left[-1] - pos + left[-1] - left[0], pos - left[0] + left[-1] - left[0])
print(min(ret, right[0] - pos) + sum(cost) // 2)


(n, p) = map(int, input().strip().split())
p = p - 1
A = input().strip()
s1 = 0
p1 = 0
p2 = float('Inf')
for i in range(int(len(A) // 2)):
	if A[i] != A[-1 * i - 1]:
		if i > p1:
			p1 = i
		if i < p2:
			p2 = i
		a = ord(A[i]) - ord(A[-1 * i - 1])
		s1 += min([a % 26, -1 * a % 26])
if p2 == float('Inf'):
	print(0)
else:
	if p >= len(A) // 2:
		(p2, p1) = (len(A) - p1 - 1, len(A) - p2 - 1)
	if p > p1 and p > p2:
		s1 += max([p - p2, p - p1])
	elif p < p1 and p < p2:
		s1 += max([p1 - p, p2 - p])
	else:
		s1 += 2 * min([p1 - p, p - p2]) + max([p1 - p, p - p2])
	print(s1)


f = lambda c: ord(c) - ord('a')
dalp = lambda x, y: min(abs(x - y), abs(x + 26 - y), abs(y + 26 - x))
dist = lambda i, j: min(abs(i - j), abs(i + n - j), abs(j + n - i))
read = lambda : list(map(int, input().split()))
(n, p) = read()
a = [f(i) for i in input()]
(pr, sf) = ([], [])
cnt = 0
for i in range(n // 2):
	if a[i] != a[n - i - 1]:
		cnt += dalp(a[i], a[n - i - 1])
		pr.append(i)
		sf.append(n - i - 1)
if pr:
	p -= 1
	d1 = dist(pr[0], pr[-1])
	d2 = min(dist(p, pr[0]), dist(p, pr[-1]), dist(p, sf[0]), dist(p, sf[-1]))
	cnt += d1 + d2
print(cnt)


(n, k) = map(int, input().split(' '))
s = input()
cnt = 0
hs = [0] * n
for i in range(n // 2):
	if s[i] != s[n - i - 1]:
		hs[i] = min(abs(ord(s[i]) - ord(s[n - i - 1])), 26 - abs(ord(s[i]) - ord(s[n - i - 1])))
		hs[n - i - 1] = hs[i]
cnt = 0
mind = -1
mxind = -1
if k <= n // 2:
	for i in range(n // 2):
		if hs[i] != 0:
			mxind = i
			cnt += hs[i]
		if hs[i] != 0 and mind == -1:
			mind = i
	if mxind != -1:
		print(cnt + mxind - mind + min(abs(mxind - k + 1), abs(mind - k + 1)))
	else:
		print(0)
else:
	for i in range(n // 2, n):
		if hs[i] != 0:
			mxind = i
			cnt += hs[i]
		if hs[i] != 0 and mind == -1:
			mind = i
	if mxind != -1:
		print(cnt + mxind - mind + min(abs(mxind - k + 1), abs(mind - k + 1)))
	else:
		print(0)


(n, p) = map(int, input().split())
s = input()
l = 0
r = n - 1
ans = 0
a = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for i in range(26):
	dic[a[i]] = i + 1
dis = []
left = {}
right = {}
while l < r:
	if s[l] != s[r]:
		ans += min(abs(dic[s[l]] - dic[s[r]]), 26 - abs(dic[s[l]] - dic[s[r]]))
		left[l] = 1
		right[r] = 1
	l += 1
	r -= 1
l = 0
r = 0
p -= 1
if p <= n // 2 - 1:
	for i in range(n // 2):
		if i <= p and i in left and (p - i > l):
			l = p - i
		elif i > p and i in left and (i - p > r):
			r = i - p
	ans += min(2 * r + l, 2 * l + r)
elif p >= n // 2:
	for i in range(n // 2, n):
		if i <= p and i in right and (p - i > l):
			l = p - i
		elif i > p and i in right and (i - p > r):
			r = i - p
	ans += min(2 * r + l, 2 * l + r)
print(ans)


import sys
from array import array

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
(n, p) = map(int, input().split())
p -= 1
s = [ord(c) - 97 for c in input().rstrip()]
delta = [min(26 - abs(s[i] - s[n - i - 1]), abs(s[i] - s[n - i - 1])) for i in range(n)]
if max(delta) == 0:
	print(0)
	exit()
if n & 1 and p == n // 2:
	ans = sum(delta) // 2
	for i in range(n // 2 + 1):
		if delta[i] != 0:
			ans += n // 2 - i
			break
	print(ans)
	exit()
if p < n // 2:
	delta = delta[:n // 2]
else:
	delta = delta[n // 2:]
	p -= n // 2
n = len(delta)
ans = sum(delta)
l = min((i for i in range(n) if delta[i] != 0))
r = max((i for i in range(n) if delta[i] != 0))
print(ans + min(max(p - l, 0) * 2 + max(r - p, 0), max(p - l, 0) + max(r - p, 0) * 2))


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, p) = I()
s = input()
a = [0] * n
p -= 1
if p >= n // 2:
	p = n - p - 1
for i in range(n // 2):
	a[i] = abs(ord(s[i]) - ord(s[n - i - 1]))
	a[i] = a[n - i - 1] = min(a[i], 26 - a[i])
ind = 0
s = sum(a)
s = s // 2
if s == 0:
	print(0)
else:
	l = r = -1
	for i in range(n // 2):
		if a[i]:
			l = i
			break
	for j in range(n // 2 - 1, -1, -1):
		if a[j]:
			r = j
			break
	if p == l or p == r:
		print(s + (r - l))
	else:
		print(min(abs(l - p) + s + (r - l), abs(r - p) + s + (r - l)))


import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
s = input().rstrip()
if p >= n // 2:
	s = s[::-1]
	p = n + 1 - p
p -= 1
ans1 = 0
ans2 = 0
l = 10 ** 6
r = -1
for i in range(n // 2):
	if s[i] != s[n - 1 - i]:
		l = min(l, i)
		r = max(r, i)
use = set()
if l <= p <= r:
	if r != -1:
		for i in range(p, r + 1):
			if s[i] != s[n - 1 - i] and i not in use:
				ans1 += min(abs(ord(s[i]) - ord(s[n - 1 - i])), 26 - abs(ord(s[i]) - ord(s[n - 1 - i])))
				ans2 += min(abs(ord(s[i]) - ord(s[n - 1 - i])), 26 - abs(ord(s[i]) - ord(s[n - 1 - i])))
				use.add(i)
		ans1 += 2 * abs(r - p)
		ans2 += abs(r - p)
	if l != 10 ** 6:
		for i in range(p, l - 1, -1):
			if s[i] != s[n - 1 - i] and i not in use:
				ans1 += min(abs(ord(s[i]) - ord(s[n - 1 - i])), 26 - abs(ord(s[i]) - ord(s[n - 1 - i])))
				ans2 += min(abs(ord(s[i]) - ord(s[n - 1 - i])), 26 - abs(ord(s[i]) - ord(s[n - 1 - i])))
				use.add(i)
		ans1 += abs(p - l)
		ans2 += 2 * abs(p - l)
	ans = min(ans1, ans2)
	print(ans)
elif p <= l:
	if r != -1:
		for i in range(p, r + 1):
			if s[i] != s[n - 1 - i]:
				ans2 += min(abs(ord(s[i]) - ord(s[n - 1 - i])), 26 - abs(ord(s[i]) - ord(s[n - 1 - i])))
		ans2 += abs(r - p)
	print(ans2)
else:
	if l != 10 ** 6:
		for i in range(p, l - 1, -1):
			if s[i] != s[n - 1 - i]:
				ans1 += min(abs(ord(s[i]) - ord(s[n - 1 - i])), 26 - abs(ord(s[i]) - ord(s[n - 1 - i])))
		ans1 += abs(p - l)
	print(ans1)


def findMirror(counter, n):
	return n - counter - 1

def checkForward(counter, n, st):
	total = 0
	done = [0] * (n + 1)
	mid = int(n / 2)
	high = 0
	if counter <= mid:
		high = mid
	else:
		high = n - 1
	i = 0
	steps = 0
	while counter <= high:
		i = i + 1
		if done[counter] == 0:
			mirror = findMirror(counter, n)
			temp = abs(ord(st[counter]) - ord(st[mirror]))
			total = total + min(temp, 26 - temp)
			done[mirror] = 1
			if min(temp, 26 - temp) != 0:
				steps = i
		counter = counter + 1
	return (total, max(steps - 1, 0))

def checkBack(counter, n, st):
	total = 0
	done = [0] * (n + 1)
	mid = int(n / 2)
	low = 0
	if counter <= mid:
		low = 0
	else:
		low = mid
	i = 0
	steps = 0
	while counter >= low:
		i = i + 1
		if done[counter] == 0:
			mirror = findMirror(counter, n)
			temp = abs(ord(st[counter]) - ord(st[mirror]))
			total = total + min(temp, 26 - temp)
			done[mirror] = 1
			if min(temp, 26 - temp) != 0:
				steps = i
		counter = counter - 1
	return (total, max(steps - 1, 0))

def main():
	(n, start) = list(map(int, input().split()))
	st = input()
	(a, left) = checkBack(start - 1, n, st)
	(b, right) = checkForward(start - 1, n, st)
	startVal = abs(ord(st[start - 1]) - ord(st[findMirror(start - 1, n)]))
	startVal = min(startVal, 26 - startVal)
	print(a + b + left + right + min(left, right) - startVal)
main()


(n, p) = [int(x) for x in input().split()]
Estrin = input()
steps = 0
pwasmid = False
parin = 0
if len(Estrin) > 1:
	if len(Estrin) % 2 == 0:
		par = True
	else:
		par = False
		parin = 1
	if par and p > n // 2:
		p = n - p + 1
	if par == False and p > n // 2 + 1:
		p = n - p + 1
	(first, second) = (Estrin[:len(Estrin) // 2], Estrin[len(Estrin) // 2 + parin:])
	first = first[::-1]
	p = len(first) - p
	x = [False] * len(first)
	flag = False
	minerr = 0
	maxerr = p
	flagmin = False
	flagmax = False
	for i in range(0, len(first)):
		if ord(first[i]) != ord(second[i]):
			x[i] = True
			if abs(ord(first[i]) - ord(second[i])) > 13:
				steps += 26 - abs(ord(first[i]) - ord(second[i]))
			else:
				steps += abs(ord(first[i]) - ord(second[i]))
			if flagmax == False:
				flagmax = True
			maxerr = i
			if flagmin == False:
				flagmin = True
				minerr = i
	if flagmin == False or flagmax == False:
		if flagmin == False:
			minerr = p
		if flagmax == False:
			maxerr = p
	if par == False and (flagmin == True or flagmax == True) and pwasmid:
		steps += 1
	if minerr <= p and maxerr >= p:
		right = maxerr - p + (maxerr - minerr)
		left = p - minerr + (maxerr - minerr)
		steps += min(right, left)
	elif minerr < p and maxerr < p:
		steps += p - minerr
	elif minerr > p and maxerr > p:
		steps += maxerr - p
else:
	steps = 0
print(steps)


import math
(l, p) = map(int, input().split())
s = input()
(p1, p2, f) = (0, 0, 1)
m = 0
for i in range(l // 2):
	if s[i] == s[l - i - 1]:
		continue
	else:
		if m == 0:
			p1 = i
			f = 0
		v = abs(ord(s[i]) - ord(s[l - i - 1]))
		if v > 13:
			m += 26 - v
		else:
			m += v
		p2 = i
if p > l // 2:
	p = l - p
	v = min(abs(p2 - p), abs(p - p1))
	if p1 == 0 and p2 == 0 and (f == 1):
		v = 0
	print(m + abs(p2 - p1) + v)
else:
	(v, p1, p2) = (0, p1 + 1, p2 + 1)
	v += min(abs(p - p1), abs(p - p2))
	if p1 == 1 and p2 == 1 and (f == 1):
		v = 0
	print(m + abs(p2 - p1) + v)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from math import inf

def main():
	(n, cursor) = map(lambda x: int(x), input().split())
	cursor -= 1
	string = input()
	presses = 0
	(leftmost, rightmost) = (inf, -inf)
	comparingRange = range(n // 2) if cursor < n // 2 else range(n // 2, n)
	for i in comparingRange:
		if string[i] != string[~i]:
			distance = abs(ord(string[i]) - ord(string[~i]))
			if distance > 13:
				distance = 26 - distance
			presses += distance
			if i < leftmost:
				leftmost = i
			if i > rightmost:
				rightmost = i
	if leftmost != inf and rightmost != -inf:
		presses += min(abs(leftmost - cursor), abs(rightmost - cursor)) + (rightmost - leftmost)
	print(presses)
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')
input = lambda : sys.stdin.readline().rstrip('\r\n')

def print(*args, **kwargs):
	sep = kwargs.pop('sep', ' ')
	file = kwargs.pop('file', sys.stdout)
	atStart = True
	for x in args:
		if not atStart:
			file.write(sep)
		file.write(str(x))
		atStart = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
main()


(n, p) = map(int, input().split())
t = input()
k = n // 2
d = [0] * (k + 1)
for i in range(k):
	d[i] = abs(ord(t[i]) - ord(t[n - i - 1]))
	if 2 * d[i] > 26:
		d[i] = 26 - d[i]
p = n - p if p > k else p - 1
if d.count(0) == k + 1:
	print(0)
else:
	(i, j) = (0, k)
	while d[i] == 0:
		i += 1
	while d[j] == 0:
		j -= 1
	if i > p:
		i = p
	if j < p:
		j = p
	print(sum(d) + min(p - 2 * i + j, 2 * j - i - p))


(n, p) = map(int, input().split())
s = input()
res = 0
left = 10 ** 9
right = 0
for i in range(n // 2):
	if s[i] != s[n - i - 1]:
		if p < n // 2:
			if i < p:
				left = min(left, i)
			else:
				right = max(right, i)
		elif i < n - p + 1:
			left = min(left, i)
		else:
			right = max(right, i)
		res += min(abs(ord(s[i]) - ord(s[n - i - 1])), abs(ord(s[i]) - ord('a') + 1 + ord('z') - ord(s[n - i - 1])), abs(ord('z') - ord(s[i]) + 1 + ord(s[n - i - 1]) - ord('a')))
if p > n // 2:
	p = n - p + 1
if left == 10 ** 9 and right == 0:
	pass
elif left == 10 ** 9:
	res += right - p + 1
elif right == 0:
	res += p - left - 1
else:
	res += right - left + min(right + 1 - p, p - 1 - left)
print(res)


(n, p) = map(int, input().split())
ans = [0] * n
if p > (n + 1) // 2:
	p = ~(p - 1) % n + 1
s = input()
for i in range(n // 2):
	ans[i] = ans[~i] = min((ord(s[i]) - ord(s[~i])) % 26, (ord(s[~i]) - ord(s[i])) % 26)
fz = 0
while fz < n and ans[fz] == 0:
	fz += 1
lz = n // 2 - 1
while lz >= 0 and ans[lz] == 0:
	lz -= 1
lz = n // 2 - 1 - lz
if fz == n:
	exit(print(0))
res = sum(ans) // 2
goleft = max(0, p - 1 - fz)
goright = max(0, n // 2 - p - lz)
if goright == 0:
	res += goleft
elif goleft == 0:
	res += goright
else:
	res += min(goleft * 2 + goright, goright * 2 + goleft)
print(res)


def dc(c, d):
	(x, y) = (ord(c) - ord('a'), ord(d) - ord('a'))
	return min(abs(x - y), 26 - max(x, y) + min(x, y))

def ds(s1, s2):
	r = 0
	(a, b) = (10 ** 5, -1)
	for i in range(len(s1)):
		(c, d) = (s1[i], s2[i])
		r += dc(c, d)
		if c != d:
			a = min(a, i)
			b = max(b, i)
	return (a, b, r)
(n, p) = list(map(int, input().split()))
s = input()
p -= 1
m = n // 2
y = m + (1 if n % 2 else 0)
(s1, s2) = (s[:m], s[y:][::-1])
(a, b, r) = ds(s1, s2)
d1 = min(abs(p - a), abs(p - b)) + abs(a - b)
d2 = min(abs(p - y - m + 1 + a), abs(p - y - m + 1 + b)) + abs(a - b)
if r == 0:
	print(0)
else:
	print(min(d1, d2) + r)


(n, p) = map(int, input().split())
s = input()
ans = []
for i in range(len(s)):
	ans.append(s[i])
sm1 = 0
la1 = 0
flag = 0
for i in range(len(ans) // 2):
	if ans[i] != ans[-1 * (i + 1)] and flag == 0:
		sm1 = i + 1
		flag = 1
	if ans[i] != ans[-1 * (i + 1)]:
		la1 = i + 1
if sm1 == 0:
	print(0)
	exit()
if len(ans) == 1:
	print(0)
	exit()
if p > len(ans) // 2:
	p = len(ans) + 1 - p
if p < sm1:
	count = 0
	for i in range(p - 1, la1):
		diff = max(ord(ans[i]), ord(ans[-1 * (i + 1)])) - min(ord(ans[i]), ord(ans[-1 * (i + 1)]))
		count += min(diff, 26 - diff)
	print(count + la1 - p)
elif sm1 <= p <= la1:
	count = la1 - sm1
	for i in range(sm1 - 1, la1):
		diff = max(ord(ans[i]), ord(ans[-1 * (i + 1)])) - min(ord(ans[i]), ord(ans[-1 * (i + 1)]))
		count += min(diff, 26 - diff)
	print(count + min(p - sm1, la1 - p))
else:
	count = 0
	for i in range(p - 1, sm1 - 2, -1):
		diff = max(ord(ans[i]), ord(ans[-1 * (i + 1)])) - min(ord(ans[i]), ord(ans[-1 * (i + 1)]))
		count += min(diff, 26 - diff)
	print(count + p - sm1)


(n, p) = [int(x) for x in input().split()]
p -= 1
atz = 'qwertyuiopasdfghjklzxcvbnm'
if len(atz) != 26:
	print('gone wrong')
d = {}
for i in atz:
	for j in atz:
		x = abs(ord(i) - ord(j))
		x = min(x, 26 - x)
		d[i, j] = x
s = input()
i = 0
j = len(s) - 1
m = (n + 1) // 2
if p >= m:
	p = n - 1 - p
	s = s[::-1]
revs = s[::-1]
cost = 0
while i < j:
	cost += d[s[i], s[j]]
	i += 1
	j -= 1
if cost == 0:
	print(cost)
	return
l = 0
while d[s[l], revs[l]] == 0:
	l += 1
r = n // 2 - 1
while d[s[r], revs[r]] == 0:
	r -= 1
cost += r - l + min(abs(l - p), abs(r - p))
print(cost)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, p) = map(int, input().split())
l = list(input())
p -= 1
k = n // 2
d = [0] * (k + 1)
for i in range(k):
	d[i] = min(abs(ord(l[i]) - ord(l[n - i - 1])), 26 - abs(ord(l[i]) - ord(l[n - i - 1])))
if p >= k:
	p = n - 1 - p
if sum(d) == 0:
	print(0)
	exit()
i = 0
j = k
while d[i] == 0:
	i += 1
while d[j] == 0:
	j -= 1
if i > p:
	i = p
if j < p:
	j = p
print(sum(d) + min(p - 2 * i + j, 2 * j - i - p))
endtime = time.time()


def distchar(a, b):
	a = ord(a) - ord('a')
	b = ord(b) - ord('a')
	if a > b:
		(a, b) = (b, a)
	return min(b - a, a + 26 - b)

def dist(i, p, n):
	if p >= i:
		sign = 1
	else:
		sign = -1
	return sign * min(abs(p - i), abs(n - 1 - i - p))
[n, p] = [int(s) for s in input().split()]
s = input().strip()
p = p - 1
count1 = 0
d = [0 for i in range(n)]
for i in range(n // 2):
	di = distchar(s[i], s[n - 1 - i])
	if di > 0:
		(d[i], d[n - 1 - i]) = (di, di)
		count1 += di
if p > n // 2:
	p = n - 1 - p
i1 = 0
while i1 < p and d[i1] == 0:
	i1 += 1
i2 = (n - 1) // 2
while i2 > p and d[i2] == 0:
	i2 -= 1
d1 = dist(i1, p, n)
d2 = dist(i2, p, n)
if d1 * d2 > 0:
	count = count1 + max(abs(d1), abs(d2))
else:
	count = count1 + 2 * min(abs(d1), abs(d2)) + max(abs(d1), abs(d2))
print(count)


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
import time
start_time = time.time()
import collections as col
import math
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	(N, P) = getInts()
	S = listStr()
	flag = False
	if P > N // 2:
		P = N - P
	else:
		P -= 1
	min_change = 10 ** 9
	max_change = -10 ** 9
	moves = 0
	for j in range(N // 2):
		if S[j] != S[N - j - 1]:
			ord1 = ord(S[j]) - ord('a')
			ord2 = ord(S[N - j - 1]) - ord('a')
			if ord1 > ord2:
				(ord1, ord2) = (ord2, ord1)
			moves += min(ord2 - ord1, ord1 + 26 - ord2)
			min_change = min(min_change, j)
			max_change = max(max_change, j)
	if not moves:
		return 0
	return moves + max_change - min_change + min(abs(P - min_change), abs(P - max_change))
print(solve())


from collections import defaultdict
from pprint import pprint
import sys
import time
from collections import Counter
from functools import total_ordering, lru_cache
from sys import stderr
from typing import Union
INF = 10 ** 18 + 3
EPS = 1e-10
MAX_CACHE = 10 ** 9

def time_it(function, output=stderr):

	def wrapped(*args, **kwargs):
		start = time.time()
		res = function(*args, **kwargs)
		elapsed_time = time.time() - start
		print('"%s" took %f ms' % (function.__name__, elapsed_time * 1000), file=output)
		return res
	return wrapped

@time_it
def main():
	(n, p) = map(int, input().split())
	p -= 1
	s = input()
	if p >= n // 2:
		s = s[::-1]
		p = n - p - 1
	left = INF
	right = 0
	n_shifts = [None] * (n // 2)
	for i in range(n // 2):
		difference = ord(s[i]) - ord(s[n - i - 1])
		n_shifts[i] = min(difference % 26, -difference % 26)
		if difference != 0:
			left = min(left, i)
			right = max(right, i)
	res = min(abs(p - left), abs(right - p)) + right - left
	for i in range(left, right + 1):
		res += n_shifts[i]
	if left == INF:
		res = 0
	print(res)

def set_input(file):
	global input
	input = lambda : file.readline().strip()

def set_output(file):
	global print
	local_print = print

	def print(*args, **kwargs):
		kwargs['file'] = kwargs.get('file', file)
		return local_print(*args, **kwargs)
set_input(open('input.txt', 'r') if 'MINE' in sys.argv else sys.stdin)
main()


(n, p) = map(int, input().split())
s = input()
ans = 0
if p > n // 2:
	s = s[::-1]
	p = n - p + 1
l = []
last = p
temp = p
l.extend(s)
while temp > 0:
	yo = min(abs(ord(s[temp - 1]) - ord(s[n - temp])), 26 - abs(ord(s[temp - 1]) - ord(s[n - temp])))
	ans += yo
	l[temp - 1] = l[n - temp]
	if yo:
		last = temp
	temp -= 1
last2 = p
temp = p + 1
while temp <= n // 2:
	yo = min(abs(ord(s[temp - 1]) - ord(s[n - temp])), 26 - abs(ord(s[temp - 1]) - ord(s[n - temp])))
	ans += yo
	if yo:
		last2 = temp
	temp += 1
ans += min(abs(p - last) * 2 + abs(last2 - p), abs(last2 - p) * 2 + abs(p - last))
print(ans)


import sys
(n, p) = map(int, input().split())
s = list(input())
p -= 1
k = n // 2
d = [0] * (k + 1)
for i in range(k):
	d[i] = min(abs(ord(s[i]) - ord(s[n - i - 1])), 26 - abs(ord(s[i]) - ord(s[n - i - 1])))
if p >= k:
	p = n - 1 - p
if sum(d) == 0:
	print(0)
else:
	(i, j) = (0, k)
	while d[i] == 0:
		i += 1
	while d[j] == 0:
		j -= 1
	if i > p:
		i = p
	if j < p:
		j = p
	print(sum(d) + min(p - 2 * i + j, 2 * j - i - p))


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

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 list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
T = 1
for _ in range(T):
	(n, p) = list(map(int, stdin.readline().rstrip().split()))
	s = list(stdin.readline().strip('\n'))
	ans = 0
	p -= 1
	P = p
	a = []
	d = {}
	ix = 1
	for i in 'abcdefghijklmnopqrstuvwxyz':
		d[i] = ix
		ix += 1
	if n % 2 == 1 and p > n // 2:
		p -= 1
	if p >= n // 2:
		p -= n // 2
	for i in range(n // 2):
		val = abs(d[s[i]] - d[s[n - i - 1]])
		if val == 0:
			a.append(0)
		else:
			a.append(1)
		ans += min(val, 26 - val)
	if P >= n // 2:
		a.reverse()
	(fi, li) = (-1, -1)
	for i in range(len(a)):
		if a[i] == 1:
			fi = i
			break
	for i in range(len(a) - 1, -1, -1):
		if a[i] == 1:
			li = i
			break
	if fi == -1 or li == -1:
		print(0)
		continue
	if fi < p and li > p:
		ans += min(abs(p + li - 2 * fi), abs(2 * li - p - fi))
	elif fi >= p:
		ans += abs(li - p)
	elif li <= p:
		ans += abs(p - fi)
	print(ans)


def palindrome_transformation(n, p, nams):
	current = p - 1
	half = n // 2
	if current >= half:
		current = n - current - 1
	weight = [0] * half
	for i in range(half):
		diff = abs(ord(nams[i]) - ord(nams[n - i - 1]))
		if diff > 13:
			diff = 26 - diff
		weight[i] = diff
	smallest_index = None
	biggest_index = None
	for (i, v) in enumerate(weight):
		if v != 0:
			smallest_index = i if smallest_index is None else min(i, smallest_index)
			biggest_index = i if biggest_index is None else max(i, biggest_index)
	if smallest_index is None or biggest_index is None:
		return 0
	return sum(weight) + biggest_index - smallest_index + min(abs(biggest_index - current), abs(current - smallest_index))
(n, p) = map(int, input().strip().split())
nams = input().strip()
print(palindrome_transformation(n, p, nams))


def dosomething(a, b):
	m1 = min(a, b)
	m2 = max(a, b)
	m1 = ord(m1) - 97
	m2 = 122 - ord(m2)
	return min(abs(ord(a) - ord(b)), m1 + m2 + 1)
arr = [int(x) for x in input().split()]
(n, k) = (arr[0], arr[1])
s = input()
mid = n // 2
if n == 1:
	print(0)
else:
	if n & 1 == 1:
		if k == mid:
			s1 = s[:mid]
			s2 = s[mid + 1:]
			ans = 2
		elif k > mid:
			s1 = s[mid + 1:]
			k -= mid + 1
			s2 = s[:mid]
			ans = 0
		else:
			s1 = s[:mid]
			s2 = s[mid + 1:]
			ans = 0
	elif k <= mid:
		s1 = s[:mid]
		s2 = s[mid:]
		ans = 0
	else:
		s1 = s[mid:]
		s2 = s[:mid]
		k -= mid
		ans = 0
	s2 = s2[::-1]
	if k >= len(s1) // 2:
		i = k - 1
		c = 0
		ans1 = ans
		last = 0
		while i < len(s1):
			if s1[i] != s2[i]:
				ans += c + dosomething(s1[i], s2[i])
				last = i
				c = 1
				i += 1
			else:
				c += 1
				i += 1
		i = k - 2
		c = 1
		if last != 0:
			ad = last - k + 1
		else:
			ad = 0
		while i >= 0:
			if s1[i] != s2[i]:
				ans += c + dosomething(s1[i], s2[i]) + ad
				ad = 0
				i -= 1
				c = 1
			else:
				c += 1
				i -= 1
		print(ans)
	else:
		i = k - 1
		c = 0
		ans1 = ans
		last = k - 1
		while i >= 0:
			if s1[i] != s2[i]:
				ans += c + dosomething(s1[i], s2[i])
				last = i
				c = 1
				i -= 1
			else:
				c += 1
				i -= 1
		i = k
		c = 1
		if last != k - 1:
			ad = k - 1 - last
		else:
			ad = 0
		while i < len(s1):
			if s1[i] != s2[i]:
				ans += c + dosomething(s1[i], s2[i]) + ad
				ad = 0
				i += 1
				c = 1
			else:
				c += 1
				i += 1
		print(ans)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
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')

class SegmentTree1:

	def __init__(self, data, default=9999999, func=lambda a, b: a | b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a * a + b * b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

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 countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, k) = map(int, input().split())
s = input()
k -= 1
if k > n // 2 - 1:
	k = n - 1 - k
ri = k
l = k
for i in range(k, n // 2):
	if s[i] == s[n - 1 - i]:
		continue
	else:
		ri = i
for i in range(k - 1, -1, -1):
	if s[i] != s[n - 1 - i]:
		l = i
tot = 2 * (ri - k) + 2 * (k - l) - max(ri - k, k - l)
for i in range(n // 2):
	t = ord(s[i])
	t1 = ord(s[n - 1 - i])
	if t < t1:
		tot += min(abs(t - t1), (t - t1) % 26)
	elif t > t1:
		tot += min(t - t1, 26 + t1 - t)
print(tot)


(n, p) = map(int, input().split())
p -= 1
a = list(input())
if p >= n // 2:
	p = n - 1 - p
leftSum = 0
mLeft = -1
rightSum = 0
mRight = p
for i in range((n + 1) // 2):
	if a[i] != a[n - 1 - i]:
		temp = min(abs(ord(a[i]) - ord(a[n - 1 - i])), 1 + ord('z') - max(ord(a[i]), ord(a[n - 1 - i])) + min(ord(a[i]), ord(a[n - 1 - i])) - ord('a'))
		if i <= p:
			if mLeft == -1:
				mLeft = i
			leftSum += temp
		else:
			mRight = i
			rightSum += temp
tot = rightSum + leftSum
if mLeft == -1:
	mLeft = p
print(min(2 * (p - mLeft) + mRight - p, p - mLeft + 2 * (mRight - p)) + tot)


import sys
import math as mt
import collections as cc

def ncr(n, r):
	import math as mt
	return mt.factorial(n) // (mt.factorial(n - r) * mt.factorial(r))
I = lambda : map(int, input().split())
(n, p) = I()
p = n - p if p > n // 2 else p - 1
s = input()
s = [ord(s[i]) for i in range(n)]
mi = n // 2
ma = -1
tot = 0
for i in range(n // 2):
	temp = abs(s[i] - s[n - i - 1])
	tot += min(temp, 26 - temp)
	if temp:
		mi = min(mi, i)
		ma = max(ma, i)
if not tot:
	print(0)
else:
	print(tot + abs(mi - ma) + min(abs(ma - p), abs(mi - p)))


from sys import stdin
import math

def check_pallindrome(string):
	i = 0
	j = len(string) - 1
	while i < j:
		if string[i] != string[j]:
			return False
		i += 1
		j -= 1
	return True

def magic(c, d):
	if ord(c) > ord(d):
		return min(ord(c) - ord(d), ord('z') - ord(c) + ord(d) - ord('a') + 1)
	else:
		(c, d) = (d, c)
		return min(ord(c) - ord(d), ord('z') - ord(c) + ord(d) - ord('a') + 1)

def difference(type, index, string, order):
	if type == 1:
		steps = 0
		mov = 0
		i = index
		j = len(string) - index - 1
		while i >= 0:
			if string[i] != string[j]:
				steps += magic(string[i], string[j])
				steps -= mov
				mov = index - i
				steps += mov
			j += 1
			i -= 1
		if check_pallindrome(string[index + 1:len(string) // 2] + string[len(string) // 2:len(string) - index - 1]) == False:
			if order:
				steps += mov
	elif type == 2:
		steps = 0
		mov = 0
		i = index
		j = len(string) - index - 1
		while i < len(string) // 2:
			if string[i] != string[j]:
				steps += magic(string[i], string[j])
				steps -= mov
				mov = i - index
				steps += mov
			j -= 1
			i += 1
		if check_pallindrome(string[:index] + string[len(string) - index:]) == False:
			if order:
				steps += mov
	return steps

def add(num):
	if num > 0:
		return num + 1
	return num

def remove_odd(string, p):
	n = len(string)
	if n % 2 == 1:
		if p > n // 2:
			p -= 1
		return (string[:n // 2] + string[n // 2 + 1:], p)
	else:
		return (string, p)
(n, p) = list(map(int, stdin.readline().split()))
string = stdin.readline().strip()
if len(string) == 1:
	print(0)
	exit()
count = 0
p = p - 1
if n % 2 == 1 and p == n // 2:
	count += 1
	p -= 1
(string, p) = remove_odd(string, p)
if p >= len(string) // 2:
	p = len(string) - p - 1
cnt_1 = difference(1, p, string, True) + add(difference(2, p + 1, string, False))
cnt_2 = difference(2, p, string, True) + add(difference(1, p - 1, string, False))
count += min(cnt_1, cnt_2)
print(count)


(n, p) = map(int, input().split())
s = input()
mid = n // 2 - 1
p -= 1
if p >= mid:
	s = s[::-1]
	p = n - p - 1
l = -1
r = -1
i = p
res = 0
while i >= 0:
	if s[i] != s[n - i - 1]:
		l = i
		diff = min(abs(ord(s[i]) - ord(s[n - i - 1])), 26 - abs(ord(s[i]) - ord(s[n - i - 1])))
		res += diff
	i -= 1
i = p + 1
while i <= mid:
	if s[i] != s[n - i - 1]:
		r = i
		diff = min(abs(ord(s[i]) - ord(s[n - i - 1])), 26 - abs(ord(s[i]) - ord(s[n - i - 1])))
		res += diff
	i += 1
if l == -1 and r == -1:
	print(0)
else:
	if r == -1:
		r = p
	if l == -1:
		l = p
	if p - l < r - p:
		res += 2 * (p - l)
		res += r - p
	else:
		res += p - l
		res += 2 * (r - p)
	print(res)


def finddistance(a, b):
	k1 = abs(122 - ord(b) + ord(a) - 96)
	k2 = abs(ord(b) - ord(a))
	k3 = abs(122 - ord(a) + ord(b) - 96)
	k4 = abs(ord(a) - ord(b))
	return min([k1, k2, k3, k4])
(n, p) = map(int, input().split())
s = list(input())
a = []
c = 0
d = 0
count = 0
for i in range(n // 2):
	if i == n - i - 1:
		pass
	elif s[i] != s[n - i - 1]:
		a.append(i)
div = n // 2
if p > div:
	p = n - p + 1
if len(a) == 0:
	print(0)
else:
	p -= 1
	last = 10 ** 6
	first = 10 ** 6
	if a[-1] >= p:
		last = a[-1] - p
	if a[0] <= p:
		first = p - a[0]
	mini = min(last, first)
	p1 = p
	if mini == first:
		c = 0
		while p1 >= a[0]:
			if count == 0:
				count = 1
			else:
				c += 1
			if s[p1] != s[n - p1 - 1]:
				c += finddistance(s[p1], s[n - p1 - 1])
				s[p1] = s[n - p1 - 1]
			p1 -= 1
		d = 0
		count = 0
		p1 += 1
		if a[-1] > p:
			while p1 <= a[-1]:
				if count == 0:
					count = 1
				else:
					d += 1
				if s[p1] != s[n - p1 - 1]:
					d += finddistance(s[p1], s[n - p1 - 1])
					s[p1] = s[n - p1 - 1]
				p1 += 1
	else:
		c = 0
		while p1 <= a[-1]:
			if count == 0:
				count = 1
			else:
				c += 1
			if s[p1] != s[n - p1 - 1]:
				c += finddistance(s[p1], s[n - p1 - 1])
				s[p1] = s[n - p1 - 1]
			p1 += 1
		d = 0
		p1 -= 1
		count = 0
		if a[0] < p:
			while p1 >= a[0]:
				if count == 0:
					count = 1
				else:
					d += 1
				if s[p1] != s[n - p1 - 1]:
					d += finddistance(s[p1], s[n - p1 - 1])
					s[p1] = s[n - p1 - 1]
				p1 -= 1
	print(c + d)


(n, p) = map(int, input().split())
string = input()

def palindrome_transformer(string, n, p):
	if n % 2 == 0:
		s_1 = string[0:int(n / 2)]
		s_2 = string[int(n / 2):len(string)]
		s_1_reversed = ''
		for numbers in range(int(len(string) / 2) - 1, -1, -1):
			s_1_reversed += s_1[numbers]
		score = 0
		different_elements = []
		for i in range(len(s_1)):
			if abs(ord(s_1_reversed[i]) - ord(s_2[i])) > 12:
				score += 26 - abs(ord(s_1_reversed[i]) - ord(s_2[i]))
				different_elements.append(1)
			else:
				if abs(ord(s_1_reversed[i]) - ord(s_2[i])) == 0:
					different_elements.append(0)
				else:
					different_elements.append(1)
				score += abs(ord(s_1_reversed[i]) - ord(s_2[i]))
		if p <= int(len(string) / 2):
			different_elements.reverse()
			start = 1
			for elements in different_elements:
				if elements == 1:
					break
				else:
					start += 1
			different_elements.reverse()
			end = int(len(string) / 2)
			for elements in different_elements:
				if elements == 1:
					break
				else:
					end -= 1
			if start == int(len(string) / 2) + 1 and end == 0:
				return 0
			score += max(p, end) - min(start, p) + min(max(end - p, 0), max(p - start, 0))
		else:
			p -= int(len(string) / 2)
			start = 1
			for elements in different_elements:
				if elements == 1:
					break
				else:
					start += 1
			different_elements.reverse()
			end = int(len(string) / 2)
			for elements in different_elements:
				if elements == 1:
					break
				else:
					end -= 1
			if start == int(len(string) / 2) + 1 and end == 0:
				return 0
			score += max(p, end) - min(start, p) + min(max(end - p, 0), max(p - start, 0))
		return score
	if n % 2 == 1:
		string_new = ''
		for i in range(len(string)):
			if i == int(len(string) / 2):
				continue
			else:
				string_new += string[i]
		if p > int(n / 2):
			p -= 1
			return palindrome_transformer(string_new, n - 1, p)
		elif p == int(n / 2):
			return palindrome_transformer(string_new, n - 1, p)
		else:
			return palindrome_transformer(string_new, n - 1, p)
print(palindrome_transformer(string, n, p))


def main():

	def parser():
		while 1:
			data = list(input().split(' '))
			for number in data:
				if len(number) > 0:
					yield number
	input_parser = parser()
	gets = lambda : next(input_parser)

	def getNum():
		data = gets()
		try:
			return int(data)
		except ValueError:
			return float(data)
	ALP_SIZE = 26
	(n, p) = (getNum(), getNum())
	p -= 1
	s = gets()
	(res, l, r) = (0, n, -1)
	for i in range(n // 2):
		t = abs(ord(s[i]) - ord(s[n - i - 1]))
		res += min(t, ALP_SIZE - t)
		if t > 0:
			pt = i
			if p >= n // 2:
				pt = n - i - 1
			l = min(l, pt)
			r = max(r, pt)
	if r < p:
		t = p - l
	elif p < l:
		t = r - p
	else:
		t = r - l + min(r - p, p - l)
	res = max(res + t, 0)
	print(res)
main()


(n, p) = map(int, input().split())
s = list(map(ord, input()))
if p > n // 2:
	p = n - p
else:
	p -= 1
l = n // 2
r = -1
ans = 0
for i in range(n // 2):
	d = abs(s[i] - s[n - i - 1])
	d = min(d, 26 - d)
	if d:
		l = min(l, i)
		r = max(r, i)
		ans += d
print(ans + r - l + min(abs(r - p), abs(l - p)) if ans else 0)