Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.

Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: [Image] 

After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.

Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.


-----Input-----

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.


-----Output-----

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.


-----Examples-----
Input
zeus

Output
18

Input
map

Output
35

Input
ares

Output
34



-----Note-----

  [Image] 

To print the string from the first sample it would be optimal to perform the following sequence of rotations:   from 'a' to 'z' (1 rotation counterclockwise),  from 'z' to 'e' (5 clockwise rotations),  from 'e' to 'u' (10 rotations counterclockwise),  from 'u' to 's' (2 counterclockwise rotations).  In total, 1 + 5 + 10 + 2 = 18 rotations are required.

Difficulty: EASY
Tags: String algorithms

Implementation

Starter code:

Solutions:
a = 'abcdefghijklmnopqrstuvwxyz'
d = {a[i]: i for i in range(0, len(a))}
w = input()
D = 0
p = 'a'
for l in w:
	D += min(abs(d[l] - d[p]), 26 - abs(d[l] - d[p]))
	p = l
print(D)


s = 'a' + input()
result = 0
for i in range(1, len(s)):
	now = ord(s[i]) - 97
	prev = ord(s[i - 1]) - 97
	result += min(abs(now - prev), 26 - abs(now - prev))
print(result)


n = input()
a = 'a'
t = 0
b = 0
for i in n:
	t = abs(ord(a) - ord(i))
	b += min(t, 26 - t)
	a = i
print(b)


n = input()
pos = 'a'
t = 0
ans = 0
for ch in n:
	t = abs(ord(pos) - ord(ch))
	ans += min(t, 26 - t)
	pos = ch
print(ans)


from sys import stdin
n = stdin.readline().strip().lower()
a = list('abcdefghijklmnopqrstuvwxyz')
b = list('zyxwvutsrqponmlkjihgfedcba')
cont = 0
m = 'a' + n
list(m)
for i in range(len(m) - 1):
	co = []
	lis = abs(a.index(m[i]) - a.index(m[i + 1]))
	lis1 = b.index(m[i]) + a.index(m[i + 1]) + 1
	lis2 = a.index(m[i]) + b.index(m[i + 1]) + 1
	co = [lis, lis1, lis2]
	cont += min(co)
print(cont)


a = input()
start = 0
input = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
i = [i for i in input]
l = {}
total = 0
for ii in range(26):
	l[i[ii]] = []
	l[i[ii]].append(i.index(i[ii]))
for ch in a:
	idx = l[ch][0]
	total = total + min(26 - abs(idx - start), abs(start - idx))
	start = idx
print(total)


x = 'a' + input()
sum = 0
for i in range(len(x) - 1):
	sum += min(abs(ord(x[i]) - ord(x[i + 1])), 26 - abs(ord(x[i]) - ord(x[i + 1])))
print(sum)


(tot, exhibit) = (0, 'a' + input())
for i in range(1, len(exhibit)):
	tot += min((ord(exhibit[i - 1]) - ord(exhibit[i])) % 26, (ord(exhibit[i]) - ord(exhibit[i - 1])) % 26)
print(tot)


from sys import stdin
w = stdin.readline()[:-1]
a = 'abcdefghijklmnopqrstuvwxyz'
(t, p) = (0, 0)
for l in w:
	for i in range(len(a) // 2):
		if p - i - 1 < -len(a):
			p += len(a)
		if p + i >= len(a):
			p -= len(a)
		if a[p + i] == l:
			t += i
			p = p + i
			break
		elif a[p - i - 1] == l:
			t += abs(-i - 1)
			p = p - i - 1
			break
print(t)


lis = input()
lis = list(lis)
i = 0
a = ord('a') - ord(lis[i])
if a < 0:
	a = a * -1
if a > 12:
	dist = 26 - a
else:
	dist = a
while i < len(lis) - 1:
	a = ord(lis[i]) - ord(lis[i + 1])
	if a < 0:
		a = a * -1
	if a > 12:
		steps = 26 - a
	else:
		steps = a
	i = i + 1
	dist = dist + steps
print(dist)


string = input()
sum = min(abs(ord(string[0]) - ord('a')), 26 - abs(ord(string[0]) - ord('a')))
for i in range(1, len(string)):
	distance = abs(ord(string[i]) - ord(string[i - 1]))
	check = 26 - distance
	sum += min(check, distance)
print(sum)


a = input()
cur = 'a'
kc = 0
count = 0
for i in range(len(a)):
	kc = abs(ord(a[i]) - ord(cur))
	if kc > 13:
		kc = 26 - kc
	count = count + kc
	cur = a[i]
print(count)


list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a = input()
l = [str(i) for i in str(a)]
l.insert(0, 'a')
l2 = []
d = len(list)
for i in range(len(l) - 1):
	a1 = l[i]
	a2 = l[i + 1]
	b = list.index(a1)
	c = list.index(a2)
	j = (b - c) % d
	k = (c - b) % d
	l2.append(min(j, k))
print(sum(l2))


s = list(map(ord, input()))
x = 0
count = 0
a = 97
for i in s:
	t = abs(a - i)
	count += min(t, 26 - t)
	a = i
print(count)


name = list(input())
lib = list('abcdefghijklmnopqrstuvwxyz')
lib.extend(lib)
flag = 0
total = 0
try:
	for temp in name:
		if flag < 13:
			flag += 26
		for i in range(14):
			if lib[flag + i] == temp or lib[flag - i] == temp:
				total += i
				break
		flag = lib.index(temp)
except Exception as e:
	print('<p>Error : %s</p>' % str(e))
print(total)


alpha = 'abcdefghijklmnopqrstuvwxyz'
l = len(alpha)
s = input()
k = 0
rot = 0
for c in s:
	index_of_c = alpha.index(c)
	rot += min(abs(index_of_c - k), l - abs(index_of_c - k))
	k = index_of_c
print(rot)


s = input()
current = 'a'
rotations = 0
for c in s:
	if c == current:
		continue
	x = ord(current) - ord('a')
	y = ord(c) - ord('a')
	rotations += min(abs(x - y), 26 - abs(x - y))
	current = c
print(rotations)


import string
alpha = string.ascii_lowercase

def min_dis(char1, char2):
	(c1, c2) = (min(char1, char2), max(char1, char2))
	(ind1, ind2) = (alpha.index(c1), alpha.index(c2))
	res = abs(ind2 - ind1)
	temp = 26 - ind2 + ind1
	if temp < res:
		res = temp
	return res
prev = 'a'
res = 0
for each_char in input():
	res += min_dis(prev, each_char)
	prev = each_char
print(res)


s = input()
k = len(s)
moves = 0
for i in range(k):
	if i != 0:
		a = s[i]
		b = s[i - 1]
		t = abs(ord(a) - ord(b))
		if t > 13:
			t = 26 - t
		moves += t
	else:
		t = abs(ord(s[0]) - ord('a'))
		if t > 13:
			t = 26 - t
		moves += t
print(moves)


s = input()
s = s.lower()
prev = 'a'
ans = 0
for i in range(len(s)):
	ans += min(abs(ord(s[i]) - ord(prev)), 26 - abs(ord(s[i]) - ord(prev)))
	prev = s[i]
print(ans)


s = 'a' + input()
ans = 0
for i in range(len(s) - 1):
	ans += min(abs(ord(s[i]) - ord(s[i + 1])), 26 - abs(ord(s[i]) - ord(s[i + 1])))
print(ans)


import sys

def distL(a, b):
	temp = ord(a) - ord(b)
	if temp < 0:
		return temp + 26
	else:
		return temp
fin = sys.stdin
fout = sys.stdout
s = 'a' + fin.readline().strip()
summ = 0
for i in range(1, len(s)):
	summ += min(distL(s[i], s[i - 1]), distL(s[i - 1], s[i]))
fout.write(str(summ))


text = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
letter_dict = {}
for i in range(len(alphabet)):
	letter_dict[alphabet[i]] = i + 1
actions = 0
now = 'a'
for letter in text:
	actions += min(abs(letter_dict[letter] - letter_dict[now]), letter_dict[letter] + 26 - letter_dict[now], letter_dict[now] + 26 - letter_dict[letter])
	now = letter
print(actions)


str = input()
str = 'a' + str
s = list(str)
n = len(s)
res = 0
for i in range(1, n):
	a = ord(s[i - 1])
	b = ord(s[i])
	d = min(abs(a - b), 26 - abs(a - b))
	res += d
print(res)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
c = 0
last = 'a'
for i in s:
	(x, y) = (min(alphabet.index(i), alphabet.index(last)), max(alphabet.index(i), alphabet.index(last)))
	(a, b) = (y - x, 26 - y + x)
	c += min(a, b)
	last = i
print(c)


s = str(input())
x = 0
pointer = 'a'
for i in range(len(s)):
	y = abs(ord(s[i]) - ord(pointer))
	if y > 13:
		x += 26 - y
	else:
		x += y
	pointer = s[i]
print(x)


key = list(map(ord, 'a' + input()))
ans = 0
for i in range(1, len(key)):
	t = abs(key[i] - key[i - 1])
	ans += min(t, 26 - t)
print(ans)


alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = input()
k = 0
curr_idx = 0
for letter in s:
	len1 = abs(curr_idx - alphabet.index(letter))
	len2 = curr_idx + 26 - alphabet.index(letter)
	len3 = 26 - curr_idx + alphabet.index(letter)
	k += min(len1, len2, len3)
	curr_idx = alphabet.index(letter)
print(k)


input_str = input()
efforts = 0
distance = 0
pointer_at = 97
for c in input_str:
	distance = abs(pointer_at - ord(c))
	if distance > 13:
		distance = 26 - distance
	efforts += distance
	pointer_at = ord(c)
print(efforts)


import string
s = input()
a = 'a'
ans = 0
for c in s:
	i = string.ascii_lowercase.index(c) - string.ascii_lowercase.index(a)
	i = abs(i)
	i = min(i, 26 - i)
	a = c
	ans += i
print(ans)


nme = input()
crnt = ord('a')
rots = 0
for each in nme:
	clokstps = abs(ord(each) - crnt)
	aticlkstps = abs(26 - clokstps)
	rots += min(clokstps, aticlkstps)
	crnt = ord(each)
print(rots)


s = input()
pointer = 'a'
sum = 0
for i in range(len(s)):
	dis = abs(ord(pointer) - ord(s[i]))
	if dis < 13:
		sum += dis
	else:
		sum = sum + (26 - dis)
	pointer = s[i]
print(sum)


s = input()
j = 97
count = 0
for i in range(len(s)):
	l = abs(abs(j - ord(s[i])) - 26)
	m = abs(ord(s[i]) - j)
	if m <= l:
		count += m
		j = ord(s[i])
	else:
		count += l
		j = ord(s[i])
print(count)


current_loc = ord('a')
word = input()
counter = 0
for i in word:
	a = abs(current_loc - ord(i))
	if a > 13:
		counter += abs(a - 26)
	else:
		counter += a
	current_loc = ord(i)
print(counter)


import math
a = 'abcdefghijklmnopqrstuvwxyz'
c = str(input())
b = 'a'
s = 0
for i in range(len(c)):
	if math.fabs(a.find(c[i]) - a.find(b)) > len(a) / 2:
		s += len(a) - math.fabs(a.find(c[i]) - a.find(b))
	else:
		s += math.fabs(a.find(c[i]) - a.find(b))
	b = b[0:0] + c[i]
print(int(s))


import sys
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())
s = insr()
order = [1] + [ord(i) - 96 for i in s]
diffs = [abs(t - s) if abs(t - s) < 14 else 26 - abs(t - s) for (s, t) in zip(order, order[1:])]
print(sum(diffs))


n = input()
i = 'a'
b = 0
s = 0
for j in n:
	b = abs(ord(i) - ord(j))
	s += min(b, 26 - b)
	i = j
print(s)


from sys import stdin

def main():
	palabra = stdin.readline().strip()
	pala = 'a' + palabra
	cont = 0
	for i in range(1, len(pala)):
		diferencia = abs(ord(pala[i]) - ord(pala[i - 1]))
		if diferencia > 13:
			diferencia = 26 - diferencia
		cont += diferencia
	print(cont)
main()


alphabet = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
alphabet = alphabet.split(' ')
n = input().strip()
cnt = 0
cur = 'a'
for i in n:
	distance = min(abs(alphabet.index(cur) - alphabet.index(i)), abs(26 - abs(alphabet.index(cur) - alphabet.index(i))))
	cnt = cnt + distance
	cur = i
print(cnt)


a = input()
tm = 0
for i in range(len(a)):
	if i == 0:
		x = abs(ord(a[i]) - ord('a'))
	else:
		x = abs(ord(a[i]) - ord(a[i - 1]))
	if x > 13:
		x = 26 - x
	tm += x
print(tm)


import copy

def main():
	name = [ord(it) - ord('a') for it in list(input())]
	rotations = 0
	word_pre = 0
	for word in name:
		rotations = rotations + min(abs(word - word_pre), abs(26 - abs(word - word_pre)))
		word_pre = word
	print(rotations)
main()


x = input()
y = 'abcdefghijklmnopqrstuvwxyz'
z = 'zyxwvutsrqponmlkjihgfedcba'
a = 0
k = 'a'
for i in x:
	o = y.index(i)
	p = y.index(k)
	u = min(abs(o - p), 26 - p + o, 26 - o + p)
	k = i
	a += u
print(a)


s = input().strip()
p = 0
l = 0
for i in s:
	c = ord(i) - ord('a')
	l += min(abs(p - c), 26 - abs(p - c))
	p = c
print(l)


c = 97
s = 0
for j in map(ord, input()):
	i = abs(c - j)
	s += min(i, 26 - i)
	c = j
print(s)


l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a = list(input())
sum = 0
for i in range(len(a)):
	if i == 0:
		p = l.index(a[i])
		if p > 13:
			sum += 26 - p
		else:
			sum += p
	else:
		p = abs(l.index(a[i]) - l.index(a[i - 1]))
		if p > 13:
			sum += 26 - p
		else:
			sum += p
print(sum)


a = input()
s = 'abcdefghijklmnopqrstuvwxyz'
first_index = 1
second_index = 0
final = 0
for i in range(len(a)):
	second_index = s.find(a[i]) + 1
	final += min(abs(second_index - first_index), len(s) - abs(second_index - first_index))
	first_index = second_index
print(final)


n = input().lower()
steps = 0
dbc = [abs(ord('a') - ord(n[0]))]
for i in range(len(n) - 1):
	dbc.append(abs(ord(n[i]) - ord(n[i + 1])))
for i in dbc:
	if i < 13:
		steps += i
	else:
		steps += 26 - i
print(steps)


s = input()
A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
(m, m1, O, minii) = ([], [], [], 999999)
(sum, I, F) = (0, [], [])
a = s[0]
(x, i) = (0, 0)
for i in range(len(s) - 1):
	m.append(abs(ord(s[i]) - ord(s[i + 1])))
F.append(0)
F.append(26)
for i in range(len(A)):
	if A[i] == s[0]:
		I.append(i)
		break
for i in range(len(m)):
	L = 26 - m[i]
	minii = min(L, m[i])
	m1.append(minii)
F.sort(reverse=True)
yt = min(abs(F[0] - I[0]), abs(F[1] - I[0]))
m1.append(yt)
for i in range(len(m1)):
	sum += m1[i]
print(sum)


s = input()
last = 'a'
ans = 0
for i in s:
	ans += min(abs(ord(i) - ord(last)), 26 - abs(ord(last) - ord(i)))
	last = i
print(ans)


s = input()
t = 0
prev = ord('a')
for i in s:
	diff = abs(ord(i) - prev)
	if diff > 13:
		t += 26 - diff
	else:
		t += diff
	prev = ord(i)
print(t)


cnt = 0
a = 97
for i in input():
	b = abs(ord(i) - a)
	cnt += min(b, 26 - b)
	a = ord(i)
print(cnt)


s = input()
N = len(s)
a = 'abcdefghijklmnopqrstuvwxyz'
pre = 0
num = 0
for i in range(N):
	k = ord(s[i]) - ord('a')
	num += min(abs(k - pre), abs(pre) + 1 + abs(25 - k), abs(25 - pre) + 1 + abs(k))
	pre = k
print(num)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
word = input()
prev_idx = 0
for char in word:
	idx = alphabet.index(char)
	alphabet = alphabet[idx:] + alphabet[:idx]
	if idx < 13:
		prev_idx += idx
	else:
		prev_idx += 26 - idx
print(prev_idx)


import sys
word = sys.stdin.readline().strip()
curr = 1
clicks = 0
for letter in word:
	n = ord(letter) - 96
	x = abs(curr - n)
	diff = x if 26 - x > x else 26 - x
	clicks += x if 26 - x > x else 26 - x
	curr = n
print(clicks)


i = ord('a')
s = 0
for c in input():
	j = ord(c)
	d = abs(j - i)
	s += min(d, 26 - d)
	i = j
print(s)


from string import ascii_lowercase as alp
alp = ' ' + alp
ind = 1
summa = 0
s = input()
for i in s:
	new = alp.index(i)
	summa += min(abs(ind - new), 26 - new + ind, 26 - ind + new)
	ind = new
print(summa)


def rotation(S, l):
	if len(S) == 1:
		return min(abs(ord(S) - ord(l)), 26 - abs(ord(S) - ord(l)))
	else:
		return rotation(S[0], l) + rotation(S[1:], S[0])
S = str(input())
print(rotation(S, 'a'))


w = 'abcdefghijklmnopqrstuvwxyz'
w2 = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
s = str(input())
i = 'a'
step = 0
for c in s:
	pi = w.index(i)
	op1 = w.index(c)
	step += min(abs(pi - op1), 26 - abs(pi - op1))
	i = c
print(step)


alpha = 'abcdefghijklmnopqrstuvwxyz'
s = input()
init = 0
count = 0
for i in s:
	count += min(abs(alpha.index(i) - init), 26 - init + alpha.index(i), 26 + init - alpha.index(i))
	init = alpha.index(i)
print(count)


name = input()
flag = 97
rota = 0
diff = 0
for i in name:
	char = ord(i)
	diff = abs(flag - char)
	if diff > 13:
		diff = 26 - diff
	rota += diff
	flag = char
print(rota)


import math
s = input()
e = 'abcdefghijklmnopqrstuvwxyz'
k = 0
p = 'a'
for i in s:
	a = e.index(i)
	b = e.index(p)
	if math.fabs(a - b) > 13:
		k += 26 - math.fabs(a - b)
	else:
		k += math.fabs(a - b)
	p = i
print(int(k))


import sys
inp = sys.stdin.readlines()
start_position = 'a'
alpha = list(map(chr, range(97, 123)))
word = inp[0].lower().strip()
rounds = 0
for letter in word:
	right = 0
	while True:
		try:
			if alpha[alpha.index(start_position) + right] == letter:
				break
		except IndexError:
			if alpha[alpha.index(start_position) + right - len(alpha)] == letter:
				break
		finally:
			right += 1
	right -= 1
	left = 0
	while True:
		try:
			if alpha[alpha.index(start_position) - left] == letter:
				break
		except IndexError:
			if alpha[alpha.index(start_position) - left + len(alpha)] == letter:
				break
		finally:
			left += 1
	left -= 1
	rounds += min(right, left)
	start_position = letter
print(rounds)


current_pos = 0
rotations = 0
enlish_alpha = 'abcdefghijklmnopqrstuvwxyz'
item = str(input())
if len(item) != 0 and item.isalpha() and item.islower():
	for char in item:
		next_pos = enlish_alpha.index(char)
		if current_pos <= next_pos:
			rotations_clockwise = next_pos - current_pos
			rotations_countclockwise = current_pos + 25 - next_pos + 1
		else:
			rotations_clockwise = 25 - current_pos + next_pos + 1
			rotations_countclockwise = current_pos - next_pos
		if rotations_clockwise <= rotations_countclockwise:
			rotations_tmp = rotations_clockwise
		else:
			rotations_tmp = rotations_countclockwise
		rotations += rotations_tmp
		current_pos = next_pos
	print(rotations)


name = input()
pointer = 0
count = 0
for char in name:
	id = ord(char) - 97
	dis = abs(pointer - id)
	if dis > 13:
		dis = 26 - dis
	count = count + dis
	pointer = id
print(count)


s = input()
prev = 'a'
ans = 0
for ch in s:
	a = abs(ord(ch) - ord(prev))
	ans += min(a, 26 - a)
	prev = ch
print(ans)


s = str(input())
a = list('abcdefghijklmnopqrstuvwxyz')
i = 0
su = 0
for c in s:
	f = abs(a.index(c) - i)
	su += min(26 - f, f)
	i = a.index(c)
print(su)


s = input()
ind = 0
moves = 0
for ch in s:
	pos = ord(ch) - 97
	walk = abs(ind - pos)
	if walk > 13:
		moves += 26 - walk
	else:
		moves += walk
	ind = pos
print(moves)


name = input().strip('\n\r')
first = abs(ord(name[0]) - ord('a'))
ans = min(first, 26 - first)
for i in range(1, len(name)):
	x = abs(ord(name[i]) - ord(name[i - 1]))
	ans += min(x, 26 - x)
print(ans)


s = input()
ans = 0
p = 97
for si in s:
	ords = ord(si)
	m = abs(ords - p)
	ans += min(m, 26 - m)
	p = ords
print(ans)


s = input()
p = 0
m = 0
for c in s:
	d = ord(c) - 97
	m += min((d - p) % 26, (p - d) % 26)
	p = d
print(m)


s = input()
a = 97
f = 0
for i in s:
	d = abs(a - ord(i))
	f = f + min(d, 26 - d)
	a = ord(i)
print(f)


a = 'a'
s = input()
sum = 0
for i in s:
	a = abs(ord(a) - ord(i))
	b = min(a, 26 - a)
	sum = sum + b
	a = i
print(sum)


name = input()
sum = 0
pre = 0
for char in name:
	now = ord(char) - ord('a')
	sum += min(abs(now - pre), 26 - abs(now - pre))
	pre = now
print(sum)


(a, c, d, e) = (0, 'a', list(input()), 0)
for b in range(len(d)):
	f = abs(ord(c) - ord(d[b]))
	if f > 13:
		f = abs(f - 26)
	(c, a) = (d[b], a + abs(f))
print(a)


n = list(input())
c = 0
p = 'a'
for i in range(len(n)):
	c += min(abs(ord(n[i]) - ord(p)), 26 - abs(ord(n[i]) - ord(p)))
	p = n[i]
print(c)


s = input()
x = 97
sol = 0
for i in s:
	sol += min((ord(i) - x + 26) % 26, (x - ord(i) + 26) % 26)
	x = ord(i)
print(sol)


res = 0
pos = 97
for char in input():
	od = abs(pos - ord(char))
	res += min(od, 26 - od)
	pos = ord(char)
print(res)


string1 = input()
string = 'a' + string1
alpha = 'abcdefghijklmnopqrstuvwxyz'
length = len(string)
letters = list(string)
step = 0

def find(n):
	for i in range(26):
		if n == alpha[i]:
			return i

def con(n):
	num1 = find(letters[n])
	num2 = find(letters[n + 1])
	step1 = abs(num1 - num2)
	step2 = abs(26 - abs(num1 - num2))
	if step1 < step2:
		return step1
	else:
		return step2
for i in range(length - 1):
	step += int(con(i))
print(step)


def main():
	s = map(ord, input())
	res = 0
	curr = 0
	A = ord('a')
	Z = ord('z')
	for x in s:
		if A <= x <= Z:
			x -= A
			res += min(abs(x - curr), 26 - abs(x - curr))
			curr = x
		else:
			break
	print(res)
main()


st = input()
n = len(st)
prev = ord('a')
count = 0
for i in range(0, n):
	ch = ord(st[i])
	count += min(abs(ch - prev), 26 - abs(ch - prev))
	prev = ch
print(count)


name = list(input())
moves = 0
start = 0
for i in name:
	index = ord(i) - 97
	length = abs(start - index)
	if length <= 13:
		moves += length
	else:
		moves += 26 - length
	start = index
print(moves)


count = 0
origin = 97
old_origin = origin
title = input()
for i in title:
	rota = 0
	rotb = 0
	while origin != ord(i):
		origin += 1
		rota += 1
		if origin > 122:
			origin = 97
	origin = old_origin
	while origin != ord(i):
		origin -= 1
		rotb += 1
		if origin < 97:
			origin = 122
	count += min(rota, rotb)
	old_origin = ord(i)
print(count)


s = input()
length = 26
cnt = 0
ind = 0
f = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(s)):
	for j in range(len(f)):
		if f[j] == s[i]:
			if j > ind:
				cnt += min(j - ind, len(f) - j + ind)
			else:
				cnt += min(ind - j, len(f) - ind + j)
			ind = j
print(cnt)


import string
name = list(input())
letters = string.ascii_lowercase
let_temp = string.ascii_lowercase
count = 0
for i in range(len(name)):
	if letters.index(name[i]) + 1 <= 14:
		count += letters.index(name[i])
	else:
		count += abs(26 - letters.index(name[i]))
	letters = let_temp[let_temp.index(name[i]):] + let_temp[:let_temp.index(name[i])]
print(count)


alpab = [chr(i) for i in range(97, 123)]
posit = [i for i in range(1, 27)]
reference = dict(zip(alpab, posit))
s = 'a' + input()
step = 0
for i in range(len(s) - 1):
	compare1 = reference[s[i + 1]] - reference[s[i]]
	compare2 = 26 - abs(compare1)
	step += min(abs(compare1), compare2)
print(step)


lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
lst2 = [x for x in reversed(lst)]
huruf = input()
count = 0
start = 'a'
for char in huruf:
	kanan = lst.index(char) - lst.index(start)
	kiri = lst2.index(char) - lst2.index(start)
	if kiri < 0:
		kiri = 26 + kiri
	if kanan < 0:
		kanan = 26 + kanan
	if kanan > kiri:
		count += kiri
	else:
		count += kanan
	start = char
print(count)


T = input()
PTR = 'a'
K = 'abcdefghijklmnopqrstuvwxyz'
L = 'azyxwvutsrqponmlkjihgfedcb'
A = 0
for I in T:
	M = K.index(I)
	N = L.index(I)
	P = min(M, N)
	A += P
	PTR = I
	K = K[M:] + K[:M]
	L = L[N:] + L[:N]
print(A)


ran = ord('z') - ord('a')
current = 'a'
distance = 0
word = input()
for c in word:
	if abs(ord(c) - ord(current)) > ran // 2:
		distance += ran - abs(ord(c) - ord(current)) + 1
	else:
		distance += abs(ord(c) - ord(current))
	current = c
print(distance)


s = input('')
m = 0
index = 0
wlak = 0
start = 0
for i in range(len(s)):
	index = ord(s[i]) - 97
	walk = abs(start - index)
	if walk < 13:
		m += walk
	else:
		m += 26 - walk
	start = index
print(m)


s = input()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l = 0
k = 0
for i in range(len(s)):
	m = a.index(s[i])
	l += min(abs(m - k), 26 - max(m, k) + min(m, k))
	k = m
print(l)


s = input()
ans = 0
start = 0
for l in s:
	i = ord(l) - 97
	walk = abs(start - i)
	if walk < 13:
		ans += walk
	else:
		ans += 26 - walk
	start = i
print(ans)


import math
import os
import random
import re
from sys import stdin, stdout
from collections import Counter
from itertools import permutations

def si():
	return str(stdin.readline())

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

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

def li():
	return list(mi())

def debug(x):
	return stdout.write(str(x))
r = 'a'
x = input()
z = 0
for i in x:
	y = abs(ord(i) - ord(r))
	z += min(y, 26 - y)
	r = i
print(z)


s = input()
res = 0
current_l = 'a'

def _ord(l):
	return ord(l) - ord('a')
for l in s:
	res += min(abs(_ord(current_l) - _ord(l)), abs(26 - abs(_ord(current_l) - _ord(l))))
	current_l = l
print(res)


def count_turns(ch1, ch2):
	d = abs(ord(ch1) - ord(ch2))
	return min(d, 26 - d)
s = 'a' + input()
print(sum((count_turns(ch1, ch2) for (ch1, ch2) in zip(s, s[1:]))))


st = input().strip()
p = 'a'
count = 0
for i in range(len(st)):
	right = abs(ord(p) - ord(st[i]))
	if right > 13:
		count += 26 - right
	else:
		count += right
	p = st[i]
print(count)


x = input()
ln = len(x)
(cur, mn, tot) = ('a', 0, 0)
for i in x:
	d = abs(ord(i) - ord(cur))
	tot += min(d, 26 - d)
	cur = i
print(tot)


import string
l = []
for i in range(1, 27):
	l.append(i)
d = dict(zip(string.ascii_lowercase, l))
s = input()
s = 'a' + s
c = 0
for i in range(len(s) - 1):
	c += min(abs(d[s[i]] - d[s[i + 1]]), abs(d[s[i]]) + abs(d[s[i + 1]] - d['z']), abs(d[s[i + 1]]) + abs(d[s[i]] - d['z']))
print(c)


s = input()
tmp = 97
res = 0
for c in s:
	if abs(ord(c) - tmp) <= 13:
		res += abs(ord(c) - tmp)
	else:
		res += 26 - abs(ord(c) - tmp)
	tmp = ord(c)
print(res)


import string
n = input()
c = min(abs(ord('a') - ord(n[0])), 26 - abs(ord('a') - ord(n[0])))
try:
	for i in range(len(n)):
		c += min(abs(ord(n[i + 1]) - ord(n[i])), 26 - abs(ord(n[i + 1]) - ord(n[i])))
except:
	pass
print(c)


s = input()
pos = ord('a')
result = 0
for ch in s:
	result += min(abs(ord(ch) - pos), 26 - abs(ord(ch) - pos))
	pos = ord(ch)
print(result)


word = [1] + list(input())
i = 1
while i < len(word):
	word[i] = ord(word[i]) - 96
	i += 1
count = 0
i = 1
while i < len(word):
	turn = word[i] - word[i - 1]
	count += min(turn % 26, -turn % 26)
	i += 1
print(count)


s = input()
n = 0
p = 'a'
for c in s:
	l = abs(ord(c) - ord(p))
	n += min(l, 26 - l)
	p = c
print(n)


import string
alpha = string.ascii_lowercase
s = input()
res = 0
for data in s:
	r = alpha.index(data)
	l = 26 - r
	res += min(r, l)
	alpha = alpha[r:27] + alpha[0:r]
print(res)


letters = list(input().strip())
current = ord('a')
cost = 0
for letter in letters:
	letterOrd = ord(letter)
	counter = (current - letterOrd) % 26
	clock = (letterOrd - current) % 26
	if counter < clock:
		cost += counter
		current += 26 - counter
	else:
		cost += clock
		current += clock
print(cost)


prev_c = 0
answer = 0
for c in map(ord, input()):
	c -= ord('a')
	a = abs(prev_c - c)
	b = min(prev_c, c) + 26 - max(prev_c, c)
	answer += min(a, b)
	prev_c = c
print(answer)


import string

def split(word):
	return [char for char in word]
letters = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
curr_letter = 1
word = input('')
word = split(word)
tot_rot = 0
for char in word:
	tot_rot += min(abs(curr_letter - letters[char]), 26 - abs(curr_letter - letters[char]))
	curr_letter = letters[char]
print(tot_rot)


s = input()
N = 26

def delta(curr, next):
	d1 = abs(ord(next) - ord(curr))
	d2 = N - d1
	if d1 > d2:
		return d2
	else:
		return d1
result = 0
curr = 'a'
for c in s:
	result += delta(curr, c)
	curr = c
print(result)


def finder(x, s):
	for i in range(len(s)):
		if s[i] == x:
			return i
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a = input()
x = 0
cnt = 0
for i in a:
	j = finder(i, l)
	if abs(j - x) <= 13:
		cnt += abs(j - x)
	else:
		cnt += abs(abs(j - x) - 26)
	x = j
print(cnt)


s = input()
d = {}
k = 1
for i in range(ord('a'), ord('z') + 1):
	d[chr(i)] = k
	k += 1
if s[0] != 'a':
	count = min(d[s[0]] - 1, 27 - d[s[0]])
else:
	count = 0
for i in range(1, len(s)):
	count += min(abs(ord(s[i - 1]) - ord(s[i])), 26 - abs(ord(s[i - 1]) - ord(s[i])))
print(count)


def min(a, b):
	if a < b:
		return a
	return b

def abs(a):
	if a > 0:
		return a
	else:
		return -a

def cost(a, b):
	p = ord(a) - ord('a')
	q = ord(b) - ord('a')
	tot = abs(p - q)
	return min(tot, 26 - tot)
c = 'a'
ans = 0
s = input()
for i in s:
	ans += cost(i, c)
	c = i
print(ans)


ans = 0
prev = 'a'
s = input()
for c in s:
	a = abs(ord(c) - ord(prev))
	if a < 13:
		ans += a
	else:
		ans += 26 - a
	prev = c
print(ans)


a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
co = 0
iz = 0
for i in s:
	k = a.find(i)
	if k > iz:
		st1 = iz + 26 - k
		st2 = k - iz
	else:
		st1 = iz - k
		st2 = k + 26 - iz
	co += min(st1, st2)
	iz = k
print(co)


n = str(input())
pre = ''
pre = ord('a')
count = 0
for i in n:
	count += min(abs(ord(i) - pre), 26 - abs(ord(i) - pre))
	pre = ord(i)
print(count)


from bisect import bisect
s = input()
e = 'abcdefghijklmnopqrstuvwxyz'
i = 1
ans = 0
for c in s:
	t = bisect(e, c)
	ans += min((t + 26 - i) % 26, (i + 26 - t) % 26)
	i = t
print(ans)


a = 97
ans = 0
for i in map(ord, input()):
	ans += min(abs(i - a), 26 - abs(i - a))
	a = i
print(ans)


string = input()
n = len(string)
rs = 0
left = ord('a') - ord(string[0])
right = -left
left = left if left >= 0 else left + 26
right = right if right >= 0 else right + 26
if left <= right:
	rs = left
else:
	rs = right
for i in range(1, n):
	left = ord(string[i]) - ord(string[i - 1])
	right = -left
	left = left if left >= 0 else left + 26
	right = right if right >= 0 else right + 26
	if left <= right:
		rs += left
	else:
		rs += right
print(rs)


str1 = input()
count = 0
temp = 97
for i in range(len(str1)):
	temp1 = ord(str1[i])
	if temp < temp1:
		count += abs(temp - temp1) if abs(temp - temp1) <= abs(temp1 - temp - 26) else abs(temp1 - temp - 26)
	else:
		count += abs(temp - temp1) if abs(temp - temp1) <= abs(temp1 + 26 - temp) else abs(temp1 + 26 - temp)
	temp = ord(str1[i])
print(count)


def index(ch):
	return ord(ch) - ord('a')
word = input()
ans = 0
prev = 0
for ch in word:
	curr = index(ch)
	if curr > prev:
		ans += min(curr - prev, prev + (26 - curr))
	else:
		ans += min(prev - curr, curr + (26 - prev))
	prev = curr
print(ans)


x = input()
l = list(x)
z = 0
k = 1
for i in l:
	y = ord(i)
	if k == 1:
		m = y - 97
		n = 123 - y
		z = min(m, n) + z
		b = y
		k = k + 1
		continue
	m = 123 - max(y, b) + (min(y, b) - 97)
	n = max(y, b) - min(y, b)
	z = min(m, n) + z
	b = y
print(z)


import string
a = dict(zip(string.ascii_lowercase, range(1, 27)))
word = 'a' + input()
k = 0
for i in range(len(word) - 1):
	v1 = abs(a[word[i]] - a[word[i + 1]])
	v2 = abs(a[word[i]] + 26 - a[word[i + 1]])
	v3 = abs(a[word[i]] - 26 - a[word[i + 1]])
	k += min(v1, v2, v3)
print(k)


wrd = input()
arr = 'abcdefghijklmnopqrstuvwxyz'
letter_list = []
j = 0
count = []
for i in arr:
	letter_list.append(i)
	count.append(i + '->' + str(j))
	j += 1
right = 0
left = 0
curr = 0
rotations = 0
for w in wrd:
	index_w = letter_list.index(w)
	rotations += min(26 - abs(index_w - curr), abs(index_w - curr))
	curr = index_w
print(rotations)


def NightAtTheMuseum(s):
	sum = 0
	if abs(ord(s[0]) - 97) < 13:
		sum += abs(ord(s[0]) - 97)
	else:
		sum += 26 - abs(ord(s[0]) - 97)
	for i in range(len(s) - 1):
		if abs(ord(s[i + 1]) - ord(s[i])) < 13:
			sum += abs(ord(s[i + 1]) - ord(s[i]))
		else:
			sum += 26 - abs(ord(s[i + 1]) - ord(s[i]))
	return sum
s = input()
print(NightAtTheMuseum(s))


name = input()
res = 0
cur = 97
for i in name:
	distance = abs(ord(i) - cur)
	if distance > 13:
		distance = 26 - distance
	res += distance
	cur = ord(i)
print(res)


s = input().lower()
current = 0
steps = 0
for letter in s:
	p = ord(letter) - 97
	q = abs(current - p)
	steps += min(q, 26 - q)
	current = p
print(steps)


def rot(curr, req):
	x = min(ord(curr) - ord('a'), ord(req) - ord('a'))
	y = max(ord(curr) - ord('a'), ord(req) - ord('a'))
	return min(y - x, x - y + 26)
st = input()
ans = rot('a', st[0])
for i in range(0, len(st) - 1):
	ans += rot(st[i], st[i + 1])
print(ans)


a = input()
c = abs(ord('a') - ord(a[0]))
z = 26 - c
if c > z:
	c = z
b = c
for x in range(len(a) - 1):
	c = abs(ord(a[x]) - ord(a[x + 1]))
	z = 26 - c
	if c > z:
		c = z
	b += c
print(b)


a = list(input())
d = 97
i = 0
p = 0
s = 0
for i in range(len(a)):
	p = ord(a[i])
	if abs(d - p) <= 13:
		s += abs(d - p)
	elif p > d:
		s += abs(d + 26 - p)
	else:
		s += 122 - d + (p - 96)
	d = ord(a[i])
print(s)


s = list(input())
c = 0
so = 'a'
de = 'a'
for i in s:
	de = i
	c = c + min(abs(ord(de) - ord(so)), 26 - abs(ord(de) - ord(so)))
	so = i
print(c)


from math import ceil, log, floor, sqrt
import math
k = 1

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_prime(n):
	m = 2
	while m * m <= n:
		if n % m == 0:
			return False
		m += 1
	return True

def find_sum(n, a):
	a.insert(0, 0)
	for i in range(1, n + 1):
		prev = a[i] & a[i - 1]
		cur = a[i] | a[i - 1]
		a[i - 1] = prev
		a[i] = cur
	return sum((m * m for m in a))

def prin_abc(x, y, z):
	l = [x, y, z]
	l.sort()
	if l[1] < l[2]:
		print('NO')
		return
	a = b = l[0]
	c = l[2]
	print('YES')
	print(a, b, c)

def get_scores(n, vals):
	l = 0
	r = n - 1
	turn = 0
	sereja = 0
	dima = 0
	while l <= r:
		if vals[l] > vals[r]:
			cur = vals[l]
			l += 1
		else:
			cur = vals[r]
			r -= 1
		if turn == 0:
			sereja += cur
		else:
			dima += cur
		turn = not turn
	print(sereja, dima)

def count_lamps(n, m):
	return (n * m + 1) // 2

def count_moves(name):
	count = 0
	cur = 'a'
	for c in name:
		dif = abs(ord(c) - ord(cur))
		count += min(dif, 26 - dif)
		cur = c
	return count
t = 1
while t:
	t = t - 1
	points = []
	name = input()
	print(count_moves(name))


s = input()
p = 'a'
s1 = 0
for i in range(len(s)):
	c = abs(ord(s[i]) - ord(p))
	c1 = abs(26 - c)
	p = s[i]
	if c < c1:
		s1 = s1 + c
	else:
		s1 = s1 + c1
print(s1)


s = input()
res = 0
cu = 0
A = ord('a')
for i in s:
	i = ord(i)
	i = i - A
	res = res + min(abs(i - cu), 26 - abs(i - cu))
	cu = i
print(res)


def main():
	name = input()
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	current = 'a'
	result = 0
	for i in range(len(name)):
		dist = abs(alphabet.find(current) - alphabet.find(name[i]))
		result += min((dist, 26 - dist))
		current = name[i]
	print(result)
main()


s = input()
a = ord('a')
z = ord('z')
start = a
cnt = 0
for i in s:
	i = ord(i)
	cnt += min(abs(i - start), abs(abs(start - a) + abs(z - i)) + 1, abs(abs(z - start) + abs(a - i)) + 1)
	start = i
print(cnt)


X = list(input())
p = 97
c = 0
for i in X:
	x = abs(ord(i) - p)
	y = 26 - x
	if x < y:
		c += x
	else:
		c += y
	p = ord(i)
print(c)


s = input()
a = []
cnt = 0
x = 1
y = ord(s[0]) - 96
for i in range(1, len(s)):
	cnt += min(26 - abs(x - y), abs(x - y))
	x = y
	y = ord(s[i]) - 96
print(cnt + min(26 - abs(x - y), abs(x - y)))


s = input()
c = 0
if s[0] <= 'a':
	x = ord('a') - ord(s[0])
	if x <= 13:
		c += x
	else:
		x += 26 - x
else:
	x = ord(s[0]) - ord('a')
	if x <= 13:
		c += x
	else:
		c += 26 - x
for i in range(len(s) - 1):
	if s[i] <= s[i + 1]:
		x = ord(s[i]) - ord(s[i + 1]) + 26
		if x <= 13:
			c += x
		else:
			c += 26 - x
	else:
		x = ord(s[i + 1]) - ord(s[i]) + 26
		if x <= 13:
			c += x
		else:
			c += 26 - x
print(c)


import string
s = input()
c = 0
wheel = string.ascii_lowercase
pointer = 'a'
for alphabet in s:
	index_p = wheel.find(pointer)
	index_a = wheel.find(alphabet)
	if index_p > index_a:
		cw = 26 - index_p + index_a
		ccw = index_p - index_a
	else:
		cw = index_a - index_p
		ccw = 26 - index_a + index_p
	c += cw if cw < ccw else ccw
	pointer = alphabet
print(c)


s = input()
k = ord('a')
c = 0
for i in range(len(s)):
	j = abs(ord(s[i]) - k)
	c += min(j, 26 - j)
	k = ord(s[i])
print(c)


s = input()
f = 97
r = 0
for i in s:
	d = abs(f - ord(i))
	if d > 13:
		d = 26 - d
	r = r + d
	f = ord(i)
print(r)


c = 97
a = 0
for z in map(ord, input()):
	i = abs(c - z)
	a += min(i, 26 - i)
	c = z
print(a)


import sys
a = []
for line in sys.stdin:
	line = line.strip()
	temp = list(line)
	for x in temp:
		a.append(ord(x) - 97)
temp = 0
sum = 0
for x in a:
	diff = abs(x - temp)
	sum += min(diff, 26 - diff)
	temp = x
print(sum)


(c, m) = (97, 0)
for x in map(ord, input()):
	d = abs(c - x)
	m += min(d, 26 - d)
	c = x
print(m)


def main():
	s = input()
	(st, res) = (0, 0)
	for c in s:
		c = ord(c) - 97
		res += min((c - st) % 26, (st - c) % 26)
		st = c
	print(res)
main()


def main():
	word = input()
	point = 1
	count = 0
	for x in word:
		current = ord(x) - 96
		right = abs(point - current)
		if current > point:
			left = abs(26 - current + point)
		else:
			left = abs(26 - point + current)
		if right < left:
			count += right
		else:
			count += left
		point = current
	print(count)
main()


alphabet = 'abcdefghijklmnopqrstuvwxyz'
wheel = list(alphabet)

def calcDiff(charOne, charTwo):
	value = abs(wheel.index(charOne) - wheel.index(charTwo))
	if value > 13:
		return 26 - value
	return value
i = input()
count = 0
currChar = 'a'
for c in list(i):
	count += calcDiff(currChar, c)
	currChar = c
print(count)


s = input()
p = 0
m = 0
for c in s:
	cc = ord(c) - ord('a')
	d1 = p - cc
	if d1 < 0:
		d1 = 26 + d1
	d2 = cc - p
	if d2 < 0:
		d2 = 26 + d2
	m += min(d1, d2)
	p = cc
print(m)


cp = 'a'
k = 0
s = input()
for i in s:
	a = abs(ord(i) - ord(cp))
	b = 26 - a
	if a > b:
		k += b
	else:
		k += a
	cp = i
print(k)


a = [0, *map(lambda x: ord(x) - 97, input())]
print(sum((min(abs(y - x), 26 + x - y, 26 + y - x) for (x, y) in zip(a, a[1:]))))


alphabet = [x for x in 'abcdefghijklmnopqrstuvwxyz']
name = 'a' + input()
rotations = 0
for i in range(1, len(name)):
	if abs(alphabet.index(name[i - 1]) - alphabet.index(name[i])) > 13:
		rotations += 26 - abs(alphabet.index(name[i - 1]) - alphabet.index(name[i]))
	else:
		rotations += abs(alphabet.index(name[i - 1]) - alphabet.index(name[i]))
print(rotations)


s = list(input())
l = ['a']
l = [min(abs(ord(x) - ord(l[-1])), abs(26 - (ord(x) - ord(l[-1])))) for x in s]
l = ['a']
c = 0
for i in range(len(s)):
	c += min(abs(ord(s[i]) - ord(l[-1])), abs(26 - abs(ord(s[i]) - ord(l[-1]))))
	l.append(s[i])
print(c)


def counter(c, c1, steps):
	steps += min(abs(ord(c) - ord(c1)), 26 - abs(ord(c) - ord(c1)))
	return steps
s = input()
s = 'a' + s
count = 0
for i in range(len(s) - 1):
	count = counter(s[i], s[i + 1], count)
print(count)


a = input()
z = 'abcdefghijklmnopqrstuvwxyz'
w = 0
q = 'a'
for j in a:
	s = abs(z.index(j) - z.index(q))
	w += min(s, 26 - s)
	q = j
print(w)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi

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

def si():
	return str(input())

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

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

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)
	print(l)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans
s = si()
count = min(ord(s[0]) - 97, 26 - ord(s[0]) + 97)
for i in range(1, len(s)):
	x = 97
	count += min(abs(ord(s[i]) - ord(s[i - 1])), 26 - abs(ord(s[i]) - ord(s[i - 1])))
print(count)


input_string = input()
current_value = ord('a') - 97
total_rotation = 0
for character in input_string:
	rotation = min(26 - abs(ord(character) - 97 - current_value), abs(ord(character) - 97 - current_value))
	total_rotation += rotation
	current_value = ord(character) - 97
print(total_rotation)


s = input()
pos = 'a'
ans = 0
for ch in s:
	turns = abs(ord(pos) - ord(ch))
	ans += min(turns, 26 - turns)
	pos = ch
print(ans)


word = input().strip()
curr = 'a'
total = 0
for ch in word:
	total += min(abs(ord(curr) - ord(ch)), 26 - abs(ord(curr) - ord(ch)))
	curr = ch
print(total)


import string
s = string.ascii_lowercase

def rotate_right(cur_letter, target_letter):
	start_index = s.index(cur_letter)
	cur_index = start_index
	incs = 0
	while True:
		if s[cur_index] == target_letter:
			break
		else:
			cur_index = (cur_index + 1) % 26
			incs += 1
	return incs

def rotate_left(cur_letter, target_letter):
	start_index = s.index(cur_letter)
	cur_index = start_index
	incs = 0
	while True:
		if s[cur_index] == target_letter:
			break
		else:
			cur_index = (cur_index - 1) % 26
			incs += 1
	return incs
word = 'a{}'.format(input())
total = 0
for i in range(0, len(word)):
	if i == len(word) - 1:
		break
	else:
		total += min(rotate_left(word[i], word[i + 1]), rotate_right(word[i], word[i + 1]))
print(total)


string = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
s = input()
ans = 0
cur = 97
for i in s:
	ans += min(abs(ord(i) - cur), 26 - abs(ord(i) - cur))
	cur = ord(i)
print(ans)


def getTheLeasteMovements(word):
	movements = 0
	index = 0
	for i in range(len(word)):
		char_index = abs(ord(word[i]) - 97)
		distance = abs(index - char_index)
		if distance < 13:
			movements += distance
		else:
			movements += 26 - distance
		index = char_index
	return movements
word = input()
print(getTheLeasteMovements(word))


s = list(input())
letter = list('abcdefghijklmnopqrstuvwxyz')
count = min(letter.index(s[0]), 26 - letter.index(s[0]))
for i in range(0, len(s) - 1):
	count += min(abs(letter.index(s[i]) - letter.index(s[i + 1])), 26 - abs(letter.index(s[i]) - letter.index(s[i + 1])))
print(count)


S = input()
count = 0
S = 'a' + S
for i in range(len(S)):
	if i == 0:
		continue
	a = abs(ord(S[i]) - ord(S[i - 1]))
	if a > 13:
		count += 26 - a
	else:
		count += a
print(count)


import string
letters = string.ascii_lowercase
tot = 0
name = input()
for i in range(len(name)):
	if i == 0:
		first = letters.find('a')
	second = letters.find(name[i])
	sol2 = (first - second) % 26
	sol3 = (-first + second) % 26
	step = min(sol2, sol3)
	tot += step
	first = second
print(tot)


s = input()
n = 97
c = 0
for i in s:
	x = abs(ord(i) - n)
	if x > 13:
		c += abs(x - 26)
	else:
		c += x
	n = ord(i)
print(c)


alpha = 'abcdefghijklmnopqrstuvwxyz'
word = input()
rotation = 0
start = 'a'
for char in word:
	a = alpha.index(start)
	b = alpha.index(char)
	rotation += min(abs(b - a), 26 - b + a, 26 - a + b)
	start = char
print(rotation)


import string
alphabet = string.ascii_lowercase
target = input()
result = 0
for c in target:
	cur_id = 0
	letter = alphabet[cur_id]
	if letter != c:
		while True:
			cur_id += 1
			left = alphabet[-cur_id]
			right = alphabet[cur_id]
			if c == left:
				alphabet = alphabet[-cur_id:] + alphabet[:-cur_id]
			elif c == right:
				alphabet = alphabet[cur_id:] + alphabet[:cur_id]
			if c in (left, right):
				result += cur_id
				break
print(result)


text = input()
current_position = 'a'
total_moves = 0
for i in range(0, len(text)):
	value = abs(ord(text[i]) - ord(current_position))
	current_position = text[i]
	value = min(value, 26 - value)
	total_moves += value
print(total_moves)


U = input()
rotation = 0
prev = 'a'
total = 0
for ch in U:
	rotate = ord(ch) - ord(prev)
	total += min(abs(rotate), 26 - abs(rotate))
	rotation += rotate % 26
	prev = ch
print(total)


ch = input()
s = 0
x = 'a'
for i in ch:
	e = ord(x) - 97
	f = ord(i) - 97
	z = abs(e - f)
	s += min(26 - z, z)
	x = i
print(s)


s = input()
su = 0
a = 97
for i in s:
	su += min(abs(ord(i) - a), 26 - abs(a - ord(i)))
	a = ord(i)
print(su)


t = input()
ch = 'abcdefghijklmnopqrstuvwxyz'
cur = 0
ans = 0
for i in range(len(t)):
	pos = ch.find(str(t[i]))
	b = abs(pos - cur)
	if b > 12:
		b = 26 - b
	ans += b
	cur = pos
print(ans)


s = input()
x = 1
z = 0
for i in s:
	c = ord(i) - 96
	if x <= 14:
		if abs(c - x) < abs(x + 26 - c):
			z += abs(c - x)
			x = c
		else:
			z += abs(x + 26 - c)
			x = c
	elif abs(c - x) < abs(c + 26 - x):
		z += abs(c - x)
		x = c
	else:
		z += abs(c + 26 - x)
		x = c
print(z)


exhibit = input()
position = 'a'
rotations = 0
for c in exhibit:
	if ord(position) - ord(c) < 0:
		if ord(c) - ord(position) > 13:
			rotations += 26 - (ord(c) - ord(position))
		else:
			rotations += ord(c) - ord(position)
	elif ord(position) - ord(c) > 0:
		if ord(position) - ord(c) > 13:
			rotations += 26 - (ord(position) - ord(c))
		else:
			rotations += ord(position) - ord(c)
	position = c
print(rotations)


a = input()
b = len(a)
c = 97
s = 0
for i in range(b):
	d = abs(c - ord(a[i]))
	if d > 13:
		s = s + (26 - d)
	else:
		s = s + d
	c = ord(a[i])
print(s)


from sys import stdin

def dist(cur, nxt):
	return min(abs(nxt - cur) % 26, abs(nxt - 26 - cur) % 26, abs(cur - 26 - nxt) % 26)
word = list(map(lambda x: ord(x) - ord('a') + 1, stdin.readline().rstrip()))
cur = 1
res = 0
for c in word:
	res += dist(cur, c)
	cur = c
print(res)


s = input()
lens = len(s)
Smove = 0
strt = 0
for i in range(0, lens):
	index = ord(s[i]) - 97
	walk = abs(strt - index)
	if walk < 13:
		Smove += walk
	else:
		Smove += 26 - walk
	strt = index
print(Smove)


s = input()
prev = 'a'
ts = 0
for i in range(len(s)):
	val = abs(ord(s[i]) - ord(prev))
	if val > 13:
		steps = 26 - val
	elif val <= 13:
		steps = val
	ts += steps
	prev = s[i]
print(ts)


g = input().strip()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
autor = 'retard'
sum = 0
a = 0
for i in g:
	p = alphabet.find(i)
	if abs(p - a) < 26 - abs(p - a):
		sum += abs(p - a)
		a = p
	else:
		sum += 26 - abs(p - a)
		a = p
print(sum)


B = 26
s = 0
x = ord('a')
for y in map(ord, input()):
	s += min((x - y) % B, (y - x) % B)
	x = y
print(s)


s = input()
init = 'a'
count = 0
for i in s:
	k = abs(ord(i) - ord(init))
	count += min(k, 26 - k)
	init = i
print(count)


x = input()
d = '0abcdefghijklmnopqrstuvwxyz'
s = min(abs(d.find(x[0]) - d.find('a')), 26 - max(d.find('a'), d.find(x[0])) + min(d.find(x[0]), d.find('a')))
for i in range(1, len(x)):
	s += min(abs(d.find(x[i]) - d.find(x[i - 1])), 26 - max(d.find(x[i - 1]), d.find(x[i])) + min(d.find(x[i]), d.find(x[i - 1])))
print(s)


def step(a, b):
	aNum = ord(a)
	bNum = ord(b)
	return min(abs(bNum - aNum), 26 - abs(bNum - aNum))
s = input()
s = 'a' + s
ans = 0
for i in range(len(s) - 1):
	ans += step(s[i], s[i + 1])
print(ans)


def solve(name: str) -> int:
	pointer = 'a'
	count = 0
	for c in name:
		dist = abs(ord(pointer) - ord(c))
		if dist <= 12:
			count += dist
		else:
			count += 26 - dist
		pointer = c
	return count
name = input()
print(solve(name))


rez = 0
text = input()
cur = 97
for i in text:
	rez += min(abs(cur - ord(i)), 26 - abs(cur - ord(i)))
	cur = ord(i)
print(rez)


def cnt(a, b):
	x = abs(ord(a) - ord(b))
	return min(x, 26 - x)
a = 'a' + input()
val = 0
for i in range(len(a) - 1):
	val += cnt(a[i], a[i + 1])
print(val)


import sys, math, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split().strip())
M = lambda : map(int, input().split())
n = input().strip()
k = 'a'
s = 0
for i in n:
	p = abs(ord(i) - ord(k))
	if p > 13:
		p = 26 - p
	s += p
	k = i
print(s)


a = 'abcdefghijklmnopqrstuvwxyz'
p = input()
y = 1
ttl = 0
for i in range(len(p)):
	x = 1 + a.index(p[i])
	z = abs(x - y)
	q = 26 - z
	if z > q:
		ttl += q
	else:
		ttl += z
	y = x
print(ttl)


s = input()
y = 0
sum = 0
str = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(s)):
	x = str.find(s[i])
	l1 = abs(x - y)
	l2 = 26 - l1
	sum += min(l1, l2)
	y = x
print(sum)


s = 'a' + input()
print(sum((min((ord(s[i + 1]) - ord(s[i])) % 26, (ord(s[i]) - ord(s[i + 1])) % 26) for i in range(len(s) - 1))))


import sys, math
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
pos = 0
vv = ord('a')
ans = 0
for i in s:
	gg = ord(i) - vv
	ans += min(int(math.fabs(gg - pos)), 26 - max(gg, pos) + min(pos, gg))
	pos = gg
print(ans)


import string

def getPos(s):
	return string.ascii_lowercase.index(s)
total = 26
sum = 0
cur = 0
file = input()
for f in file:
	if getPos(f) == cur:
		continue
	temp = getPos(f) - cur
	if abs(temp) > 13:
		sum += 26 - abs(temp)
	else:
		sum += abs(temp)
	cur = getPos(f)
print(sum)


name = [x for x in input()]
pre = 'a'
rotations = 0
for i in name:
	if ord(pre) > ord(i):
		anti_cw = abs(ord(i) - ord(pre))
		cw = ord('z') - ord(pre) + 1 + ord(i) - ord('a')
		rotations += min(anti_cw, cw)
	else:
		cw = abs(ord(i) - ord(pre))
		anti_cw = ord(pre) - ord('a') + 1 + ord('z') - ord(i)
		rotations += min(anti_cw, cw)
	pre = i
print(rotations)


def get_distance(letter1, letter2):
	number2 = ord(letter2) - 96
	number1 = ord(letter1) - 96
	if abs(number1 - number2) > 13:
		return 26 - abs(number1 - number2)
	return abs(number1 - number2)
word = input()
sm = 0
sm += get_distance('a', word[0])
for i in range(0, len(word) - 1):
	sm += get_distance(word[i], word[i + 1])
print(sm)


letters = list(input())
rotations = 0
lastLetter = 'a'
for i in letters:
	rotations = rotations + min(abs(ord(lastLetter) - ord(i)), 26 - abs(ord(lastLetter) - ord(i)))
	lastLetter = i
print(rotations)


s = str(input())
prev = 'a'
count = 0
for i in s:
	if i > prev:
		count += min(ord(i) - ord(prev), ord(prev) - ord('a') + ord('z') - ord(i) + 1)
	else:
		count += min(ord(prev) - ord(i), ord('z') - ord(prev) + ord(i) - ord('a') + 1)
	prev = i
print(count)


s = str(input())
temp1 = 0
temp2 = 0
sum = 0
prev = 'a'
for i in s:
	temp1 = abs(ord(prev) - ord(i))
	temp2 = ord(prev) - ord('a') + 1 + (ord('z') - ord(i))
	temp3 = abs(ord(i) - ord('a') + (ord('z') - ord(prev)) + 1)
	prev = i
	sum += min(temp1, temp2, temp3)
print(sum)


s = input()
print(sum((min(abs(ord(i) - ord(t)), 26 - abs(ord(i) - ord(t))) for (i, t) in zip(s, 'a' + s))))


Positions = {'r': 17, 'f': 5, 'q': 16, 'x': 23, 'h': 7, 'w': 22, 't': 19, 'm': 12, 'p': 15, 'z': 25, 'k': 10, 'u': 20, 'a': 0, 'y': 24, 'b': 1, 'c': 2, 'i': 8, 'g': 6, 's': 18, 'd': 3, 'l': 11, 'v': 21, 'o': 14, 'e': 4, 'n': 13, 'j': 9}
nom = input()
pointeur = 0
S = 0
for i in nom:
	mouvements = (Positions[i] - pointeur) % 26
	pointeur = mouvements + pointeur
	if mouvements > 13:
		mouvements = 26 - mouvements
	S += mouvements
print(S)


a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = input()
(j, k, counter, sum) = (0, 0, 0, 0)
for i in s:
	while True:
		if a[j] == i or a[k] == i:
			sum += counter
			j = a.index(i)
			k = a.index(i)
			counter = 0
			break
		if j == len(a) - 1:
			j = 0
		else:
			j += 1
		k -= 1
		counter += 1
print(sum)


name = list('a' + input())
sum = 0
for i in range(len(name) - 1):
	sum += min(abs(ord(name[i]) - ord(name[i + 1])), 26 - abs(ord(name[i]) - ord(name[i + 1])))
print(sum)


st = input()
r = 0
cur = 1
for i in st:
	j = ord(i) - 96
	clock = abs(cur - j)
	anticlock = abs(26 - clock)
	r = r + min(clock, anticlock)
	cur = j
print(r)


(curr, ans) = ('a', 0)
s = input()
for i in s:
	x = abs(ord(curr) - ord(i))
	ans += min(x, 26 - x)
	curr = i
print(ans)


s = input()
cost = 0
start = 'a'
for i in s:
	cost += min(abs(ord(i) - ord(start)), 26 - abs(ord(i) - ord(start)))
	start = i
print(cost)


def night_at_the_museum():
	word = input()
	wheel = 'abcdefghijklmnopqrstuvwxyz'
	total = 0
	current_letter = 'a'
	for letter in word:
		comp = abs(wheel.index(current_letter) - wheel.index(letter))
		total += min(comp, 26 - comp)
		current_letter = letter
	print(total)
night_at_the_museum()


import string
name = list(input())
alpha = list(string.ascii_lowercase[:26])
number_of_rotations = 0
index_old = 0
for e in name:
	if abs(index_old - alpha.index(e)) > 13:
		index = 26 - abs(index_old - alpha.index(e))
	else:
		index = abs(index_old - alpha.index(e))
	index_old = alpha.index(e)
	number_of_rotations = number_of_rotations + index
print(number_of_rotations)


y = 97
ans = 0
for i in map(ord, input()):
	x = abs(i - y)
	ans += min(x, 26 - x)
	y = i
print(ans)


from string import ascii_lowercase
name = input()
current = 0
rotations = 0
for char in name:
	char_index = ascii_lowercase.index(char)
	vals = [abs(char_index - current), 26 - abs(char_index - current)]
	rotations += min(vals)
	current = char_index
print(rotations)


A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
start = 0
read = input()
word = []
for i in read:
	word.append(i)
result = 0
for i in word:
	index = A.index(i)
	if abs(start - index) > 13:
		if start - index < 0:
			x = (start - index) % 26
		else:
			x = -(start - index) % 26
		result += x
		start = index
	else:
		if start - index < 0:
			x = -(start - index) % 26
		else:
			x = start - index
		result += x
		start = index
print(result)


from typing import List
from collections import Counter

class Embosser:

	def count(self):
		string = input()
		start = 'a'
		count = 0
		for chr in string:
			if start != chr:
				diff = abs(ord(start) - ord(chr))
				mn = min(diff, 26 - diff)
				count += mn
				start = chr
		print(count)
spin = Embosser()
spin.count()


alph = 'abcdefghijklmnopqrstuvwxyz'
s = input()
letr = 'a'
ln = 0
for letter in s:
	poz = abs(alph.index(letr) - alph.index(letter))
	ln += min(poz, 26 - poz)
	letr = letter
print(ln)


s = list(input())
a = ord('a')
cont = 0
for i in s:
	act = ord(i)
	t1 = abs(act - a)
	t2 = abs(abs(act - a) - 26)
	if t1 > t2:
		cont += t2
	else:
		cont += t1
	a = ord(i)
print(cont)


text = input('')
alphabet = 'abcdefghijklmnopqrstuvwxyz'
actual_letter = 'a'
count = 0
for letter in text:
	value = abs(alphabet.index(actual_letter) - alphabet.index(letter))
	if value > 13:
		value = 26 - value
	count += value
	actual_letter = letter
print(count)


s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
b = 0
c = 0
for i in s:
	d = a.find(i)
	b += min(abs(d - c), abs(26 - abs(d - c)))
	c = d
print(b)


c = 'abcdefghijklmnopqrstuvwxyz'
s = input()
i = 0
k = 0
from math import fabs as abs
for x in s:
	j = c.index(x)
	k += min(abs(j - i), 26 - j + i, 26 - i + j)
	i = j
print(int(k))


n = input()
(x, res) = ('a', 0)
for i in range(len(n)):
	diff = abs(ord(n[i]) - ord(x))
	res += min(diff, 26 - diff)
	x = n[i]
print(res)


def conta(a, b):
	x = abs(a - b)
	if x > 13:
		return 26 - x
	return x
s = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
v = 1
d = {}
for i in alf:
	d[i] = v
	v += 1
ant = 'a'
resp = 0
for i in s:
	resp += conta(d[ant], d[i])
	ant = i
print(resp)


st = 'a' + input()
cnt = 0
for x in range(1, len(st)):
	y = abs(ord(st[x]) - ord(st[x - 1]))
	cnt += min(y, 26 - y)
print(cnt)


s = '0abcdefghijklmnopqrstuvwxyz'
n = input()
sm = 0
u = 'a'
for i in range(len(n)):
	sm += min(abs(s.index(u) - s.index(n[i])), 26 - abs(s.index(u) - s.index(n[i])))
	u = n[i]
print(sm)


SEQ = 'abcdefghijklmnopqrstuvwxyz'

def dist(a, b):
	a = ord(a) - ord('a')
	b = ord(b) - ord('a')
	d = abs(a - b)
	return min(d, 26 - d)

def __starting_point():
	seq = input()
	pos = 'a'
	r = 0
	for c in seq:
		r += dist(pos, c)
		pos = c
	print(r)
__starting_point()


s = list(map(ord, input()))
m = 0
k = 97
for i in range(len(s)):
	p = abs(k - s[i])
	m += min(p, 26 - p)
	k = s[i]
print(m)


def main():
	string = input()
	prev = 97
	step = 0
	for char in string:
		dest = ord(char)
		head = abs(dest - prev)
		back = abs(26 - head)
		prev = dest
		if head < back:
			step += head
		else:
			step += back
	print(step)
main()


L = list(input())
start = 'a'
rotations = 0
for i in L:
	n = abs(ord(i) - ord(start))
	if n < 26 - n:
		rotations += n
	else:
		rotations += 26 - n
	start = i
print(rotations)


string = str(input())
length = len(string)
counter = 0
holder = 1
for i in range(length):
	buffer = ord(string[i]) - 97 + 1
	if buffer >= holder:
		size1 = buffer - holder
	else:
		size1 = holder - buffer
	if holder <= 13:
		size2 = holder + (26 - buffer)
	else:
		size2 = 26 - holder + buffer
	result = min(size1, size2)
	counter += result
	holder = buffer
print(counter)


import string
alpha = string.ascii_lowercase
s = input()
actual = 'a'
ss = 0
for c in s:
	diff = alpha.index(actual) - alpha.index(c)
	diff = abs(diff)
	if diff > 13:
		diff = 26 - diff
	ss += diff
	actual = c
print(ss)


s = input()
st = 'a'
n = len(s)
l1 = 0
l2 = 0
sumd = 0
for i in range(n):
	l1 = abs(ord(s[i]) - ord(st))
	l2 = 26 - abs(ord(s[i]) - ord(st))
	sumd += min(l1, l2)
	st = s[i]
print(sumd)


curr = 'a'
sum = 0
for i in input().strip():
	sum += min(abs(ord(i) - ord(curr)), 26 - abs(ord(i) - ord(curr)))
	curr = i
print(sum)


n = input()
z = ord('a')
m = 0
for i in range(len(n)):
	p = ord(n[i])
	z1 = abs(p - z)
	z2 = abs(26 - z1)
	m += min(z1, z2)
	z = ord(n[i])
print(m)


line = input()

def findMinStep(name):
	nameCharacters = list(name)
	point = 'a'
	sum = 0
	dist = 0
	for i in range(len(nameCharacters)):
		dist = abs(ord(nameCharacters[i]) - ord(point))
		if dist < 13:
			sum += dist
		else:
			sum += 26 - dist
		point = nameCharacters[i]
	print(sum)
findMinStep(line)


line = input()
start = 'a'
count = 0
for i in line:
	count += min(abs(ord(start) - ord(i)), 26 - abs(ord(start) - ord(i)))
	start = i
print(count)


s = input()
s = list(s)
l = [1]
sum = 0
for i in range(len(s)):
	l.append(ord(s[i]) - 96)
for i in range(len(l) - 1):
	a = l[i]
	b = l[i + 1]
	d1 = abs(a - b)
	m = max(a, b)
	n = min(a, b)
	M = 26 - m
	d2 = M + n
	sum += min(d1, d2)
print(sum)


def rotation(word):
	count1 = abs(ord(word[0]) - ord('a'))
	count = min(count1, 26 - count1)
	i = 0
	while i < len(word) - 1:
		count1 = abs(ord(word[i]) - ord(word[i + 1]))
		count2 = 26 - count1
		count += min(count1, count2)
		i += 1
	return count
a = input().strip()
print(rotation(a))


n = str(input())
import string
full = list(string.ascii_lowercase)
num = list(range(1, 27))
full = [x for x in zip(full, num)]
full3 = [v[1] for v in full if v[0] == 'a']
rotate = 0
for y in list(n):
	for (a, b) in full:
		if a == y:
			full3.append(b)
		else:
			pass
for i in range(0, len(full3) - 1):
	c1 = abs(full3[i + 1] - full3[i])
	c2 = abs(26 - c1)
	if c1 > c2:
		rotate += c2
	else:
		rotate += c1
print(rotate)


now = 'a'
ans = 0
S = input()
for s in S:
	x = abs(ord(s) - ord(now))
	ans += min(x, 26 - x)
	now = s
print(ans)


name = input()
total_steps = 0
pointer = 'a'
for i in name:
	steps = abs(ord(i) - ord(pointer))
	if steps <= 13:
		total_steps += steps
	else:
		total_steps += 26 - steps
	pointer = i
print(total_steps)


s1 = 'abcdefghijklmnopqrstuvwxyz'
s2 = s1[::-1]
i = 1
sum1 = 0
dict1 = {}
for i in range(0, len(s1)):
	dict1[s1[i]] = i + 1
s = input()
counter = s1[0]
for i in range(len(s)):
	ans1 = abs(dict1[counter] - dict1[s[i]])
	ans2 = abs(26 - ans1)
	sum1 = sum1 + min(ans1, ans2)
	counter = s[i]
print(sum1)


_input = input()
_sum = 0
distance = None
for i in range(0, len(_input)):
	if i == 0:
		if ord(_input[i]) - ord('a') <= 13:
			distance = ord(_input[i]) - ord('a')
			_sum = _sum + distance
		else:
			distance = 26 - (ord(_input[i]) - ord('a'))
			_sum = _sum + distance
	else:
		a = _input[i - 1]
		b = _input[i]
		c = ord(a)
		d = ord(b)
		if c > d:
			if c - d <= 13:
				distance = c - d
				_sum = _sum + distance
			else:
				distance = 26 - (c - d)
				_sum = _sum + distance
		elif d - c <= 13:
			distance = d - c
			_sum = _sum + distance
		else:
			distance = 26 - (d - c)
			_sum = _sum + distance
print(_sum)


sts = input()
sts = list(sts)
stess = 'abcdefghijklmnopqrstuvwxyz'
stess = list(stess)
firs = stess.index(sts[0])
if firs > 13:
	firs = 25 - abs(stess.index('a') - firs) + 1
elif firs <= 13:
	firs = firs
for i in range(len(sts) - 1):
	lens = abs(stess.index(sts[i]) - stess.index(sts[i + 1]))
	if lens > 13:
		lens = 25 - lens + 1
	elif lens <= 13:
		lens = lens
	firs += lens
print(firs)


string = input()
moves = 0
pointer = 0
index = 0
walk = 0
for i in range(len(string)):
	index = ord(string[i]) - 97
	walk = abs(pointer - index)
	if walk <= 13:
		moves += walk
	else:
		moves += 26 - walk
	pointer = index
print(moves)


s = map(ord, input())
start = 97
total = 26
result = 0
for i in s:
	rotation = abs(start - i)
	result += min(rotation, total - rotation)
	start = i
print(result)


word = str(input())

def min(a, b):
	orda = ord(a) - 96
	ordb = ord(b) - 96
	if abs(ordb - orda) <= 13:
		return ordb - orda
	elif ordb - orda > 13:
		return ordb - orda - 26
	elif ordb - orda < -13:
		return ordb - orda + 26
count = abs(min('a', word[0]))
for i in range(len(word) - 1):
	count += abs(min(word[i], word[i + 1]))
print(count)


s = input()
ls = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
j = 1
d = {}
for i in ls:
	d[i] = j
	j = j + 1
c = 0
ip = 'a'
for i in s:
	x1 = abs(d[i] - d[ip])
	x2 = 26 - x1
	c = c + min(x1, x2)
	ip = i
print(c)


import math
ck = 'abcdefghijklmnopqrstuvwxyz'
n = input()
if abs(ck.index(n[0])) < 26 - abs(ck.index(n[0])):
	s = abs(ck.index(n[0]))
else:
	s = 26 - abs(ck.index(n[0]))
for i in range(1, len(n)):
	if abs(ck.index(n[i]) - ck.index(n[i - 1])) < 26 - abs(ck.index(n[i]) - ck.index(n[i - 1])):
		s += abs(ck.index(n[i]) - ck.index(n[i - 1]))
	else:
		s += 26 - abs(ck.index(n[i]) - ck.index(n[i - 1]))
print(s)


a = list(input().strip())
c = 97
count = 0
for i in a:
	d = ord(i)
	if abs(d - c) < 13:
		count += abs(d - c)
	else:
		count += 26 - abs(d - c)
	c = d
print(count)


word = map(ord, input())
last_char = ord('a')
rotation = 0
for char in word:
	rot = abs(char - last_char)
	if rot > 13:
		rot = 26 + min(last_char, char) - max(last_char, char)
	rotation += rot
	last_char = char
print(rotation)


string = input()
curr = 97
moves = 0
for order in map(ord, string):
	x = abs(curr - order)
	moves += min(x, abs(26 - x))
	curr = order
print(moves)


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
s = input()
ans = 0
current = 'a'
for letter in s:
	ans += min(abs(ord(letter) - ord(current)), 26 - abs(ord(letter) - ord(current)))
	current = letter
print(ans)


s = list(map(str, input().lower()))
count = 0
temp = 0
for i in s:
	a = ord(i) - 97
	b = abs(temp - a)
	if b <= 13:
		count += b
	if b > 13:
		count += 26 - b
	temp = a
print(count)


import math
import os
import random
import re
import sys
s = input()
l = [1, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
c = 0
b = l.index('a')
for x in s:
	if abs(l.index(x) - b) > 13:
		c = c + 26 - abs(l.index(x) - b)
	else:
		c = c + abs(l.index(x) - b)
	b = l.index(x)
print(c)


ex_name = input()
result = 0
cur_pos = 97
for c in ex_name:
	result += min(abs(ord(c) - cur_pos), 26 - abs(ord(c) - cur_pos))
	cur_pos = ord(c)
print(result)


alpha = 'abcdefghijklmnopqrstuvwxyz'
r = 0
x = input()
for j in x:
	for i in range(len(alpha)):
		if alpha[i] == j:
			if i == 0:
				break
			elif i < 13:
				r += i
				alpha = alpha[i:] + alpha[:i]
				break
			else:
				r += 26 - i
				alpha = alpha[i:] + alpha[:i]
				break
print(r)


count = 0
word = input()
for i in range(len(word)):
	if i == 0:
		rotations = min(abs(ord(word[i]) - ord('a')), 26 - abs(ord(word[i]) - ord('a')))
		count += rotations
	else:
		rot = min(abs(ord(word[i]) - ord(word[i - 1])), 26 - abs(ord(word[i]) - ord(word[i - 1])))
		count += rot
print(count)


s = str(input())
count = min(abs(ord(s[0]) - ord('a')), 26 - abs(ord(s[0]) - ord('a')))
for i in range(1, len(s)):
	count += min(abs(ord(s[i]) - ord(s[i - 1])), 26 - abs(ord(s[i]) - ord(s[i - 1])))
print(count)


word = input()
curr_pos = 0
answ = 0
for letter in word:
	temp = abs(ord(letter) - ord('a') - curr_pos)
	answ += min(temp, 26 - temp)
	curr_pos = ord(letter) - ord('a')
print(answ)


string = 'abcdefghijklmnopqrstuvwxyz'
value = {}
j = 1
for i in string:
	value[i] = j
	j += 1
name = input()
count = 0
initial = 'a'
for i in name:
	adding = min(value[initial], value[i]) + 26
	count += min(abs(value[i] - value[initial]), abs(max(value[initial], value[i]) - adding))
	initial = i
print(count)


s = input()
check = 'abcdefghijklmnopqrstuvwxyz'

def left(ini, cur):
	lin = abs(ini - cur)
	nlin = ini + (26 - cur)
	return min(lin, nlin)

def right(ini, cur):
	lin = abs(ini - cur)
	nlin = 26 - ini + cur
	return min(lin, nlin)
ini = 0
res = 0
for i in s:
	cur = check.index(i)
	if ini <= cur:
		res += left(ini, cur)
	else:
		res += right(ini, cur)
	ini = cur
print(res)


string = input()
min_clock_rotations = min(ord(string[0]) - ord('a'), (ord('a') - ord(string[0])) % 26)
for i in range(1, len(string)):
	min_clock_rotations += min((ord(string[i]) - ord(string[i - 1])) % 26, (ord(string[i - 1]) - ord(string[i])) % 26)
print(min_clock_rotations)


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
from time import time
import os
import string
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = 'a' + input()
	order = 'abcdefghijklmnopqrstuvwxyzabcdefghijklm'
	count = 0
	for i in range(len(n) - 1):
		num1 = n[i]
		num2 = n[i + 1]
		dummy = abs(order.find(num1) - order.find(num2))
		dummy2 = abs(order.rindex(num1) - order.rindex(num2))
		count += min(dummy, dummy2)
	print(count)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


s = input()
ans = 0
cur = 'a'
for c in s:
	minC = min(ord(cur), ord(c))
	maxC = max(ord(cur), ord(c))
	ans += min(maxC - minC, minC + 26 - maxC)
	cur = c
print(ans)


(x, count, base) = (input(), 0, 'a')
alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]
for i in x:
	m = abs(alphabet.index(base) - alphabet.index(i))
	count += min(m, 26 - m)
	base = i
print(count)


s = input()
if s[0] == 'a':
	ss = 0
elif ord(s[0]) - ord('a') <= 13:
	ss = ord(s[0]) - ord('a')
else:
	ss = 26 - ord(s[0]) + ord('a')
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		ss += 0
	elif ord(max(s[i - 1], s[i])) - ord(min(s[i - 1], s[i])) <= 13:
		ss += ord(max(s[i - 1], s[i])) - ord(min(s[i - 1], s[i]))
	else:
		ss += 26 - ord(max(s[i - 1], s[i])) + ord(min(s[i - 1], s[i]))
print(ss)


s = input()
l = len(s)
ans = min(26 + 97 - ord(s[0]), ord(s[0]) - 97)
for i in range(0, l - 1):
	a = max(ord(s[i]), ord(s[i + 1]))
	b = min(ord(s[i]), ord(s[i + 1]))
	a = min(26 + b - a, a - b)
	ans += a
print(ans)


from sys import stdin

def main():
	clock = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	start = 0
	left = 0
	right = 0
	cost = 0
	desplace = 0
	word = stdin.readline().strip()
	for i in word:
		while start != 50000:
			if clock[right % 26] == i:
				desplace = abs(right - start)
				left = right
				break
			if clock[left % 26] == i:
				desplace = abs(left - start)
				right = left
				break
			right += 1
			left -= 1
		cost += abs(desplace)
		start = right
	print(cost)
main()


s = input()
curr = ans = 0
for p in s:
	d = ord(p) - ord('a')
	if curr < d:
		ans += min(d - curr, 26 - d + curr)
	else:
		ans += min(curr - d, 26 + d - curr)
	curr = d
print(ans)


str = input()
r = 0
cu = 1
for i in str:
	j = ord(i) - 96
	clock = abs(cu - j)
	anticlock = abs(26 - clock)
	r = r + min(clock, anticlock)
	cu = j
print(r)


from string import ascii_lowercase
pls = f'a{input()}'
sum = 0
for i in range(1, len(pls)):
	delta = abs(ascii_lowercase.index(pls[i]) - ascii_lowercase.index(pls[i - 1]))
	if delta > 13:
		sum += 26 - delta
	else:
		sum += delta
print(sum)


s = input()
t = 'a'
c = 0
for i in s:
	if ord(i) < ord(t):
		c += min(ord(t) - ord(i), abs(ord('z') - ord(t) + ord(i) - ord('a') + 1))
		t = i
	else:
		c += min(ord(i) - ord(t), abs(ord('z') - ord(i) + ord(t) - ord('a') + 1))
		t = i
print(c)


s = input()
cur = 'a'
count = 0
for ch in s:
	x = (26 + ord(ch) - ord(cur)) % 26
	count += min(x, 26 - x)
	cur = ch
print(count)


t = input()
a = list(t)
s = 0
pr = 0
h = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(a)):
	x = h.index(a[i]) - pr
	y = 26 - abs(x)
	pr = h.index(a[i])
	s += min(abs(x), abs(y))
print(s)


def main():
	x = input()
	current_pos = ord('a')
	moves = 0
	for i in range(0, len(x)):
		dist = abs(ord(x[i]) - current_pos)
		if dist < 13:
			moves += dist
		else:
			moves += 26 - dist
		current_pos = ord(x[i])
	print(moves)
main()


s = input()
p = ord('a')
ans = 0
for l in s:
	ol = ord(l)
	ans += min(abs(ol - p), 26 - abs(ol - p))
	p = ol
print(ans)


s = input()
c = 0
p = 97
for i in s:
	c += min((ord(i) - p + 26) % 26, (p - ord(i) + 26) % 26)
	p = ord(i)
print(c)


str = 'a' + input()
aplha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
counter = 0
i = 0
while i < len(str) - 1:
	if abs(aplha.index(str[i]) - aplha.index(str[i + 1])) > 26 - abs(aplha.index(str[i]) - aplha.index(str[i + 1])):
		counter = counter + (26 - abs(aplha.index(str[i]) - aplha.index(str[i + 1])))
		i = i + 1
	else:
		counter = counter + abs(aplha.index(str[i]) - aplha.index(str[i + 1]))
		i = i + 1
print(counter)


def main():
	from sys import stdin, stdout
	s = map(ord, stdin.read())
	res = 0
	curr = 0
	A = ord('a')
	Z = ord('z')
	for x in s:
		if A <= x <= Z:
			x -= A
			res += min(abs(x - curr), 26 - abs(x - curr))
			curr = x
		else:
			break
	stdout.write(str(res) + '\n')
main()


def NightAtMuseum(word):
	curChr = ord('a')
	totalMoves = 0
	for ch in word:
		chV = ord(ch)
		diff = abs(curChr - chV)
		totalMoves += diff if diff < 13 else 13 - diff % 13
		curChr = chV
	return totalMoves
inputStr = input()
print(NightAtMuseum(inputStr))


s = input()
if ord(s[0]) - ord('a') > 13:
	count = 26 - abs(ord(s[0]) - ord('a'))
elif ord(s[0]) - ord('a') <= 13:
	count = abs(ord(s[0]) - ord('a'))
for i in range(1, len(s)):
	if abs(ord(s[i]) - ord(s[i - 1])) > 13:
		count += 26 - abs(ord(s[i]) - ord(s[i - 1]))
	else:
		count += abs(ord(s[i]) - ord(s[i - 1]))
print(count)


s = 'a' + input()
alth = 'abcdefghijklmnopqrstuvwxy'
ans = 0
for i in range(1, len(s)):
	ans += 13 - abs(13 - abs(alth.find(s[i]) - alth.find(s[i - 1])))
print(ans)


def CW(a, b):
	if a < b:
		step = ord(b) - ord(a)
	elif a > b:
		step = ord('z') - ord(a) + ord(b) - ord('a') + 1
	else:
		step = 0
	return step

def CCW(a, b):
	if a > b:
		step = ord(a) - ord(b)
	elif a < b:
		step = ord(a) - ord('a') + ord('z') - ord(b) + 1
	else:
		step = 0
	return step

def main():
	ch = input()
	sumVal = 0
	ch = 'a' + ch
	for i in range(1, len(ch)):
		sumVal += min(CW(ch[i - 1], ch[i]), CCW(ch[i - 1], ch[i]))
	print(sumVal)
main()


alphabets = 'abcdefghijklmnopqrstuvwxyz'
word = input()
total = 0
x = alphabets[0]
for i in range(len(word)):
	if i == 0:
		x = alphabets[0]
		y = word[i]
		total += min(abs(alphabets.index(x) + 1 - (alphabets.index(y) + 1)), abs(26 - abs(alphabets.index(x) + 1 - (alphabets.index(y) + 1))))
	else:
		x = y
		y = word[i]
		total += min(abs(alphabets.index(x) + 1 - (alphabets.index(y) + 1)), abs(26 - abs(alphabets.index(x) + 1 - (alphabets.index(y) + 1))))
print(total)


n = input()
output = 0
c = 'a'
for i in n:
	d = abs(ord(i) - ord(c))
	output += min(d, 26 - d)
	c = i
print(output)


s = input()
x = 'abcdefghijklmnopqrstuvwxyz'
cur = 'a'
ans = 0
for c in s:
	p = abs(x.find(cur) - x.find(c))
	p = min(p, 26 - p)
	ans += p
	cur = c
print(ans)


alp = 'abcdefghijklmnopqrstuvwxyz'
alph = '1' + alp[::-1]
s = input()
c = min(alp.index(s[0]), alph.index(s[0]))
for i in range(1, len(s)):
	c += min(alp.index(s[i]) + alph.index(s[i - 1]), alph.index(s[i]) + alp.index(s[i - 1]), abs(alp.index(s[i]) - alp.index(s[i - 1])))
print(c)


n = input()

def obrót(l1, l2):
	if l1 > l2:
		ord_max = ord(l1)
		ord_min = ord(l2)
	else:
		ord_max = ord(l2)
		ord_min = ord(l1)
	przeciwnie = ord_max - ord_min
	zgodnie = 26 - przeciwnie
	wynik = min(przeciwnie, zgodnie)
	return wynik
l1 = 'a'
suma = 0
for i in n:
	l2 = i
	suma += obrót(l1, l2)
	l1 = l2
print(suma)


alnum = {chr(i): j for (i, j) in zip(range(97, 123), range(1, 27))}
s = input()
x = 1
c = 0
for i in s:
	c += min([abs(alnum[i] - x), abs(alnum[i] - x - 26), abs(alnum[i] - x + 26)])
	x = alnum[i]
print(c)


key = 'abcdefghijklmnopqrstuvwxyz'
alphaval = {key: idx for (idx, key) in enumerate(key, start=1)}
word = 'a' + input()
wordvals = [alphaval[letter] for letter in word]
scrolls = 0
for i in range(1, len(wordvals)):
	alphadist = max(wordvals[i - 1], wordvals[i]) - min(wordvals[i - 1], wordvals[i])
	if alphadist > 13:
		scrolls += 26 - alphadist
	else:
		scrolls += alphadist
print(scrolls)


a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = input()
cn = 0
turns = 0
for c in s:
	x = a.index(c) - cn
	cn = a.index(c)
	if x > 13:
		turns += abs(x - 26)
	elif x < -13:
		turns += x + 26
	else:
		turns += abs(x)
print(str(turns))


def count_clockwise(i, j):
	j = j % 26
	counter = 0
	while i % 26 != j:
		i += 1
		counter += 1
	return counter

def count_counter_clockwise(i, j):
	j = j % 26
	counter = 0
	while i % 26 != j:
		i -= 1
		counter += 1
	return counter

def count_minimal(start, end):
	i = ord(start) - 97
	j = ord(end) - 97
	cw = count_clockwise(i, j)
	ccw = count_counter_clockwise(i, j)
	if cw <= ccw:
		return cw
	else:
		return ccw
raw = input()
turn = count_minimal('a', raw[0])
for i in range(1, len(raw)):
	turn += count_minimal(raw[i - 1], raw[i])
print(turn)


z = 'a' + input()
print(sum((min(abs(ord(z[i]) - ord(z[i + 1])), 26 - abs(ord(z[i]) - ord(z[i + 1]))) for i in range(len(z) - 1))))


s = input()
c = 97
rotations = 0
for i in range(len(s)):
	d = abs(c - ord(s[i]))
	if d > 13:
		d = 26 - d
	rotations += d
	c = ord(s[i])
print(rotations)


import math
a = input()
cur = ord('a')
ans = int(0)
for i in a:
	ans += min(abs(cur - ord(i)), abs(cur + 26 - ord(i)), abs(cur - 26 - ord(i)))
	cur = ord(i)
print(ans)


s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
(t, x1) = (0, 0)
for i in range(len(s)):
	x = a.index(s[i])
	t += min((x - x1) % 26, 26 - (x - x1) % 26)
	x1 = x
print(t)


s = list(map(lambda c: ord(c) - ord('a'), 'a' + str(input())))
a = 0
for i in range(1, len(s)):
	x = abs(s[i] - s[i - 1])
	a += min(x, 26 - x)
print(a)


alfa = 'abcdefghijklmnopqrstuvwxyz'
s = input()
ch = 0
sol = 0
for i in s:
	pos = alfa.find(i)
	if ch > pos:
		sol += min(ch - pos, 26 - ch + pos)
	else:
		sol += min(pos - ch, 26 - pos + ch)
	ch = pos
print(sol)


s = input()
import string
d = dict(zip(string.ascii_lowercase, range(1, 27)))
if abs(d['a'] - d[s[0]]) < 26 - abs(d['a'] - d[s[0]]):
	count = abs(d['a'] - d[s[0]])
else:
	count = 26 - abs(d['a'] - d[s[0]])
for i in range(len(s) - 1):
	if abs(d[s[i]] - d[s[i + 1]]) < 26 - abs(d[s[i]] - d[s[i + 1]]):
		count += abs(d[s[i]] - d[s[i + 1]])
	else:
		count += 26 - abs(d[s[i]] - d[s[i + 1]])
print(count)


from sys import stdin

def main():
	abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	pal = stdin.readline().strip()
	posicion = 0
	total = 0
	for i in pal:
		final = abc.index(i)
		if posicion == final:
			total = total
		else:
			if posicion == 0 and final < 26:
				pasos = abs(final)
			elif final == 0 and posicion < 26:
				pasos = abs(posicion)
			else:
				pasos = abs(posicion - final)
			(opcion, opcion1) = (abs(26 - posicion) + final, abs(posicion + 26 - final))
			if opcion1 < opcion:
				opcion = opcion1
			if pasos < opcion:
				total += pasos
			else:
				total += opcion
		posicion = final
	print(total)
main()


s = input()
ans = 0
prev = 'a'
for c in s:
	v = abs(ord(c) - ord(prev))
	ans += min(v, 26 - v)
	prev = c
print(ans)


ans = 0
inp = input()
letters = 'abcdefghijklmnopqrstuvwxyz'
pos = 0
for i in inp:
	for x in range(26):
		if i == letters[x]:
			if abs(pos - x) > abs(25 - abs(pos - x)):
				ans += abs(26 - abs(pos - x))
			else:
				ans += abs(pos - x)
			pos = x
print(ans)


s = input()
res = 0
x = 0
A = 0
for i in range(len(s)):
	x = abs(ord(s[i]) - 97 - A)
	A = ord(s[i]) - 97
	if x < 13:
		res = res + x
	else:
		res = res + (26 - x)
print(res)


s = input('')
a = 'a'
x = 0
for i in s:
	if abs(ord(i) - ord(a)) > 13:
		x = 26 - abs(ord(i) - ord(a)) + x
		a = i
	else:
		x = abs(ord(i) - ord(a)) + x
		a = i
print(x)


a = 97
o = 0
e = 0
for i in input():
	o = abs(ord(i) - a)
	e += min(o, abs(26 - o))
	a = ord(i)
print(e)


anchor = 'a'
name = input()
step = 0
for i in range(len(name)):
	distance = abs(ord(anchor) - ord(name[i]))
	if distance < 13:
		step += distance
	else:
		step += 26 - distance
	anchor = name[i]
print(step)


alphabrt_length = 26
first_symbol_code = ord('a')
alphabet = {chr(i + first_symbol_code): i for i in range(alphabrt_length)}
word = input()
prev = 0
turn_count = 0
for letter in word:
	variant1 = abs(alphabet[letter] - prev)
	variant2 = alphabrt_length - variant1
	turn_count += min(variant1, variant2)
	prev = alphabet[letter]
print(turn_count)


s = input()
count = 0
last = 1
for i in s:
	tmp = abs(ord(i) - 96 - last)
	last = ord(i) - 96
	count += min(tmp, abs(tmp - 26))
print(count)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet_ls = list(alphabet)
str_input = list(input())
current_pos = 0
sum_rotation = 0
for c in str_input:
	pos1 = alphabet_ls.index(c)
	distance = min(abs(pos1 - current_pos), 26 - abs(pos1 - current_pos))
	rotation = distance
	current_pos = pos1
	sum_rotation += rotation
print(sum_rotation)


s = input()
curr = 'a'
ans = 0
for i in s:
	c = abs(ord(curr) - ord(i))
	if c > 13:
		c = 26 - c
	ans += c
	curr = i
print(ans)


st = list(input())
cl = 0
t = 0
for i in st:
	i = ord(i) - 97
	if abs(cl - i) < 13:
		t += abs(cl - i)
	else:
		t += 26 - abs(cl - i)
	cl = i
print(t)


s = input()
count = min(ord(s[0]) - ord('a'), 26 - (ord(s[0]) - ord('a')))
for i in range(0, len(s)):
	if i + 1 == len(s):
		print(count)
	else:
		a = int(abs(ord(s[i + 1]) - ord(s[i])))
		count += min(a, 26 - a)


from string import ascii_lowercase
word = input()
res = 0
curr = 'a'
for c in word:
	p1 = abs(ord(c) - ord(curr))
	p2 = abs(ord(c) + 26 - ord(curr))
	p3 = abs(ord(curr) + 26 - ord(c))
	res += min(p1, p2, p3)
	curr = c
print(res)


offset = ord('a')
current = 0
total = 0
letters = list(map(lambda x: ord(x) - offset, list(input())))
for l in letters:
	difference = abs(l - current)
	if difference > 13:
		difference = 26 - difference
	total += difference
	current = l
print(total)


def conv(x):
	return ord(x) - ord('a') + 1
x = input()
ln = len(x)
(cur, mn, tot) = (1, 0, 0)
for i in x:
	aa = abs(conv(i) - cur)
	bb = 26 - aa
	cur = conv(i)
	tot += min(aa, bb)
print(tot)


def f(src, dest):
	return min(abs(dest - src), abs(26 - dest + src))
s = input()
r = 0
x = 1
y = 0
for i in s:
	y = ord(i) - 96
	if x < y:
		r += f(x, y)
	else:
		r += f(y, x)
	x = y
print(r)


s = input()
pos = 'a'
count = 0
for i in s:
	val = min(abs(ord(i) - ord(pos)), 26 - abs(ord(i) - ord(pos)))
	count += val
	pos = i
print(count)


x = input()
y = 'abcdefghijklmnopqrstuvwxyz'
a = 0
for i in range(len(x) - 1):
	if abs(y.index(x[i]) - y.index(x[i + 1])) > 13:
		a += 26 - abs(y.index(x[i]) - y.index(x[i + 1]))
	else:
		a += abs(y.index(x[i]) - y.index(x[i + 1]))
if abs(y.index('a') - y.index(x[0])) > 13:
	a += 26 - abs(y.index('a') - y.index(x[0]))
else:
	a += abs(y.index('a') - y.index(x[0]))
print(a)


l = list(input())
l1 = list('abcdefghijklmnopqrstuvwxyz')
n = 1
to = 0
for i in l:
	n1 = l1.index(i) + 1
	to += min(abs(n1 - n), 26 - abs(n1 - n))
	n = n1
print(to)


a = input()
s = 'abcdefghijklmnopqrstuvwxyz'
l = 0
for i in a:
	if s.find(i) > 26 - s.find(i):
		l += 26 - s.find(i)
		s = s[s.find(i):] + s[:s.find(i)]
	else:
		l += s.find(i)
		s = s[s.find(i):] + s[:s.find(i)]
print(l)


x = list(input())
x = ['a'] + x
count = 0
for i in range(len(x) - 1):
	val = abs(ord(x[i]) - ord(x[i + 1]))
	count += min(val, 26 - val)
print(count)


s = input()
alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
dict_alph = dict()
for i in range(len(alph)):
	dict_alph[alph[i]] = i
dict_ind = dict()
ans = 0
pos = 0
l = len(alph)
for letter in s:
	new_let = dict_alph[letter]
	if pos < new_let:
		ans += min(new_let - pos, pos + l - new_let)
	else:
		ans += min(pos - new_let, l - pos + new_let)
	pos = new_let
print(ans)


lettersStr = 'abcdefghijklmnopqrstuvwxyz'
letters = list(lettersStr)
startPointer = 0
endPointer = 25
total = 0
word = input()
pointer1 = 0
pointer2 = 0
for char in word:
	charPointer = letters.index(char)
	counter1 = 0
	counter2 = 0
	while pointer1 != charPointer:
		counter1 += 1
		if pointer1 != 25:
			pointer1 += 1
		else:
			pointer1 = 0
	pointer1 = charPointer
	while pointer2 != charPointer:
		counter2 += 1
		if pointer2 != 0:
			pointer2 -= 1
		else:
			pointer2 = 25
	pointer2 = charPointer
	if counter1 < counter2:
		total += counter1
	else:
		total += counter2
print(total)


word = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
rotations = 0
current_letter = 'a'
length = len(word)
for letter in word:
	normal_clockwise_rotations = alphabet.index(letter) - alphabet.index(current_letter)
	if normal_clockwise_rotations < 0:
		normal_clockwise_rotations *= -1
	if normal_clockwise_rotations > 13:
		normal_clockwise_rotations = 26 - normal_clockwise_rotations
	rotations += normal_clockwise_rotations
	current_letter = letter
print(rotations)


from string import ascii_lowercase

def make_hash():
	dic = {}
	pos = 0
	for i in ascii_lowercase:
		dic[i] = pos
		pos = pos + 1
	return dic

def min_distance(string1, string2, dic):
	index_min = 0
	index_max = 26
	term0 = dic[string1]
	term1 = dic[string2]
	term_ = 0
	if term1 < term0:
		term_ = term1
		term1 = term0
		term0 = term_
	term3 = term0 - index_min + index_max - term1
	return min(term3, abs(term0 - term1))

def rotate(dictionary_alphabet, input_string):
	length = len(input_string)
	result = 0
	for i in range(0, length - 1):
		min_ = min_distance(input_string[i], input_string[i + 1], dic)
		result = result + min_
	result = result + min_distance('a', input_string[0], dic)
	return result
input_string = str(input())
dic = make_hash()
print(rotate(dic, input_string))


from sys import stdin

def main():
	abc = 'abcdefghijklmnopqrstuvwxyz'
	pala = stdin.readline().strip()
	suma = 0
	pos = 1
	for i in range(len(pala)):
		k = abc.index(pala[i]) + 1
		h = min(k, pos)
		t = max(k, pos)
		l = 26 + h - t
		y = t - h
		u = min(l, y)
		suma += u
		pos = k
	print(suma)
main()


word = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def w(n):
	if n == 1:
		return 1
	else:
		for i in range(26):
			if n == word[i]:
				return int(i + 1)

def cha(a, b):
	if abs(a - b) > 13:
		return 26 - abs(a - b)
	else:
		return abs(a - b)
s = input()
ww = []
ans = 0
ww.append(1)
for i in range(len(s)):
	ww.append(s[i])
for i in range(len(ww) - 1):
	ans += cha(w(ww[i]), w(ww[i + 1]))
print(ans)


from string import ascii_lowercase

def solve():
	s = input()
	t = 0
	ans = 0
	for x in s:
		t1 = 0
		t2 = 0
		while ascii_lowercase[(t + t1) % 26] != x:
			t1 += 1
		while ascii_lowercase[t + t2] != x:
			t2 -= 1
		if abs(t1) < abs(t2):
			ans += t1 % 26
		else:
			ans += abs(t2) % 26
		t = (t + t1) % 26
	print(ans)
solve()


name = input()
letter = 'a'
total = 0
for i in name:
	temp = abs(ord(i) - ord(letter))
	if temp <= 13:
		total += temp
	else:
		total += 13 - temp % 13
	letter = i
print(total)


def main():
	palavra = input()
	codigos = []
	for l in palavra:
		codigos.append(ord(l))
	pos_ponteiro = 97
	total = 0
	for l in palavra:
		pos_letra = ord(l)
		difference = abs(pos_letra - pos_ponteiro)
		if difference > 13:
			difference = 13 - (difference - 13)
		total += difference
		pos_ponteiro = pos_letra
	print(total)
	return 0
main()


string = input()
cnt = 0
current = 'a'
for char in string:
	min1 = abs(ord(char) - ord(current))
	min2 = abs(26 - min1)
	cnt += min(min1, min2)
	current = char
print(cnt)


def distance(From, To):
	D = abs(ord(From) - ord(To))
	if D > 13:
		return 26 - D
	else:
		return D
x = input()
i = len(x)
sum = 0
triger = True
for j in range(0, i - 1):
	if triger:
		sum += distance('a', x[j])
		triger = False
	sum += distance(x[j], x[j + 1])
if i == 1:
	print(distance('a', x[0]))
else:
	print(sum)


import sys, math
line = input()
length = len(line)
cur = 'a'
sumn = 0
for c in line:
	diff = abs(ord(c) - ord(cur))
	sumn += min(diff, 26 - diff)
	cur = c
print(sumn)


a = str(input())
c = ''
if a[0] != 'a':
	c = 'a' + a
	a = c
k = 0
for i in range(1, len(a)):
	if abs(ord(a[i - 1]) - ord(a[i])) > 13:
		k += 26 - abs(ord(a[i - 1]) - ord(a[i]))
	else:
		k += abs(ord(a[i - 1]) - ord(a[i]))
print(k)


s = input()
pointer = 'a'
w = 0
for item in s:
	v = abs(ord(pointer) - ord(item))
	if v > 13:
		v = 26 - v
	w += v
	pointer = item
print(w)


import string
x = [x for x in string.ascii_lowercase]
s = input()
lastIndex = 0
index = 0
count = 0
for i in s:
	index = x.index(i)
	if abs(index - lastIndex) > 13:
		count += 26 - abs(index - lastIndex)
	else:
		count += abs(index - lastIndex)
	lastIndex = index
print(count)


def position(lo, hi):
	z = ord('z') - ord('a')
	cw = hi - lo
	ccw = z - hi + lo + 1
	if cw < ccw:
		return cw
	else:
		return ccw

def main():
	word = input()
	i = 0
	a = ord('a')
	total = 0
	c = 0
	while i < len(word):
		n = ord(word[i]) - a
		if n > c:
			total += position(c, n)
		else:
			total += position(n, c)
		c = n
		i = i + 1
	print(total)
main()


s = input()
sum = 0
pos = 97
for i in range(len(s)):
	a = ord(s[i])
	if a > pos:
		b = min(a - pos, pos + 26 - a)
	else:
		b = min(pos - a, a + 26 - pos)
	sum += b
	pos = a
print(sum)


s = input()
p1 = 'a'
step = 0

def calStep(p1, p2):
	t1 = abs(ord(p2) - ord(p1))
	t2 = 26 - t1
	if t1 <= t2:
		return t1
	else:
		return t2
for i in range(len(s)):
	if i == 0:
		p2 = s[0]
		step += calStep(p1, p2)
		p1 = p2
	else:
		p2 = s[i]
		step += calStep(p1, p2)
		p1 = p2
print(step)


a = list(input())
n = len(a)
curr = 'a'
res = 0
for i in range(n):
	if ord(a[i]) > ord(curr):
		res += min(ord(a[i]) - ord(curr), ord(curr) + 26 - ord(a[i]))
	else:
		res += min(ord(curr) - ord(a[i]), ord(a[i]) + 26 - ord(curr))
	curr = a[i]
print(res)


a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
c = input()
n = len(c)
l = k = ans = 0
for i in range(0, n):
	for j in range(0, 26):
		if a[j] == c[i]:
			l = j
			break
	p = l - k
	if p < 0:
		p *= -1
	q = 26 - p
	ans += min(p, q)
	k = l
print(ans)


str = str(input())
count = 0
index = 0
start = 0
walk = 0
for i in range(0, len(str)):
	index = ord(str[i]) - 97
	walk = abs(index - start)
	if walk < 13:
		count += walk
	else:
		count += 26 - walk
	start = index
print(count)


n = input()
sum = 0
for i in range(len(n) - 1):
	a = min(abs(ord(n[i]) - ord(n[i + 1])), 26 - abs(ord(n[i]) - ord(n[i + 1])))
	sum += a
b = min(abs(ord('a') - ord(n[0])), 26 - abs(ord('a') - ord(n[0])))
sum += b
print(sum)


(s, x, a) = (input(), 'a', 0)
for i in range(len(s)):
	a += min(26 - abs(ord(s[i]) - ord(x)), abs(ord(s[i]) - ord(x)))
	x = s[i]
print(a)


x = {}
for (i, j) in enumerate(range(97, 123)):
	x[chr(j)] = i
y = input()
summ = 0
prev = x['a']
for i in y:
	summ = summ + min(abs(x[f'{i}'] - prev), 26 - abs(x[f'{i}'] - prev))
	prev = x[f'{i}']
print(summ)


inp = input()
sum = min(abs(ord(inp[0]) % 96 - ord('a') % 96), 26 - abs(ord(inp[0]) % 96 - ord('a') % 96))
for i in range(len(inp) - 1):
	sum += min(abs(ord(inp[i]) % 96 - ord(inp[i + 1]) % 96), 26 - abs(ord(inp[i]) % 96 - ord(inp[i + 1]) % 96))
print(sum)


letter = 'abcdefghijklmnopqrstuvwxyz'
n = input()
p = 0
t = 0
for x in n:
	l = p - letter.find(x)
	if l < 0:
		l += 26
	r = letter.find(x) - p
	if r < 0:
		r += 26
	p = letter.find(x)
	if l < r:
		t += l
	else:
		t += r
print(t)


s = input()
s = 'a' + s
m = 0
for i in range(1, len(s)):
	p = s[i - 1]
	d1 = min(abs(ord(p) - ord(s[i])), 26 - abs(ord(p) - ord(s[i])))
	m = m + d1
print(m)


def main():
	f = input()
	l = 'a'
	suma = 0
	for i in range(len(f)):
		d = abs(ord(f[i]) - ord(l))
		if d >= 13:
			d = 26 - d
		suma += d
		l = f[i]
	print(suma)
main()


text = input()
prev_pos = 1
cost = 0
for letter in text:
	current_pos = ord(letter) - 96
	temp_cost = abs(current_pos - prev_pos)
	cost += min(temp_cost, abs(26 - temp_cost))
	prev_pos = current_pos
print(cost)


s = input()
c = 0
k = abs(ord('a') - ord(s[0]))
temp = abs(k - 26)
if k > temp:
	c += temp
else:
	c += k
for i in range(1, len(s)):
	t = abs(ord(s[i - 1]) - ord(s[i]))
	temp = abs(t - 26)
	if t > temp:
		c += temp
	else:
		c += t
print(c)


st = input()
cnt = 0
li = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
c = v = ind = ind2 = 0
for i in range(len(st)):
	while li[ind2] != st[i]:
		v += 1
		ind2 -= 1
	while li[ind] != st[i]:
		if ind == 25:
			c += li.index(st[i]) + 1
			break
		else:
			c += 1
		ind += 1
	if c > v:
		cnt += v
	else:
		cnt += c
	c = v = 0
	ind = ind2 = li.index(st[i])
print(cnt)


s = input()
ans = 0
cur = 'a'
for i in range(len(s)):
	nex = s[i]
	k = abs(ord(cur) - ord(nex))
	ans += min(k, abs(26 - k))
	cur = nex
print(ans)


from sys import stdin

def main():
	ab = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
	let = 'a' + stdin.readline().strip()
	let = let.replace('', ' ').split()
	con = 0
	for i in range(len(let) - 1):
		(a, b) = (let[i], let[i + 1])
		if a != b:
			der = abs(ab[a] - ab[b])
			iz = 26 - der
			con += min(der, iz)
	print(con)
main()


t = input()
p = 97
res = 0
for i in t:
	res += min(abs(ord(i) - p), 26 - abs(ord(i) - p))
	p = ord(i)
print(res)


s = input()
c = ord('a')
t = 0
for i in s:
	t += min(abs(ord(i) - c), 26 - abs(ord(i) - c))
	c = ord(i)
print(t)


string = input()
pos = 0
count = 0
for char in string:
	dest = ord(char) - 97
	if dest > pos:
		count += min(dest - pos, pos + 26 - dest)
	else:
		count += min(pos - dest, dest + 26 - pos)
	pos = dest
print(count)


name = input()

def no_of_rotations(ch1, ch2):
	order = list('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')
	frwrd_moves = abs(order.index(ch1) - order.index(ch2))
	order.remove(min(ch1, ch2))
	bckwrd_moves = abs(order.index(ch1) - order.index(ch2))
	return min(frwrd_moves, bckwrd_moves)
intial_push = no_of_rotations('a', name[0])
name_push = sum([no_of_rotations(name[i], name[i + 1]) for i in range(len(name) - 1)])
print(intial_push + name_push)


S1 = 'abcdefghijklmnopqrstuvwxyz'
S = input()
v = 0
k = 0
for i in range(len(S)):
	p = S1.index(S[i])
	if abs(p - v) < 25 - abs(p - v):
		k = k + abs(p - v)
	else:
		k = k + 25 - abs(p - v) + 1
	v = p
print(k)


x = input()
(cur, tot) = ('a', 0)
for i in x:
	d = abs(ord(i) - ord(cur))
	tot += min(d, 26 - d)
	cur = i
print(tot)


exhibit_name = input().lower()
point = 'a'
total = 0
distance = 0
for i in range(len(exhibit_name)):
	distance = abs(ord(exhibit_name[i]) - ord(point))
	if distance < 13:
		total += distance
	else:
		total += 26 - distance
	point = exhibit_name[i]
print(total)


n = [int(ord(i)) for i in input()]
add = min(abs(97 - n[0]), 26 - abs(97 - n[0]))
for i in range(len(n) - 1):
	f = abs(n[i] - n[i + 1])
	add += min(f, 26 - f)
print(add)


tofind = list(input())
counter1 = 0
counter2 = 0
counts = 0
trials = 0
alphabets = list('abcdefghijklmnopqrstuvwxyz')
for i in range(len(tofind)):
	for j in range(len(alphabets)):
		if tofind[i] == alphabets[j]:
			counter2 = j
			counts = min(abs(counter2 - counter1), 26 - abs(counter2 - counter1))
			trials = trials + counts
		counter1 = counter2
print(trials)


a = str(input())
x = int(0)
k = int(0)
b = int(1)
while x < len(a):
	if a[x] == 'a':
		c = 1
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'b':
		c = 2
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'c':
		c = 3
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'd':
		c = 4
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'e':
		c = 5
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'f':
		c = 6
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'g':
		c = 7
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'h':
		c = 8
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'i':
		c = 9
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'j':
		c = 10
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'k':
		c = 11
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'l':
		c = 12
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'm':
		c = 13
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'n':
		c = 14
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'o':
		c = 15
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'p':
		c = 16
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'q':
		c = 17
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'r':
		c = 18
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 's':
		c = 19
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 't':
		c = 20
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'u':
		c = 21
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'v':
		c = 22
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'w':
		c = 23
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'x':
		c = 24
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'y':
		c = 25
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	elif a[x] == 'z':
		c = 26
		d = abs(b - c)
		e = 26 - d
		f = min(d, e)
		k = k + f
		b = c
	x = x + 1
print(k)


(c, v) = (0, 0)
for ch in input():
	i = ord(ch) - ord('a')
	x = (i - c + 26) % 26
	v += min(x, 26 - x)
	c = i
print(v)


s = input()
x = 'abcdefghijklmnopqrstuvwxyz'
current = 'a'
count = 0
for character in s:
	pos = abs(x.find(current) - x.find(character))
	pos = min(pos, 26 - pos)
	count += pos
	current = character
print(count)


def alpha():
	inp = input()
	pointer = 0
	counter = 0
	i = 0
	for i in range(len(inp)):
		if abs(pointer - (ord(inp[i]) - 97)) < abs(26 - abs(pointer - (ord(inp[i]) - 97))):
			counter += abs(pointer - (ord(inp[i]) - 97))
		else:
			counter += abs(26 - abs(pointer - (ord(inp[i]) - 97)))
		pointer = ord(inp[i]) - 97
	return counter
print(alpha())


v = input()
sum = 0
x1 = 0
for f in v:
	x2 = ord(f) - ord('a')
	d1 = (x2 - x1 + 26) % 26
	d2 = (x1 - x2 + 26) % 26
	if d1 > d2:
		sum = sum + d2
	else:
		sum = sum + d1
	x1 = x2
print(sum)


O = [97] + [ord(x) for x in list(input())]
m = 0
for i in range(len(O) - 1):
	m += min(abs(O[i] - O[i + 1]), 26 - abs(O[i] - O[i + 1]))
print(m)


word = input()
turns = [min(abs(ord(i) - ord(j)), 26 - abs(ord(i) - ord(j))) for (i, j) in list(zip('a' + word, ('a' + word)[1:]))]
print(sum(turns))


s = 'a' + input()
a = 0
for i in range(1, len(s)):
	v1 = abs(ord(s[i]) - ord(s[i - 1]))
	v2 = ord('z') - ord('a') + 1 - v1
	a += min(v1, v2)
print(a)


s = input()
current = 0
result = 0
for i in s:
	numb = ord(i) - ord('a')
	result += min(abs(current - numb), abs(26 - numb + current), abs(26 + numb - current))
	current = numb
print(result)


word = input()
res = 0
for i in range(len(word)):
	if i == 0:
		res += min(ord(word[i]) - ord('a'), 26 - (ord(word[i]) - ord('a')))
	else:
		res += min(abs(ord(word[i]) - ord(word[i - 1])), 26 - abs(ord(word[i]) - ord(word[i - 1])))
print(res)


def main():
	t = ['#', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	st = list(input())
	ans = 0
	i = 1
	for el in st:
		it = t.index(el)
		ans += min(max(it, i) - min(it, i), max(it, i) % 26 + min(it, i), 26 - max(it, i) % 26 + min(it, i))
		i = it
	print(ans)
main()


s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
p = 0
m = a.index(s[0])
for i in range(len(s) - 1):
	q = abs(a.index(s[i]) - a.index(s[i + 1]))
	if q > 12:
		p += 26 - q
	else:
		p += q
if m > 12:
	m = 26 - m
print(p + m)


s = input()
ans = 0
curr = 1
for c in s:
	ans += min(abs(ord(c) - 96 - curr), 26 - abs(ord(c) - 96 - curr))
	curr = ord(c) - 96
print(ans)


alphabet = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
word = input()
sol = 0
index = 26
for c in word:
	if c != alphabet[index]:
		left = alphabet.find(c, index - 26)
		sol1 = index - left
		right = alphabet.find(c, index + 1)
		sol2 = right - index
		sol += min(sol1, sol2)
		index = alphabet.find(c, 26)
print(sol)


r = 'a'
x = input()
s = 0
for i in x:
	y = abs(ord(i) - ord(r))
	if y > 13:
		y = 26 - y
	s += y
	r = i
print(s)


import string
a = string.ascii_lowercase
t = 0
b = input()
res = 0
for k in b:
	f = a.index(k)
	m1 = min(t, f)
	m2 = max(t, f)
	sum = min(m2 - m1, 26 - (m2 - m1))
	res += sum
	t = f
print(res)


s = input()
pin = 'a'
count = 0
for char in s:
	if abs(ord(pin) - ord(char)) > 13:
		count += 26 - abs(ord(char) - ord(pin))
	else:
		count += abs(ord(char) - ord(pin))
	pin = char
print(count)


n = input()
k = abs(ord('a') - ord(n[0]))
if k > 12:
	k = 26 - k
else:
	k = k
for i in range(1, len(n)):
	m = abs(ord(n[i - 1]) - ord(n[i]))
	if m > 12:
		k += 26 - m
	else:
		k += m
print(k)


s = input()
M = ord('z') - ord('a') + 1
ans = 0
last = ord('a')
for c in s:
	curr = ord(c)
	ans += min((curr - last + M) % M, (last - curr + M) % M)
	last = curr
print(ans)


s = input()
prev = 'a'
ans = 0
for x in s:
	diff = abs(ord(x) - ord(prev))
	ans += min(diff, 26 - diff)
	prev = x
print(ans)


def printing(name):
	point = ord('a')
	count = 0
	for letter in name:
		if abs(ord(letter) - point) < 13:
			count += abs(ord(letter) - point)
			point = ord(letter)
		elif abs(ord(letter) - point) >= 13:
			count += 26 - abs(ord(letter) - point)
			point = ord(letter)
	return count
name_exhibit = str(input())
count = printing(name_exhibit)
print(count)


name = input()
if abs(97 - ord(name[0])) < 26 - abs(97 - ord(name[0])):
	count = abs(97 - ord(name[0]))
else:
	count = 26 - abs(97 - ord(name[0]))
for i in range(len(name) - 1):
	if abs(ord(name[i + 1]) - ord(name[i])) <= 26 - abs(ord(name[i + 1]) - ord(name[i])):
		count += abs(ord(name[i + 1]) - ord(name[i]))
	else:
		count += 26 - abs(ord(name[i + 1]) - ord(name[i]))
print(count)


c = 97
t = 0
for l in map(ord, input().lower()):
	i = abs(c - l)
	t += min(i, 26 - i)
	c = l
print(t)


s = input()
cur = 'a'
ans = 0
for alph in s:
	dist = abs(ord(alph) - ord(cur))
	ans += min(dist, 26 - dist)
	cur = alph
print(ans)


password = input()
a = 'a'
realpass = 0
for i in password:
	realpass += min(abs(ord(a) - ord(i)), 26 - abs(ord(a) - ord(i)))
	a = i
print(realpass)


def position(letter):
	return ord(letter) - 96
name = input()
rotations = 0
current_position = 1
for letter in name:
	letter_position = position(letter)
	displacement = abs(letter_position - current_position)
	rotations += min(displacement, 26 - displacement)
	current_position = letter_position
print(rotations)


s = str(input())
l = 'a'
m = 0
for ch in s:
	x = ord(ch) - ord(l)
	if x < 0:
		x = x + 26
	if x > 13:
		x = 26 - x
	m = m + x
	l = ch
print(m)


s = input()
c = 0
o = ord(s[0]) - ord('a')
c = c + min(o, 26 - o)
for i in range(1, len(s)):
	if ord(s[i]) > ord(s[i - 1]):
		o = ord(s[i]) - ord(s[i - 1])
		c = c + min(o, 26 - o)
	else:
		o = ord(s[i - 1]) - ord(s[i])
		c = c + min(o, 26 - o)
print(c)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
li = [chr(i) for i in range(97, 123)]
l = z()
ans = 0
k = 1
for i in l:
	t = li.index(i) + 1
	ans += min(abs(t - k), 26 - abs(t - k))
	k = t
print(ans)


word = input()
curr_c = 'a'
rotate = 0
for c in word:
	rotate += min(abs(ord(curr_c) - ord(c)), abs(ord(curr_c) + 26 - ord(c)), abs(ord(curr_c) - 26 - ord(c)))
	curr_c = c
print(rotate)


name = input()
key = 1
sum1 = 0
for i in range(len(name)):
	char_value = ord(name[i]) - 96
	if abs(key - char_value) <= 13:
		sum1 += abs(key - char_value)
	else:
		sum1 += 26 - abs(key - char_value)
	key = char_value
print(sum1)


def answer():
	a = list('abcdefghijklmnopqrstuvwxyz')
	b = [x for x in range(0, 13)]
	c = [x for x in range(1, 14)]
	c.reverse()
	d = []
	for x in b:
		d.append(x)
	for x in c:
		d.append(x)
	new = list(input())
	i = 0
	old = 'a'
	e = [x for x in d]
	ans = 0
	while i < len(new):
		current = new[i]
		position = a.index(current)
		cool = e[position]
		ans += cool
		old = current
		j = 0
		newb = 0
		while j < 26:
			e[(j + position) % 26] = d[j]
			j += 1
			if j == 26 and (not newb):
				j = 0
				newb = 1
		i += 1
	print(ans)
answer()


s = input()
prev = 'a'
ans = 0
for i in s:
	if ord(i) > ord(prev):
		ans += min(ord(i) - ord(prev), ord(prev) - ord(i) + 26)
	else:
		ans += min(ord(prev) - ord(i), ord(i) - ord(prev) + 26)
	prev = i
print(ans)


name = input()
dif = abs(ord(name[0]) - ord('a'))
lent = min(dif, abs(26 - dif))
for i in range(len(name) - 1):
	dif = abs(ord(name[i]) - ord(name[i + 1]))
	lent += min(dif, abs(26 - dif))
print(lent)


s = input()
alfabet = 'abcdefghijklmnopqrstuvwxyz'
rot = 0
curr = 0
for c in s:
	goto = alfabet.index(c)
	rot += min(abs(goto - curr), abs(curr + 26 - goto), abs(curr - goto - 26))
	curr = goto
print(rot)


from sys import stdin

def findRes(a):
	n = len(a)
	res = 0
	for i in range(n - 1):
		x = ord(a[i])
		y = ord(a[i + 1])
		path1 = abs(x - y)
		path2 = 26 - path1
		res += min(path1, path2)
	return res
s = stdin.readline().rstrip()
solution = findRes('a' + s[0]) + findRes(s)
print(solution)


from string import ascii_lowercase

def solve(w):
	s = 0
	p = 0
	for i in w:
		j = ascii_lowercase.index(i)
		s += min(abs(p - j), 26 - max(j, p) + min(j, p))
		p = j
	return s

def main():
	print(solve(input()))
main()


a = input()
sum = 0
prev = 'a'
for i in a:
	count = abs(ord(i) - ord(prev))
	if count > 12:
		count = abs(26 - count)
	sum = sum + count
	prev = i
print(sum)


word = input()
m = 0
c = 'a'
for each in word:
	t = abs(ord(c) - ord(each))
	m += min(t, 26 - t)
	c = each
print(m)


s = str(input())
cnt = 0
for i in range(len(s) - 1):
	dif = abs(ord(s[i]) - ord(s[i + 1]))
	if dif <= 13:
		cnt += dif
	else:
		cnt += 26 - dif
dif1 = abs(ord('a') - ord(s[0]))
if dif1 <= 13:
	cnt += dif1
else:
	cnt += 26 - dif1
print(cnt)


word = input()
curr = 'a'
cost = 0
for c in word:
	tmp = ord(c) - ord(curr)
	tmp = abs(tmp)
	cost = cost + min(abs(tmp), abs(26 - tmp))
	curr = c
print(cost)


str1 = input()
index = 1
output = 0
for i in str1:
	nindex = ord(i) - 96
	movs = abs(index - nindex)
	if movs < 26 - movs:
		output += movs
		index = nindex
	else:
		output += 26 - movs
		index = nindex
print(output)


word = input()
pos = ord('a')
ans = 0
for c in word:
	d = abs(pos - ord(c))
	if d > 13:
		ans += 26 - d
	else:
		ans += d
	pos = ord(c)
print(ans)


a = input()
n = 97
ans = 0
b = 0
for i in range(len(a)):
	b = abs(ord(a[i]) - n)
	ans += min(b, 26 - b)
	n = ord(a[i])
print(ans)


def solve(word):
	n = len(word)
	s = 0
	pointer = 'a'
	next_letter = word[0]
	i = 1
	while True:
		d = ord(next_letter) - ord(pointer)
		if d > 0:
			if d > 13:
				s += abs(d - 26)
			else:
				s += d
		elif abs(d) > 13:
			s += d + 26
		else:
			s += abs(d)
		if i < n:
			pointer = next_letter
			next_letter = word[i]
			i += 1
		else:
			break
	return s
string = input()
print(solve(string))


import math
s = input()
ans = 0
a = 97
for i in range(len(s)):
	diff = abs(ord(s[i]) - a)
	if diff > 13:
		diff = 26 - diff
	ans += diff
	a = ord(s[i])
print(ans)


alphadict = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
current = 'a'
s = input()
count = 0
for x in s:
	count += min(abs(alphadict[current] - alphadict[x]), 26 - abs(alphadict[current] - alphadict[x]))
	current = x
print(count)


s = input()
z = 0
c = 1
for i in s:
	j = ord(i) - 96
	clock = abs(c - j)
	anticlock = abs(26 - clock)
	z = z + min(clock, anticlock)
	c = j
print(z)


import string
list_apha = list(string.ascii_lowercase)
custom_alphas = list(input())
current_index = 0
result = 0
for alpha in custom_alphas:
	new_index = list_apha.index(alpha.lower())
	distance_1 = abs(new_index - current_index)
	distance_2 = 26 - distance_1
	steps = min(distance_1, distance_2)
	result += steps
	current_index = new_index
print(result)


n = input()
f_char = 'a'
sum = 0
for i in n:
	s = abs(ord(i) - ord(f_char))
	sum += min(s, 26 - s)
	f_char = i
print(sum)


string = list(input())
string.insert(0, 'a')
step = 0
i = 1
for c in string:
	if len(string) == i:
		break
	dist = abs(ord(string[i - 1]) - ord(string[i]))
	i += 1
	if dist <= 13:
		step += dist
	elif dist > 13:
		step += 26 - dist
print(step)


alphabets = list('abcdefghijklmnopqrstuvwxyz')
currentSequence = alphabets
currentSequenceReversed = list(reversed(currentSequence))
wordlist = list(input())
rotations = 0
for i in range(len(wordlist)):
	indexInSequence = currentSequence.index(wordlist[i])
	indexInSequenceReversed = currentSequenceReversed.index(wordlist[i])
	if indexInSequence <= indexInSequenceReversed:
		rotations += indexInSequence
	else:
		rotations += indexInSequenceReversed + 1
	currentSequence = [c for c in currentSequence[indexInSequence:] + currentSequence[0:indexInSequence]]
	currentSequenceReversed = list(reversed(currentSequence))
print(rotations)


key = input()
c = 0
x = abs(ord('a') - ord(key[0]))
x = min(x, 26 - x)
c += x
for i in range(1, len(key)):
	x = abs(ord(key[i - 1]) - ord(key[i]))
	x = min(x, 26 - x)
	c += x
print(c)


import string
counter = 0
input = input()
letters = string.ascii_lowercase
numberOfLetters = len(letters)
point = letters[0]
for char in input:
	indexOfPoint = letters.index(point) + 1
	indexOfTarget = letters.index(char) + 1
	clockwise = abs(indexOfPoint - indexOfTarget)
	counterclockwise = numberOfLetters - clockwise
	step = min(clockwise, counterclockwise)
	counter += step
	point = char
print(counter)


s = input()
som = 0
res = ord(s[0]) - ord('a')
som += min(res, 26 - res)
for i in range(len(s) - 1):
	res = abs(ord(s[i + 1]) - ord(s[i]))
	som += min(res, 26 - res)
print(som)


u = 0
s = 'abcdefghijklmnopqrstuvwxyz'
ls = len(s)
ans = 0
for i in input():
	ans += min(abs(s.index(i) - u), ls - s.index(i) + u, ls - u + s.index(i))
	u = s.index(i)
print(ans)


stringus = input()
casual = 'a'
x = 0
for i in range(len(stringus)):
	ris = abs(ord(casual) - ord(stringus[i]))
	x += min(ris, 26 - ris)
	casual = stringus[i]
print(x)


string = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
alphalist = list(alpha)
alphadict = dict()
temp = 'a'
moves = 0
for i in range(len(alphalist)):
	alphadict[alphalist[i]] = i
for j in range(len(string)):
	if string[j] == temp:
		continue
	else:
		clock = abs(alphadict[temp] - alphadict[string[j]])
		anticlock = 26 - clock
		moves += min(clock, anticlock)
		temp = string[j]
print(moves)


s = input()

def min_path(s):
	pointer = 'a'
	count = 0
	for i in range(len(s)):
		dist = abs(ord(pointer) - ord(s[i]))
		if dist < 13:
			count += dist
		else:
			count += 26 - dist
		pointer = s[i]
	return count
print(min_path(s))


rotation = 0
flag = 97
body = input()
for i in body:
	diff = abs(flag - ord(i))
	if diff > 13:
		diff = 26 - diff
	rotation += diff
	flag = ord(i)
print(rotation)


string = input()
total_rotation = 0
intial = 'a'
for letter in string:
	if letter >= intial:
		if ord(letter) - ord(intial) >= 13:
			total_rotation += 26 - (ord(letter) - ord(intial))
		else:
			total_rotation += ord(letter) - ord(intial)
	elif ord(intial) - ord(letter) >= 13:
		total_rotation += 26 - (ord(intial) - ord(letter))
	else:
		total_rotation += ord(intial) - ord(letter)
	intial = letter
print(total_rotation)


s = str(input())
c = 'a'
min_num = 0
for i in s:
	x = ord(i) - ord(c)
	if x < 0:
		x = x + 26
	if x > 13:
		x = 26 - x
	min_num = min_num + x
	c = i
print(min_num)


s = str(input())
ans = 0
i = 1
for j in s:
	t = ord(j) - 96
	ans += min((t - i) % 26, (26 + i - t) % 26)
	i = t
print(ans)


s = input()
ans = 0
for i in range(len(s)):
	a = ord(s[i - 1])
	b = ord(s[i])
	if not i:
		a = 97
	ans += min(abs(b - a), 26 - abs(b - a))
print(ans)


n = input().strip()
all = 'abcdefghijklmnopqrstuvwxyz'
indeks = 1
otvet = 0
for i in n:
	indeksi = all.find(i) + 1
	if indeks < indeksi:
		otvet = otvet + min(abs(indeksi - indeks), 26 - indeksi + indeks)
	else:
		otvet = otvet + min(abs(indeksi - indeks), 26 - indeks + indeksi)
	indeks = indeksi
print(otvet)


str = input()
start = c = 0
l = list(str)
for i in range(0, len(l)):
	index = ord(l[i]) - 97
	walk = abs(start - index)
	if walk < 13:
		c += walk
	else:
		c += 26 - walk
	start = index
print(c)


s = input()
ans = 0
for i in range(len(s) - 1):
	k = []
	k.append(ord(s[i]))
	k.append(ord(s[i + 1]))
	k.sort()
	a = abs(k[0] - k[1])
	b = abs(ord('a') - k[0]) + abs(ord('z') - k[1]) + 1
	tt = min(a, b)
	ans += tt
kk = min(abs(ord(s[0]) - ord('a')), abs(ord(s[0]) - ord('z')) + 1)
print(ans + kk)


di = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 12, 'p': 11, 'q': 10, 'r': 9, 's': 8, 't': 7, 'u': 6, 'v': 5, 'w': 4, 'x': 3, 'y': 2, 'z': 1}
data = input()
i = 1
count = di[data[0]]
while i < len(data):
	z = di[data[i]] + di[data[i - 1]]
	x = 26 - z
	order = ord(data[i]) - ord(data[i - 1])
	if order >= 0:
		order = order
	else:
		order = -order
	if z <= x and z <= order:
		count = count + z
	elif x <= z and x <= order:
		count = count + x
	elif order <= z and order <= x:
		count = count + order
	i = i + 1
print(count)


ch = 'a'
ms = 0
s = input()
for i in range(len(s)):
	d = abs(ord(ch) - ord(s[i]))
	if d < 13:
		ms = ms + d
	else:
		ms = ms + (26 - d)
	ch = s[i]
print(ms)


a = []
x = ord('a')
for i in range(26):
	a.append(chr(x))
	x += 1
s = input()
pi = 0
c1 = 0
c2 = 0
res = 0
for i in range(len(s)):
	j = pi
	while a[j] != s[i]:
		c1 += 1
		j += 1
		if j == 26:
			j = 0
	j = pi
	while a[j] != s[i]:
		c2 += 1
		j -= 1
	if c1 < c2:
		res += c1
	else:
		res += c2
	c1 = 0
	c2 = 0
	pi = a.index(s[i])
print(res)


ch = input()
n = len(ch)
p = abs(ord(ch[0]) - ord('a'))
if p > 13:
	p = 26 - p
for i in range(n - 1):
	c = abs(ord(ch[i]) - ord(ch[i + 1]))
	if c > 13:
		c = 26 - c
	p = p + c
print(p)


s = input()
q = 97
count = 0
for i in s:
	w = abs(ord(i) - q)
	count += min((w, 26 - w))
	q = ord(i)
print(count)


s = input()
cnt = 0
a = 0
for i in s:
	b = ord(i) - 97
	x = abs(a - b)
	y = 26 - max(a, b) + min(a, b)
	if x < y:
		cnt += x
	else:
		cnt += y
	a = b
print(cnt)


name = input()
(curl, curr, count) = ('a', 'a', 0)
for i in name:
	(cl, cr) = (0, 0)
	while curl != i and curr != i:
		curl = chr(ord(curl) - 1)
		curr = chr(ord(curr) + 1)
		cl += 1
		cr += 1
		if ord(curl) == 96:
			curl = 'z'
		if ord(curr) == 123:
			curr = 'a'
	count += min(cl, cr)
	(curl, curr) = (i, i)
print(count)


def main():
	s = input()
	s = list(map(lambda x: ord(x) - ord('a'), s))
	cur = 0
	k = 26
	result = 0
	for el in s:
		f = (k + cur - el) % k
		s = (k - cur + el) % k
		cur = el
		result += min(f, s)
	print(result)
main()


def reverse(s):
	return ''.join(reversed(s))
s = input()
s = reverse(s)
s = s + 'a'
s = reverse(s)
ans = 0
for i in range(1, len(s)):
	x = ord(s[i]) - ord(s[i - 1])
	x = abs(x)
	ans = ans + min(x, 26 - x)
print(ans)


s = 'a' + input()
letters = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
prev = 0
for i in range(1, len(s)):
	post = letters.find(s[i])
	if post > prev:
		ans += min(post - prev, 26 - post + prev)
	elif post < prev:
		ans += min(prev - post, 26 + post - prev)
	prev = post
print(ans)


m = 'abcdefghijklmnopqrstuvwxyz'
s = input()
(zmax, zmin) = (max(m.index('a'), m.index(s[0])) + 1, min(m.index('a'), m.index(s[0])) + 1)
sum = min(zmax - zmin, 26 - zmax + zmin)
for x in range(1, len(s)):
	(zmax, zmin) = (max(m.index(s[x - 1]), m.index(s[x])) + 1, min(m.index(s[x - 1]), m.index(s[x])) + 1)
	sum += min(zmax - zmin, 26 - zmax + zmin)
print(sum)


s = 'a' + input()
ans = 0
for i in range(len(s) - 1):
	val = abs(ord(s[i]) - ord(s[i + 1]))
	if val > 13:
		ans += 26 - val
	else:
		ans += val
print(ans)


s = input()
res = 0
curr = 1
hashmap = ' abcdefghijklmnopqrstuvwxyz'
for i in s:
	n = curr - hashmap.index(i)
	if n < 0:
		n += 26
	m = hashmap.index(i) - curr
	if m < 0:
		m += 26
	res += min(n, m)
	curr = hashmap.index(i)
print(res)


name = input()
alph = 'abcdefghijklmnopqrstuvwxyz'
x = 0
if alph.index(name[0]) > 13:
	x = 26 - alph.index(name[0])
else:
	x = alph.index(name[0])
for i in range(1, len(name), 1):
	if abs(alph.index(name[i]) - alph.index(name[i - 1])) > 13 and alph.index(name[i - 1]) <= 13:
		x += 26 - alph.index(name[i]) + alph.index(name[i - 1])
	elif abs(alph.index(name[i]) - alph.index(name[i - 1])) > 13 and alph.index(name[i - 1]) > 13:
		x += alph.index(name[i]) + 26 - alph.index(name[i - 1])
	elif abs(alph.index(name[i]) - alph.index(name[i - 1])) <= 13:
		x += abs(alph.index(name[i]) - alph.index(name[i - 1]))
print(x)


s = input()
beg = 'a'
c = 0
for i in range(len(s)):
	if ord(s[i]) >= ord(beg):
		a = ord(s[i]) - ord(beg)
		b = 26 - a
		c += min(a, b)
		beg = s[i]
	else:
		a = ord(beg) - ord(s[i])
		b = 26 - a
		c += min(a, b)
		beg = s[i]
print(c)


s = input()
su = 0
p = 97
for i in s:
	t = ord(i)
	su += min(abs(t - p), 26 - abs(t - p))
	p = t
print(su)


s = input()
ans = 0
previous_position = 'a'
for i in range(0, len(s)):
	next_position = s[i]
	ans += min(abs(ord(next_position) - ord(previous_position)), 26 - abs(ord(next_position) - ord(previous_position)))
	previous_position = next_position
print(ans)


dct = dict(zip('abcdefghijklmnopqrstuvwxyz', range(26)))
jarak = dict(zip(range(26), list(range(14)) + list(range(12, 0, -1))))
kata = input()
cek = 0
cnt = 0
for i in range(len(kata)):
	cnt += jarak[abs(dct[kata[i]] - cek)]
	cek = dct[kata[i]]
print(cnt)


import math as m
string = input()
hitung = 0
ord_median = ord('n')
ord_start = ord('a')
putaran = 0
geser = 0
for i in string:
	if m.fabs(ord_start - ord(i)) <= m.fabs(ord_start - ord_median):
		putaran += int(m.fabs(ord(i) - ord_start))
		geser = ord(i) - ord_start
		ord_start = ord(i)
		ord_median = ord(chr(ord_median + geser))
		if ord_median > ord('z'):
			ord_median = ord(chr(ord_median - 26))
	else:
		putaran += 26 - int(m.fabs(ord_start - ord(i)))
		geser = ord(i) - ord_start
		ord_start = ord(i)
		ord_median = ord(chr(ord_median + geser))
		if ord_median < ord('a'):
			ord_median = ord(chr(ord_median + 26))
print(putaran)


a = 'a' + input()
(b, c) = (list(a), 0)
for x in range(1, len(b)):
	d = ord(b[x]) - ord(b[x - 1])
	if d < 0:
		d = -1 * d
		if d > 13:
			if ord('z') - ord(b[x - 1]) < ord(b[x - 1]) - ord('a'):
				c += ord('z') - ord(b[x - 1]) + 1 + ord(b[x]) - ord('a')
			else:
				c += ord('z') - ord(b[x]) + 1 + ord(b[x - 1]) - ord('a')
		else:
			c += d
	elif d > 13:
		if ord('z') - ord(b[x - 1]) < ord(b[x - 1]) - ord('a'):
			c += ord('z') - ord(b[x - 1]) + 1 + ord(b[x]) - ord('a')
		else:
			c += ord('z') - ord(b[x]) + 1 + ord(b[x - 1]) - ord('a')
	else:
		c += d
print(c)


from string import ascii_lowercase
from sys import stdin
s = stdin.readline().strip()
current = 0
result = 0
for letter in s:
	pos = ascii_lowercase.find(letter)
	result += min(abs(current - pos), len(ascii_lowercase) - abs(current - pos))
	current = pos
print(result)


s = str(input())
test = 'abcdefghijklmnopqrstuvwxyz'
current_pos = 0
minimum_dis = 0
for i in s:
	x = test.find(i)
	y = test[::-1].find(i) + 1
	if test.find(i) != current_pos:
		minimum_dis = minimum_dis + min(x, y)
	index = test.find(i)
	test = test[index:] + test[:index]
print(minimum_dis)


from sys import stdout
alphabet = 'abcdefghijklmnopqrstuvwxyz'
word = input()
idx = 0
out = 0
for c in word:
	pos = alphabet.find(c)
	l = abs(idx - pos if idx > pos else pos - idx)
	r = abs(idx - pos - 26 if idx > pos else pos - idx - 26)
	idx = pos
	out += l if l < r else r
stdout.write(str(out))


import string

class cycle:

	def __init__(self, C):
		self.c = C
		self.d = {char: i for (i, char) in enumerate(self.c)}

	def search_right(self, start, key):
		if start == key:
			return 0
		if self.d[key] > self.d[start]:
			return self.d[key] - self.d[start]
		else:
			return len(self.d) - self.d[start] + self.d[key]

	def search_left(self, start, key):
		if start == key:
			return 0
		if self.d[key] < self.d[start]:
			return self.d[start] - self.d[key]
		else:
			return self.d[start] + len(self.d) - self.d[key]

	def min_dist(self, start, key):
		return min(self.search_left(start, key), self.search_right(start, key))
s = cycle(list(string.ascii_lowercase))
name = input()
dist = 0
start = 'a'
for char in name:
	key = char
	dist += s.min_dist(start, key)
	start = char
print(dist)


pointer = 97
word = input()
acum = 0
for i in word:
	temp1 = ord(i) - pointer
	if temp1 < 0:
		temp1 = temp1 * -1
		temp2 = abs(ord(i) - 97) + abs(122 - pointer) + 1
	else:
		temp2 = abs(pointer - 97) + abs(122 - ord(i)) + 1
	acum += min(temp1, temp2)
	pointer = ord(i)
print(acum)


a = input()
list1 = list(a)
list2 = list([ord(i) for i in list1])
start = ord('a')
ans = 0
for i in range(0, len(list2)):
	if ord(a[i]) > start:
		c = min(ord(a[i]) - start, 26 - (ord(a[i]) - start))
	else:
		c = min(start - ord(a[i]), 26 - (start - ord(a[i])))
	ans += c
	start = ord(a[i])
print(ans)


def solve(s):
	alpha = ['0abcdefghijklmnopqrstuvwxyz']
	count = 0
	curr = 'a'
	for c in s:
		first = abs(ord(curr) - 96 - (ord(c) - 96))
		second = min(26 - (ord(curr) - 96) + (ord(c) - 96), 26 - (ord(c) - 96) + (ord(curr) - 96))
		move = min(first, second)
		count += move
		curr = c
	return count
s = input()
print(solve(s))


def dist(start, end):
	(oe, oa) = (ord(start), ord(end))
	if oe > oa and oe - oa <= 13:
		return oe - oa
	elif oe > oa and oe - oa > 13:
		return 26 - (oe - oa)
	elif oe < oa and oa - oe <= 13:
		return oa - oe
	elif oe < oa and oa - oe > 13:
		return 26 - (oa - oe)
	else:
		return 0
name = input()
curr = 'a'
ans = 0
for c in name:
	ans += dist(curr, c)
	curr = c
print(ans)


s = input()
index = 97
c = 0
for i in range(len(s)):
	tc = abs(ord(s[i]) - index)
	if tc > 13:
		c = c + (26 - tc)
	else:
		c = c + tc
	index = ord(s[i])
print(c)


ans = 0
cursor = 'a'
for i in input():
	ans += min(abs(ord(i) - ord(cursor)), abs(ord(i) - ord(cursor) + 26), abs(ord(i) - ord(cursor) - 26))
	cursor = i
print(ans)


data = input()
initial = ord('a')
spins = 0
for letter in data:
	if abs(ord(letter) - initial) <= 13:
		spins += abs(ord(letter) - initial)
	else:
		spins += 26 - abs(ord(letter) - initial)
	initial = ord(letter)
print(spins)


s = str(input())
a = 97
c = 0
for i in s:
	if abs(int(ord(i)) - a) <= 12:
		c += abs(int(ord(i)) - a)
	elif abs(int(ord(i)) - a) > 12:
		c += 26 - abs(int(ord(i)) - a)
	a = int(ord(i))
print(c)


import string
exponat = input()
letters = string.ascii_lowercase
wheel = []
counter = 0
position = 0
for i in letters:
	wheel.append(i)
for i in exponat:
	let_ind = wheel.index(i)
	if abs(let_ind - position) <= 13:
		counter += abs(let_ind - position)
	else:
		counter += len(wheel) - abs(let_ind - position)
	position = let_ind
print(counter)


def solution():
	string = input()
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	now = 'a'
	res = 0
	for i in range(len(string)):
		d = abs(alphabet.find(now) - alphabet.find(string[i]))
		res += min(d, 26 - d)
		now = string[i]
	print(res)
solution()


s = input()
t = 97
res = 0
for i in s:
	tt = ord(i)
	a = tt
	if tt < t:
		(t, tt) = (tt, t)
	res += min(tt - t, t + 26 - tt)
	t = a
print(res)


def main():
	word = list(input().strip())
	start = 'a'
	sum_moves = 0
	for i in word:
		diff = ord(i) - ord(start)
		if diff > 0:
			clock_w = diff
			counter_w = 26 - clock_w
		elif diff < 0:
			counter_w = ord(start) - ord(i)
			clock_w = 26 - counter_w
		else:
			clock_w = counter_w = 0
		best = min(clock_w, counter_w)
		sum_moves += best
		start = i
	print(sum_moves)
main()


d = input()
n = len(d)
last = 'a'
ret = 0
for i in range(0, n):
	rr = abs(ord(d[i]) - ord(last))
	ret += min(rr, 26 - rr)
	last = d[i]
print(ret)


s = input()
count = 0
first = abs(ord(s[0]) - ord('a'))
first_ = 26 - first
add = first if first <= first_ else first_
for i in range(len(s) - 1):
	x = abs(ord(s[i]) - ord(s[i + 1]))
	y = 26 - x
	if x <= y:
		count += x
	else:
		count += y
print(count + add)


s = input()
list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
pointer = 1
pointed = 0
count = 0
for c in s:
	pointed = list.index(c) + 1
	count += min(abs(pointer - pointed), 26 - abs(pointer - pointed))
	pointer = pointed
print(count)


a = input()
cnt = 0
cnt += min(abs(ord('a') - ord(a[0])), 26 - abs(ord('a') - ord(a[0])))
for i in range(0, len(a) - 1):
	cnt += min(abs(ord(a[i + 1]) - ord(a[i])), 26 - abs(ord(a[i]) - ord(a[i + 1])))
print(cnt)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def main():
	s = input()
	a = list(s)
	for i in range(len(a)):
		a[i] = 26 - (ord('z') - ord(a[i]))
	b = 0
	c = []
	d = 0
	e = 26 - (ord('z') - ord('a'))
	for i in range(len(a)):
		if abs(a[i] - e) > 13:
			b += 26 - abs(a[i] - e)
		else:
			b += abs(a[i] - e)
		e = a[i]
	print(b)
main()


ch = 97
s = 0
for i in map(ord, input()):
	x = abs(i - ch)
	x = min(x, 26 - x)
	s = s + x
	ch = i
print(s)


def embosser(s):
	moves = 0
	last = 'a'
	for i in range(len(s)):
		moves += min((ord(s[i]) - ord(last)) % 26, (ord(last) - ord(s[i])) % 26)
		last = s[i]
	return moves
s = input().strip()
print(embosser(s))


s = input()
total = 0
initial = 'a'
for x in range(0, len(s)):
	cloclockwiseD = 0
	anticlockwiseD = 0
	goTo = s[x]
	if ord(initial) < ord(goTo):
		clockwiseD = ord(goTo) - ord(initial)
		anticlockwiseD = 26 - clockwiseD
		total += min(clockwiseD, anticlockwiseD)
	elif ord(initial) > ord(goTo):
		anticlockwiseD = ord(initial) - ord(goTo)
		clockwiseD = 26 - anticlockwiseD
		total += min(clockwiseD, anticlockwiseD)
	initial = goTo
print(total)


t = input()
q = abs(ord('a'))
w = 0
for e in range(len(t)):
	u = abs(q - ord(t[e]))
	if u > 13:
		w = w + 26 - u
		q = ord(t[e])
	else:
		w = w + u
		q = ord(t[e])
print(w)


from collections import defaultdict
import sys, os, math
s = input()
(pos, ans) = (0, 0)
for i in range(len(s)):
	if i == 0:
		ans += min(abs(ord(s[i]) - ord('a')), 26 - abs(ord(s[i]) - ord('a')))
	else:
		ans += min(abs(ord(s[i]) - ord(s[i - 1])), 26 - abs(ord(s[i]) - ord(s[i - 1])))
print(ans)


def find_min_key(bykva, sumvol):
	global key, kolvo
	if (ord(sumvol) - ord(bykva)) % 26 < (ord(bykva) - ord(sumvol)) % 26:
		kolvo += (ord(sumvol) - ord(bykva)) % 26
	else:
		kolvo += (ord(bykva) - ord(sumvol)) % 26
kolvo = 0
slovo = input().upper()
and_sumvol = 'A'
for bykv in slovo:
	find_min_key(bykva=bykv, sumvol=and_sumvol)
	and_sumvol = bykv
print(str(kolvo))


s = input()
alp = 26
cnt = 0
tmp = ord('a')
for i in s:
	cnt += min(abs(ord(i) - tmp), alp - abs(ord(i) - tmp))
	tmp = ord(i)
print(cnt)


s = input()
p = 'a'
dist = 0
for c in s:
	temp = abs(ord(c) - ord(p))
	dist += min(temp, 26 - temp)
	p = c
print(dist)


string = input()
alph = [chr(x) for x in range(97, 123)]
current = alph.index(string[0])
result = 0
for i in range(1, len(string)):
	distance = alph.index(string[i]) - alph.index(string[i - 1])
	if abs(distance) <= 12:
		result += abs(distance)
	else:
		result += 25 - abs(distance) + 1
if current <= 12:
	result += current
else:
	result += 26 - current
print(result)


def solve(str):
	str = 'a' + str
	totalmove = 0
	for i in range(1, len(str)):
		prechar = str[i - 1]
		currentchar = str[i]
		forwardmove = abs(ord(prechar) - ord(currentchar))
		backwardmove = 26 - forwardmove
		totalmove += min(forwardmove, backwardmove)
	return totalmove
str = input()
print(solve(str))


s = input()
cnt = 0
init = 'a'
for c in s:
	dis = abs(ord(c) - ord(init))
	cnt += min(dis, 26 - dis)
	init = c
print(cnt)


string = input()

def minStep(string):
	mapp = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
	ans = 0
	begin = 'a'
	for i in range(len(string)):
		subtraction = abs(mapp[string[i]] - mapp[begin])
		if subtraction > 13:
			ans += 26 - subtraction
		else:
			ans += subtraction
		begin = string[i]
	return ans
print(minStep(string))


s = 'abcdefghijklmnopqrstuvwxyz'
d = {s[i - 1]: i for i in range(1, 27)}
s = input()
c = 0
cur = 'a'
for i in s:
	k = min((d[cur] - d[i] + 26) % 26, (d[i] - d[cur] + 26) % 26)
	c += k
	cur = i
print(c)


d = dict()
for i in range(97, 123):
	d[chr(i)] = abs(97 - i) + 1
n = list(input())
a = d['a']
r = 0
for i in n:
	b = d[i]
	r += min(abs(b - a), 26 - abs(b - a))
	a = b
print(r)


s = input()
s1 = 'abcdefghijklmnopqrstuvwxyz'
s = 'a' + s
count = 0
for i in range(len(s) - 1):
	z = abs(s1.index(s[i]) - s1.index(s[i + 1]))
	x = 25 - s1.index(s[i]) + s1.index(s[i + 1]) + 1
	y = s1.index(s[i]) + 1 + (25 - s1.index(s[i + 1]))
	count = count + min(x, y, z)
print(count)


n = 'abcdefghijklmnopqrstuvwxyz'
count = 0
p = 0
s = input()
for i in s:
	k = abs(n.index(i) - p)
	count = count + min(k, 26 - k)
	p = n.index(i)
print(count)


s = input()
alphabet = dict(zip(list('abcdefghijklmnopqrstuvwxyz'), [i for i in range(1, 27)]))
summ = 0
cur_letter = 'a'
for letter in s:
	summ += min(abs(alphabet[letter] - alphabet[cur_letter]), 26 - abs(alphabet[letter] - alphabet[cur_letter]))
	cur_letter = letter
print(summ)


arr = 'abcdefghijklmnopqrstuvwxyz'
pt = 0
s = input()
spin = 0
for i in s:
	if arr.index(i) > 13:
		spin += arr[::-1].index(i) + 1
	elif arr.index(i) < 13:
		spin += arr.index(i)
	else:
		spin += 13
	arr = arr[arr.index(i):] + arr[:arr.index(i)]
print(spin)


a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
cur = 'a'
c = 0
for i in s:
	ind = abs(a.find(cur) - a.find(i))
	c += min(ind, 26 - ind)
	cur = i
print(c)


l = []
c = []
a = 0
for i in range(96, 123):
	l.append(i)
for i in list(input()):
	c.append(l.index(ord(i)))
a = min(abs(1 - c[0]), abs(26 - abs(1 - c[0])))
for i in range(1, len(c)):
	a = min(abs(c[i - 1] - c[i]), abs(26 - abs(c[i - 1] - c[i]))) + a
print(a)


n = input()
res = 0
if ord(n[0]) >= ord('a'):
	if ord(n[0]) - ord('a') > 13:
		res += 26 - (ord(n[0]) - ord('a'))
	else:
		res += ord(n[0]) - ord('a')
for i in range(len(n) - 1):
	if abs(ord(n[i]) - ord(n[i + 1])) > 13:
		res += 26 - abs(ord(n[i]) - ord(n[i + 1]))
	else:
		res += abs(ord(n[i]) - ord(n[i + 1]))
print(res)


s = input()

def split(word):
	return [char for char in word]
s = split(s)
steps = 0
j = ord('a')
for i in s:
	steps += min(26 - abs(j - ord(i)), abs(j - ord(i)))
	j = ord(i)
print(steps)


import string
lowers = string.ascii_lowercase
name = list(input().strip())
rotations = 0
prev = lowers.find('a')
for char in name:
	rotations += min(abs(lowers.find(char) - prev), 26 - abs(prev - lowers.find(char)))
	prev = lowers.find(char)
print(rotations)


import string
text = input().strip()
ma = string.ascii_lowercase
out = 0
flag = ma.index('a')
for i in range(len(text)):
	idx = ma.index(text[i])
	y = abs(flag - idx)
	x = len(ma) - y
	if x > y:
		out += y
	else:
		out += x
	flag = idx
print(out)


import string
base_arr = list(string.ascii_lowercase)
str_input = input()
count = 0
initial = 'a'
for item in str_input:
	index_current = base_arr.index(initial)
	index_item = base_arr.index(item)
	count += abs(index_current - index_item) if abs(index_current - index_item) < 13 else 26 - abs(index_current - index_item)
	initial = item
print(count)


def solver(string):
	solution = 0
	current_char = 'a'
	ref = ord(current_char)
	for char in string:
		dir_1 = ord(char) - ord(current_char)
		dir_2 = 26 + min(ord(current_char), ord(char)) - max(ord(current_char), ord(char))
		solution += min(abs(dir_1), abs(dir_2))
		current_char = char
	print(solution)
solver(input())


n = input()
s = 0
p = 'a'
for i in range(len(n)):
	k = abs(ord(n[i]) - ord(p))
	s += min(k, 26 - k)
	p = n[i]
print(s)


word = input()
aword = 'a' + word
n = len(word)
t = 0
for i in range(n):
	t = t + min(abs(ord(aword[i + 1]) - ord(aword[i])), 26 - abs(ord(aword[i + 1]) - ord(aword[i])))
print(t)


s = input()
l = list(s)
start = 'a'
sm = 0
for i in range(len(l)):
	l1 = abs(ord(l[i]) - ord(start))
	l2 = 26 - abs(l1)
	sm += min(l1, l2)
	start = l[i]
print(sm)


(movezz, c, z) = (0, 0, 25)
word = input()
for w in word:
	d = ord(w) - 97
	clkwise = d - c if d >= c else d + z - c + 1
	alkwise = c - d if c >= d else c + z - d + 1
	movezz += min(alkwise, clkwise)
	c = d
print(movezz)


def Circle():
	letters = 'abcdefghijklmnopqrstuvwxyz'
	letter = 'a'
	letterIndex = 0
	times = 0
	s = input()
	for l in s:
		i = letters.index(l)
		times += min(abs(i - letterIndex), 26 - abs(i - letterIndex))
		letter = l
		letterIndex = i
	print(times)
Circle()


import os
LOCAL_PC = 'n1amr' in os.path.expanduser('~')

def process_file(in_name, out_name):
	with open(in_name, 'r') as fin:
		with open(out_name, 'w') as fout:

			def read():
				return fin.readline().rstrip('\n')

			def write(*args, end='\n'):
				text = ' '.join(map(str, args)) + end
				fout.write(text)
				print(text, end='')
			t = int(fin.readline())
			for i in range(t):
				read()
				write('Case #{T}: \n'.format(T=i + 1), end='')
				solve(read, write)
				write()

def process_stdio():

	def read():
		return input()

	def write(*args, end='\n'):
		print(*args, end=end)
	solve(read, write)

def solve(input, print):
	s = input()
	p = 'a'
	cnt = 0
	for c in s:
		cnt += distance(p, c)
		p = c
	print(cnt)

def distance(c1, c2):
	diff = abs(ord(c1) - ord(c2))
	return min(diff, 26 - diff)
if LOCAL_PC:
	in_name = __file__[:-3] + '.in'
	out_name = __file__[:-3] + '.out'
	process_file(in_name, out_name)
else:
	process_stdio()


import sys

def c():
	_input = sys.stdin.readlines()
	s = _input[0].strip()
	start = ord('a')
	_sum = 0
	for c in s:
		_sum += min((ord(c) - start) % 26, (start - ord(c)) % 26)
		start = ord(c)
	print(_sum)
c()


word = input()
total = 0
position = 97
z = 122
for letter in word:
	v1 = ord(letter) - position
	v2 = position - ord(letter) + 26
	if v1 < 0:
		v1 += 26
	if v2 > 26:
		v2 -= 26
	position = ord(letter)
	total += min(v1, v2)
print(total)


str1 = input()
res = 0
i = 'a'
for a in str1:
	t = abs(ord(a) - ord(i))
	res = res + min(t, 26 - t)
	i = a
print(res)


wordToPrint = input()
charList = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
noOfRotations = 0
for (index, val) in enumerate(wordToPrint):
	if index != 0:
		previousChar = wordToPrint[index - 1]
	else:
		previousChar = charList[0]
	diff = abs(charList.index(previousChar) - charList.index(val))
	noOfRotations += min(diff, 26 - diff)
print(noOfRotations)


import string
alphabets = list(string.ascii_lowercase)
word = list(input())
p = 0
j = 0
count = 0
for i in word:
	j = p
	p = alphabets.index(i)
	d = p - j
	if 26 - abs(d) >= 13:
		count = abs(d) + count
	else:
		count = 26 - abs(d) + count
print(count)


name = input()
count = 0
starter = 'a'
for i in name:
	if abs(ord(starter) - ord(i)) < 26 - abs(ord(starter) - ord(i)):
		count += abs(ord(starter) - ord(i))
		starter = i
	else:
		count += 26 - abs(ord(starter) - ord(i))
		starter = i
print(count)


s = input()
b = 'abcdefghijklmnopqrstuvwxyz'
c = 0
now = 0
for i in range(len(s)):
	need = b.find(s[i])
	c += min(abs(now - need), abs(26 - abs(now - need)))
	now = need
print(c)


from sys import stdin, stdout
okay = input()
s = 'a'
tot = 0
for i in okay:
	if s < i:
		a = abs(ord(i) - ord(s))
		b = abs(ord(s) - ord(i) + 26)
	else:
		a = abs(ord(i) - ord(s) + 26)
		b = abs(ord(s) - ord(i))
	tot += min(a, b)
	s = i
stdout.write(str(tot))


str = input('')

def solve(str):
	str = 'a' + str
	t = 0
	for i in range(1, len(str)):
		p = str[i - 1]
		c = str[i]
		f = abs(ord(p) - ord(c))
		b = 26 - f
		t = t + min(f, b)
	return t
print(solve(str))


s = input()
letter = 'a'
ans = 0
for i in s:
	term = abs(ord(letter) - ord(i))
	ans += min(term, 26 - term)
	letter = i
print(ans)


alpha = 'abcdefghijklmnopqrstuvwxyz'
i = 0
s = input().strip()
moves = 0
for c in s:
	j = alpha.index(c)
	moves += min(abs(i - j), abs(len(alpha) + j - i), abs(len(alpha) + i - j))
	i = j
print(moves)


import string
input_str = input()
embosser = string.ascii_lowercase
pointer = 0
total = 0
for index in range(len(input_str)):
	position = embosser.index(input_str[index])
	rotate = abs(position - pointer)
	if rotate > 13:
		rotate = 25 - rotate + 1
	pointer = position
	total += rotate
print(total)


def wheel(s):
	prev = 97
	ans = 0
	for i in s:
		cur = ord(i)
		big = max(prev, cur)
		smol = min(prev, cur)
		path1 = big - smol
		path2 = smol + 26 - big
		ans += min(path2, path1)
		prev = cur
	return ans
s = input()
print(wheel(s))


import math, sys, re, itertools, pprint
(ri, rai) = (lambda : int(input()), lambda : list(map(int, input().split())))
s = input()
i = 0
zz = ord('z') - ord('a')
res = 0
for c in s:
	t = ord(c) - ord('a')
	x = min(i + abs(zz - t) + 1, abs(i - t), abs(zz - i) + t + 1)
	i = t
	res += abs(x)
print(res)


letters = 'abcdefghijklmnopqrstuvwxyz'
word = list(input())
currentLetter = 'a'
result = 0
for letter in word:
	withClock = len(letters[letters.find(currentLetter):letters.find(letter)])
	if withClock == 0:
		reveresdLetters = letters[::-1]
		withClock = len(reveresdLetters[reveresdLetters.find(currentLetter):reveresdLetters.find(letter)])
	againstClock = 26 - withClock
	if withClock > againstClock:
		result += againstClock
	else:
		result += withClock
	currentLetter = letter
print(result)


def dorogi(words):
	spisok = [words, [words[0]] + list(reversed(words[1:len(words)]))]
	return spisok
eksponat = input()
words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
d = dorogi(words)
d1 = d[0]
d2 = d[1]
xods = 0
for i in range(len(eksponat)):
	if d1.index(eksponat[i]) < d2.index(eksponat[i]):
		xods = xods + d1.index(eksponat[i])
	else:
		xods = xods + d2.index(eksponat[i])
	words = words[words.index(eksponat[i]):len(words)] + words[0:words.index(eksponat[i])]
	d = dorogi(words)
	d1 = d[0]
	d2 = d[1]
print(xods)


string = map(ord, input().lower())
A = ord('a')
Z = ord('z')
result = 0
pointer = 0
for letter in string:
	if A <= letter <= Z:
		letter -= A
		result += min(abs(letter - pointer), 26 - abs(letter - pointer))
		pointer = letter
	else:
		break
print(result)


t = input()
s = 0
f = 0
for i in range(len(t)):
	if f == 0:
		f = 1
		q = ord(t[i]) - 96
		q1 = ord('a') - 96
		s = s + min(abs(q - q1), 26 - abs(q - q1))
	elif f == 1:
		q = ord(t[i]) - 96
		q1 = ord(t[i - 1]) - 96
		s = s + min(abs(q - q1), 26 - abs(q - q1))
print(s)


x = [ord(i) for i in str(input())]
(a, s) = (97, 0)
for j in range(len(x)):
	s += min(abs(x[j] - a), abs(122 - x[j]) + abs(a - 97) + 1, abs(122 - a) + abs(x[j] - 97) + 1)
	a = x[j]
print(s)


characters = map(ord, input())
total = 0
temp = 0
for char in characters:
	first = ord('a')
	last = ord('z')
	if first <= char <= last:
		char -= first
		total += min(abs(char - temp), 26 - abs(char - temp))
		temp = char
	else:
		break
print(total)


y = input()
minNumOfRotations = 0
prev = 'a'
for i in range(len(y)):
	if abs(ord(y[i]) - ord(prev)) > 13:
		minNumOfRotations += 26 - abs(ord(y[i]) - ord(prev))
	else:
		minNumOfRotations += abs(ord(y[i]) - ord(prev))
	prev = y[i]
print(str(minNumOfRotations))


s = input()
res = 0
aux = 'a'
for i in s:
	d1 = abs(ord(aux) - ord(i))
	d2 = min(ord(aux), ord(i)) - ord('a') + (ord('z') - max(ord(aux), ord(i))) + 1
	res = res + min(d1, d2)
	aux = i
print(res)


import string

class ListElem:

	def __init__(self, val):
		self.val = val
		self.prev = None
		self.next = None

	def define_next(self, next):
		self.next = next

	def define_prev(self, prev):
		self.prev = prev
is_first = True
for c in string.ascii_letters[:len(string.ascii_letters) // 2]:
	if is_first:
		head = prev = ListElem(c)
		is_first = False
		continue
	elem = ListElem(c)
	prev.define_next(elem)
	elem.define_prev(prev)
	prev = elem
prev.define_next(head)
head.define_prev(prev)

def right_walk(head, target):
	elems = head
	count = 0
	while True:
		if elems.val == target:
			break
		count += 1
		elems = elems.next
	return count

def left_walk(head, target):
	elems = head
	count = 0
	while True:
		if elems.val == target:
			break
		count += 1
		elems = elems.prev
	return count

def set_as_mid(head, new_val, way):
	if way == 'right':
		while True:
			if head.val == new_val:
				return head
			head = head.next
	else:
		while True:
			if head.val == new_val:
				return head
			head = head.prev
res_turn = 0
for c in input():
	turn1 = right_walk(head, c)
	turn2 = left_walk(head, c)
	way = 'left' if turn1 > turn2 else 'right'
	head = set_as_mid(head, c, way)
	res_turn += turn2 if turn1 > turn2 else turn1
print(res_turn)


w = list(map(ord, list(input())))
l = 97
s = 0
for c in w:
	d1 = abs(c - l)
	d2 = 26 - d1
	s += min(d1, d2)
	l = c
print(s)


let = input()
let = 'a' + let

def minletter(a, b):
	h = abs(ord(a) - ord(b))
	if h > 13:
		return 26 - h
	else:
		return h
sum = 0
listt = list(let)
for i in range(len(listt) - 1):
	m = minletter(listt[i], listt[i + 1])
	sum += m
print(sum)


def ABS(x):
	if x < 0:
		return -x
	return x
s = input()
p = 'a'
count = 0
for c in s:
	dist = abs(ord(p) - ord(c))
	if dist < 13:
		count += dist
	else:
		count += 26 - dist
	p = c
print(count)


name = input()
moves = 0
start = 0
for i in range(len(name)):
	index = int(ord(name[i]) - 97)
	walk = abs(start - index)
	if walk < 13:
		moves = moves + walk
	else:
		moves = moves + 26 - walk
	start = index
print(moves)


s = input()
ans = 0
b = 'a'
for f in range(len(s)):
	if abs(ord(b) - ord(s[f])) <= 13:
		ans += abs(ord(b) - ord(s[f]))
	else:
		ans += 26 - abs(ord(b) - ord(s[f]))
	b = s[f]
print(ans)


def btoc(c):
	return ord(c) - 97
a = input()
bal = 0
last = 0
for i in a:
	bal += min(abs(btoc(i) - last), 26 - abs(btoc(i) - last))
	last = btoc(i)
print(bal)


name = input()
curr_ord = ord('a')
total = 0
for char in name:
	if abs(curr_ord - ord(char)) > 13:
		total += 26 - abs(curr_ord - ord(char))
	else:
		total += abs(curr_ord - ord(char))
	curr_ord = ord(char)
print(total)


s = input()
ans = 0
pos = 1
for x in s:
	charPos = ord(x) - 96
	difference = abs(pos - charPos)
	pos = charPos
	ans += min(difference, abs(26 - difference))
print(ans)


string = input()
current_pos = ord('a')
turns = 0
for i in string:
	rotation_1 = abs(ord(i) - current_pos)
	rotation_2 = 26 - rotation_1
	min_rotation = min(rotation_1, rotation_2)
	turns += min_rotation
	current_pos = ord(i)
print(turns)


letras = 'abcdefghijklmnopqrstuvwxyza'
x = 0
y = 0
inicio = 0
palavra = input()
rotacoes = 0
for i in range(len(palavra)):
	while True:
		if letras[x] == palavra[i]:
			rotacoes += min(abs(x - inicio), 26 - abs(x - inicio))
			y = x
			inicio = x
			break
		elif letras[y] == palavra[i]:
			rotacoes += min(abs(inicio - y), 26 - abs(inicio - y))
			x = y
			inicio = y
			break
		else:
			x -= 1
			y += 1
			if y > 25:
				y = 25
			if x < 0:
				x = 0
print(rotacoes)


from string import ascii_lowercase
a = list(ascii_lowercase)
s = input()
i = ans = 0
for c in s:
	d = abs(i - a.index(c))
	if d > 13:
		ans += 26 - d
	else:
		ans += d
	i = a.index(c)
print(ans)


set1 = ['m', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n']
khuti = 12
s = input()
l = len(s)
ans = 0
for i in range(l):
	for j in range(26):
		if s[i] == set1[j]:
			ind = j
			break
	if khuti > ind:
		ans += min(abs(khuti - ind), 25 - khuti + ind + 1)
	else:
		ans += min(abs(khuti - ind), khuti + 25 - ind + 1)
	khuti = ind
print(ans)


import math

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime
get_int = lambda : map(int, input().split())
a = input()
a = 'a' + a
ans = 0
for i in range(1, len(a)):
	x = math.fabs(ord(a[i]) - ord(a[i - 1]))
	ans += min(x, 26 - x)
print(int(ans))


s = input()
sum = 0
cur_pos = ord('a')
for i in range(len(s)):
	pos = ord(s[i])
	sum += min(abs(pos - cur_pos), 26 - abs(pos - cur_pos))
	cur_pos = pos
print(sum)


s = input()
a = [chr(i) for i in range(ord('a'), ord('z') + 1)]
(z, res) = (0, 0)
for i in s:
	(x, y) = (z, z)
	(k1, k2) = (0, 0)
	while a[x] != i:
		x = (x + 25) % 26
		k1 += 1
	while a[y] != i:
		y = (y + 1) % 26
		k2 += 1
	res += min(k1, k2)
	if k1 < k2:
		z = x
	else:
		z = y
print(res)


word = str(input())
lenght = len(word)
smoves = 0
strt = 0
for i in range(lenght):
	index = ord(word[i]) - 97
	walk = abs(strt - index)
	if walk < 13:
		smoves += walk
	else:
		smoves += 26 - walk
	strt = index
print(smoves)


n = input()
a = list(n)
a.insert(0, 'a')
k = 0
for i in range(1, len(a)):
	if abs(ord(a[i]) - ord(a[i - 1])) > 13:
		k += 26 - abs(ord(a[i]) - ord(a[i - 1]))
	else:
		k += abs(ord(a[i]) - ord(a[i - 1]))
print(k)


w = 'a' + input()
print(sum([min(abs(a - b), 26 - abs(a - b)) for (a, b) in zip(map(ord, w[:-1]), map(ord, w[1:]))]))


def main(s):
	s = 'a' + s

	def dist(a, b):
		x = max(ord(a), ord(b))
		y = min(ord(a), ord(b))
		return min(x - y, 26 + y - x)
	ret = 0
	for i in range(len(s) - 1):
		ret += dist(s[i], s[i + 1])
	return ret
print(main(input()))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
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 fractions import Fraction
mod = 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)]
s = data()
pointer = 'a'
answer = 0
for i in s:
	answer += min(abs(ord(i) - ord(pointer)), 26 - abs(ord(i) - ord(pointer)))
	pointer = i
out(answer)


from collections import deque
str = input()
a = 'a'
arr = []
x = 0
y = 0
z = 0
for i in range(0, 26):
	arr.append(a)
	a = chr(ord(a) + 1)
d = deque(arr)
for i in range(len(str)):
	for j in range(0, 26):
		if str[i] == d[j]:
			break
	for k in range(25, 0, -1):
		if str[i] == d[k]:
			break
	x = j
	y = 26 - k
	if x > y:
		z += y
	else:
		z += x
	d.rotate(26 - j)
	x = 0
	y = 0
print(z)


s = input()
i = 'a'
tot = 0
for j in s:
	if abs(ord(i) - ord(j)) > 13:
		tot += 26 - abs(ord(i) - ord(j))
	else:
		tot += abs(ord(i) - ord(j))
	i = j
print(tot)


c = 97
s = 0
f = map(ord, input())
for x in f:
	i = abs(c - x)
	s += min(i, 26 - i)
	c = x
print(s)


s = 'a' + input()
r = 0
for i in range(1, len(s)):
	t = (ord(s[i]), ord(s[i - 1]))
	(a, b) = (min(t), max(t))
	r += min(b - a, a + 26 - b)
print(r)


pos = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
text = input()
step = 0
step1 = 0
step2 = 0
for i in range(len(text)):
	a = alp.find(text[i])
	pos1 = pos
	while pos1 != a:
		step1 += 1
		pos1 += 1
		if pos1 == 26:
			pos1 = 0
	pos1 = pos
	while pos1 != a:
		step2 += 1
		pos1 += -1
		if pos1 == -1:
			pos1 = 25
	if step1 > step2:
		step += step2
	else:
		step += step1
	step1 = 0
	step2 = 0
	pos = a
print(step)


a = input()
b = list(map(lambda x: int(ord(x) - ord('a')), a))
(mi, ma) = (100, 0)
prev = b[0]
s = prev if prev < 13 else 26 - prev
for i in range(1, len(b)):
	temp = abs(b[i] - prev)
	s += 26 - temp if temp > 13 else temp
	prev = b[i]
print(s)


let = 'abcdefghijklmnopqrstuvwxyz'
w = input()
counter = p = 0
for l in w:
	d1 = 26 - abs(p - let.find(l))
	d2 = abs(p - let.find(l))
	counter += min(d1, d2)
	p = let.find(l)
print(counter)


a = input()
b = [1]
cnt = 0
for i in a:
	c = ord(i) - 96
	b.append(c)
for i in range(len(b) - 1):
	cnt += min(abs(b[i] - b[i + 1]), 26 - abs(b[i] - b[i + 1]))
print(cnt)


def gMin(c, j):
	return min(abs(c - j), 26 - j + c, 26 - c + j)
s = input()
p = 0
l = 1
for i in s:
	p += gMin(l, ord(i) - 96)
	l = ord(i) - 96
print(p)


wheel = input()
ch = 'a'
count = 0
m = 0
for i in wheel:
	m = abs(ord(ch) - ord(i))
	if m < 13:
		count = count + m
	else:
		count = count + 26 - m
	ch = i
print('%d' % count)


name = input()
rotation = 0
a = abs(ord('a') - ord(name[0]))
if a > 13:
	a = 26 - a
rotation += a
for i in range(len(name) - 1):
	a = abs(ord(name[i]) - ord(name[i + 1]))
	if a > 13:
		a = 26 - a
	rotation += a
print(rotation)


s = input()
ans = 0
cur_pos = 0
for index in s:
	count = (ord(index) - 97) % 26
	ans = ans + min(abs(cur_pos - count), 26 - abs(cur_pos - count))
	cur_pos = count
print(ans)


input_string = input()
cur = 'a'
counter = 0
for i in range(0, len(input_string)):
	temp = abs(ord(input_string[i]) - ord(cur))
	counter = counter + min(temp, 26 - temp)
	cur = input_string[i]
print(counter)


t = input()
count = 0
curr = ord('a')
diff = ord('n') - ord('a')
for i in t:
	if abs(ord(i) - curr) > diff:
		count += 26 - abs(ord(i) - curr)
	else:
		count += abs(ord(i) - curr)
	curr = ord(i)
print(count)


ans = 0
prev = 'a'
for i in list(input()):
	ans += min(abs(ord(prev) - ord(i)), abs(26 - abs(ord(prev) - ord(i))))
	prev = i
print(ans)


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

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

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

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

def sin():
	return input()

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

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

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

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

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

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

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

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

def main():
	char = sin()
	count = 0
	temp = 'a'
	alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	for i in range(len(char)):
		count += min((alp.index(char[i]) - alp.index(temp)) % 26, (26 - alp.index(char[i]) + alp.index(temp)) % 26)
		temp = char[i]
	print(count)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

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

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

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

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

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

class IOWrapper(IOBase):

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


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline().strip())

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

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

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

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r
d = {}
for i in range(97, 123):
	d[chr(i)] = i - 97

def solve():
	s = st()
	p = 0
	r = 0
	for i in s:
		if i < chr(97 + p):
			r += min(26 - p + d[i], abs(d[i] - p))
		else:
			r += min(d[i] - p, p + 26 - d[i])
		p = d[i]
	pr(r)
solve()


ans = 0
p = ord('a')
for x in map(ord, input()):
	ans += min((x - p + 26) % 26, (p - x + 26) % 26)
	p = x
print(ans)


s = input()
pointer = 0
move = 0
for i in s:
	i = ord(i) - 97
	walk = abs(i - pointer)
	if walk < 13:
		move += walk
	else:
		move += 26 - walk
	pointer = i
print(move)


def night_at_the_musium(s):
	current = 'a'
	cur_index = 0
	table = 'abcdefghijklmnopqrstuvwxyz'
	total = 0
	for i in s:
		pos = table.find(i)
		if pos > cur_index:
			if pos - cur_index > len(table) / 2:
				distance = cur_index - (pos - len(table))
			else:
				distance = pos - cur_index
		elif cur_index - pos > len(table) / 2:
			distance = pos - (cur_index - len(table))
		else:
			distance = cur_index - pos
		total += distance
		cur_index = pos
	return total
x = input()
print(night_at_the_musium(x))


def min(*a):
	min = a[0]
	for i in a:
		if i < min:
			min = i
	return min

def clock(a, b):
	if a < b:
		(a, b) = (b, a)
	return min(ord(b) - ord('a') + (ord('z') - ord(a)) + 1, ord(a) - ord(b))
s = input()
p = 'a'
sum = 0
for i in s:
	sum = sum + clock(i, p)
	p = i
print(sum)


import string
alpha = string.ascii_lowercase
s = input()
ch = 'a'
i = 0
count = 0
while i < len(s):
	d = abs(alpha.index(ch) - alpha.index(s[i]))
	if d < 13:
		count += d
	else:
		count += 26 - d
	ch = s[i]
	i += 1
print(count)


l = list(map(lambda x: ord(x) - ord('a'), input()))
now = 0
res = 0
for i in range(len(l)):
	if abs(l[i] - now) < 26 - abs(l[i] - now):
		res += abs(l[i] - now)
	else:
		res += 26 - abs(l[i] - now)
	now = l[i]
print(res)


s = input()
i = 0
t = 0
if abs(ord('a') - ord(s[i])) > 26 - abs(ord('a') - ord(s[i])):
	t += 26 - abs(ord('a') - ord(s[i]))
else:
	t += abs(ord('a') - ord(s[i]))
while i < len(s) - 1:
	if abs(ord(s[i]) - ord(s[i + 1])) > 26 - abs(ord(s[i]) - ord(s[i + 1])):
		t += 26 - abs(ord(s[i]) - ord(s[i + 1]))
	else:
		t += abs(ord(s[i]) - ord(s[i + 1]))
	i += 1
print(t)


c = 'a'
ans = 0
x = input()
for i in x:
	b = abs(ord(i) - ord(c))
	if b < 13:
		ans += b
	else:
		ans += 26 - b
	c = i
print(ans)


n = input()
l1 = []
l1.append('a')
l1[0] = 'a'
l2 = list(n)
list1 = l1 + l2
len1 = len(list1)
list2 = []
for i in range(len(list1) - 1):
	o1 = ord(list1[i]) - ord(list1[i + 1])
	o2 = ord(list1[i + 1]) - ord(list1[i])
	if o1 > 0 and o1 < 13:
		list2.append(o1)
	elif o2 > 0 and o2 < 13:
		list2.append(o2)
	elif o1 > 0:
		o126 = 26 - o1
		list2.append(o126)
	elif o2 > 0:
		o226 = 26 - o2
		list2.append(o226)
if list1[1] != 'a':
	print(sum(list2))
elif list1[1] == 'a' and list1[len(list1) - 1] != 'a':
	print(sum(list2))
else:
	print(sum(list2))


str1 = input()
pointer1 = ord('a')
count = 0
for i in range(len(str1)):
	diff = ord(str1[i]) - pointer1
	if diff < 0:
		diff *= -1
	if diff <= 13:
		count += diff
	else:
		count += 26 - diff
	pointer1 = ord(str1[i])
print(count)


def main():
	name = input()
	alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	wheelIndex = 0
	seekIndex = 0
	leftDistance = 0
	rightDistance = 0
	totalDistance = 0
	while seekIndex != len(name):
		tempIndex = wheelIndex
		rightDistance = 0
		while name[seekIndex] != alphabets[tempIndex]:
			tempIndex += 1
			tempIndex = tempIndex % len(alphabets)
			rightDistance += 1
		tempIndex = wheelIndex
		leftDistance = 0
		while name[seekIndex] != alphabets[tempIndex]:
			tempIndex -= 1
			if tempIndex == -1:
				tempIndex = len(alphabets) - 1
			leftDistance += 1
		wheelIndex = tempIndex
		totalDistance += min(rightDistance, leftDistance)
		seekIndex += 1
	print(totalDistance)
	return True
main()


import string
STRING_TO_NUMS = {d: a for (a, d) in enumerate(string.ascii_lowercase, start=1)}
(current, sum_) = (1, 0)
for char in input():
	sum_ += min(abs(STRING_TO_NUMS[char] - current), 26 - abs(STRING_TO_NUMS[char] - current))
	current = STRING_TO_NUMS[char]
print(sum_)


ALPHABET = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
WORD = input()
current_index = ACC = 0
for ch in WORD:
	letter_index = ALPHABET.index(ch)
	index_anterior = current_index
	dist_left = dist_right = 0
	while True:
		if current_index - 1 < 0:
			current_index = 25
		else:
			current_index -= 1
		dist_left += 1
		if letter_index == current_index:
			break
	dist_right = 26 - abs(dist_left)
	if dist_left <= dist_right:
		ACC += dist_left
	else:
		ACC += dist_right
	current_index = letter_index
print(ACC)


n = input()
c = 0
m = list(n)
m.insert(0, 'a')
for i in range(1, len(m)):
	c = c + min(26 - abs(ord(m[i]) - ord(m[i - 1])), abs(ord(m[i]) - ord(m[i - 1])))
print(c)


import math
a = input()
id = 0
res = 0
for i in range(len(a)):
	x = ord(a[i]) - ord('a')
	res += min((x - id + 26) % 26, (id - x + 26) % 26)
	id = x
print(res)


import string

def min_distance(letter1, letter2):
	idx1 = string.ascii_lowercase.index(letter1)
	idx2 = string.ascii_lowercase.index(letter2)
	d1 = abs(idx1 - idx2)
	d2 = min(idx1, idx2) + 26 - max(idx1, idx2)
	return min(d1, d2)
s = input()
last = 'a'
d = 0
for (i, l) in enumerate(s):
	d += min_distance(last, l)
	last = l
print(d)


def solve(arr):
	diff = abs(ord('a') - ord(arr[0]))
	maxOrd = ord('z') - ord('a') + 1
	if diff > maxOrd - diff:
		ans = maxOrd - diff
	else:
		ans = diff
	for (index, i) in enumerate(arr):
		if index == len(arr) - 1:
			break
		diff = abs(ord(i) - ord(arr[index + 1]))
		if diff > maxOrd - diff:
			ans += maxOrd - diff
		else:
			ans += diff
	print(ans)
string = input()
solve(string)


a = str(input())
b = 'abcdefghijklmnopqrstuvwxyz'
l = len(b)
a = 'a' + a
s = 0
for i in range(0, len(a) - 1):
	b1 = b.index(a[i])
	b2 = b.index(a[i + 1])
	s = s + min(abs(b2 - b1), l - abs(b2 - b1))
print(s)


s = 'a' + input()
A = dict(zip('abcdefghijklmnopqrstuvwxyz', range(26)))
res = 0
for i in range(len(s) - 1):
	v1 = (A[s[i]] - A[s[i + 1]]) % 26
	v2 = (A[s[i + 1]] - A[s[i]]) % 26
	res += v1 if v1 < v2 else v2
print(res)


name = input()
alf = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
tp = 0
k = 0
for i in range(len(name)):
	x = alf.index(name[i])
	if tp >= x and tp - 13 <= x:
		k += tp - x
	elif tp < x and tp + 13 >= x:
		k += x - tp
	elif tp >= x and tp - 13 > x:
		k += x + 26 - tp
	else:
		k += tp + 26 - x
	tp = x
print(k)


s = input()
i = 0
c = 0
for cc in s:
	ind = ord(cc) - 97
	dis = abs(i - ind)
	if dis > 13:
		c += 26 - dis
	else:
		c += dis
	i = ind
print(c)


a = input()
n = 'a'
answer = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(a)):
	b = abs(alphabet.find(n) - alphabet.find(a[i]))
	c = 26 - b
	answer += min(b, c)
	n = a[i]
print(answer)


s = input()
l = []
for i in range(97, 123):
	l.append(chr(i))
rot = 0
for i in range(len(s)):
	if i == 0:
		a = abs(l.index(s[i]) - l.index('a'))
		b = 26 - l.index(s[i])
		rot = rot + min(a, b)
	else:
		a = abs(l.index(s[i]) - l.index(s[i - 1]))
		b = 26 - a
		rot = rot + min(a, b)
print(rot)


a = 'a' + input()
b = 'abcdefghijklmnopqrstuvwxyz'
wheel = ''
rotation = 0
for i in range(len(a)):
	g = b.index(a[i])
	if g > 12:
		b = b[g:] + b[:g]
		rotation = rotation + len(b[g:])
	else:
		b = b[g:] + b[:g]
		rotation = rotation + g
print(rotation)


letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
word = input()
count = 0
initial_pos = 'a'
for i in range(len(word)):
	for j in range(26):
		if word[i] == letters[j]:
			if abs(j - letters.index(initial_pos)) > 12:
				count += 26 - abs(j - letters.index(initial_pos))
			else:
				count += abs(j - letters.index(initial_pos))
			initial_pos = letters[j]
			break
print(count)


y = str(input())
y = 'a' + y
(j, t) = (0, 0)
b = [0] * len(y)
for i in range(len(y)):
	b[j] = ord(y[i]) - 96
	j += 1
for k in range(len(y)):
	if b[k + 1] > b[k]:
		f = 26 + b[k] - b[k + 1]
		e = abs(b[k] - b[k + 1])
	else:
		f = 26 + b[k + 1] - b[k]
		e = abs(b[k] - b[k + 1])
	if f > e:
		t += e
	else:
		t += f
	k += 1
	if k + 1 >= len(y):
		break
print(t)


a = 'a' + input()
b = 0
for i in range(len(a) - 1):
	c = abs(ord(a[i]) - ord(a[i + 1]))
	b += min(c, 26 - c)
print(b)


word = input()
s = 0
curr = 'a'
for c in word:
	if ord(c) >= ord(curr):
		d = ord(c) - ord(curr)
		if d >= 13:
			x = 26 - d
		else:
			x = d
	else:
		d = ord(curr) - ord(c)
		if d >= 13:
			x = 25 - d + 1
		else:
			x = d
	curr = c
	s += x
print(s)


s = input()
crr = 0
tot = 0
for i in s:
	nxt = ord(i) - 97
	if nxt > crr:
		if nxt - crr > 26 - nxt + crr:
			tot += 26 - nxt + crr
		else:
			tot += nxt - crr
	elif crr - nxt > 26 + nxt - crr:
		tot += 26 + nxt - crr
	else:
		tot += crr - nxt
	crr = nxt
print(tot)


s = input()
coN = 0
curr = 97
for i in s:
	rot = abs(curr - ord(i))
	if rot > 13:
		rot = 26 - rot
	coN += rot
	curr = ord(i)
print(coN)


c = 0
cur = 'a'
for i in input():
	c += min(abs(ord(i) - ord(cur)), 26 - abs(ord(i) - ord(cur)))
	cur = i
print(c)


__author__ = 'Think'
name = input()
prev = 'a'
total = 0
for s in name:
	total += min(abs(ord(s) - ord(prev)), 26 - abs(ord(s) - ord(prev)))
	prev = s
print(total)


al = 'abcdefghijklmnopqrstuvwxyz' * 3
current = 26
num = 0
word = input()
for i in word:
	num += min(abs(current - al.find(i, current - 26, current)), abs(current - al.find(i, current)))
	current = al.find(i, 26, 52)
print(num)


t = input()
z = ord(t[0]) - ord('a')
cnt = min(26 - z, z)
for i in range(len(t) - 1):
	(b, a) = (ord(t[i + 1]), ord(t[i]))
	m = max(a, b) - min(a, b)
	cnt += min(26 - m, m)
print(cnt)


S = list(input())
R = 0
C = 'a'
for c in S:
	k = abs(ord(c) - ord(C))
	R += min(k, 26 - k)
	C = c
print(R)


import sys
input = sys.stdin.readline

def dist(a, b):
	x = ord(a) % 97
	y = ord(b) % 97
	diff = abs(x - y)
	return min(diff, 26 - diff)
s = 'a' + input().strip()
d = 0
for i in range(1, len(s)):
	d += dist(s[i - 1], s[i])
print(d)


def charDefrance(ch1, ch2):
	ch1 = ord(ch1) - 96
	ch2 = ord(ch2) - 96
	if ch1 > ch2:
		if 26 - (ch1 - ch2) < ch1 - ch2:
			return 26 - (ch1 - ch2)
		else:
			return ch1 - ch2
	elif 26 - (ch2 - ch1) < ch2 - ch1:
		return 26 - (ch2 - ch1)
	else:
		return ch2 - ch1

def rotationCount(string):
	count = 0
	count += charDefrance('a', string[0])
	for i in range(len(string) - 1):
		count += charDefrance(string[i], string[i + 1])
	return count
input = input()
print(rotationCount(input))


l = list((x for x in input()))
s = 0
dif = abs(ord('a') - ord(l[0]))
if dif > 13:
	dif = 26 - dif
for i in range(len(l) - 1):
	v = ord(l[i]) - ord('a')
	v1 = ord(l[i + 1]) - ord('a')
	v2 = abs(v1 - v)
	if v2 > 13:
		v2 = 26 - v2
	s = s + v2
print(s + dif)


s = input()
res = 0
cur = 'a'
for i in range(len(s)):
	x = abs(ord(cur) - ord(s[i]))
	res += x if x <= 13 else 26 - x
	cur = s[i]
print(res)


s = input()
prev = 'a'
turns = 0
for x in s:
	turns += min(abs(ord(x) - ord(prev)), abs(ord(prev) - ord(x)), (ord(x) - ord(prev)) % 26, (ord(prev) - ord(x)) % 26)
	prev = x
print(turns)


s = str(input())
(prv, res) = ('a', 0)
for i in range(len(s)):
	diff = abs(ord(s[i]) - ord(prv))
	res += min(diff, 26 - diff)
	prv = s[i]
print(res)


a = input()
b = 'a'
count = 0
for i in a:
	d = abs(ord(i) - ord(b))
	count += min(d, 26 - d)
	b = i
print(count)


def main():
	moves = 0
	word = input()
	previous_letter = 'a'
	for i in word:
		moves_if_forward = abs(ord(i) - 96 - (ord(previous_letter) - 96))
		moves_if_backward = 26 - abs(ord(i) - 96 - (ord(previous_letter) - 96))
		moves += min(moves_if_forward, moves_if_backward)
		previous_letter = i
	print(moves)
main()


a = input()
x = 1
order = []
for i in a:
	order.append(ord(i) - ord('a') + 1)
rot = 0
for i in order:
	anticlockwise = x + (26 - i)
	clockwise = 26 - x + i
	rot += min(clockwise % 26, anticlockwise % 26)
	x = i
print(rot)


s = str(input())
alphabet = 'abcdefghijklmnopqrstuvwxyz'
temp_index = 0
steps = 0
for i in range(len(s)):
	steps += min(abs(alphabet.index(s[i]) - temp_index), 26 - abs(alphabet.index(s[i]) - temp_index))
	temp_index = alphabet.index(s[i])
print(steps)


def d(x, y):
	return min(abs(ord(x) - ord(y)), 26 - abs(ord(x) - ord(y)))
ans = 0
s = 'a' + input()
for i in range(len(s) - 1):
	ans += d(s[i], s[i + 1])
print(ans)


s = input().strip().lower()
n = len(s)
ptr = 'a'
rot = 0
for i in range(n):
	if s[i] > ptr:
		diff = ord(s[i]) - ord(ptr)
	else:
		diff = ord(ptr) - ord(s[i])
	diff = min(diff, 26 - diff)
	rot += diff
	ptr = s[i]
print(rot)


x = 'a' + input()
print(sum([26 - abs(ord(x[i]) - ord(x[i + 1])) if abs(ord(x[i]) - ord(x[i + 1])) >= 13 else abs(ord(x[i]) - ord(x[i + 1])) for i in range(len(x) - 1)]))


abc = 'abcdefghijklmnopqrstuvwxyz'
a = input()
t = 0
for i in range(len(a)):
	if i == 0:
		x = 'a'
		y = a[i]
	else:
		x = a[i - 1]
		y = a[i]
	ans1 = abs(abc.find(x) - abc.find(y))
	ans2 = 26 - ans1
	t += min(ans1, ans2)
print(t)


import math
import re
s = input()
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
letter = 'a'
l_ = 0
for ch in s:
	l1 = max(letters.index(ch), letters.index(letter)) - min(letters.index(ch), letters.index(letter))
	l2 = abs(len(letters) - max(letters.index(ch), letters.index(letter)) + min(letters.index(ch), letters.index(letter)))
	l_ += min(l1, l2)
	letter = ch
print(l_)


text = input()
ancien = ord('a')
n = 0
for c in text:
	nouv = ord(c)
	l1 = min(nouv, ancien)
	l2 = max(nouv, ancien)
	n += min(l2 - l1, l1 - l2 + 26)
	ancien = nouv
print(n)


word = input()
length = len(word)
number_of_moves = 0
start = 0
for char in word:
	index = ord(char) - 97
	walk = abs(start - index)
	if walk <= 13:
		number_of_moves += walk
	else:
		number_of_moves += 26 - walk
	start = index
print(number_of_moves)


import math

def computeMinMovement(nextChar, prevChar):
	loChar = min(nextChar, prevChar)
	hiChar = max(nextChar, prevChar)
	return int(min(math.fabs(ord(hiChar) - ord(loChar)), math.fabs(ord(loChar) + 26 - ord(hiChar))))

def getAns(word):
	totMoves = 0
	prevChar = 'a'
	for i in range(len(word)):
		totMoves += computeMinMovement(word[i], prevChar)
		prevChar = word[i]
	return totMoves
word = input()
print(getAns(word))


s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
t = 0
k = 0
for i in range(len(s)):
	k1 = abc.find(s[i])
	d1 = abs(t - k1)
	d2 = 26 - d1
	k += min(d1, d2)
	t = k1
print(k)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	S = Scanner.string()
	ans = 0
	p = 'a'
	for s in S:
		a = string.ascii_lowercase.index(s)
		b = string.ascii_lowercase.index(p)
		ans += min(abs(a - b), 26 - abs(a - b))
		p = s
	print(ans)

def main():
	solve()
main()


LENGTH = 26

def min_distance(a, b):
	return min(abs(ord(a) - ord(b)), LENGTH - abs(ord(a) - ord(b)))

def night_at_museum(mstr):
	if mstr == None:
		return None
	lstr = list(mstr)
	rotation = min_distance(lstr[0], 'a')
	for c in range(1, len(lstr)):
		rotation += min_distance(lstr[c - 1], lstr[c])
	return rotation
mystr = str(input().strip())
print(night_at_museum(mystr))


from math import *
s = list(input())
count = 0
point = 'a'
for i in range(len(s)):
	dist = abs(ord(point) - ord(s[i]))
	if dist < 13:
		count = count + dist
	else:
		count = count + 26 - dist
	point = s[i]
print(count)


exhibitName = [i for i in input()]
letters = 'abcdefghijklmnopqrstuvwxyz'
lettersDict = dict()
letterIndex = 1
for i in letters:
	lettersDict[i] = letterIndex
	letterIndex += 1
startIndex = 'a'
rotationsCount = 0
for letter in exhibitName:
	currentIndex = lettersDict[startIndex]
	if currentIndex <= 13:
		currentIndex += 26
	else:
		currentIndex -= 26
	rotationsCount += min(abs(lettersDict[startIndex] - lettersDict[letter]), abs(currentIndex - lettersDict[letter]))
	startIndex = letter
print(rotationsCount)


f = lambda : map(int, input().split())
s = input()
(c, mn) = ('a', 0)
al = 'abcdefghijklmnopqrstuvwxyz'
for i in s:
	k = abs(al.find(c) - al.find(i))
	mn += min(26 - k, k)
	c = i
print(mn)


s = input()
out = 0
x = 'a'
for i in s:
	d = abs(ord(x) - ord(i))
	out += min(d, 26 - d)
	x = i
print(out)


s = input()
start = 'a'
res = 0
for i in s:
	move = abs(ord(i) - ord(start))
	if move > 13:
		move = 26 - move
	res += move
	start = i
print(res)


import string

def solve():
	s = input()
	chs = string.ascii_lowercase
	d = {chs[i]: i for i in range(len(chs))}
	cost = 0
	last_ch = 'a'
	for ch in s:
		clock_wise = abs(d[ch] - d[last_ch])
		if ch > last_ch:
			counter_clock = 26 - d[ch] + d[last_ch]
		else:
			counter_clock = 26 - d[last_ch] + d[ch]
		cost += min(clock_wise, counter_clock)
		last_ch = ch
	print(cost)
solve()


word = list(input())
word.insert(0, 'a')
count = 0
for i in range(len(word) - 1):
	dif1 = abs(ord(word[i + 1]) - ord(word[i]))
	dif2 = 26 - dif1
	minn = min(dif1, dif2)
	count += minn
print(count)


n = input()
a = 'abcdefghijklmnopqrstuvwxyz'
my_list = []
c = 0
for i in n:
	c += 1
	last_index = a.index(i)
	if c < 2:
		my_list.append(min(len(a[a.index('a'):last_index]), abs(len(a[a.index('a'):last_index]) - 26)))
	elif first_index <= last_index:
		my_list.append(min(len(a[first_index:last_index]), abs(len(a[first_index:last_index]) - 26)))
	else:
		my_list.append(min(len(a[last_index:first_index]), abs(len(a[last_index:first_index]) - 26)))
	first_index = a.index(i)
print(sum(my_list))


letters = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
curr_letter = 1
string = input().strip()
moves = 0
for letter in string:
	through = abs(letters[letter] - curr_letter)
	cut_across = 26 + min(letters[letter] - curr_letter, curr_letter - letters[letter])
	moves += min(through, cut_across)
	curr_letter = letters[letter]
print(moves)


import string
alpha = [' ']
alpha.extend(list(string.ascii_lowercase))
s = input()
count = min(abs(1 - alpha.index(s[0])), 26 - abs(1 - alpha.index(s[0])))
for i in range(1, len(s)):
	k = abs(alpha.index(s[i]) - alpha.index(s[i - 1]))
	j = 26 - k
	count += min(k, j)
print(count)


Word = input()
ini_pos = 0
rotations = 0
for i in Word:
	fin_pos = ord(i) - 97
	pos = abs(fin_pos - ini_pos)
	ini_pos = fin_pos
	if pos < 14:
		rotations += pos
	else:
		rotations += 26 - pos
print(rotations)


a = input()
s = []
t = 0
for i in range(len(a)):
	s.append(ord(a[i]))
for j in range(len(a) - 1):
	if abs(s[j] - s[j + 1]) <= 13:
		t = t + abs(s[j] - s[j + 1])
	else:
		t = t + 26 - abs(s[j] - s[j + 1])
if abs(ord('a') - s[0]) <= 13:
	t = t + abs(ord('a') - s[0])
else:
	t = t + 26 - abs(ord('a') - s[0])
print(t)


c = 97
s1 = 0
for i in map(ord, input()):
	x = abs(c - i)
	s1 = s1 + min(x, 26 - x)
	c = i
print(s1)


letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
exhibit = input()
ind = 0
moves = 0
left = 0
right = 0
for x in range(len(exhibit)):
	for y in range(ind, ind - 26, -1):
		if letters[y] == exhibit[x]:
			break
		else:
			left += 1
	if ind > letters.index(exhibit[x]):
		right += 26 - (ind - letters.index(exhibit[x]))
	elif ind < letters.index(exhibit[x]):
		right += letters.index(exhibit[x]) - ind
	ind = letters.index(exhibit[x])
	if left <= right:
		moves += left
	else:
		moves += right
	left = 0
	right = 0
print(moves)


inp = input()
start = 'a'
my_dict = {'a': 1}
for i in range(2, 27):
	start = chr(ord(start) + 1)
	my_dict[start] = i
rotation = 0
counter = 'a'
for i in inp:
	distance1 = my_dict[counter] - my_dict[i]
	distance2 = my_dict[i] - my_dict[counter]
	if distance1 < 0:
		distance1 += 26
	if distance2 < 0:
		distance2 += 26
	rotation += min(distance1, distance2)
	counter = i
print(rotation)


s = input()
l = 26
cnt = 0
x = 97
for i in range(len(s)):
	y = ord(s[i])
	cnt += min(abs(x - y), l - abs(x - y))
	x = ord(s[i])
print(cnt)


aplha = list('abcdefghijklmnopqrstuvwxyz')
s = list(input())
count = 0
past = 'a'
for i in s:
	curr = i
	index1 = aplha.index(past)
	index2 = aplha.index(curr)
	diff = min(abs(index1 - index2), abs(abs(index1 - index2) - 26))
	count += diff
	past = i
print(count)


a = input()
letters = list(map(ord, list(a)))
last = ord('a')
r = 0
for each in letters:
	r += min(abs(each - last), 26 - abs(each - last))
	last = each
print(r)


n = input()
m = 0
s = 'a' + n
for i in range(len(s) - 1):
	a = ord(s[i]) - ord(s[i + 1])
	if a < 0:
		a = a * -1
	b = 26 - a
	if b < 0:
		b = b * -1
	if a < b:
		m = m + a
	else:
		m = m + b
print(m)


s = input()
ch = 'a'
res = 0
for i in s:
	m = abs(ord(i) - ord(ch))
	if m < 13:
		res += m
	else:
		res += 26 - m
	ch = i
print(res)


s = input()
cur = 'a'
total = 0
for i in s:
	v = abs(ord(i) - ord(cur))
	total += min(v, 26 - v)
	cur = i
print(total)


try:
	s = input()
	pointer = 'a'
	ans = 0
	for i in s:
		m1 = 26 - abs(ord(pointer) - ord(i))
		m2 = abs(ord(pointer) - ord(i))
		if m1 < m2:
			ans += m1
		else:
			ans += m2
		pointer = i
	print(ans)
except Exception:
	pass


def main():
	d = input()
	c = 'a'
	r = 0
	for v in d:
		r += min(abs(ord(v) - ord(c)), abs(26 + ord(c) - ord(v)), abs(26 + ord(v) - ord(c)))
		c = v
	print(r)
main()


name = input()
cur = 'a'
res = 0
for i in name:
	if abs(ord(cur) - ord(i)) <= 13:
		res += abs(ord(cur) - ord(i))
	else:
		res += 26 - abs(ord(cur) - ord(i))
	cur = i
print(res)


s = input()
d = abs(ord(s[0]) - ord('a'))
rot = min(d, 26 - d)
n = len(s)
for i in range(n - 1):
	d = abs(ord(s[i + 1]) - ord(s[i]))
	rot += min(d, 26 - d)
print(rot)


s = input()
prev = 'a'
answer = 0
for c in s:
	temp1 = abs(ord(c) - ord(prev))
	temp2 = 26 - temp1
	temp = min(temp1, temp2)
	answer += temp
	prev = c
print(answer)


c = 0
ch = 97
s = input()
tmp = 0
for i in s:
	if ch > ord(i):
		tmp += 26 + ord(i) - ch
	else:
		tmp += 26 + ch - ord(i)
	c += min(abs(ord(i) - ch), tmp)
	ch = ord(i)
	tmp = 0
print(c)


n = input()
a = []
for i in range(97, 123):
	a.append(chr(i))
s = 0
for i in range(-1, len(n)):
	bs = a.index(n[i])
	if i == -1:
		bs = a.index('a')
	try:
		nbs = a.index(n[i + 1])
	except IndexError:
		nbs = a.index(n[-1])
	stf = 0
	stb = 0
	while bs != nbs:
		stf += 1
		bs += 1
		if bs > 25:
			bs = 0
	bs = a.index(n[i])
	if i == -1:
		bs = a.index('a')
	try:
		nbs = a.index(n[i + 1])
	except IndexError:
		nbs = a.index(n[-1])
	while bs != nbs:
		stb += 1
		bs -= 1
		if bs < 0:
			bs = 25
	if stf > stb:
		s += stb
	else:
		s += stf
print(s)


s = input().lower()
current = 'a'
counter = 0
for char in s:
	right = abs(ord(current) - ord(char))
	left = 26 - right
	if right < left:
		counter += right
	else:
		counter += left
	current = char
print(counter)


pointer = 0
s = input()
c = 0
for x in s:
	k = ord(x) - ord('a')
	crr = []
	if k - pointer >= 0:
		crr.append(k - pointer)
	else:
		crr.append(k - pointer + 26)
	if pointer - k >= 0:
		crr.append(pointer - k)
	else:
		crr.append(pointer - k + 26)
	pointer = k
	c += min(crr)
print(c)


s = input()
count = 0
point = ord('a')
for i in range(len(s)):
	i_point = ord(s[i])
	dist = abs(point - i_point)
	if dist < 13:
		count += dist
	else:
		count += 26 - dist
	point = i_point
print(count)


a = 'abcdefghijklmnopqrstuvwxyz'
letter = input()
move = 0
for i in letter:
	clock = a.index(i)
	antiClock = 26 - a.index(i)
	ad = clock
	if clock > antiClock:
		ad = antiClock
	move = move + ad
	a = a[a.index(i):len(a)] + a[0:a.index(i)]
print(move)


nameOfExhibit = input()
currentPosOfEmbosser = 1
minRotationsReq = 0
for i in range(0, len(nameOfExhibit)):
	nextPosOfEmbosser = ord(nameOfExhibit[i]) - 96
	if nextPosOfEmbosser > currentPosOfEmbosser:
		large = nextPosOfEmbosser
		small = currentPosOfEmbosser
	else:
		large = currentPosOfEmbosser
		small = nextPosOfEmbosser
	rotationType_1 = large - small
	rotationType_2 = 26 - large + small
	if rotationType_1 < rotationType_2:
		minRotationsReq += rotationType_1
	else:
		minRotationsReq += rotationType_2
	currentPosOfEmbosser = nextPosOfEmbosser
print(minRotationsReq)


lis = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
name = []
for ch in input():
	name.append(ch)
answer = 0
current_pos = 'a'
for alphabet in name:
	if abs(lis.index(alphabet) - lis.index(current_pos)) > 26 - abs(lis.index(alphabet) - lis.index(current_pos)):
		answer += 26 - abs(lis.index(alphabet) - lis.index(current_pos))
	else:
		answer += abs(lis.index(alphabet) - lis.index(current_pos))
	current_pos = alphabet
print(answer)


import math
a = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'

def find(a, i, s):
	ans = 50
	ind = 0
	for j in enumerate(a):
		if j[1] == s:
			if ans > abs(j[0] - i) % 26 or ans > 26 - abs(j[0] - i) % 26:
				ind = j[0]
				ans = min(abs(j[0] - i) % 26, 26 - abs(j[0] - i) % 26)
	return (ans, ind)
string = input()
ans = 0
ind = 0
for s in string:
	(val, ind) = find(a, ind, s)
	ans += val
print(ans)


ans = 0
n = input()
ch = 'a'
for i in n:
	num = abs(ord(i) - ord(ch))
	ans = ans + min(num, 26 - num)
	ch = i
print(ans)


import string
chars = string.ascii_lowercase
word = input()
list_of_chars = []
max_moves = 0
initial_pos = 0
found = 0
for i in word:
	list_of_chars.append(i)
for i in list_of_chars:
	found = chars.find(i)
	distance = abs(initial_pos - found)
	if distance < 13:
		max_moves += distance
	else:
		max_moves += 26 - distance
	initial_pos = found
print(max_moves)


s = input()
total = 0
start = 0
for i in s:
	l = ord(i) - 97
	total += min(abs(start - l), 26 - abs(start - l))
	start = l
print(total)


a = list(input())
a.insert(0, 'a')
alph = list('abcdefghijklmnopqrstuvwxyz')
alph_rev = alph.copy()
alph_rev.reverse()

def counting(base, where):
	ln = len(alph[alph.index(base):alph.index(where)])
	if ln == 0 and base != where:
		ln = len(alph_rev[alph_rev.index(base):alph_rev.index(where)])
	if ln > 13:
		return 26 - ln
	if ln <= 13:
		return ln
count = 0
for every in range(len(a)):
	try:
		count += counting(a[every], a[every + 1])
	except IndexError:
		None
print(count)


word = input()
position = 0
moves = 0
for character in word:
	newPosition = ord(character) - ord('a')
	if abs(newPosition - position) <= 13:
		moves += abs(newPosition - position)
	else:
		moves += 26 - abs(newPosition - position)
	position = newPosition
print(moves)


al = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = input()
m = 0
x = 0
for i in range(len(s)):
	y = al.index(s[i])
	if x > y:
		if abs(x - y) > abs(25 - x + y + 1):
			m += abs(25 - x + y + 1)
		else:
			m += abs(x - y)
	elif abs(x - y) > abs(25 - y + x + 1):
		m += abs(25 + x - y + 1)
	else:
		m += abs(x - y)
	(x, y) = (y, x)
print(m)


A = 'abcdefghijklmnopqrstuvwxyz'
B = 'zyxwvutsrqponmlkjihgfedcba'
S = input()
p = 0
m = 0
for c in S:
	d = ord(c) - 97
	m += min((d - p) % 26, (p - d) % 26)
	p = d
print(m)


inp = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
curLoc = 0
totalStep = 0
for i in inp:
	iLoc = alphabet.index(i)
	step = min(abs(curLoc - iLoc), 26 - abs(curLoc - iLoc))
	curLoc = iLoc
	totalStep += step
print(totalStep)


s1 = input()
rot = 0
c = ord('a')
for i in s1:
	m = abs(c - ord(i))
	rot += min(m, 26 - m)
	c = ord(i)
print(rot)


s = input()
point = 'a'
res = 0
for i in s:
	res += min(abs(ord(point) - ord(i)), 26 - abs(ord(point) - ord(i)))
	point = i
print(res)


from sys import stdin
s = map(ord, stdin.readline().rstrip())
temp = 97
res = 0
for x in s:
	d1 = abs(x - temp)
	d2 = 26 - d1
	temp = x
	res += min(d1, d2)
print(res)


cursor = ord('a')
word = input()
steps = 0
for i in word:
	n = ord(i)
	CW = abs(n - cursor)
	ACW = abs(26 - CW)
	steps += min(CW, ACW)
	cursor = n
print(steps)


import os
from math import ceil
import sys
from io import BytesIO, IOBase
import sys, bisect, copyreg, copy, statistics, os

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

def IIX():
	return (int(x) for x in sys.stdin.readline().split())

def II():
	return int(inp())

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

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

def L(x):
	return list(x)

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

class GraphAL:

	def __init__(self, Nodes, isDirected=False):
		self.nodes = [x for x in range(Nodes + 1)]
		self.adj_list = {}
		self.isDirected = isDirected
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, x, y):
		self.adj_list[x].append(y)
		if self.isDirected == False:
			self.adj_list[y].append(x)

	def return_graph(self):
		return self.adj_list

class GraphAM:

	def __init__(self, Nodes, isDirected=False):
		self.adj_matrix = [[0] * (Nodes + 1) for x in range(Nodes + 1)]
		self.isDirected = isDirected

	def add_edge(self, x, y):
		if self.isDirected:
			self.adj_matrix[x][y] = 1
		elif self.isDirected == False:
			self.adj_matrix[x][y] = 1
			self.adj_matrix[y][x] = 1

	def delete_edge(self, x, y):
		if self.isDirected:
			self.adj_matrix[x][y] = 0
		if self.isDirected == False:
			self.adj_matrix[x][y] = 0
			self.adj_matrix[y][x] = 0

	def degree(self, x):
		l = self.adj_matrix[x]
		return l.count(1)

	def return_graph(self):
		return self.adj_matrix

def solve():
	st = inp()
	alph = 'abcdefghijklmnopqrstuvwxyz'
	start = 'a'
	cost = 0
	for x in st:
		i = alph.index(start)
		j = alph.index(x)
		diff = abs(j - i)
		cost += abs(min(diff, 26 - diff))
		start = x
	out(cost)
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.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		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')
try:
	t = 1
	for _ in range(t):
		solve()
except EOFError as e:
	out('')
except RuntimeError as r:
	out('')


start = 97
sum = 0
for c in map(ord, input()):
	d = abs(c - start)
	start = c
	sum += min(d, 26 - d)
print(sum)


alpha = 'abcdefghijklmnopqrstuvwxyz'
alphalist = []
for x in range(2):
	for i in range(len(alpha)):
		alphalist.append(alpha[i])
basepointer = 26
distanceCW = 0
distanceCCW = 0
counter = 0
word = input()
for j in range(len(word)):
	letter = word[j]
	if letter != alphalist[basepointer]:
		for i in range(basepointer + 1, len(alphalist)):
			distanceCW += 1
			if letter == alphalist[i]:
				pointerCW = i
				break
		for i in range(basepointer - 1, -1, -1):
			distanceCCW += 1
			if letter == alphalist[i]:
				pointerCCW = i
				break
		if distanceCW < distanceCCW:
			counter += distanceCW
			basepointer = pointerCW
		else:
			counter += distanceCCW
			basepointer = pointerCCW
		distanceCW = 0
		distanceCCW = 0
		if basepointer >= 39:
			basepointer -= 26
		if basepointer < 13:
			basepointer += 26
print(counter)


n = input()
prev = 'a'
ans = 0
for i in range(len(n)):
	k = min(abs(ord(n[i]) - ord(prev)), 26 - abs(ord(n[i]) - ord(prev)))
	ans += k
	prev = n[i]
print(ans)


string = input().lower()
ascii_list = []
a = 0
counter = a
rotations = 0
for char in string:
	ascii_list.append(ord(char) - 97)
for num in ascii_list:
	if abs(num - counter) >= 13:
		rotations += 26 - abs(num - counter)
		counter = num
	else:
		rotations += abs(num - counter)
		counter = num
print(rotations)


import math
from fractions import Fraction as frac
MOD = 1000000000.0 + 7

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

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

def solve(case_no):
	s = str(input())
	s = 'a' + s
	ans = 0
	for i in range(1, len(s)):
		d = abs(ord(s[i]) - ord(s[i - 1]))
		ans += min(d, 26 - d)
	print(ans)
t = 1
for i in range(1, t + 1):
	solve(i)


import sys
import math
input = sys.stdin.readline
s = list(input())
ans = 0
cur = 'a'
for c in s:
	if c == '\n':
		continue
	(p, q) = (ord(c) - ord('a'), ord(cur) - ord('a'))
	ans += min(abs(p - q), 26 - abs(p - q))
	cur = c
print(ans)


st = input()
(c, ans) = ('a', 0)
for i in st:
	ans += min(abs(ord(c) - ord(i)), 26 - abs(ord(c) - ord(i)))
	c = i
print(ans)


wheel = input()
ch = 'a'
tong = 0
for i in wheel:
	res = abs(ord(i) - ord(ch))
	ch = i
	if res < 13:
		tong += res
	else:
		tong += 26 - res
print(tong)


al = 'abcdefghijklmnopqrstuvwxyz'
s = input()
(point, move) = (0, 0)
for i in range(len(s)):
	tmp = al.find(s[i])
	diff = abs(tmp - point)
	move += min(diff, 26 - diff)
	point = tmp
print(move)


c = 0
p = 0
for i in input():
	c += min(ord(i) - 97 - p if ord(i) - 97 >= p else 26 - p + ord(i) - 97, p + 26 - (ord(i) - 97) if ord(i) - 97 >= p else p - (ord(i) - 97))
	p = ord(i) - 97
print(c)


s = input()
r = 0
ch = 'a'
for i in s:
	r1 = abs(ord(i) - ord(ch))
	r2 = 26 - abs(ord(i) - ord(ch))
	r += min(r1, r2)
	ch = i
print(r)


word = input()
num = [ord(char) - 96 for char in word.lower()]
s = 0
i = 0
while i < len(num) - 1:
	if abs(num[i + 1] - num[i]) > 26 - abs(num[i + 1] - num[i]):
		s += 26 - abs(num[i + 1] - num[i])
	else:
		s += abs(num[i + 1] - num[i])
	i += 1
if num[0] > 28 - num[0]:
	s += 27 - num[0]
else:
	s += num[0] - 1
print(s)


from sys import stdin

def main():
	alfabeto = 'abcdefghijklmnopqrstuvwxyz'
	pal = stdin.readline().strip()
	pal = 'a' + pal
	cont = 0
	for i in range(len(pal) - 1):
		c = []
		t1 = abs(alfabeto.find(pal[i + 1]) - alfabeto.find(pal[i]))
		t2 = 26 + alfabeto.find(pal[i]) - alfabeto.find(pal[i + 1])
		t3 = abs(alfabeto.find(pal[i]) - alfabeto.find(pal[i + 1]))
		t4 = 26 + alfabeto.find(pal[i + 1]) - alfabeto.find(pal[i])
		c.append(t1)
		c.append(t2)
		c.append(t3)
		c.append(t4)
		cont += min(c)
	print(cont)
main()


s = input()
sum = 0
curr = 'a'
for i in s:
	a = abs(ord(curr) - ord(i))
	if 26 - a < a:
		sum += 26 - a
	else:
		sum += a
	curr = i
print(sum)


name = map(ord, input())
now = 97
count = 0
for i in name:
	if abs(i - now) < 26 - abs(now - i):
		count += abs(i - now)
	else:
		count += 26 - abs(i - now)
	now = i
print(count)


s = input()
t = 0
o = 97
for c in s:
	n = ord(c)
	d = abs(n - o)
	t += d if d < 14 else 26 - d
	o = n
print(t)


s = input()
start = 0
steps = 0
for i in s:
	index = ord(i) - 97
	walk = abs(start - index)
	if walk < 13:
		steps += walk
	else:
		steps += 26 - walk
	start = index
print(steps)


s = input()
total = 0
current = 'a'
for c in s:
	d = abs(ord(c) - ord(current))
	if d > 13:
		total += 26 % d
	else:
		total += d % 26
	current = c
print(total)


target = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
result = 0
for c in target:
	cur_id = 0
	(left, right) = (alphabet[-cur_id], alphabet[cur_id])
	while c not in (left, right):
		cur_id += 1
		(left, right) = (alphabet[-cur_id], alphabet[cur_id])
	result += cur_id
	cur_id = -cur_id if c == left else cur_id
	alphabet = alphabet[cur_id:] + alphabet[:cur_id]
print(result)


n = input()
x = 'a'
d = 0
chars = 'abcdefghijklmnopqrstuvwxyz'
for i in n:
	(a, s) = (chars.find(i), chars.find(x))
	f = 26 - abs(a - s)
	k = abs(a - s)
	d += min(f, k)
	x = i
print(d)


(a, x) = (97, 0)
for b in map(ord, input()):
	x += min((a - b) % 26, (b - a) % 26)
	a = b
print(x)


m = 0
a = 0
v = []
x = [str(z) for z in input()]
if len(x) <= 100:
	for c in x:
		if c.islower():
			v.append(c)
	if len(v) == len(x):
		v.insert(0, 'a')
		for b in range(len(v) - 1):
			m = ord(v[0]) - ord(v[1])
			if m < 0:
				m = m * -1
			v.remove(v[0])
			if m <= 13:
				a = a + m
			else:
				s = 26 - m
				a = a + s
		print(a)


s = input()
i = 'a'
sum = 0
for f in s:
	o = abs(ord(f) - ord(i))
	if f > i:
		t = ord(i) - ord('a') + ord('z') - ord(f) + 1
	else:
		t = ord(f) - ord('a') + ord('z') - ord(i) + 1
	if o > t:
		sum += t
	else:
		sum += o
	i = f
print(sum)


n = input()
li = []
dial = 0
count = 0
for i in range(97, 123):
	li.append(chr(i))
for i in n:
	j = li.index(i)
	count += min(abs(dial - j), abs(26 - abs(dial - j)))
	dial = j
print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 10
mod = 10 ** 9 + 7

def f():
	r = 0
	s = input()
	c = 0
	ai = ord('a')
	t = 0
	for si in s:
		sc = ord(si) - ai
		if sc > c:
			t = min(26 + c - sc, sc - c)
		else:
			t = min(c - sc, sc + 26 - c)
		r += t
		c = sc
	return r
print(f())


forw = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
stri = input()
(fo, bo, suf, sub) = (0, 0, 0, 0)
for j in stri:
	fi = forw.index(j)
	suf += min(abs(fi - fo), 26 - abs(fi - fo))
	fo = fi
print(suf)


string = list(input())
x = 'a'
total = 0
for i in string:
	s = abs(ord(i) - ord(x))
	if s < 13:
		total += s
	else:
		total += 26 - s
	x = i
print(total)


import math

def s():
	stri = input()
	current_chr = 'a'
	ans = 0
	for x in stri:
		current_chr = ord(current_chr)
		tgt_chr = ord(x)
		if tgt_chr - current_chr > 0:
			temp = min(tgt_chr - current_chr, 123 - tgt_chr + current_chr - 97)
		elif tgt_chr - current_chr <= 0:
			temp = min(123 - current_chr + tgt_chr - 97, current_chr - tgt_chr)
		ans += temp
		current_chr = x
	return ans
ans = s()
print(ans)


list = list(input())
cnt = 0
size = 26
pos = 1
for (i, char) in enumerate(list):
	dist = ord(char) - 96
	cnt += min(min(100 if dist - pos < 0 else dist - pos, size - pos + dist), min(pos + size - dist, 100 if pos - dist < 0 else pos - dist))
	pos = dist
print(cnt)


import sys
from math import ceil, log
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

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

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

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

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

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

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

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

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('Yes')

def NO():
	print('No')
INF = 10 ** 18
MOD = 10 ** 9 + 7
s = ri()
s = 'a' + s
cnt = 0
for i in range(1, len(s)):
	cnt += min(abs(ord(s[i]) - ord(s[i - 1])), 26 - abs(ord(s[i]) - ord(s[i - 1])))
print(cnt)


w = input()
start = 97
score = 0
for c in w:
	v = ord(c)
	if v > start:
		score += min(v - start, start - 97 + 123 - v)
	else:
		score += min(start - v, v - 97 + 123 - start)
	start = v
print(score)


part1 = []
part2 = []
count = 0

def anchor(ch):
	xho1 = ord(ch)
	xho2 = xho1
	part1.append(chr(xho1))
	part2.append(chr(xho2))
	for i in range(13):
		if chr(xho1) == 'z':
			xho1 = 96
		if chr(xho2) == 'a':
			xho2 = 123
		xho1 = xho1 + 1
		xho2 = xho2 - 1
		if i != 12:
			part1.append(chr(xho1))
		part2.append(chr(xho2))
str = input()
for i in range(len(str)):
	if i == 0:
		anchor('a')
		if str[0] in part1:
			count += part1.index(str[0])
		else:
			count += part2.index(str[0])
		part1.clear()
		part2.clear()
	if i + 1 >= len(str):
		break
	anchor(str[i])
	if str[i + 1] in part1:
		count += part1.index(str[i + 1])
	else:
		count += part2.index(str[i + 1])
	part1.clear()
	part2.clear()
print(count)


alfa = '0abcdefghijklmnopqrstuvwxyz'
word = input()
wo = 'a' + word
hasil = 0
for i in range(len(wo) - 1):
	cl = abs(alfa.index(wo[i + 1]) - alfa.index(wo[i]))
	cc = 26 - cl
	hasil = hasil + min(cc, cl)
print(hasil)


alpha = [item for item in 'abcdefghijklmnopqrstuvwxyz']
string = input()
l = []
if abs(alpha.index(string[0]) - alpha.index('a')) <= 13:
	l.append(abs(alpha.index(string[0]) - alpha.index('a')))
elif abs(alpha.index(string[0]) - alpha.index('a')) > 13:
	l.append(26 - abs(alpha.index(string[0]) - alpha.index('a')))
for item in range(0, len(string) - 1):
	if abs(alpha.index(string[item + 1]) - alpha.index(string[item])) <= 13:
		l.append(abs(alpha.index(string[item + 1]) - alpha.index(string[item])))
	elif abs(alpha.index(string[item + 1]) - alpha.index(string[item])) > 13:
		l.append(26 - abs(alpha.index(string[item + 1]) - alpha.index(string[item])))
print(sum(l))


from sys import stdin
A = stdin.readline()
now = 97
sum = 0
for t in range(0, len(A) - 1):
	MAX = max(now, ord(A[t]))
	MIN = min(now, ord(A[t]))
	sum += min(MAX - MIN, MIN - MAX + 26)
	now = ord(A[t])
print(sum)


letters = 'abcdefghijklmnopqrstuvwxyz'
s = input()
prev = 0
output = 0
for i in s:
	actual = letters.index(i)
	rotations = abs(actual - prev)
	prev = actual
	if rotations > 13:
		output += 26 - rotations
	else:
		output += rotations
print(output)


def order(l, x):
	s1 = 'abcdefghijklmnopqrstuvwxyz'
	l1 = int(s1.index(l))
	l2 = abs(l1 - x)
	if l2 <= 13:
		return l2
	else:
		return 26 - l2
s = input()
count = 0
c_pos = 0
s_a = 'abcdefghijklmnopqrstuvwxyz'
for letter in s:
	count += order(letter, c_pos)
	c_pos = s_a.index(letter)
print(count)


def dystans(a, b):
	wynik = abs(ord(a) - ord(b))
	if wynik > 13:
		return 26 - wynik
	else:
		return wynik
n = input()
n = 'a' + n
suma = 0
for i in range(len(n) - 1):
	suma += dystans(n[i], n[i + 1])
print(suma)


total_count = 0
i = ord('a')
j = chr(i)
x = ord('a')
y = chr(x)
word = input()
for letter in word:
	count_for = 0
	count_back = 0
	while True:
		if letter == j:
			break
		if j == 'z':
			i = ord('a')
			j = chr(i)
			count_for = count_for + 1
			continue
		i = i + 1
		j = chr(i)
		count_for = count_for + 1
	while True:
		if letter == y:
			break
		if y == 'a':
			x = ord('z')
			y = chr(x)
			count_back = count_back + 1
			continue
		x = x - 1
		y = chr(x)
		count_back = count_back + 1
	if count_for <= count_back:
		total_count += count_for
	else:
		total_count += count_back
print(total_count)


n = input()
k = list(n)
initial = ord('a')
result = 0
for i in k:
	result += min(abs(ord(i) - initial), 26 - abs(ord(i) - initial))
	initial = ord(i)
print(result)


entrada = input('')
alfabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
indexCenter = 0
sumTotal = 0
for i in range(len(entrada)):
	letra = entrada[i]
	for j in range(0, 14):
		esquerda = indexCenter - j
		if esquerda < 0:
			esquerda = 26 - abs(esquerda)
		direita = indexCenter + j
		if alfabet[esquerda] == letra:
			indexCenter -= j
			indexCenter = indexCenter % 26
			sumTotal += j
			break
		if alfabet[direita % 26] == letra:
			indexCenter += j
			indexCenter = indexCenter % 26
			sumTotal += j
			break
print(sumTotal)


str = input()
res = 0
ch = 'a'
for x in str:
	d = abs(ord(x) - ord(ch))
	if d > 13:
		d = 26 - d
	res += d
	ch = x
print(res)


alp = '#abcdefghijklmnopqrstuvwxyz'
alp = list(alp)
s = input()
cnt = 0
for i in range(len(s) - 1):
	k1 = max(alp.index(s[i]), alp.index(s[i + 1])) - min(alp.index(s[i]), alp.index(s[i + 1]))
	k2 = max(alp.index(s[i]), alp.index(s[i + 1])) - (min(alp.index(s[i]), alp.index(s[i + 1])) + 26)
	cnt += min(abs(k1), abs(k2))
l1 = max(alp.index(s[0]), 1) - min(alp.index(s[0]), 1)
l2 = max(alp.index(s[0]), 1) - (min(alp.index(s[0]), 1) + 26)
cnt += min(abs(l1), abs(l2))
print(cnt)


x = input()
ans = 0
pointer = 'a'
for i in x:
	ans += min(abs(ord(pointer) - ord(i)), 26 - abs(ord(pointer) - ord(i)))
	pointer = i
print(ans)


name = list(input())
wheel = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
pos = 0
count = 0
middle = len(wheel) / 2
for i in range(len(name)):
	ind = wheel.index(name[i])
	if ind > pos:
		diff = ind - pos
		if diff < middle:
			count += diff
		else:
			count += len(wheel) - diff
	elif pos > ind:
		diff = pos - ind
		if diff < middle:
			count += diff
		else:
			count += len(wheel) - diff
	pos = ind
print(count)


string = 'a' + input()
temp = 0
for i in range(1, len(string)):
	temp1 = 26 - abs(ord(string[i]) - ord(string[i - 1]))
	temp += min(temp1, abs(ord(string[i]) - ord(string[i - 1])))
print(temp)


d = {}
from string import ascii_lowercase
a = ascii_lowercase
for i in range(1, 27):
	d[a[i - 1]] = i
s = input()
ds = len(s)
e = 1
r = 0
for i in range(ds):
	r += min(abs(e - d[s[i]]), abs(abs(e - d[s[i]]) - 26))
	e = d[s[i]]
print(r)


import string
n = input()
arr = [None] + list(string.ascii_lowercase)
current = 'a'
count = 0
for i in n:
	count += min((arr.index(i) - arr.index(current)) % 26, (arr.index(current) - arr.index(i)) % 26)
	current = i
print(count)


s = input()
c_p = 'a'
steps = 0
for i in s:
	gap = abs(ord(c_p) - ord(i))
	if gap <= 13:
		steps += gap
		c_p = i
	if gap > 13:
		steps += abs(gap - 26)
		c_p = i
print(steps)


name = input()
total = 0
prev = 'a'
for i in range(len(name)):
	leftWheel = abs(ord(prev) - ord(name[i]))
	total += min(leftWheel, 26 - leftWheel)
	prev = name[i]
print(total)


s = [1]
ss = [ord(n) - 96 for n in input()]
l = 0
s = s + ss
for n in range(1, len(s)):
	d = abs(s[n] - s[n - 1])
	l += 13 - abs(13 - d)
print(l)


s = input()
li = list(s)
s1 = 'abcdefghijklmnopqrstuvwxyz'
li2 = list(s1)
pos = 0
count = 0
for ch in li:
	ind = li2.index(ch)
	if pos != ind:
		if abs(pos - ind) > 13:
			count += 26 - abs(pos - ind)
		else:
			count += abs(pos - ind)
		pos = ind
if count > 0:
	print(count)
else:
	print(count)


str = input()
g = 0
cur = 1
for i in str:
	j = ord(i) - 96
	clock = abs(cur - j)
	anticlock = abs(26 - clock)
	g = g + min(clock, anticlock)
	cur = j
print(g)


s = input().strip()
total = 0
cur = 'a'
for c in s:
	total += min(abs(ord(c) - ord(cur)), 26 - abs(ord(c) - ord(cur)))
	cur = c
print(total)


s = input()
total = 0
curl = 'a'
for i in s:
	m = min(abs(ord(i) - ord(curl)), 26 - abs(ord(i) - ord(curl)))
	total += m
	curl = i
print(total)


s = input()
prev = ord('a')
d = 0
for i in s:
	c1 = abs(prev - ord(i))
	c2 = abs(26 - c1)
	d = d + min(c1, c2)
	prev = ord(i)
print(d)


b = list(map(str, input().lower().strip()))
x = 0
y = 0
for i in range(len(b)):
	a = ord(b[i]) - 97
	c = abs(y - a)
	if c < 13:
		x = x + c
	else:
		x = x + 26 - c
	y = a
print(x)


g = input()
count = 0
g = 'a' + g
for i in range(len(g) - 1):
	if abs(ord(g[i]) - ord(g[i + 1])) <= 13:
		rot = abs(ord(g[i]) - ord(g[i + 1]))
	else:
		rot = 26 - abs(ord(g[i]) - ord(g[i + 1]))
	count = count + rot
print(count)


s = input()
m = 0
curr = 0
for i in s:
	d = ord(i) - 97
	m += min((d - curr) % 26, (curr - d) % 26)
	curr = d
print(m)


import string

def main():
	alph = string.ascii_lowercase
	l = len(alph)
	suka = input()
	(i, ans) = (0, 0)
	for c in suka:
		ci = alph.index(c)
		ans += min(abs(max(ci, i) - min(ci, i)), abs(min(ci, i) + l - max(ci, i)))
		i = ci
	return ans
print(main())


s = input()
last = 0
k = 0
for i in s:
	xi = ord(i) % 97
	if abs(xi - last) <= 13:
		k += abs(xi - last)
	elif xi > last:
		k += last + 26 - xi
	else:
		k += xi + 26 - last
	last = xi
print(k)


word = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
summ = 0
start = 'a'
for c in word:
	indexStart = alphabet.index(start)
	indexC = alphabet.index(c)
	maxx = max(indexStart, indexC)
	minn = min(indexStart, indexC)
	dist1 = maxx - minn
	dist2 = 25 - maxx + minn + 1
	summ += min(dist1, dist2)
	start = c
print(summ)


st = input()
c = 0
current = 97
for i in st:
	if abs(ord(i) - current) <= 26 - abs(ord(i) - current):
		c += abs(current - ord(i))
	else:
		c += 26 - abs(ord(i) - current)
	current = ord(i)
print(c)


import string
s = input()
j = []
l = []
k = 0
for i in enumerate(string.ascii_lowercase):
	j.append(i[1])
ini = 'a'
for i in range(len(s)):
	t = j.index(s[i]) - j.index(ini)
	k += min(abs(t), abs(26 - abs(t)))
	ini = s[i]
print(k)


from sys import stdin
import string
s = 'a' + stdin.readline().strip()

def solution(word):
	sum = 0
	alpha = list(string.ascii_lowercase)
	for (i, c) in enumerate(word):
		if i == len(s) - 1:
			return sum
		f = abs(alpha.index(word[i]) - alpha.index(word[i + 1]))
		b = 26 - f
		if f > b:
			sum += b
		else:
			sum += f
	return sum
print(solution(s))


a = input()
pos = 'a'
sum = 0
for i in a:
	if abs(ord(pos) - ord(i)) > 26 - abs(ord(pos) - ord(i)):
		sum += 26 - abs(ord(pos) - ord(i))
		pos = i
	else:
		sum += abs(ord(pos) - ord(i))
		pos = i
print(sum)


def main():
	word = input()
	position = int(ord('a'))
	count = 0
	for i in word:
		steps = abs(int(ord(i)) - position)
		if steps > 13:
			steps = 26 - steps
		count += steps
		position = int(ord(i))
	print(count)
main()


s = input()
res = 0
flag = 97
for i in s:
	diff = abs(flag - ord(i))
	if diff > 13:
		diff = 26 - diff
	res += diff
	flag = ord(i)
print(res)


s = input()
alf = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
alf = alf.split()
index = {}
for i in alf:
	index.setdefault(i, ord(i) - 97)
pointer = 0
summ = 0
s = s.lower()
for i in s:
	new_pos = index[i]
	d = min((pointer - new_pos + 26) % 26, (new_pos - pointer + 26) % 26)
	summ = summ + d
	pointer = new_pos
print(summ)


string = input()
su = min(ord(string[0]) - 97 - 0, 26 - ord(string[0]) + 97 - 0)
for i in range(1, len(string)):
	if string[i - 1] > string[i]:
		su += min(abs(ord(string[i]) - 97 - (ord(string[i - 1]) - 97)), abs(26 + (ord(string[i]) - 97) - (ord(string[i - 1]) - 97)))
	else:
		su += min(abs(ord(string[i]) - 97 - (ord(string[i - 1]) - 97)), abs(26 - (ord(string[i]) - 97) + (ord(string[i - 1]) - 97)))
print(su)


word = input()
n = 0
s = 0
for letter in word:
	m = ord(letter) - 97
	s += min(abs(n - m), 26 - abs(n - m))
	n = m
print(s)


Alphabet = 'abcdefghijklmnopqrstuvwxyz'
S = input()
output = 0
for i in range(len(S)):
	for j in range(len(Alphabet)):
		if S[i] == Alphabet[j]:
			Alphabet = Alphabet[j:] + Alphabet[:j]
			if j <= 13:
				output += j
			else:
				output += 26 - j
print(output)


s = input()
ans = 0
i = 'a'
for c in s:
	l = abs(ord(c) - ord(i))
	ans = ans + min(l, 26 - l)
	i = c
print(ans)


string = input()
answer = 0
state = 'a'
for i in string:
	answer += min(26 - (max(ord(i), ord(state)) - min(ord(i), ord(state))), max(ord(i), ord(state)) - min(ord(i), ord(state)))
	state = i
print(answer)


n = str(input())
h = 0
for (i, s) in enumerate(n):
	if i == 0:
		k = min(abs(ord(s) - ord('a')), abs(abs(ord(s) - ord('a')) - 26))
		h += k
	else:
		k = min(abs(ord(s) - ord(n[i - 1])), abs(abs(ord(s) - ord(n[i - 1])) - 26))
		h += k
print(h)


import string
alpha = string.ascii_lowercase

def moves(name):
	current = alpha[0]
	counter = 0
	for i in name:
		distance = abs(alpha.index(i) - alpha.index(current))
		back_distance = 26 - distance
		minimum = min(distance, back_distance)
		counter += minimum
		current = i
	return counter
inp = input()
print(moves(inp))


def minMoves(x, c):
	t = min(abs(ord(x) - ord(c)), abs(26 + ord(x) - ord(c)), abs(26 + ord(c) - ord(x)))
	return t
s = input()
currentChar = 'a'
x = 0
for i in s:
	x += minMoves(currentChar, i)
	currentChar = i
print(x)


from sys import stdin
s = input().rstrip()
count = 0
pos = 'a'
for i in s:
	count += min((ord(i) - ord(pos)) % 26, (ord(pos) - ord(i)) % 26)
	pos = i
print(count)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
name = list(get_string())
alpha = list('abcdefghijklmnopqrstuvwxyz')
pointer = 0
total = 0
for ele in name:
	index = alpha.index(ele)
	clock = abs(pointer - index)
	anticlock = abs(26 - clock)
	rotation = min(clock, anticlock)
	total += rotation
	pointer = index
print(total)


z = 0
x = 97
s = input()
for i in s:
	if ord(i) < x:
		if x - ord(i) > 13:
			n = ord(i) + 26
			z = z + n - x
		else:
			z = z + x - ord(i)
	elif x < ord(i):
		if ord(i) - x > 13:
			x = x + 26
			z = z + x - ord(i)
		else:
			z = z + ord(i) - x
	x = ord(i)
print(z)


name = input()
current_position = 0
rotation = 0
for i in name:
	index = ord(i) - 97
	walk = abs(current_position - index)
	if walk > 13:
		rotation += 26 - walk
	else:
		rotation += walk
	current_position = index
print(rotation)


def getMinNumOfRotation(itemName):
	rotationCount = 0
	cp = 97
	for i in range(0, len(itemName)):
		np = ord(itemName[i])
		clockWise = np
		cr = acr = 0
		if np > cp and np <= 122:
			cr = np - cp
		if np < cp:
			cr = 122 - cp + 1 + np - 97
		if np < cp and np >= 97:
			acr = cp - np
		if np > cp:
			acr = 122 - np + 1 + cp - 97
		cp = np
		rotationCount += min(cr, acr)
	return rotationCount

def main():
	print(getMinNumOfRotation(input()))
main()


p = input()
q = 0
for i in range(len(p)):
	if i == 0:
		q += min(123 - ord(p[i]), ord(p[i]) - 97)
	else:
		t = abs(ord(p[i - 1]) - ord(p[i]))
		t1 = 26 - t
		q += min(t, t1)
print(q)


from string import ascii_lowercase as alphabet
a = input()

def dist(x, y):
	(x, y) = (alphabet.index(x), alphabet.index(y))
	d = abs(x - y)
	return min([26 - d, d])
b = 0
t = 'a'
for i in a:
	b += dist(t, i)
	t = i
print(b)


def split(w):
	return [_ for _ in w]
List = split(input())
Num_list = []
alphabet = split('abcdefghijklmnopqrstuvwxyz')
i = 0
for j in List:
	while alphabet[i] != j:
		i += 1
	Num_list.append(i)
	i = 0
S = min(Num_list[0], 26 - Num_list[0])
for i in range(0, len(List) - 1):
	u = abs(Num_list[i + 1] - Num_list[i])
	S += min(u, 26 - u)
print(S)


ch = input()
ch2 = 'a' + ch
s = 0
i = 0
while i < len(ch2) - 1:
	s = s + min(abs(ord(ch2[i + 1]) - ord(ch2[i])), abs(26 - abs(ord(ch2[i + 1]) - ord(ch2[i]))))
	i = i + 1
print(f'{s}')


s = input()
d = {}
c = 1
l = 'abcdefghijklmnopqrstuvwxyz'
for i in l:
	d[i] = c
	c = c + 1
p = 'a'
c = 0
for i in s:
	c = c + min(abs(d[i] - d[p]), abs(d[i] - d[p] + 26), abs(d[i] - d[p] - 26))
	p = i
print(c)


s = input()
prev = 'a'
res = 0
for i in s:
	res += min((ord(prev) - ord(i) + 26) % 26, (ord(i) - ord(prev) + 26) % 26)
	prev = i
print(res)


(a, c, d) = (0, 'a', input())
for b in d:
	f = abs(ord(c) - ord(b))
	if f > 13:
		f = abs(f - 26)
	(c, a) = (b, a + f)
print(a)


str = input()
temp = 97
out = []
for ch in str:
	if abs(temp - ord(ch)) < 13:
		out.append(abs(temp - ord(ch)))
	else:
		out.append(26 - abs(temp - ord(ch)))
	temp = ord(ch)
print(sum(out))


str = input()
ans = 0
cur = 'a'
for ch in str:
	sub = abs(ord(ch) - ord(cur))
	ans += min(sub, 26 - sub)
	cur = ch
print(ans)


n = input()
x = 'abcdefghijklmnopqrstuvwxyz'
counter = 0
for i in n:
	if x.find(i) > 13:
		neg = 26 - x.find(i)
		counter = counter + neg
		str1 = x[x.find(i):]
		str2 = x[:x.find(i)]
		x = str1 + str2
	else:
		counter = counter + x.find(i)
		str1 = x[x.find(i):]
		str2 = x[:x.find(i)]
		x = str1 + str2
print(int(counter))


a = 'a' + input()
z = 0
for i in range(1, len(a)):
	if abs(ord(a[i]) - ord(a[i - 1])) > 13:
		z += 26 - abs(ord(a[i]) - ord(a[i - 1]))
	else:
		z += abs(ord(a[i]) - ord(a[i - 1]))
print(z)


embosser = 'abcdefghijklmnopqrstuvwxyz'
exhibits = input()
rotations = 0
pointer = 0
x = 0
y = 0
for i in exhibits:
	x = abs(pointer - embosser.index(i))
	y = 26 - x
	rotations += min(x, y)
	pointer = embosser.index(i)
print(rotations)


l = list(input())
z = min(ord(l[0]) - ord('a'), 26 - (ord(l[0]) - ord('a')))
for _ in range(1, len(l)):
	z += min(abs(ord(l[_]) - ord(l[_ - 1])), 26 - abs(ord(l[_]) - ord(l[_ - 1])))
print(z)


str = input()
flag = 'a'
result = 0
for s in str:
	n1 = abs(ord(s) - ord(flag))
	n2 = 26 - n1
	flag = s
	result += min(n1, n2)
print(result)


import string

def calculate(input_str):
	alphabets = string.ascii_lowercase
	current_loc = 0
	count = 0
	for char in input_str:
		index = alphabets.index(char)
		walk = abs(current_loc - index)
		if walk < 13:
			count += walk
		else:
			count += abs(26 - walk)
		current_loc = index
	return count
input_str = input().replace('\n', '')
rotations = calculate(input_str)
print(rotations)


s = input()
k = 97
sum = 0
for i in range(len(s)):
	p = abs(ord(s[i]) - k)
	k = ord(s[i])
	if p > 13:
		sum += 26 - p
	else:
		sum += p
print(sum)


s = input()
prev = 'a'
score = 0
for ch in s:
	rot = ord(ch) - ord(prev)
	if rot < 0:
		rot = min(rot + 26, -rot)
	else:
		rot = min(rot, 26 - rot)
	score += rot
	prev = ch
print(score)


ms = 'abcdefghijklmnopqrstuvwxyz'
ds = input()
if ds[0] != 'a':
	ds = 'a' + ds
ans = 0
for i in range(1, len(ds)):
	s = abs(ms.index(ds[i]) - ms.index(ds[i - 1]))
	t = 26 - s
	ans += min(s, t)
print(ans)


alp = '0abcdefghijklmnopqrstuvwxyz'
point = 1
ans = 0
for i in input():
	ans += min(abs(alp.index(i) - point), 26 - abs(alp.index(i) - point))
	point = alp.index(i)
print(ans)


s = input()
clockwise_alphabets = [x for x in 'abcdefghijklmnopqrstuvwxyz']
x = 'a'
c = 0
for i in range(len(s)):
	f = clockwise_alphabets.index(x) + 1
	l = clockwise_alphabets.index(s[i]) + 1
	if f < l:
		k = l - f
	else:
		k = f - l
	c += min(k, 26 - k)
	x = s[i]
print(c)


s = input()
(moves, strt) = (0, 0)
for l in s:
	index = ord(l) - 97
	walk = abs(strt - index)
	if walk < 13:
		moves += walk
	else:
		moves += 26 - walk
	strt = index
print(moves)


def NightAtMuseum(word):
	word = list(map(ord, word))
	curChr = ord('a')
	totalMoves = 0
	for ch in word:
		inrDiff = abs(curChr - ch)
		if ch < curChr:
			outDiff = ch - 96 + 122 - curChr
		else:
			outDiff = curChr - 96 + 122 - ch
		totalMoves += inrDiff if inrDiff < outDiff else outDiff
		curChr = ch
	return totalMoves
inputStr = input()
if len(inputStr) == 0:
	print(0)
else:
	print(NightAtMuseum(inputStr))


def solve(stri):
	stri = 'a' + stri
	totalMoves = 0
	for i in range(1, len(stri)):
		prevChar = stri[i - 1]
		curChar = stri[i]
		forwardMove = abs(ord(prevChar) - ord(curChar))
		backwardMove = 26 - forwardMove
		totalMoves += min(forwardMove, backwardMove)
	return totalMoves
s = input()
print(solve(s))


data = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
str1 = input()
half = 13
wheel = 0
if abs(data['a'] - data[str1[0]]) > half:
	result = data['a'] + (26 - data[str1[0]])
	wheel += result
else:
	wheel += abs(data['a'] - data[str1[0]])
for i in range(len(str1) - 1):
	x = str1[i]
	y = str1[i + 1]
	if abs(data[x] - data[y]) > half:
		if x < y:
			result = data[x] + (26 - data[y])
			wheel += result
		else:
			result = data[y] + (26 - data[x])
			wheel += result
	else:
		wheel += abs(data[x] - data[y])
print(wheel)


import string

def main():
	word = input()
	wheel = string.ascii_lowercase
	total = 0
	current = 0
	for char in word:
		step = 0
		forward = current
		backward = current
		while (wheel[forward] != char) & (wheel[backward] != char) & (char != wheel[current]):
			backward = (backward - 1) % len(wheel)
			forward = (forward + 1) % len(wheel)
			step += 1
		total += step
		current = wheel.find(char)
	print(total)
main()


s = input()
diff = ord(s[0]) - ord('a')
moves = 0
for i in range(len(s)):
	if 0 <= abs(diff) < 13:
		moves += abs(diff)
	else:
		diff = abs(diff) - 26
		moves += abs(diff)
	try:
		diff = ord(s[i]) - ord(s[i + 1])
	except:
		break
print(moves)


s = input()
chars = 'abcdefghijklmnopqrstuvwxyz'
res = 0
pos = 'a'
for ch in s:
	a = chars.index(pos)
	b = chars.index(ch)
	res += min(abs(a - b), a + 26 - b, b + 26 - a)
	pos = ch
print(res)


s = input()
i = 0
mov = 0
for c in s:
	dst = ord(c) - ord('a')
	(l, r) = (0, 0)
	l = abs(dst - i)
	if i < dst:
		r = 26 - dst + i
	else:
		r = 26 - i + dst
	mov += min(l, r)
	i = dst
print(mov)


alpha = list('5abcdefghijklmnopqrstuvwxyz')
s = input()
zero = alpha.index(s[0])
rotations = min(zero - 1, 26 - (zero - 1))
for i in range(0, len(s) - 1):
	a = alpha.index(s[i])
	b = alpha.index(s[i + 1])
	rotations += min(abs(a - b), 26 - abs(a - b))
print(rotations)


s = input()
x = 'a'
ans = 0
for i in s:
	tmp = abs(ord(x) - ord(i))
	tmp = min(tmp, 1 + abs(ord('z') - ord(x)) + abs(ord('a') - ord(i)))
	tmp = min(tmp, 1 + abs(ord('a') - ord(x)) + abs(ord('z') - ord(i)))
	ans += tmp
	x = i
print(ans)


def findx(a, b):
	for i in range(0, 26):
		if (a + i) % 26 == b:
			return i
		elif (a - i) % 26 == b:
			return i
name = list(map(ord, input()))
name = list(map(lambda x: x - 97, name))
ans = 0
cur = 0
for i in range(len(name)):
	move = findx(cur, name[i])
	ans += move
	cur = name[i]
print(ans)


n = list(input())
n.insert(0, 'a')
i = 0
k = 0
while i < len(n) - 1:
	y = 0
	z = 0
	y = ord(n[i + 1]) - ord(n[i])
	z = 26 - abs(y)
	if abs(z) >= abs(y):
		k += abs(y)
	elif abs(y) > abs(z):
		k += abs(z)
	i += 1
print(k)


import string
s = input()
res = 0
current = 'a'
for i in s:
	if current < i:
		res += min(abs(ord(i) - 96 - (ord(current) - 96)), 26 + (ord(current) - 96) - (ord(i) - 96))
	else:
		res += min(abs(ord(i) - 96 - (ord(current) - 96)), 26 + (ord(i) - 96) - (ord(current) - 96))
	current = i
print(res)


s = input()
A = [1]
for i in s:
	A.append(ord(i) - 96)
Sum = 0
for j in range(0, len(A) - 1):
	if abs(A[j + 1] - A[j]) > 13:
		Sum = Sum + 26 - abs(A[j + 1] - A[j])
	else:
		Sum = Sum + abs(A[j + 1] - A[j])
print(Sum)


s = input()
minz = min(abs(ord('a') - ord(s[0])), abs(ord(s[0]) - ord('z')) + 1)
for i in range(len(s) - 1):
	minz += min(abs(ord(s[i + 1]) - ord(s[i])), abs(ord(s[i + 1]) - ord('z')) + abs(ord(s[i]) - ord('a')) + 1, abs(ord(s[i]) - ord('z')) + abs(ord(s[i + 1]) - ord('a')) + 1)
print(minz)


st = input()
current_index = 0
counter = 0
for i in st:
	next_index = ord(i) - 97
	if abs(current_index - next_index) <= 13:
		counter += abs(current_index - next_index)
	else:
		counter += 26 - abs(current_index - next_index)
	current_index = next_index
print(counter)


x = input()
rotation = 0
pointer = 97
for i in range(len(x)):
	difference = abs(pointer - ord(x[i]))
	if difference > 13:
		difference = 26 - difference
	rotation += difference
	pointer = ord(x[i])
print(rotation)


ans = 0
cur = 'a'
for c in input():
	diff = abs(ord(cur) - ord(c))
	cur = c
	ans += min(diff, 26 - diff)
print(ans)


t = 0
a = 97
s = input()
for i in s:
	b = abs(ord(i) - a)
	t += min(b, 26 - b)
	a = ord(i)
print(t)


def move():
	a = ['0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	arrow = a[1]
	l = []
	for i in word:
		letter = a.index(i)
		if letter - a.index(arrow) > 13:
			move = 26 - letter + a.index(arrow)
			arrow = i
			l.append(move)
		elif a.index(arrow) - letter > 13:
			move = 26 - a.index(arrow) + letter
			arrow = i
			l.append(move)
		elif a.index(arrow) - letter <= 13 and a.index(arrow) - letter > 0:
			move = a.index(arrow) - letter
			arrow = i
			l.append(move)
		elif a.index(arrow) == letter:
			move = 0
			l.append(move)
		else:
			move = letter - a.index(arrow)
			arrow = i
			l.append(move)
	print(sum(l))
word = str(input())
move()


from math import *

def dist(a, b):
	return min(int(fabs(ord(a) - ord(b))), int(ord('z') - fabs(ord(a) - ord(b)) - ord('a') + 1))
s = 'a' + input()
ans = 0
y = []
for i in range(1, len(s)):
	ans += dist(s[i], s[i - 1])
	y.append(dist(s[i], s[i - 1]))
print(ans)


__author__ = 'artyom'

def main():
	s = 'a' + read(0)
	c = 0
	for i in range(1, len(s)):
		d = abs(ord(s[i - 1]) - ord(s[i]))
		if d > 13:
			d = 26 - d
		c += d
	return c

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


s = input()
t = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
c = 'a'
n = len(s)
for i in range(n):
	if c == 'a' and s[i] == 'z':
		ans += 1
		c = 'z'
	else:
		d1 = abs(t.index(c) - t.index(s[i]))
		d2 = 0
		if t.index(c) < t.index('z') - t.index(c):
			d2 = t.index(c) + 1 + t.index('z') - t.index(s[i])
		else:
			d2 = t.index('z') - t.index(c) + 1 + t.index(s[i])
		ans += min(d1, d2)
		c = s[i]
print(ans)


def solve(test):
	s = input()
	t = 'a'
	ans = 0
	for c in s:
		ans += min(abs(ord(c) - ord(t)), 26 - abs(ord(c) - ord(t)))
		t = c
	print(ans)
t = 1
for _ in range(t):
	solve(_ + 1)


name = input()
ans = 0
p = 'a'
for i in name:
	ans += min(abs(ord(i) - ord(p)), 26 - abs(ord(i) - ord(p)))
	p = i
print(ans)


s = input()
ans = 0
prev = ord('a')
for i in range(len(s)):
	curr = ord(s[i])
	ans += min((prev - curr) % 26, (curr - prev) % 26)
	prev = curr
print(ans)


s = list(input())
s = ['a'] + s
rot = 0
for i in range(len(s) - 1):
	rot += min((ord(s[i]) - ord(s[i + 1])) % 26, (ord(s[i + 1]) - ord(s[i])) % 26)
print(rot)


_str = input()
now = 'a'
count = 0
for char in _str:
	x = max(ord(char), ord(now)) - min(ord(char), ord(now))
	y = 26 - x
	count += min(x, y)
	now = char
print(count)


ans = 0
cur = 0
for x in input():
	x = ord(x) - ord('a')
	ans += min(abs(x - cur), 26 - abs(x - cur))
	cur = x
print(ans)


word = input()
key = 0
result = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(word)):
	key2 = alphabet.find(word[i])
	a = abs(key2 - key)
	b = 26 - a
	result += min(a, b)
	key = key2
print(result)


list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
word = input()
ind = 0
k = 0
for i in word:
	right = abs(list1.index(i) - ind)
	left = 25 - right
	if right < left:
		k += right
		ind = list1.index(i)
	else:
		k += left + 1
		ind = list1.index(i)
print(k)


def shortest_path(a, b):
	clockwise = ord(a) - ord(b)
	anti_clockwise = 0
	if clockwise < 0:
		anti_clockwise = clockwise + 26
		clockwise = abs(clockwise)
	else:
		anti_clockwise = ord(b) - ord(a) + 26
	if clockwise <= anti_clockwise:
		return clockwise
	else:
		return anti_clockwise
string = input()
count = shortest_path('a', string[0])
for i in range(len(string) - 1):
	value = shortest_path(string[i], string[i + 1])
	count += value
print(count)


def solve():
	cost = 0
	last_ch = 97
	for ch in input():
		clock_wise = abs(ord(ch) - last_ch)
		cost += min(clock_wise, 26 - clock_wise)
		last_ch = ord(ch)
	print(cost)
solve()


letter = 'a'
s = 0
string = input()
for i in string:
	s += min(abs(ord(letter) - ord(i)), 26 - abs(ord(letter) - ord(i)))
	letter = i
print(str(s), end='')


ct = 0
tek = 'a'
s = input()
for i in s:
	ct += min(abs(ord(i) - ord(tek)), 26 - abs(ord(i) - ord(tek)))
	tek = i
print(ct)


list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
word = input()
num1 = 0
a = 0
for i in word:
	num2 = list.index(i)
	c = abs(num2 - num1)
	if c > 13:
		a += 26 - c
	else:
		a += c
	num1 = num2
print(a)


li = list(input())
n = len(li)
k = 'a'
i = 0
t = 0
count = 0
while i < n:
	t = abs(ord(k) - ord(li[i]))
	if t < 13:
		count = count + t
	else:
		count = count + abs(t - 26)
	k = li[i]
	i = i + 1
print(count)


a = input().strip()
x = 0
p = 'a'
for i in a:
	l = abs(ord(i) - ord(p))
	if not l:
		l += 26
	if l <= 26 // 2:
		x += l
		p = i
	else:
		x += 26 - l
		p = i
print(x)


strs = input()
curr = 'a'
k = 0
for i in range(len(strs)):
	diff = abs(ord(curr) - ord(strs[i]))
	k += min(diff, 26 - diff)
	curr = strs[i]
print(k)


s = 'a' + input()
dis = 0
for i in range(len(s) - 1):
	c = ord(s[i])
	n = ord(s[i + 1])
	dis += min(abs(c - n), 26 - abs(c - n))
print(dis)


import math
letters = list('abcdefghijklmnopqrstuvwxyz')
word = list(input())
word.insert(0, 'a')
count = 0

def min_r(lst, a, b):
	if lst.index(a) + 13 > lst.index(b):
		return abs(lst.index(a) - lst.index(b))
	else:
		return abs(lst.index(a) + len(lst) - lst.index(b))

def check(lst, a, b):
	return min([min_r(lst, a, b), min_r(lst, b, a)])
for i in range(1, len(word)):
	count += check(letters, word[i - 1], word[i])
print(count)


a = input()
sum = 0
t1 = 1
t = 0
l = len(a)
for i in range(l):
	t = ord(a[i]) - 96
	if t > t1:
		s = t - t1
		s1 = t1 - 0 + (26 - t)
	else:
		s = t1 - t
		s1 = t - 0 + (26 - t1)
	t1 = t
	if s >= s1:
		sum = sum + s1
	else:
		sum = sum + s
print(sum)


import math
z = input()
start = ord('a')
n = 0
for i in range(len(z)):
	a = math.fabs(start - int(ord(z[i])))
	if a > math.fabs(start - int(ord(z[i])) - 26):
		a = math.fabs(start - int(ord(z[i])) - 26)
	if a > math.fabs(start - int(ord(z[i])) + 26):
		a = math.fabs(start - int(ord(z[i])) + 26)
	start = ord(z[i])
	n = n + a
print(int(n))


from sys import stdin, stdout

def ri():
	return map(int, stdin.readline().split())
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
cur = 0
l = len(a)
for c in s:
	aa = abs(a.index(c) - cur)
	ans += min(l - aa, aa)
	cur = a.index(c)
print(ans)


s = input()
c = 0
a = 'a'
for i in s:
	s1 = abs(ord(i) - ord(a))
	s2 = 26 - s1
	a = i
	if s1 < s2:
		c += s1
	else:
		c += s2
print(c)


s = 'a'
s += input()
l = 'abcdefghijklmnopqrstuvwxyz'
ans = int(0)
for i in range(1, len(s), 1):
	ans += min(abs(l.index(s[i]) - l.index(s[i - 1])), 26 - abs(l.index(s[i]) - l.index(s[i - 1])))
print(ans)


alfabeto = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
palavra = input()
result = 0
inicial = 'a'
for letra in palavra:
	count1 = abs(alfabeto[inicial] - alfabeto[letra])
	count2 = 26 - count1
	if count1 <= count2:
		result += count1
	else:
		result += count2
	inicial = letra
print(result)


import string
import math
embosser = list(string.ascii_lowercase)
name = input()
name = 'a' + name
N = len(name)
E = len(embosser)
total = 0
i_start = 0
for k in range(N - 1):
	i_end = embosser.index(name[k + 1])
	total += min(abs(i_end - i_start), min(i_start, i_end) + E - max(i_start, i_end))
	i_start = i_end
print(total)


a = 'a'

def get(i):
	global a
	x = abs(ord(a) - ord(i))
	y = ord(a) - ord('a') + ord('z') - ord(i) + 1
	z = ord('z') - ord(a) + ord(i) - ord('a') + 1
	a = i
	return min(x, y, z)
s = input()
S = 0
for i in s:
	S += get(i)
print(S)


def calculate_rotations_number(string):
	string = 'a' + string
	total = 0
	for i in range(len(string) - 1):
		num = abs(ord(string[i + 1]) - ord(string[i]))
		if num < 13:
			total += num
		else:
			total += 26 - num
	return total
string = input()
print(calculate_rotations_number(string))


alphabet = 'abcdefghijklmnopqrstuvwxyz'
a = input()
old = 'a'
summary = 0
for i in range(len(a)):
	b = a[i]
	old_cordinates = alphabet.find(old)
	b_cordinates = alphabet.find(b)
	result = abs(b_cordinates - old_cordinates)
	result2 = 26 - result
	now = min(result, result2)
	summary += now
	old = b
print(summary)


e = 'abcdefghijklmnopqrstuvwxyz'
p = 1
c = 0
s = input()
for i in s:
	t = e.index(i) + 1
	c += min(abs(p - t), 26 - abs(p - t))
	p = t
print(c)


n = input().split()[0]
x = 'a'
m = 0
for i in range(0, len(n)):
	m += min(abs(ord(x) - ord(n[i])), 26 - abs(ord(x) - ord(n[i])))
	x = n[i]
print(m)


s = 'a' + input()
(x, y, z) = (0, 1, 0)
while y < len(s):
	if abs(ord(s[x]) % 26 - ord(s[y]) % 26) > 13:
		z += 26 - abs(ord(s[x]) % 26 - ord(s[y]) % 26)
	else:
		z += abs(ord(s[x]) % 26 - ord(s[y]) % 26)
	x += 1
	y += 1
print(z)


name = str(input())
start = 'a'
total = 0
for i in name:
	move = min(abs(ord(start) - ord(i)), abs(26 - abs(ord(start) - ord(i))))
	total += int(move)
	start = i
print(total)


alpha = 'abcdefghijklmnopqrstuvwxyz'
s = input()
i = 0
answer = 0
for char in s:
	i1 = alpha.index(char)
	dist = abs(i1 - i)
	answer += min(dist, 26 - dist)
	i = i1
print(answer)


inp = input()
cur = 'a'
out = 0
for i in inp:
	out += min(abs(ord(i) - ord(cur)), 26 - abs(ord(i) - ord(cur)))
	cur = i
print(out)


s = input()
new = 'a' + s
moves = 0
v = 97
for item in new:
	z = abs(int(ord(item)) - v)
	if z <= 13:
		moves = moves + z
	else:
		z = abs(z - 26)
		moves = moves + z
	v = int(ord(item))
print(moves)


my_text = [x for x in input()]
target_position = 0
pointer = 0
total = 0
for i in range(len(my_text)):
	target_position = ord(my_text[i]) - 97
	uzunluk = 0
	if pointer < target_position:
		uzunluk = min(target_position - pointer, 26 - target_position + pointer)
	else:
		uzunluk = min(pointer - target_position, 26 - pointer + target_position)
	total += uzunluk
	pointer = target_position
print(total)


s = input()
sum = 0
for i in range(len(s)):
	if i == 0:
		diff = abs(ord(s[i]) - ord('a'))
	else:
		diff = abs(ord(s[i]) - ord(s[i - 1]))
	if diff > 13:
		sum += 26 - diff
	else:
		sum += diff
print(sum)


letter = list(input())
letter = ['a'] + letter
rot = 0
for i in range(len(letter) - 1):
	rot = rot + min(max(ord(letter[i]), ord(letter[i + 1])) - min(ord(letter[i]), ord(letter[i + 1])), min(ord(letter[i]), ord(letter[i + 1])) - max(ord(letter[i]), ord(letter[i + 1])) + 26)
print(rot)


import logging
import copy
import sys
import math
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def solve(word):
	start = 'a'
	s = 0
	for w in word:
		candi = [ord(w) - ord(start), ord(start) - ord(w)]
		for i in range(2):
			if candi[i] < 0:
				candi[i] += 26
		s += min(candi)
		start = w
	return s

def main():
	print(solve(input()))

def log(*message):
	logging.debug(message)
main()


str1 = input()
pos = ord('a') & 31
count = 0
for x in str1:
	a = ord(x) & 31
	if max(a, pos) - min(a, pos) > 26 - max(a, pos) + min(a, pos):
		count += 26 - max(a, pos) + min(a, pos)
		pos = a
	else:
		count += max(a, pos) - min(a, pos)
		pos = a
print(count)


s = input()
res = 0
cur = 'a'
for char in s:
	temp = ord(cur) - ord(char)
	if temp < -13:
		res += temp + 26
	elif temp > 13:
		res += 26 - temp
	elif -14 < temp < 0:
		res += abs(temp)
	else:
		res += temp
	cur = char
print(res)


def getRotations(s: str) -> int:
	(count, ic) = (0, 'a')
	for c in s:
		f = ord(ic) - ord('a') + 1 - (ord(c) - ord('a') + 27) if ord(ic) > ord(c) else ord(ic) - ord('a') + 27 - (ord(c) - ord('a') + 1)
		s = ord(c) - ord('a') + 1 - (ord(ic) - ord('a') + 1)
		count += min(abs(f), abs(s))
		ic = c
	return count
string = input().strip()
print(getRotations(string))


n = input()
s = 0
sm = 0
for i in range(len(n)):
	m = ord(n[i]) - 97
	walk = abs(s - (ord(n[i]) - 97))
	if walk < 13:
		sm += walk
	else:
		sm += 26 - walk
	s = m
print(sm)


import sys
sys.setrecursionlimit(100000)
INF = int(10000000.0 + 1)
MAX = 105

def main():
	s = input()
	pre = 'a'
	res = 0
	for ch in s:
		if ord(ch) > ord(pre):
			(maxi, mini) = (ord(ch), ord(pre))
		else:
			(maxi, mini) = (ord(pre), ord(ch))
		add = min(maxi - mini, ord('z') - maxi + mini - ord('a') + 1)
		res += add
		pre = ch
	print(res)
main()


tape = input()
ini = 'a'
steps = 0
for letter in tape:
	d = abs(ord(letter) - ord(ini))
	steps += min(d, 26 - d)
	ini = letter
print(steps)


def number(i):
	return ord(i) - 96

def f(i, j):
	score = abs(j - i)
	if score > 13:
		score = 26 - score
	return score
total = 0
s = input()
s = 'a' + s
nums = [number(l) for l in s]
for (i, j) in zip(nums, nums[1:]):
	total += f(i, j)
print(total)


s = input()
d = 'a'
ans = 0
for i in s:
	if ord(d) <= ord('n'):
		tmp1 = abs(ord(d) - ord(i))
		tmp2 = abs(ord('z') - ord(i)) + 1 + abs(ord(d) - ord('a'))
		if tmp1 < tmp2:
			ans += tmp1
		else:
			ans += tmp2
	else:
		tmp1 = abs(ord(d) - ord(i))
		tmp2 = abs(ord(d) - ord('z')) + 1 + abs(ord('a') - ord(i))
		if tmp1 < tmp2:
			ans += tmp1
		else:
			ans += tmp2
	d = i
print(ans)


s = input()
strt = 0
moves = 0
for i in range(len(s)):
	index = ord(s[i]) - 97
	ind = abs(strt - index)
	if ind < 13:
		moves += ind
	else:
		moves += 26 - ind
	strt = index
print(moves)


c = 97
d = 0
for i in map(ord, input()):
	e = abs(c - i)
	d += min(e, 26 - e)
	c = i
print(d)


x = input()
rotations_count = 0
cur_position = ord('a')
for (i, next_chr) in enumerate(x):
	next_pos = ord(next_chr)
	straight = abs(next_pos - cur_position)
	left = cur_position - ord('a') + ord('z') - next_pos + 1
	right = ord('z') - cur_position + next_pos - ord('a') + 1
	rotations_count += min([straight, left, right])
	cur_position = next_pos
print(rotations_count)


s = input()
dis = abs(ord('a') - ord(s[0])) if abs(ord('a') - ord(s[0])) <= 13 else 26 - abs(ord('a') - ord(s[0]))
for i in range(len(s) - 1):
	mov = abs(ord(s[i]) - ord(s[i + 1]))
	dis += mov if mov <= 13 else 26 - mov
print(dis)


import string
tot = 0
listA = []
g = string.ascii_lowercase
for i in g:
	listA.append(i)
s = input('')
x = listA.index('a') + 1
y = listA.index(s[0]) + 1
tot += min(abs(x - y), 26 - abs(x - y))
for i in range(1, len(s)):
	x = listA.index(s[i - 1]) + 1
	y = listA.index(s[i]) + 1
	tot += min(abs(x - y), 26 - abs(x - y))
print(tot)


s = input()
first_char = 'a'
sum = 0
for i in s:
	d = abs(ord(i) - ord(first_char))
	sum += min(d, 26 - d)
	first_char = i
print(sum)


s = str(input())
j = min(26 - ord(s[0]) + 97, 26 + ord(s[0]) + 95, abs(ord(s[0]) - 97))
for _ in range(len(s) - 1):
	j += min(26 - (ord(s[_]) - 96) + (ord(s[_ + 1]) - 96), 26 - (ord(s[_ + 1]) - 96) + (ord(s[_]) - 96), abs(ord(s[_]) - ord(s[_ + 1])))
print(j)


s = str(input())
s = s.strip()
res = 0
aord = ord('a')
for i in range(len(s)):
	t = abs(ord(s[i]) - aord)
	aord = ord(s[i])
	res = res + min(t, 26 - t)
print(res)


text = input()
answer = 0
check = 'a'
for i in text:
	answer += min(abs(ord(i) - ord(check)), 26 - abs(ord(i) - ord(check)))
	check = i
print(answer)


import string
s = input()
lenn = len(s)
moves = 0
start = 0
for i in range(lenn):
	index = ord(s[i]) - 97
	walk = abs(start - index)
	if walk < 13:
		moves += walk
	else:
		moves += 26 - walk
	start = index
print(moves)


st = str(input())
cnt = 0
atm = 'a'
for i in range(len(st)):
	dist = abs(ord(st[i]) - ord(atm))
	cnt += min(dist, 26 - dist)
	atm = st[i]
print(cnt)


s = input()
now = ord('a')
ans = 0
for c in s:
	if ord(c) > now:
		ans += min(ord(c) - now, now + 26 - ord(c))
	else:
		ans += min(now - ord(c), 26 + ord(c) - now)
	now = ord(c)
print(ans)


keys = list('abcdefghijklmnopqrstuvwxyz')
values = [i for i in range(1, 27)]
a = dict(zip(keys, values))
x = list(input())
s = 1
count = 0
for i in range(len(x)):
	dis = abs(a[x[i]] - s)
	count += min(26 - dis, dis)
	s = a[x[i]]
print(count)


def NightAtTheMuseum():
	label = input().strip()
	current = ord('a')
	moves = 0
	for i in label:
		i = ord(i)
		right_shift = current - i
		left_shift = i - current
		if right_shift < 0:
			right_shift += 26
		if left_shift < 0:
			left_shift += 26
		moves += min(right_shift, left_shift)
		current = i
	return moves
a = NightAtTheMuseum()
print(a)


name = input()
count = 0
pointer = 'a'
for i in range(0, len(name)):
	distance = abs(ord(pointer) - ord(name[i]))
	if distance < 13:
		count += distance
	else:
		count += 26 - distance
	pointer = name[i]
print(count)


x = [1] + [ord(i) - 96 for i in input()]
print(sum([min((x[i] - x[i + 1]) % 26, (x[i + 1] - x[i]) % 26) for i in range(len(x) - 1)]))


while True:
	try:
		name = input()
		mov = 0
		c = 'a'
		for ch in name:
			mov += min(abs(ord(ch) - ord(c)), 26 - abs(ord(ch) - ord(c)))
			c = ch
		print(mov)
	except EOFError:
		break


def solve():
	s = input()
	prev = 0
	res = 0
	for c in s:
		now = ord(c) - ord('a')
		diff = abs(prev - now)
		diff = min(diff, 26 - diff)
		prev = now
		res += diff
	print(res)
solve()


s = 'a' + input()
r = 0
for i in range(1, len(s)):
	f = ord(s[i - 1]) - ord('a')
	t = ord(s[i]) - ord('a')
	if f > t:
		(f, t) = (t, f)
	r += min(t - f, f - t + 26)
print(r)


inStr = input()
EnglishLetters = 'abcdefghijklmnopqrstuvwxyz'
globalSteps = 0
currentPos = 0
for i in range(len(inStr)):
	forwardSteps = 0
	backwardSteps = 0
	backwardPos = currentPos
	while True:
		if EnglishLetters[currentPos] == inStr[i]:
			break
		forwardSteps += 1
		currentPos += 1
		if currentPos > 25:
			currentPos = 0
		if EnglishLetters[backwardPos] == inStr[i]:
			break
		backwardSteps += 1
		backwardPos -= 1
		if backwardPos < 0:
			currentPos2 = 25
	currentPos = EnglishLetters.find(inStr[i])
	globalSteps += min(forwardSteps, backwardSteps)
print(globalSteps)


import math
val = input()
answer = 0
ords = ord('a')
for i in val:
	min = int(math.fabs(ord(i) - ords))
	min2 = int(math.fabs(ord('z') - ord('a') - min)) + 1
	answer += min if min < min2 else min2
	ords = ord(i)
print(answer)


word = input()
count = 0
c = 97
for i in word:
	x = abs(ord(i) - c)
	if x < 26 - x:
		count += x
	else:
		count += 26 - x
	c = ord(i)
print(count)


s = 'abcdefghijklmnopqrstuvwxyz'
sr = input()
x = 0
sum1 = 0
for i in sr:
	like = min(abs(x - s.find(i)), len(s) - abs(x - s.find(i)))
	sum1 += like
	x = s.find(i)
print(sum1)


def get_min(i, j):
	return min(abs(i - j), 25 - max(i, j) + min(i, j) + 1)
d = {}
s = 'a'
for i in range(26):
	d[s] = i
	s = chr(ord(s) + 1)
l = input()
res = 0
res += get_min(d['a'], d[l[0]])
prev = l[0]
for i in range(1, len(l)):
	res += get_min(d[prev], d[l[i]])
	prev = l[i]
print(res)


import string
alphabet = string.ascii_lowercase
target = input()
result = 0
for c in target:
	if alphabet[0] != c:
		cur_id = 0
		(left, right) = (None, None)
		while c not in (left, right):
			cur_id += 1
			(left, right) = (alphabet[-cur_id], alphabet[cur_id])
		result += cur_id
		cur_id = -cur_id if c == left else cur_id
		alphabet = alphabet[cur_id:] + alphabet[:cur_id]
print(result)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet = list(alphabet)
word = list(input(''))
arrow = 'a'
sum = 0
for x in word:
	cw = abs(alphabet.index(arrow) + 1 - (alphabet.index(x) + 1))
	ccw = 26 - abs(alphabet.index(arrow) + 1 - (alphabet.index(x) + 1))
	if cw < ccw:
		sum += cw
	else:
		sum += ccw
	arrow = x
print(sum)


import string
alphabet = string.ascii_lowercase
i = 1
ans = 0
for x in input():
	t = alphabet.find(str(x))
	t += 1
	ans += min((i - t) % 26, (t - i) % 26)
	i = t
print(ans)


s = str(input())
clock = [chr(c) for c in range(97, 97 + 26)]
idx = 0
rotatinos = 0
for c in s:
	t1 = 0
	t2 = 0
	t = idx
	for i in range(idx, idx + 26):
		if clock[i % 26] == c:
			break
		t1 += 1
	for j in range(idx, idx - 26, -1):
		if abs(j) >= 26:
			j = j + 26
		if clock[j] == c:
			break
		t2 += 1
	idx = i % 26 if t1 < t2 else j
	rotatinos += min(t1, t2)
print(rotatinos)


string = input()
l = []
for i in string:
	l.append(ord(i))
if l[0] > 110:
	rot = 123 - l[0]
else:
	rot = l[0] - 97
for i in range(len(l) - 1):
	if abs(l[i] - l[i + 1]) > 13:
		rot += 26 - abs(l[i] - l[i + 1])
	else:
		rot += abs(l[i] - l[i + 1])
print(rot)


s = input()
alfavit = 'abcdefghijklmnopqrstuvwxyz'
t = 0
ans = 0
for i in range(len(s)):
	k = alfavit.find(s[i])
	d1 = abs(t - k)
	d2 = 26 - d1
	ans += min(d1, d2)
	t = k
print(ans)


dist = lambda s, f: min(abs(f - s), len(a) - abs(f - s))
name = list(input().strip())
a = 'abcdefghijklmnopqrstuvwxyz'
cur = 0
out = 0
for i in range(len(name)):
	out += dist(cur, a.index(name[i]))
	cur = a.index(name[i])
print(out)


import string
L = string.ascii_lowercase
d = {c: i for (i, c) in enumerate(L)}
s = 'a' + input().strip()
print(sum([min(abs(d[s[i]] - d[s[i + 1]]), 26 - abs(d[s[i]] - d[s[i + 1]])) for i in range(len(s) - 1)]))


a = input()
ded = 0
rota = 0
flag = 97
for i in a:
	ded = abs(flag - ord(i))
	if ded > 13:
		ded = 26 - ded
	rota += ded
	flag = ord(i)
print(rota)


(now, cnt) = (97, 0)
for i in input():
	x = abs(now - ord(i))
	cnt += min(x, 26 - x)
	now = ord(i)
print(cnt)


arr = list(map(str, input()))
arr.insert(0, 'a')
forward = 0
backward = 0
cnt = 0
for i in range(1, len(arr)):
	if ord(arr[i]) == ord(arr[i - 1]):
		continue
	if ord(arr[i]) > ord(arr[i - 1]) or ord(arr[i]) < ord(arr[i - 1]):
		forward = abs(ord(arr[i]) - ord(arr[i - 1]))
		backward = 26 - forward
	cnt += min(forward, backward)
print(cnt)


n = input()
n_lst = []
alphabet = []
i = 97
while i <= ord('z'):
	alphabet.append(chr(i))
	i += 1
for i in n:
	n_lst.append(i)
flag = 'a'
f = 0
cnt = 0
for i in n:
	cnt1 = 0
	j = ord(flag) - 97
	while alphabet[j] != i:
		j += 1
		cnt1 += 1
		if j > 25:
			j = 0
	cnt2 = 0
	j = ord(flag) - 97
	while alphabet[j] != i:
		j -= 1
		cnt2 += 1
		if j < -26:
			j = 0
	cnt += min(cnt1, cnt2)
	flag = i
print(cnt)


st = input()
letters = 'abcdefghijklmnopqrstuvwxyz'
answer = 0
posindex = 0
for ch in st:
	nextindex = letters.find(ch)
	answer += min(min(abs(nextindex - posindex), abs(nextindex + 26 - posindex)), abs(nextindex - 26 - posindex))
	posindex = nextindex
print(answer)


s = input()
p = 'a'
k = 0
for c in s:
	d = abs(ord(p) - ord(c))
	k += min(d, 26 - d)
	p = c
print(k)


def indx(s):
	return ord(s) - 97

def modd(s):
	if s < 0:
		s = s * -1
	return s
str = input()
(cur, ans) = (0, 0)
for i in range(len(str)):
	d = indx(str[i])
	diff = modd(cur - d)
	if diff > 13:
		ans = ans + (26 - diff)
	else:
		ans = ans + diff
	cur = d
print(ans)


s = input()
c = 'a'
r = 0
for i in s:
	if i > c:
		r += min(abs(ord(c) - ord(i)), abs(ord(i) - ord(c) - 26))
	else:
		r += min(abs(ord(i) - ord(c)), abs(ord(c) - ord(i) - 26))
	c = i
print(r)


from sys import stdin

def rotaciones(cad, lis):
	res = []
	inicio = abs(0 - lis.index(cad[0]))
	if inicio > 13:
		inicio = 13 - (inicio - 13)
	res.append(inicio)
	inicio = lis.index(cad[0])
	cad = cad[1:]
	if len(cad) > 0:
		for i in cad:
			r = abs(inicio - lis.index(i))
			if r > 13:
				r = 13 - (r - 13)
			res.append(r)
			inicio = lis.index(i)
			cad = cad[1:]
		return res
	return res

def main():
	Cadena = stdin.readline().strip()
	Lista_alf = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	res = rotaciones(Cadena, Lista_alf)
	print(sum(res))
main()


b = input()
s = 'a'
f = 0
a = 'abcdefghijklmnopqrstuvwxyz'
for i in b:
	x = a.find(s)
	v = a.find(i)
	k = abs(x - v)
	j = 26 - k
	f += min(k, j)
	s = i
print(f)


s = list(input())
s = [ord(ss) - 97 for ss in s]
pointer = 0
rots = 0
for x in range(len(s)):
	if s[x] > 13:
		s[x] = s[x] - 26
for x in s:
	diff = abs(x - pointer)
	if diff > 13:
		diff = 26 - diff
	rots += diff
	pointer = x
print(rots)


import sys
from math import sqrt, floor
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def solve():
	s = list(map(ord, list(inp().strip())))
	t = 97
	sume = 0
	for i in s:
		sume += min(26 - abs(i - t), abs(i - t))
		t = i
	print(sume)
solve()


s = input()
a = 'a'
count = 0
for i in range(len(s)):
	if s[i] < a:
		b = ord(a) - ord(s[i])
		c = 26 - ord(a) + ord(s[i])
	else:
		b = ord(s[i]) - ord(a)
		c = 26 - ord(s[i]) + ord(a)
	if b < c:
		count += b
	else:
		count += c
	a = s[i]
print(count)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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

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

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
name = read_str()
last = 'a'
moves = 0
for x in name:
	distance = abs(ord(x) - ord(last))
	last = x
	moves += min(distance, 26 - distance)
print(moves)


exhibit_name = input()
rotation_count = 0
current_character = 'a'
for character in exhibit_name:
	distance = abs(ord(current_character) - ord(character))
	if distance < 13:
		rotation_count += distance
	else:
		rotation_count += 26 - distance
	current_character = character
print(rotation_count)


x = input()
strt = 0
walks = 0
z = 0
while z < len(x):
	ind = ord(x[z]) - ord('a')
	if abs(strt - ind) < 13:
		walks += abs(strt - ind)
	else:
		walks += 26 - abs(strt - ind)
	strt = ind
	z += 1
print(walks)


word = input()
prevChar = 'a'
spins = 0
for char in word:
	spin1 = abs(ord(char) - ord(prevChar))
	spin2 = 26 - spin1
	spins += min(spin1, spin2)
	prevChar = char
print(spins)


import string

def split(word):
	return [char for char in word]

def inverse_mapping(f):
	return f.__class__(map(reversed, f.items()))
letters = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
curr_letter = 1
word = input('')
word = split(word)
tot_rot = 0
for char in word:
	char_num = letters[char]
	dis = abs(curr_letter - char_num)
	if dis > 13:
		if char_num > 13:
			rot = 26 - char_num + curr_letter
		else:
			rot = 26 - curr_letter + char_num
		tot_rot = tot_rot + rot
		fin_num = curr_letter
	else:
		fin_num = curr_letter
		tot_rot = tot_rot + dis
		pass
	curr_letter = char_num
print(tot_rot)


array_1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
array_2 = input()
array_2 = 'a' + array_2
index1 = index2 = index3 = index4 = 0
t = 0
for i in range(len(array_2) - 1):
	index1 = array_1.index(array_2[i]) + 1
	index2 = array_1.index(array_2[i + 1]) + 1
	index3 = abs(index1 - index2)
	index4 = 26 - index3
	if index3 > index4:
		t += index4
	else:
		t += index3
print(t)


def distancia(a, b):
	return min(abs(numalphabet[alphabet.index(a)] - numalphabet[alphabet.index(b)]), abs(26 - abs(numalphabet[alphabet.index(a)] - numalphabet[alphabet.index(b)])))
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
numalphabet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0]
actual = 'a'
pasada = ''
suma = 0
palabra = str(input())
for k in range(0, len(palabra)):
	pasada = actual
	actual = palabra[k]
	suma += distancia(pasada, actual)
print(suma)


s = input()
pos = 1
ans = 0
for i in s:
	q = ord(i) - 96
	ans += min(abs(q - pos), 26 - abs(q - pos))
	pos = q
print(ans)


import sys

def main():
	stdin = sys.stdin.read()
	embosser_moves(stdin)

def embosser_moves(word):
	word = 'a' + word.strip()
	total = 0
	for ind in range(1, len(word)):
		diff = ord(word[ind - 1]) - ord(word[ind])
		if diff < 0:
			diff += 26
		if diff >= 13:
			diff = abs(26 - diff)
		total += diff
	print(total)
main()


import sys
n = input()
koor = 1
summa = 0
for i in n:
	if ord(i) - 96 == koor:
		summa += 0
	else:
		summa += min([abs(ord(i) - 96 - koor), 26 - abs(ord(i) - 96 - koor)])
		koor = ord(i) - 96
print(summa)


name = input()
p = steps = 0
for char in name:
	index = ord(char) - 97
	way = abs(p - index)
	if way < 13:
		steps += way
	else:
		steps += 26 - way
	p = index
print(steps)


s = input()
count = 0
y = abs(ord(s[0]) - ord('a'))
z = min(y, 26 - y)
for i in range(len(s) - 1):
	x = abs(ord(s[i]) - ord(s[i + 1]))
	count += min(x, 26 - x)
print(count + z)


import string
s = input()
now = 0
ans = 0
for c in s:
	next = ord(c) - ord('a')
	diff1 = (next - now) % 26
	diff2 = (now - next) % 26
	diff = min(diff1, diff2)
	ans += diff
	now = next
print(ans)


s = 'a' + input()

def diff(v1, v2):
	if v1 > v2:
		(v1, v2) = (v2, v1)
	return min(v2 - v1, v1 + 26 - v2)
print(sum([diff(ord(c1), ord(c2)) for (c1, c2) in zip(s, s[1:])]))


ans = 0
str = input()
c = 'a'
for i in str:
	num = abs(ord(i) - ord(c))
	ans += min(num, 26 - num)
	c = i
print(ans)


s = input()
a = 97
difference = 0
rotation = 0
for i in range(len(s)):
	difference = abs(a - ord(s[i]))
	if difference > 13:
		difference = 26 - difference
	rotation += difference
	a = ord(s[i])
print(rotation)


import math
word = input()
c = 0
letter = 'a'
for j in word:
	tmp = ord(j) - 97
	tmp1 = ord(letter) - 97
	s = min(max(tmp, tmp1) - min(tmp, tmp1), min(tmp1, tmp) + 26 - max(tmp, tmp1))
	c += s
	letter = j
print(int(math.fabs(c)))


try:
	s = input()
	l = ['xyz', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	ans = 0
	s = 'a' + s
	for A in range(0, len(s) - 1):
		ans1 = l.index(s[A])
		ans2 = l.index(s[A + 1])
		ans3 = abs(ans1 - ans2)
		ans += min(ans3, 26 - ans3)
	print(ans)
except:
	pass


c = 97
s = 0
word = input()
for x in word:
	i = abs(c - ord(x))
	s += min(i, 26 - i)
	c = ord(x)
print(s)


s = input()
ans = 0
cur = 'a'
for x in s:
	cw = (ord(x) - ord(cur) + 26) % 26
	ccw = (ord(cur) - ord(x) + 26) % 26
	ans += min(cw, ccw)
	cur = x
print(ans)


st = input().lower()
sol = min(abs(ord('a') - ord(st[0])), 26 - abs(ord('a') - ord(st[0])))
for i in range(len(st) - 1):
	sol += min(abs(ord(st[i]) - ord(st[i + 1])), 26 - abs(ord(st[i]) - ord(st[i + 1])))
print(sol)


s = input()
c = 'a'
sum = 0
for ch in s:
	if ch == c:
		continue
	else:
		sum += min(abs(ord(c) - ord(ch)), 26 - abs(ord(c) - ord(ch)))
		c = ch
print(sum)


s = 'abcdefghijklmnopqrstuvwxyz'
c = 0
p = 'a'
for k in input():
	c += min(abs(s.index(k) - s.index(p)), 26 - s.index(k) + s.index(p))
	p = k
	s = s[s.index(k):26] + s[0:s.index(k)]
print(c)


st = input()
pre = 'a'
rot = 0
for i in range(len(st)):
	diff = abs(ord(st[i]) - ord(pre))
	rot = rot + min(diff, 26 - diff)
	pre = st[i]
print(rot)


s = input()
import string
alpha = string.ascii_lowercase
cur = 0
summ = 0
for i in range(len(s)):
	fut = alpha.find(s[i])
	t = abs(fut - cur)
	pos = min(t, 26 - t)
	cur = fut
	summ += pos
print(summ)


import math

def encryption(s):
	s = s.replace(' ', '')
	tamanho = len(s)
	raiz = math.sqrt(tamanho)
	rows = math.floor(raiz)
	columns = math.ceil(raiz)
	matrizPalavras = []
	counter = 0
	sFinal = ''
	if rows * columns < tamanho:
		rows += 1
	for i in range(rows):
		sBuffer = ''
		for j in range(columns):
			if counter < len(s):
				sBuffer += s[counter]
			counter += 1
			if counter >= len(s):
				sBuffer += ' '
		matrizPalavras.append(sBuffer)
	for i in range(columns):
		sBuffer = ''
		for j in range(rows):
			if matrizPalavras[j][i] != ' ':
				sBuffer += matrizPalavras[j][i]
		sFinal += sBuffer + ' '
	return sFinal

def nightAtMuseum():
	alfabeto = ['o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
	rotacoes = 0
	ponteiroF = 12
	ponteiroA = 12
	string = input()
	for c in string:
		charPF = ''
		charPA = ''
		while charPF != c and charPA != c:
			if ponteiroF == len(alfabeto):
				ponteiroF = 0
			if ponteiroA == -1:
				ponteiroA = 25
			charPF = alfabeto[ponteiroF]
			charPA = alfabeto[ponteiroA]
			if charPF != c and charPA != c:
				ponteiroF += 1
				ponteiroA -= 1
				rotacoes += 1
		ponteiroA = alfabeto.index(c)
		ponteiroF = alfabeto.index(c)
	print(rotacoes)
nightAtMuseum()


import sys
line = sys.stdin.readline().strip()
total = 0
A = ord('a')
prev = 0
for char in line:
	curr = ord(char) - A
	if (prev - curr) % 26 < (curr - prev) % 26:
		total += (prev - curr) % 26
	else:
		total += (curr - prev) % 26
	prev = curr
print(total)


try:
	size = 26
	while True:
		s = list(input())
		rotations = 0
		src = 0
		for c in s:
			dest = ord(c) - 97
			if dest > src:
				clock = dest - src
				counterclock = src + (size - dest)
			elif dest < src:
				clock = dest + (26 - src)
				counterclock = src - dest
			else:
				clock = 0
				counterclock = 0
			src = dest
			steps = clock if clock < counterclock else counterclock
			rotations += steps
		print(rotations)
except EOFError:
	exit()


s = int()
ref_wheel = int(97)
for c in input():
	if ord(c) == ref_wheel:
		continue
	elif ord(c) < ref_wheel:
		s += min(ref_wheel - ord(c), ord(c) - 97 + (123 - ref_wheel))
		ref_wheel = ord(c)
		continue
	else:
		s += min(ord(c) - ref_wheel, ref_wheel - 97 + (123 - ord(c)))
		ref_wheel = ord(c)
		continue
print(s)


value = 97
count = 0
for i in map(ord, input()):
	c = abs(value - i)
	count += min(c, 26 - c)
	value = i
print(count)


total = 0
s = input()
start = 0
for i in range(len(s)):
	diff = abs(ord(s[i]) - 97 - start)
	if diff > 13:
		total += 26 - diff
	else:
		total += diff
	start = ord(s[i]) - 97
print(total)


s = input()
x = 'a'
sum = 0
for y in s:
	t = abs(ord(x) - ord(y))
	sum = sum + min(26 - t, t)
	x = y
print(sum)


import string
characters = string.ascii_lowercase
rank = {char: k for (k, char) in enumerate(characters)}
word = input()
current_char = 'a'
moves = 0
for char in word:
	moves += min(abs(rank[char] - rank[current_char]), 26 - abs(rank[char] - rank[current_char]))
	current_char = char
print(moves)


s = input()
rot = 0
prev = 'a'
for i in range(len(s)):
	tmp = abs(ord(s[i]) - ord(prev))
	prev = s[i]
	rot += min(abs(26 - tmp), tmp)
print(rot)


arr = []
st = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
	a = []
	for j in range(26):
		dif = ord(st[j]) - ord(st[i])
		if dif < 0:
			dif = 26 + dif
		a.append(dif)
	arr.append(a)

def countrotation(c1: chr, c2: chr):
	base = ord('a')
	n1 = ord(c1) - base
	n2 = ord(c2) - base
	return min(arr[n1][n2], arr[n2][n1])
givenstring = input()
total = countrotation('a', givenstring[0])
for i in range(len(givenstring) - 1):
	total += countrotation(givenstring[i], givenstring[i + 1])
print(total)


name = input()
rotations = 0
if ord(name[0]) - ord('a') <= 13:
	rotations = ord(name[0]) - ord('a')
else:
	rotations = 122 - ord(name[0]) + (ord('a') - 96)
for i in range(1, len(name)):
	if abs(ord(name[i]) - ord(name[i - 1])) <= 13:
		rotations += abs(ord(name[i - 1]) - ord(name[i]))
	elif ord(name[i]) > ord(name[i - 1]):
		rotations += 122 - ord(name[i]) + (ord(name[i - 1]) - 96)
	else:
		rotations += 122 - ord(name[i - 1]) + (ord(name[i]) - 96)
print(rotations)


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

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

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

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

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

def S():
	return input()

def main():
	l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	s = list(S())
	x = 'a'
	c = 0
	for a in s:
		sa = abs(l.index(x) - l.index(a))
		if sa < 14:
			c += sa
		else:
			c += 26 - sa
		x = a
	return c
print(main())


def count(i, g):
	cost = ord(g) - ord(i)
	if cost < 0:
		cost = 26 + cost
	if cost > 13:
		cost = 26 - cost
	return cost
s = input().strip()
i = 'a'
cnt = 0
for c in s:
	cnt += count(i, c)
	i = c
print(cnt)


word = input()
ascii = [0]
for w in word:
	for ch in w:
		ascii.append(ord(ch) - 97)
sum = 0
for i in range(1, len(ascii)):
	pos = (ascii[i] - ascii[i - 1]) % 26
	neg = (ascii[i - 1] - ascii[i]) % 26
	if pos > neg:
		sum += neg
	else:
		sum += pos
print(sum)


x = 97
cnt = 0
for i in map(ord, input()):
	tmp = abs(x - i)
	cnt += min(tmp, 26 - tmp)
	x = i
print(cnt)


import sys
n = input()
result = 0
prev = 'a'
for i in n:
	x = ord(i) - ord(prev)
	y = 26 + ord(prev) - ord(i)
	z = ord(i) - ord(prev) + 26
	result = result + min(abs(x), abs(y), abs(z))
	prev = i
print(result, end='')


l = list(input())
s = 0
for i in range(len(l)):
	if i == 0:
		a = abs(ord(l[i]) - ord('a'))
		if a < 13:
			s += a
		else:
			s += 26 - a
	else:
		a = abs(ord(l[i]) - ord(l[i - 1]))
		if a < 13:
			s += a
		else:
			s += 26 - a
print(s)


word = input()
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
count = 0
for x in range(len(word)):
	pos = letters.index(word[x])
	if x == 0:
		count += min(pos, 26 - pos)
	else:
		value = word[x - 1]
		pos2 = letters.index(value)
		difference = abs(pos - pos2)
		count += min(difference, 26 - difference)
print(count)


s = input()
print(sum([min(abs(ord(s[i + 1]) - ord(s[i])), 26 - abs(ord(s[i + 1]) - ord(s[i]))) for i in range(len(s) - 1)], min(abs(97 - ord(s[0])), 26 - abs(97 - ord(s[0])))))


s = input()
t1 = 97
c = 0
d = 0
for i in s:
	z = ord(i)
	d = abs(z - t1)
	if d > 13:
		d = 26 - d
	c = c + d
	t1 = z
print(c)


string_1 = input()
length = len(string_1)
distance = 0
for index in range(0, length):
	if index == 0:
		a = abs(ord(string_1[index]) - ord('a'))
		b = 26 - abs(ord(string_1[index]) - ord('a'))
	else:
		a = abs(ord(string_1[index]) - ord(string_1[index - 1]))
		b = 26 - abs(ord(string_1[index]) - ord(string_1[index - 1]))
	distance += min(a, b)
print(distance)


import string
mylist = list(string.ascii_lowercase)
mydict = {}

def mods(a):
	if a >= 0:
		return a
	else:
		return -a
b = 1
for j in mylist:
	mydict[j] = b
	b += 1
a = 0
prev = 1
mine = input()
for i in mine:
	c = mods(mydict[i] - prev)
	d = 26 - c
	a += min(c, d)
	prev = mydict[i]
print(a)


s = input()
c = 'a'
ans = 0
for i in s:
	ac = ord(c) - 97
	ai = ord(i) - 97
	ans += min(abs(ac - ai), abs(25 - max(ac, ai) + min(ac, ai) + 1))
	c = i
print(ans)


list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
name = input()
start = list.index('a')
final = 0
for i in name:
	count = 0
	end = list.index(i)
	if start > end:
		step = -1
	else:
		step = 1
	for i in list[start:end:step]:
		count += 1
	start = end
	if count > 13:
		count = 26 - count
	final = final + count
print(final)


total = 0
pointer = 'a'
for letter in input():
	dist = abs(ord(letter) - ord(pointer))
	total += min(dist, 26 - dist)
	pointer = letter
print(total)


word = input()
total = 0
curr = 97
for c in word:
	if ord(c) > curr:
		diff = ord(c) - curr
		if diff > 13:
			total += 26 - diff
		else:
			total += diff
	else:
		diff = curr - ord(c)
		if diff > 13:
			total += 26 - diff
		else:
			total += diff
	curr = ord(c)
print(total)


wheel = input()
pointer = 'a'
count = 0
for c in wheel:
	dist = abs(ord(pointer) - ord(c))
	if dist < 13:
		count = count + dist
	else:
		count = count + (26 - dist)
	pointer = c
print(count)


abc = 'abcdefghijklmnopqrstuvwxyz'
a = input()
c = abc[0]
res = 0
for i in a:
	b = abc.find(i)
	d = abc.find(c)
	x = abs(int(d) - int(b))
	y = 26 - x
	res += min(x, y)
	c = i
print(res)


s = input()
t = 'abcdefghijklmnopqrstuvwxyz'
c = 0 + min(t.index(s[0]), 26 - t.index(s[0]))
for i in range(1, len(s)):
	e = min(t.index(s[i - 1]), t.index(s[i]))
	f = max(t.index(s[i - 1]), t.index(s[i]))
	g = e + (26 - f)
	d = abs(t.index(s[i - 1]) - t.index(s[i]))
	c += min(d, g)
print(c)


import string
arr = [i for i in string.ascii_lowercase]
current = 'a'
s = str(input())
count = 0
for i in s:
	if i != current:
		lar = max(i, current)
		small = min(i, current)
		lar_index = arr.index(lar)
		small_index = arr.index(small)
		small = i if i < current else current
		count += min(lar_index - small_index, len(arr[:small_index]) + len(arr[lar_index:]))
		current = i
print(count)


g = input().strip()
bot = 'gey'
alphabet = 'abcdefghijklmnopqrstuvwxyz'
sum = 0
a = 0
for i in g:
	p = alphabet.find(i)
	if abs(p - a) < 26 - abs(p - a):
		sum += abs(p - a)
		a = p
	else:
		sum += 26 - abs(p - a)
		a = p
print(sum)


s = input()
if abs(ord(s[0]) - 97) < 13:
	counter = abs(ord(s[0]) - 97)
else:
	counter = 26 - abs(97 - ord(s[0]))
for i in range(1, len(s)):
	if abs(ord(s[i]) - ord(s[i - 1])) < 13:
		counter += abs(ord(s[i]) - ord(s[i - 1]))
	else:
		counter += 26 - abs(ord(s[i]) - ord(s[i - 1]))
print(counter)


name = input()
point = 0
turns = 0
for char in name:
	turns += min(abs(point - (ord(char) - ord('a'))), ord('z') - ord('a') + 1 - abs(point - (ord(char) - ord('a'))))
	point = ord(char) - ord('a')
print(turns)


str0 = input()
counter = 0
order = 97
for i in str0:
	if abs(ord(i) - order) < 13:
		counter += abs(ord(i) - order)
	else:
		counter += abs(abs(ord(i) - order) - 26)
	order = ord(i)
print(counter)


s = input()
res = 0
prev = ord('a')
for c in s:
	k = ord(c)
	res += min(abs(k - prev), abs(k - prev - 26), abs(k - prev + 26))
	prev = k
print(res)


string1 = 'abcdefghijklmnopqrstuvwxyz'
total = 0
summary = 0
previous = 0
current = 0
count = 0
s = input()
for x in s:
	summary = 0
	if count == 0:
		current = string1.index(x)
		if current <= 12:
			previous = current
			total += current
			count += 1
		else:
			previous = current
			total = abs(25 - current) + 1
			count += 1
	else:
		current = string1.index(x)
		summary = abs(current - previous)
		if summary <= 12:
			total += summary
			previous = current
		else:
			big = max(current, previous)
			small = min(current, previous)
			summary = abs(25 - big) + abs(0 - small) + 1
			total += summary
			previous = current
print(total)


import sys
s = 'a' + sys.stdin.readline().strip()
a = ord('a')
total = 0
for i in range(1, len(s)):
	clock = abs(ord(s[i]) - a - (ord(s[i - 1]) - a))
	new = min(clock, 26 - clock)
	total += new
print(total)


x = input()
k = 0
s = 0
t = ord('a')
for i in range(len(x)):
	if i == 0:
		if ord(x[i]) - ord('a') > 26 - ord(x[i]) + ord('a'):
			k = 26 - ord(x[i]) + ord('a')
		else:
			k = ord(x[i]) - ord('a')
	else:
		t = ord(x[i]) - ord(x[i - 1])
		if t < 0:
			t = ord(x[i - 1]) - ord(x[i])
		if t > 26 - t:
			k = 26 - t
		else:
			k = t
	s = s + k
print(s)


embosser = 'opqrstuvwxyzabcdefghijklmn'
input_str = list(input())
total = 0
start = embosser.find('a')
for ch in input_str:
	pos = abs(embosser.find(ch) - start)
	if pos > 12:
		pos = len(embosser) - pos
	total += pos
	start = embosser.find(ch)
print(total)


count = 0
beg = 'a'
st = input()
c = 0
for i in range(len(st)):
	c = abs(ord(beg) - ord(st[i]))
	count += min(c, 26 - c)
	beg = st[i]
print(count)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
A = [chr(ord('a') + i) for i in range(26)]

def step(pos, t):
	a = 0
	i = pos
	while A[i] != t:
		i = (i + 1) % 26
		a += 1
	b = 0
	i = pos
	while A[i] != t:
		i = (i - 1 + 26) % 26
		b += 1
	return min(a, b)
S = input()
ans = 0
pos = 0
for v in S:
	ans += step(pos, v)
	pos = A.index(v)
print(ans)


def od(x):
	return ord(x) - 96
answer = 0
s = input()
current = 1
for i in s:
	target = od(i)
	a = abs(current - target)
	if current > target:
		b = 26 - current + target
	else:
		b = 26 - target + current
	answer += min([a, b])
	current = target
print(answer)


(turns, current) = (0, 'a')
for next in input():
	d = abs(ord(current) - ord(next))
	(turns, current) = (turns + min(d, 26 - d), next)
print(turns)


s = input()
l = list(s)
sum = 0
for i in range(len(l)):
	if i == 0:
		c = 26 - (ord(l[i]) - ord('a'))
		c1 = abs(ord(l[i]) - ord('a'))
		if c > c1:
			sum += c1
		else:
			sum += c
	else:
		c = 26 - abs(ord(l[i]) - ord(l[i - 1]))
		c1 = abs(ord(l[i]) - ord(l[i - 1]))
		if c > c1:
			sum += c1
		else:
			sum += c
print(sum)


embosser = 'abcdefghijklmnopqrstuvwxyz'
pointer = 'a'
(counter, diff1, diff2) = (0, 0, 0)
inpt = input()
for x in inpt:
	diff1 = abs(embosser.index(x) - embosser.index(pointer))
	diff2 = 26 - diff1
	if diff1 > diff2:
		counter += diff2
	else:
		counter += diff1
	pointer = x
print(counter)


s = input()
s = list(s)
s.insert(0, 'a')
n = len(s)
step = 0
for i in range(n - 1):
	m = abs(ord(s[i]) - ord(s[i + 1]))
	if m > 13:
		step += 26 - m
	else:
		step += m
print(step)


name = input()
count = 0
pointer = 'a'
for ch in name:
	abs_distance = abs(ord(pointer) - ord(ch))
	count = count + min(abs_distance, 26 - abs_distance)
	pointer = ch
print(count)


from sys import stdin

def giros(cad):
	lista = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	con = 0
	pos1 = 0
	pos2 = 0
	for x in range(len(cad)):
		while lista[pos1] != cad[x] or lista[pos2] != cad[x]:
			if cad[x] == lista[pos1] or cad[x] == lista[pos2]:
				if cad[x] == lista[pos1]:
					pos2 = pos1
				else:
					pos1 = pos2
			else:
				pos1 += 1
				pos2 -= 1
				if pos1 > 25:
					pos1 = 0
				if pos2 < -25:
					pos2 = 0
				con += 1
	print(con)

def main():
	giros(stdin.readline().strip())
main()


import math
alp = [0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a = str(input())
ans = 0
c = [1]
for i in range(len(a)):
	for x in range(len(alp)):
		if a[i] == alp[x]:
			c.append(x)
for g in range(1, len(c)):
	if math.fabs(c[g] - c[g - 1]) > 13:
		ans += math.fabs(26 - math.fabs(c[g] - c[g - 1]))
	else:
		ans += math.fabs(c[g] - c[g - 1])
print(int(ans))


s = input()
a = ''.join([chr(i) for i in range(ord('a'), ord('z') + 1)])
if s[0] is not 'a':
	s = 'a' + s
sum = 0

def distance(len_string, l_1, l_2):
	i = (l_1 - l_2) % len_string
	j = (l_2 - l_1) % len_string
	return min(i, j)
for i in range(len(s) - 1):
	sum += distance(len(a), a.index(s[i]), a.index(s[i + 1]))
print(sum)


def move_char(ch1, ch2):
	num = abs(ord(ch1) - ord(ch2))
	return min(num, abs(26 - num))

def main():
	s = input()
	ans = move_char(s[0], 'a')
	if len(s) == 1:
		print(ans)
	else:
		for i in range(len(s) - 1):
			ans += move_char(s[i], s[i + 1])
		print(ans)
main()


string = input()
count = 0
pointer = 'a'
for i in string:
	j = abs(ord(i) - ord(pointer))
	if j > 13:
		j = 26 - j
	count += j
	pointer = i
print(count)


def solution(s):
	rotations = 0
	curr = 'a'
	for c in s:
		diff = abs(ord(c) - ord(curr))
		if diff > 13:
			rotations += 26 - diff
		else:
			rotations += diff
		curr = c
	return rotations
s = input()
print(solution(s))


a = list(map(ord, 'a' + input()))
s = 0
for i in range(1, len(a)):
	j = abs(a[i - 1] - a[i])
	s += min(j, 26 - j)
print(s)


arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
letter = 26

def func(start, end):
	a = abs(arr.index(end) - arr.index(start))
	b = abs(26 - a)
	return min(a, b)
string = str(input())
string = 'a' + string
sum = 0
for i in range(len(string) - 1):
	sum += func(string[i], string[i + 1])
print(sum)


word = list(input())
pointer = 'a'
counter = 0
for i in word:
	length1 = abs(ord(i) - ord(pointer))
	length2 = 26 - abs(length1)
	counter += min(length1, length2)
	pointer = i
print(counter)


res = idx = 0
d = 97
for s in input():
	des = ord(s) - d
	res += min((idx + 26 - des) % 26, (des - idx + 26) % 26)
	idx = des
print(res)


([string], count, ch) = (map(str, input().split()), 0, 'a')
for i in string:
	count += min(abs(ord(i) - ord(ch)), 26 - abs(ord(i) - ord(ch)))
	ch = i
print(count)


s = input()
l = 26
m = 'a'
k = 0
for i in s:
	k = k + min(abs(ord(m) - ord(i)), l - abs(ord(m) - ord(i)))
	m = i
print(k)


import math
a = input()
steps = 0
last = 0
for i in range(0, len(a)):
	c = a[i]
	char_a = 'a'
	c_num = ord(c) - ord('a')
	count1 = math.fabs(c_num - last)
	count2 = 26 - count1
	if count1 <= count2:
		steps += count1
	else:
		steps += count2
	last = c_num
print(int(steps))


import sys
line = sys.stdin.readline().replace('\n', '')
alphabet = {c: i for (i, c) in enumerate('abcdefghijklmnopqrstuvwxyz')}
total = 0
curr = 'a'
for char in list(line):
	if alphabet[curr] > alphabet[char]:
		total += min(alphabet[curr] - alphabet[char], alphabet[char] + len(alphabet) - alphabet[curr])
	else:
		total += min(alphabet[char] - alphabet[curr], alphabet[curr] + len(alphabet) - alphabet[char])
	curr = char
sys.stdout.write(str(total))


str = input()
st = 0
smoves = 0
for i in range(len(str)):
	index = ord(str[i]) - 97
	walk = abs(st - index)
	if walk > 13:
		smoves += 26 - walk
	else:
		smoves += walk
	st = index
print(smoves)


s = input()

def mind(a, b):
	if ord(b) < ord(a):
		(a, b) = (b, a)
	if ord(b) - ord(a) > 13:
		return 26 - (ord(b) - ord(a))
	else:
		return ord(b) - ord(a)
m = 0
s = 'a' + s
for i in range(1, len(s)):
	m += mind(s[i - 1], s[i])
print(m)


s = input()
currC = 'a'
ans = 0
for c in s:
	ans += min(abs(ord(currC) - ord(c)), 26 - abs(ord(currC) - ord(c)))
	currC = c
print(ans)


NUM_OF_ALPHABET = ord('z') - ord('a') + 1
s = input()
total = 0
cur = 'a'
for c in s:
	total += min((ord(cur) - ord(c) + NUM_OF_ALPHABET) % NUM_OF_ALPHABET, (ord(c) - ord(cur) + NUM_OF_ALPHABET) % NUM_OF_ALPHABET)
	cur = c
print(total)


alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s = input()
sum = 0
now = 0
for i in s:
	need = alph.index(i)
	if need > now:
		if now + 26 - need < need - now:
			sum += now + 26 - need
		else:
			sum += need - now
	elif 26 - now + need < now - need:
		sum += 26 - now + need
	else:
		sum += now - need
	now = need
print(sum)


import math
from collections import *
import sys
from functools import reduce

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

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
s = input()
pos = 'a'
ans = 0
for i in s:
	fir = ord(pos)
	sec = ord(i)
	diff = max(fir, sec) - min(fir, sec)
	ans += min(diff, 26 - diff)
	pos = i
print(ans)


n = list(input())
n.insert(0, '$#%@')
l = list((chr(x) for x in range(97, 123)))
s = 0
k = 'a'
for x in n[1:]:
	rot = abs(int(l.index(x) - l.index(k)))
	if rot <= 13:
		s = s + rot
		k = x
	elif rot > 0:
		z = 26 - rot
		s = s + z
		k = x
	else:
		z = 26 + rot
		s = s + z
		k = x
print(s)


word = str(input())
positions = []
current_position = 1
total_rotations = 0
for i in range(len(word)):
	letter_position1 = ord(word[i]) - 96
	if i > 0:
		letter_position2 = ord(word[i - 1]) - 96
	else:
		letter_position2 = 1
	forward = abs(letter_position1 - letter_position2)
	backward = 26 - abs(letter_position1 - letter_position2)
	total_rotations += min(forward, backward)
print(total_rotations)


pos = 'a'
cont = 0
n = input()
for letra in n:
	if (ord(pos) - ord(letra)) % 26 > (ord(letra) - ord(pos)) % 26:
		cont += (ord(letra) - ord(pos)) % 26
	else:
		cont += (ord(pos) - ord(letra)) % 26
	pos = letra
print(cont)


string = input()
curr = 97
total = 0
for i in string:
	curr_dist = abs(ord(i) - curr)
	if curr_dist > 13:
		curr_dist = 26 - curr_dist
	total += curr_dist
	curr = ord(i)
print(total)


s = input()
a = ord('a')
z = ord('z')
mark = z - a + 1
times = 0
now = ord('a')
for i in s:
	code = ord(i)
	times += min(abs(code - now), abs(now - code + z - 96 if code >= now else min(now - code, code - now + z - 96)))
	now = ord(i)
print(times)


s = input()
answer = 0
start = 'a'
for ch in s:
	answer += min(abs(ord(ch) - ord(start)), 26 - abs(ord(ch) - ord(start)))
	start = ch
print(answer)


word = input()
total = 0
index = ord('a')
for c in word:
	current = ord(c)
	d = abs(index - current)
	total += d if d < 13 else 26 - d
	index = current
print(total)


n = input()
d = abs(min(ord(n[0]) - 97, abs(26 - ord(n[0]) + 97)))
for i in range(1, len(n)):
	d = d + abs(min(abs(ord(n[i]) - ord(n[i - 1])), abs(26 - abs(ord(n[i]) - ord(n[i - 1])))))
print(d)


name = list(input())
for i in range(len(name)):
	name[i] = ord(name[i]) - 96
name = [1] + name
ct = 0
for i in range(len(name) - 1):
	a = name[i]
	b = name[i + 1]
	c = a
	ct1 = 0
	ct2 = 0
	while c != b:
		if c == 26:
			c = 1
		else:
			c += 1
		ct1 += 1
	c = a
	while c != b:
		if c == 1:
			c = 26
		else:
			c -= 1
		ct2 += 1
	ct += min(ct1, ct2)
print(ct)


s = input()
ini = 1
rotate = 0
for i in range(len(s)):
	num = (ord(s[i]) - 96) % 26
	if num == 0:
		num = 26
	diff = abs(num - ini)
	step1 = diff
	step2 = 26 - diff
	rotate += min(step1, step2)
	ini = num
print(rotate)


name = list(input())
name.insert(0, 'a')
n = len(name)
steps = 0
for i in range(1, n):
	distance = abs(ord(name[i]) - ord(name[i - 1]))
	steps += min(distance, 26 - distance)
print(steps)


import string
a = string.ascii_lowercase
r = input()

def embosser(start_l, end_l):
	bear = abs(a.index(start_l) - a.index(end_l))
	if bear > 13:
		return 26 - bear
	return bear
counter = 0
c = 'a'
for letter in r:
	counter += embosser(c, letter)
	c = letter
print(counter)


def move_chars1(force, alphabet):
	return alphabet[force:] + alphabet[:force]

def move_chars2(force, alphabet):
	return alphabet[len(alphabet) - force:] + alphabet[:len(alphabet) - force]

def calc_path1(letter, alphabet):
	count = 0
	for i in range(len(alphabet)):
		if alphabet[i] == letter:
			return count
		count += 1
	return 0

def calc_path2(letter, alphabet):
	count = 1
	for i in range(len(alphabet) - 1, -1, -1):
		if alphabet[i] == letter:
			return count
		count += 1
	return 0
exhibitName = input('')
alphabet = 'abcdefghijklmnopqrstuvwxyz'
path1 = path2 = 0
sum = 0
for letter in exhibitName:
	path1 = calc_path1(letter, alphabet)
	path2 = calc_path2(letter, alphabet)
	if path1 < path2:
		alphabet = move_chars1(path1, alphabet)
		sum += path1
	elif path1 > path2:
		alphabet = move_chars2(path2, alphabet)
		sum += path2
	else:
		alphabet = move_chars1(path1, alphabet)
		sum += path1
print(sum)


s = input()
pre = 'a'
ans = 0
for i in range(len(s)):
	time = ord(pre) - ord(s[i])
	if time < 0:
		time = -time
	if time > 12:
		ans += 26 - time
	else:
		ans += time
	pre = s[i]
print(ans)


al = 'qwertyuiopasdfghjklzxcvbnm'
alpha = [[ord(i) - ord('a'), -(26 - (ord(i) - ord('a')))] for i in al]
roll = {}
for i in range(26):
	roll[al[i]] = alpha[i]
temp = 'a'
ans = 0
for each in input():
	ans += min(abs(roll[temp][0] - roll[each][0]), abs(roll[temp][0] - roll[each][1]), abs(roll[temp][1] - roll[each][1]), abs(roll[temp][1] - roll[each][0]))
	temp = each
print(ans)


import math

def to_num(c):
	c = str(c)
	return ord(c) - 96
s = input()
a = [x for x in s]
pos = 'a'
res = 0
for x in a:
	var1 = abs(to_num(x) - to_num(pos))
	var2 = 26 - max(to_num(x), to_num(pos)) + min(to_num(x), to_num(pos))
	res += min(var1, var2)
	pos = x
print(res)


ch = input()
k = 0
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in ch:
	if l.index(i) < 13:
		k = k + l.index(i)
	else:
		k = k + len(l) - l.index(i)
	l = l[l.index(i):len(l)] + l[0:l.index(i)]
print(k)


str = input()
res = 0
lastSmb = 0
for smb in str:
	sid = ord(smb) - ord('a')
	diff = sid - lastSmb
	if diff < 0:
		diff = -diff
	if diff > 13:
		diff = 26 - diff
	res += diff
	lastSmb = sid
print(res)


ch1 = 'a'
ans = 0
s = input()
for ch2 in s:
	i = ch2
	if ch2 < ch1:
		(ch1, ch2) = (ch2, ch1)
	ans += min(ord(ch1) - ord('a') + 123 - ord(ch2), ord(ch2) - ord(ch1))
	ch1 = i
print(ans)


s = input()
cnt = 0
p = 97
for i in range(len(s)):
	if abs(p - ord(s[i])) <= 12:
		cnt += abs(p - ord(s[i]))
	else:
		cnt += 26 - abs(p - ord(s[i]))
	p = ord(s[i])
print(cnt)


x = [ord(c) for c in input()]
offset = ord('a')
steps = 0
for a in x:
	step = abs(offset - a)
	if step < 13:
		steps += step
	else:
		steps += 26 - step
	offset = a
print(steps)


s = input()
prsnt = 'a'

def forwardDiff(ch1, ch2):
	if ord(ch1) == ord(ch2):
		return 0
	if ord(ch2) > ord(ch1):
		return ord(ch2) - ord(ch1)
	return 122 - ord(ch1) + (ord(ch2) - 97) + 1

def backwardDiff(ch1, ch2):
	if ord(ch1) == ord(ch2):
		return 0
	if ord(ch2) < ord(ch1):
		return ord(ch1) - ord(ch2)
	return ord(ch1) - 97 + (122 - ord(ch2)) + 1
rotations = 0
for i in s:
	rotations += min(forwardDiff(prsnt, i), backwardDiff(prsnt, i))
	prsnt = i
print(rotations)


def clock_distance(string):
	distance = 0
	last_place = 0
	for letter in string:
		value = ord(letter) - 97
		normal_distance = abs(value - last_place)
		cross_distance = abs(last_place - value + 26) if value > last_place else abs(last_place - value - 26)
		distance += min(normal_distance, cross_distance)
		last_place = value
	return distance
print(clock_distance(input()))


s = input()
ip = 'a'
cnt = 0
for i in s:
	if abs(ord(ip) - ord(i)) > abs(26 - abs(ord(ip) - ord(i))):
		cnt = cnt + abs(26 - abs(ord(ip) - ord(i)))
	else:
		cnt = cnt + abs(ord(ip) - ord(i))
	ip = i
print(cnt)


st = list(input().strip())
amount = 0
curr = 'a'
for c in st:
	if abs(ord(c) - ord(curr)) > 13:
		amount += 26 - abs(ord(c) - ord(curr))
	else:
		amount += abs(ord(c) - ord(curr))
	curr = c
print(amount)


s = input()
n = len(s)
cnt = 0
for i in range(n):
	if i == 0:
		cnt += min(abs(97 - ord(s[i])), 26 - abs(97 - ord(s[i])))
	else:
		cnt += min(abs(ord(s[i - 1]) - ord(s[i])), 26 - abs(ord(s[i - 1]) - ord(s[i])))
print(cnt)


def ans(str):
	str = 'a' + str
	s = 0
	for i in range(1, len(str)):
		p = str[i - 1]
		c = str[i]
		f = abs(ord(p) - ord(c))
		b = 26 - f
		s += min(f, b)
	return s
str = input()
print(ans(str))


import string

class NAM:

	def __init__(self):
		self.pivot = 'a'
		self.rotations = 0

	def get_char_index(self, selected_char):
		assert isinstance(selected_char, object)
		return alphabet.index(selected_char)

	def shortest_diff(self, selected_char):
		diff = 0
		diff = abs(self.get_char_index(self.pivot) - self.get_char_index(selected_char))
		if diff <= 13:
			clockwise = abs(self.get_char_index(self.pivot) - self.get_char_index(selected_char))
		elif self.pivot == 'a':
			clockwise = len(alphabet) - self.get_char_index(selected_char)
		elif self.get_char_index(self.pivot) > 13:
			clockwise = abs(len(alphabet) - self.get_char_index(self.pivot)) + self.get_char_index(selected_char)
		else:
			clockwise = abs(len(alphabet) - self.get_char_index(selected_char)) + self.get_char_index(self.pivot)
		return clockwise

	def total_rotations(self, word):
		for j in word:
			self.rotations += self.shortest_diff(j)
			self.pivot = j
		return self.rotations
alphabet = list(string.ascii_lowercase)
nam = NAM()
print(nam.total_rotations(input()))


total = 0
st = input()
st = 'a' + st
for i in range(0, len(st) - 1):
	t = 0
	t = abs(ord(st[i + 1]) - ord(st[i]))
	if t > 13:
		t = 26 - t
		total = total + t
	else:
		total = total + t
print(total)


def func(n):
	distance = min(ord(n[0]) - 96 - (ord('a') - 96), 26 - abs(ord('a') - 96 - (ord(n[0]) - 96)))
	for i in range(len(n) - 1):
		right_distance = abs(ord(n[i]) - 96 - (ord(n[i + 1]) - 96))
		left_distance = 26 - abs(ord(n[i]) - 96 - (ord(n[i + 1]) - 96))
		distance += min(right_distance, left_distance)
	print(distance)
n = input()
func(n)


word = input()
word = 'a' + word
alphabet = 'abcdefghijklmnopqrstuvwxyz'
dist = {j: i for (i, j) in enumerate(alphabet)}
count = 0
for i in range(0, len(word) - 1):
	start = dist[word[i]]
	end = dist[word[i + 1]]
	if start < end:
		first = end - start
		second = 26 - end + start
		count += min(first, second)
	elif end < start:
		first = start - end
		second = end + 26 - start
		count += min(first, second)
print(count)


import sys
lines = sys.stdin.readlines()
st = lines[0].strip()
st = 'a' + st
res = 0
for i in range(1, len(st)):
	res += min(abs(ord(st[i]) - ord(st[i - 1])), abs(ord(st[i - 1]) + 26 - ord(st[i])), abs(ord(st[i - 1]) - 26 - ord(st[i])))
print(res)


name = input()
result = 0
current_c = 'a'
for c in name:
	r1 = abs(ord(c) - ord(current_c))
	r2 = 26 - abs(ord(c) - ord(current_c))
	result += min(r1, r2)
	current_c = c
print(result)


for _ in range(1):
	string = input()
	curr = 'a'
	total = 0
	for i in range(len(string)):
		temp = total
		total += min(abs(ord(string[i]) - ord(curr)), 26 - abs(ord(string[i]) - ord(curr)))
		curr = string[i]
	print(total)


base = ord('a')
total = ord('z') - base + 1
s = input()
current = 0
moves = 0
for c in s:
	newp = ord(c) - base
	op1 = abs(current - newp)
	op2 = 26 - op1
	mn = min(op1, op2)
	moves += mn
	current = newp
print(moves)


s = str(input())
c = 'a'
ans = 0
for ch in s:
	x = ord(ch) - ord(c)
	if x < 0:
		x = x + 26
	if x > 13:
		x = 26 - x
	ans = ans + x
	c = ch
print(ans)


from string import ascii_lowercase as letters
s = input()
cnt = 0
idx = 0
for i in s:
	pos = letters.find(i)
	cnt += min(abs(idx - pos), 26 - abs(idx - pos))
	idx = pos
print(cnt)


st = input()
start = 'a'
sum1 = 0
for letter in st:
	sub1 = abs(ord(letter) - ord(start))
	sum1 += min(sub1, 26 - sub1)
	start = letter
print(sum1)


s = input()
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
sm = 0
for i in range(len(s)):
	if i == 0:
		l1 = l[1:] + l[:1]
		a = abs(l.index('a') - l.index(s[i]))
		b = abs(l1.index('a') - l1.index(s[i]))
		sm += min(a, b)
	else:
		a = l.index(s[i - 1])
		b = l.index(s[i])
		l1 = l[a:] + l[:a]
		l2 = l[a + 1:] + l[:a + 1]
		x = abs(l1.index(s[i - 1]) - l1.index(s[i]))
		y = abs(l2.index(s[i - 1]) - l2.index(s[i]))
		sm += min(x, y)
print(sm)


import sys

def i():
	return input()

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

def li():
	return input().split()

def mi():
	return list(map(int, input().split()))
rotation = 'abcdefghijklmnopqrstuvwxyz'
n = 'a' + i()
ans = 0
for i in range(len(n) - 1):
	a = rotation.index(n[i])
	b = rotation.index(n[i + 1])
	ans += min((b - a) % 26, (a - b) % 26)
print(ans)


string = input()
count = 0
currentLetter = 'a'
for char in string:
	currentpos = ord(currentLetter)
	charpos = ord(char)
	first = abs(charpos - currentpos)
	second = abs(charpos + 26 - currentpos)
	third = abs(currentpos + 26 - charpos)
	count += min(first, second, third)
	currentLetter = char
print(count)


s = input()
l = list(s)
n = ord('a')
sum = 0
for i in range(len(l)):
	m = abs(n - ord(s[i]))
	if m > 13:
		m = 26 - m
	sum += m
	n = ord(s[i])
print(sum)


s = input()
t = 'abcdefghijklmnopqrstuvwxyz'
currid = 0
den = 0
for i in s:
	temp = abs(currid - t.index(i))
	if temp > len(t) - temp:
		den += len(t) - temp
	else:
		den += temp
	currid = t.index(i)
print(den)


name = input().strip()
code = [1] + [ord(i) - 96 for i in name]
no_moves = 0
for i in range(len(code) - 1):
	no_moves += min(abs(code[i] - code[i + 1]), 26 - abs(code[i] - code[i + 1]))
print(no_moves)


s = input()
x = list('abcdefghijklmnopqrstuvwxyz')
idx = 0
ans = 0
for (i, c) in enumerate(s):
	if x[idx] == c:
		continue
	temp = abs(ord(c) - ord(x[idx]))
	m = min(temp, 26 - temp)
	ans += m
	idx = ord(c) - ord('a')
print(ans)


word = input().lower()
letters = 'abcdefghijklmnopqrstuvwxyz'
cursor = 0
moves = 0
for i in word:
	pointer = letters.index(i)
	x = abs(cursor - pointer)
	if x <= 12:
		moves += x
	else:
		moves += 26 - x
	cursor = pointer
print(moves)


s = str(input())
k = 0
s = 'a' + s
for i in range(len(s) - 1):
	if ord(s[i]) > ord(s[i + 1]):
		t1 = ord(s[i]) - ord(s[i + 1])
		t2 = 26 - (ord(s[i]) - ord(s[i + 1]))
	else:
		t1 = ord(s[i + 1]) - ord(s[i])
		t2 = 26 - (ord(s[i + 1]) - ord(s[i]))
	k += min(t1, t2)
print(k)


while True:
	try:
		now = input()
		l = len(now)
		cnt = 0
		cnt += min(ord(now[0]) - ord('a'), ord('z') - ord(now[0]) + 1)
		for i in range(1, l):
			a = ord(now[i])
			b = ord(now[i - 1])
			c = max(a, b)
			d = min(a, b)
			cnt += min(c - d, d + 26 - c)
		print(cnt)
	except:
		break


indice = 'a'
s = 0
for i in input():
	s += min((ord(indice) - ord(i)) % 26, 26 - (ord(indice) - ord(i)) % 26)
	indice = i
print(s)


n = input()
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
import math
a = math.fabs(l.index('a') - l.index(n[0]))
d = 26 - a
c = 0
c += min(a, d)
for i in range(1, len(n)):
	a = math.fabs(l.index(n[i]) - l.index(n[i - 1]))
	d = 26 - a
	c += min(a, d)
print(int(c))


def main():
	x = input()
	state = 'a'
	ans = 0
	for i in x:
		t = abs(ord(i) - ord(state))
		ans += min(t, abs(26 - t))
		state = i
	print(ans)
main()


import string
import sys
s = sys.stdin.readline()[:-1]
abc = list(string.ascii_lowercase)
rotate_count = 0
current_letter = 'a'
current_index = 0
for x in s:
	index = abc.index(x)
	if abs(index - current_index) > 12:
		rotate_count += 25 - max(index, current_index) + min(index, current_index) + 1
	else:
		rotate_count += abs(index - current_index)
	current_index = index
print(rotate_count)


s = input()
c = 'a'
sum = 0
for ch in s:
	backward = 26 - abs(ord(ch) - ord(c))
	forward = abs(ord(ch) - ord(c))
	n = min(backward, forward)
	c = ch
	sum += n
print(sum)


import string
n = input()
l = list(string.ascii_lowercase)
sum = 0
c = []
for i in range(len(n)):
	c.append(ord(n[i]) - 97)
for i in range(len(n)):
	if i == 0:
		sum += min(c[0], 26 - c[0])
	else:
		sum += min(abs(c[i - 1] - c[i]), abs(26 - max(c[i - 1], c[i]) + min(c[i - 1], c[i])))
print(sum)


import string
letter = string.ascii_lowercase
word_num = dict()
for i in range(26):
	word_num[letter[i]] = i
word = input()
answer = 0
previous = 0
for i in word:
	current = word_num[i]
	diff = current - previous
	answer += min(diff % 26, -diff % 26)
	previous = current
print(answer)


w = str(input().strip())
curr = ord('a')
total = 0
for c in w:
	_c = ord(c)
	v = abs(_c - curr)
	total += min(v, 26 - v)
	curr = _c
print(total)


a = input()
i = 0
d = 0
b = 'a'
while i != len(a):
	c = abs(ord(b) - ord(a[i]))
	d += min(c, 26 - c)
	b = a[i]
	i += 1
print(d)


str = input()
result = 0
start = 'a'
for c in str:
	diff = abs(ord(c) - ord(start))
	other_diff = 26 - diff
	movement = min(diff, other_diff)
	result += movement
	start = c
print(result)


str = input()
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def index(c):
	for i in range(26):
		if l[i] == c:
			return i
last = 'a'
compteur = 0
for c in str:
	i = index(last)
	j = index(c)
	if abs(i - j) > 13:
		compteur += 26 - abs(i - j)
	else:
		compteur += abs(i - j)
	last = c
print(compteur)


import string
alphabets = string.ascii_lowercase
test_string = input()
rotations = 0
rotations += min(alphabets.find(test_string[0]), 26 - alphabets.find(test_string[0]))
for i in range(len(test_string) - 1):
	delta = abs(alphabets.find(test_string[i + 1]) - alphabets.find(test_string[i]))
	rotations += min(delta, 26 - delta)
print(rotations)


d = dict()
for i in range(97, 123):
	d[chr(i)] = i - 96
s = input()
tmp = 1
ans = 0
for i in s:
	mi = min(tmp, d[i])
	ma = max(tmp, d[i])
	t1 = ma - mi
	t2 = mi - ma + 26
	ans += min(t1, t2)
	tmp = d[i]
print(ans)


from math import gcd

def main():
	s = input()
	abc = {a: b for (a, b) in zip('abcdefghijklmnopqrstuvwxyz', range(1, 27))}
	ans = 0
	last = 1
	n = 0
	for i in s:
		n = max(last, abc[i]) - min(last, abc[i])
		ans += n if n <= 13 else 26 - n
		last = abc[i]
	print(ans)
main()


grigoriye = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l = len(grigoriye)
staticpointer = grigoriye[0]

def get_least_distance(value):
	total = 0
	staticpointer_index = 0
	for i in value:
		value_index = grigoriye.index(i)
		min_distance = abs(min(value_index - staticpointer_index, l - (value_index - staticpointer_index)))
		if min_distance > 13:
			min_distance = 26 - min_distance
		staticpointer_index = value_index
		total += min_distance
	return total
value = str(input())
least_distance = get_least_distance(value)
print(least_distance)


import string
enumerated_alphabet = [(num, alpha) for (num, alpha) in enumerate(string.ascii_lowercase)]
alpha_dict = {}
for each in enumerated_alphabet:
	alpha_dict[each[1]] = each[0]

def count_rotation(string, initial='a'):
	count = 0
	if string == '':
		return 0
	current = string[0]
	distance = abs(alpha_dict[current] - alpha_dict[initial])
	if distance >= 13:
		return 26 - distance + count_rotation(string[1:], current)
	else:
		return distance + count_rotation(string[1:], current)
print(count_rotation(input()))


s = 'abcdefghijklmnopqrstuvwxyz'
a = str(input())
k = 0
d = 'a'
for i in range(len(a)):
	k += min(abs(s.index(a[i]) - s.index(d)), 26 - abs(s.index(a[i]) - s.index(d)))
	d = a[i]
print(k)


s = input()
(x, r) = (0, 0)
for y in s:
	y = ord(y) - ord('a')
	r += min(abs(y - x), 26 - abs(x - y))
	x = y
print(r)


n = input()
ini = 'a'
minnmoves = 0
for i in n:
	minnmoves += min(26 - abs(ord(ini) - ord(i)), abs(ord(ini) - ord(i)))
	ini = i
print(minnmoves)


word = list(input())
my_dict = dict()
alpha = 'a'
for i in range(0, 26):
	my_dict[alpha] = i + 1
	alpha = chr(ord(alpha) + 1)
steps = 0
current_letter = 'a'
for letter in word:
	v1 = max(my_dict[letter], my_dict[current_letter]) - min(my_dict[letter], my_dict[current_letter])
	v2 = 26 - v1
	current_letter = letter
	steps += min(v1, v2)
print(steps)


s = input()
c = ord('a')
r = 0
for i in range(len(s)):
	x = abs(ord(s[i]) - c)
	y = abs(26 - x)
	r += min(x, y)
	c = ord(s[i])
print(r)


word = input()
curr = 0
res = 0
for e in word:
	val = ord(e) - 97
	if curr < val:
		res += min(val - curr, curr + 26 - val)
	elif curr > val:
		res += min(curr - val, 26 - curr + val)
	else:
		continue
	curr = val
print(str(res))


def find_diff(current_word, next_word):
	cost = 0
	x = 1
	d = dict()
	e = dict()
	alphabet = list('abcdefghijklmnopqrstuvwxyz')
	for i in alphabet:
		d[i] = x
		x += 1
	return min(abs(d[current_word] - d[next_word]), 26 - abs(d[current_word] - d[next_word]))

def driver(text):
	text = list(text)
	total_cost = find_diff('a', text[0])
	for i in range(0, len(text) - 1):
		current_cost = find_diff(text[i], text[i + 1])
		total_cost += current_cost
	print(total_cost)

def main():
	n = input()
	driver(n)
main()


s = input()
prev = 'a'
sum = 0
for char in s:
	sum += min(abs(ord(char) - ord(prev)), ord(prev) - ord('a') + 1 + ord('z') - ord(char), ord(char) - ord('a') + 1 + ord('z') - ord(prev))
	prev = char
print(sum)


import sys
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())

def test_case():
	w = insr()
	alpha = list('abcdefghijklmnopqrstuvwxyz')
	cpt = 0
	pos = 'a'
	for l in w:
		i = alpha.index(l)
		cpt += min(abs(i - alpha.index(pos)), len(alpha) - abs(i - alpha.index(pos)))
		pos = alpha[i]
	print(cpt)
test_case()


s = input()
n = 97
sum = 0
for i in s:
	nn = abs(ord(i) - n)
	n = ord(i)
	if nn > 13:
		nn = 26 - nn
	sum = sum + nn
print(sum)


s = input()

def proA(st):
	ans = 0
	fi = 0
	for i in st:
		ini = ord(i) % 97
		ans += min(abs(ini - fi), 26 - abs(ini - fi))
		fi = ini
	return ans
print(proA(s))


word = input()
lc = 'a'
t = 0
for c in word:
	x = max(ord(c) - ord('a') + 1, ord(lc) - ord('a') + 1)
	y = min(ord(c) - ord('a') + 1, ord(lc) - ord('a') + 1)
	if x - y <= 13:
		t += x - y
	else:
		t += 26 + y - x
	lc = c
print(t)


is_debug = False
s = 'abcdefghijklmnopqrstuvwxyz'
m = {}
for i in range(0, len(s)):
	m[s[i]] = i
print(f'm={m}') if is_debug else ''
s = input()
v = 0
for i in range(0, len(s)):
	pre = 'a' if i == 0 else s[i - 1]
	cur = s[i]
	v1 = 26 - abs(m[pre] - m[cur])
	v2 = abs(m[pre] - m[cur])
	v = v + (v1 if v1 < v2 else v2)
	print(f'pre={pre}, cur={cur}, v1={v1}, v2={v2}, v={v}') if is_debug else ''
print(v)


def distance(curr, old):
	x = abs(ord(curr) - ord(old))
	return min(26 - x, x)
word = input()
word = 'a' + word
count = 0
for i in range(1, len(word)):
	count += distance(word[i], word[i - 1])
print(count)


l = 'abcdefghijklmnopqrstuvwxyz'
c = 0
k = 0
s = input()
for i in s:
	x = abs(l.index(i) - k)
	c += min(x, 26 - x)
	k = l.index(i)
print(c)


name = input()
ans = 0
ptr = 1
for i in name:
	pos = ord(i) - 96
	ans += min(abs(ptr - pos), 26 - abs(ptr - pos))
	ptr = pos
print(ans)


str = input()
temp = ord('a') - 97
sum = 0
for i in str:
	temp1 = ord(i) - 97
	swalk = abs(temp - temp1)
	if swalk < 13:
		sum += swalk
	else:
		sum += 26 - swalk
	temp = temp1
print(sum)


def countRotation(s):
	count = 0
	currentChar = 'a'

	def findDistanceFromA(letter):
		if ord(letter) < ord('n'):
			return ord(letter) - ord('a')
		else:
			return 26 - (ord(letter) - ord('a'))
	for let in s:
		count += min(findDistanceFromA(currentChar) + findDistanceFromA(let), abs(ord(currentChar) - ord(let)))
		currentChar = let
	return count
s = input()
print(countRotation(s))


import string
word = input()
al = list(string.ascii_lowercase)
c = 0
t = 0
for l in word:
	r = abs(al.index(l) - c)
	c = al.index(l)
	t += r if r < len(al) // 2 else len(al) - r
print(t)


p = r = 0
for x in map(ord, list(input())):
	v = x - ord('a')
	r += min(abs(p - v + 26) % 26, abs(p - v - 26) % 26)
	p = v
print(r)


s = 0
v = 'a'
for i in list(input()):
	s += min(abs(ord(v) - ord(i)), abs(26 - abs(ord(v) - ord(i))))
	v = i
print(s)


n = input()
k = ord('a') - 96
c = 0
for i in n:
	a = ord(i) - 96
	if a > k:
		cw = int(a - k)
		acw = 26 - cw
		k = a
		c = c + min(cw, acw)
	if a < k:
		cw = int(k - a)
		acw = abs(26 - cw)
		k = a
		c = c + min(cw, acw)
	if a == k:
		cw = acw = 0
		k = a
		c = c + min(cw, acw)
print(c)


s = input()
h = lambda x, y: ord(x) - ord(y)

def dist(x, y):
	return min(abs(h(x, y)), 26 - abs(h(x, y)))
lc = 'a'
d = 0
for c in s:
	d += dist(lc, c)
	lc = c
print(d)


from sys import stdin
phrase = input()
lettreActuelle = 0
total = 0
for lettre in phrase:
	gauche = (ord(lettre) - ord('a') - lettreActuelle) % 26
	droite = (lettreActuelle - ord(lettre) + ord('a')) % 26
	rotation = min(gauche, droite)
	total += rotation
	lettreActuelle = ord(lettre) - ord('a')
print(total)


name = input()
turn = 0
strt = ord('a')
for i in name:
	d0 = min(strt, ord(i)) + 26 - max(strt, ord(i))
	d1 = abs(ord(i) - strt)
	m = min(d0, d1)
	turn += m
	strt = ord(i)
print(turn)


r = 'a'
x = input()
z = 0
for i in x:
	y = abs(ord(i) - ord(r))
	z += min(y, 26 - y)
	r = i
print(z)


s = input()
a = 0
c = 97
for x in s:
	a += min(abs(c - ord(x)), 26 - abs(c - ord(x)))
	c = ord(x)
print(a)


v = sorted(list('qwertyuioplkjhgfdsazxcvbnm'))
x = {}
for i in range(26):
	x[v[i]] = i
n = 'a'
g = 0
s = input()
for i in s:
	t = abs(x[n] - x[i])
	g += min(26 - t, t)
	n = i
print(g)


w = str(input())
ans = 0
cc = ord('a')
for c in w:
	temp0 = abs(ord(c) - cc)
	ans = ans + min(temp0, 26 - temp0)
	cc = ord(c)
print(ans)


word = list(input())

def pos(ch):
	position = ord(ch) - ord('a') + 1
	return position
prev = 'a'
sumL = 0
for ch in word:
	d1 = pos(ch) + (pos('z') - pos(prev))
	d2 = pos(prev) + (pos('z') - pos(ch))
	d3 = pos(prev) - pos(ch)
	d4 = pos(ch) - pos(prev)
	min_d = min(abs(d1), abs(d2), abs(d3), abs(d4))
	prev = ch
	sumL += min_d
print(sumL)


s = input()
d = {}
for i in range(0, 26):
	d[chr(ord('a') + i)] = i
init = 'a'
res = 0
for i in s:
	i1 = abs(d[i] - d[init])
	i2 = abs(abs(d[i] - d[init]) - 26)
	res += min(i1, i2)
	init = i
print(res)


import string
string.ascii_lowercase
strname = input('')
length = len(strname)
letters = string.ascii_lowercase
dis = letters.index(strname[0])
if dis > 13:
	dis = 26 - dis
for x in range(1, length):
	dis2 = abs(letters.index(strname[x]) - letters.index(strname[x - 1]))
	if dis2 > 13:
		dis2 = 26 - dis2
	dis += dis2
print(dis)


x = input()
a = 97
tot = 0
for i in x:
	b = abs(a - ord(i))
	tot += min(b, 26 - b)
	a = ord(i)
print(tot)


a = list('abcdefghijklmnopqrstuvwxyz')
s = list(input())
l = 0
for i in range(1, len(s)):
	k = abs(a.index(s[i]) - a.index(s[i - 1]))
	l += min(k, 26 - k)
print(l + min(a.index(s[0]), 26 - a.index(s[0])))


x = list(input())
z = min(abs(ord(x[0]) - ord('a')), abs(ord('z') - max(ord(x[0]), ord('a')) + min(ord(x[0]), ord('a')) - ord('a') + 1))
for i in range(len(x) - 1):
	y = abs(ord(x[i + 1]) - ord(x[i]))
	q = abs(ord('z') - max(ord(x[i + 1]), ord(x[i])) + min(ord(x[i + 1]), ord(x[i])) - ord('a') + 1)
	mn = min(q, y)
	z += mn
print(z)


import string
d = dict(zip(string.ascii_lowercase, range(1, 27)))
s = input()
s_listed = [1] + [d[c] for c in s]
cnt = 0
for i in range(len(s_listed) - 1):
	diff = (s_listed[i + 1] - s_listed[i]) % 26
	cnt += min(diff, 26 - diff)
print(cnt)


l = input()
res = 0
start = 0
for i in l:
	index = ord(i) - 97
	walk = abs(index - start)
	if walk <= 13:
		res += walk
	else:
		res += 26 - walk
	start = index
print(res)


def steps(str1, stp=0, init='a'):
	if len(str1) == 0:
		return stp
	else:
		curr = str1[0]
		num = abs(ord(curr) - ord(init))
		num1 = min(26 - num, num)
		stp += num1
		return steps(str1[1:], stp, curr)
str1 = input()
print(steps(str1))


l = list(input())
i = 1
ans = 0
for x in l:
	j = ord(x) - 96
	ans += min(abs(i - j), 26 - abs(i - j))
	i = j
print(ans)


n = input()
(p, count) = ('a', 0)
for i in n:
	x = abs(ord(p) - ord(i))
	b = min(x, abs(26 - x))
	p = i
	count += b
print(count)


z = input()
a = []
for i in range(97, 123):
	a.append(chr(i))
c = 0
q = 0
we = []
for i in z:
	m = 0
	while True:
		if c >= 26:
			c = 0
		if q <= -26:
			q = 0
		if i == a[c]:
			q = c
			break
		elif i == a[q]:
			c = q
			break
		c += 1
		q -= 1
		m += 1
	we.append(m)
print(sum(we))


n = list(input())
l = 'abcdefghijklmnopqrstuvwxyz'
s = 0
k = 'a'
for i in n:
	w = abs(l.index(i) - l.index(k))
	s += min(w, 26 - w)
	k = i
print(s)


s = 'a' + input()
print(sum([min(abs(ord(a) - ord(b)), 26 - abs(ord(a) - ord(b))) for (a, b) in zip(s[:-1], s[1:])]))


n = input()
l = []
a = int(len(n))
c = 0
p = int(97)
for i in range(a):
	l.append(n[i])
	if int(abs(p - ord(l[i]))) > 13:
		c = c + abs(abs(p - ord(l[i])) - 26)
	else:
		k = int(abs(ord(l[i]) - p))
		c = c + k
	p = int(ord(l[i]))
print(c)


abc = 'abcdefghijklmnopqrstuvwxyz'
word = input()
s = 0
current = 'a'
for i in word:
	currentIndex = abc.index(current)
	mustIndex = abc.index(i)
	if abs(mustIndex - currentIndex) > 13:
		s += 26 - abs(mustIndex - currentIndex)
	else:
		s += abs(mustIndex - currentIndex)
	current = i
print(s)


alf = 'abcdefghijklmnopqrstuvwxyz'
s = input().split()[0]
cur = 'a'
povs = 0
for i in range(len(s)):
	povs += min(abs(alf.find(s[i]) - alf.find(cur)), min(abs(-alf.find(s[i]) + 26 + alf.find(cur)), alf.find(s[i]) + 26 - alf.find(cur)))
	cur = s[i]
print(povs)


my_string = input()
len_str = int(len(my_string))
result = 0
pos = 97
for i in range(len_str):
	distance = abs(ord(my_string[i]) - pos)
	if distance > 13:
		result = result + (26 - distance)
	else:
		result += distance
	pos = ord(my_string[i])
print(result)


import math
tape = input()
letter = 'a'
counter = 0
for x in tape:
	d = int(math.fabs(ord(x) - ord(letter)))
	if d < 13:
		counter += d
	else:
		counter += 26 - d
	letter = x
print(counter)


d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
inp = input()
counter = 'a'
no = 0
for dest in inp:
	if dest > counter:
		if d['z'] - d[dest] + d[counter] < abs(d[counter] - d[dest]):
			no += d['z'] - d[dest] + d[counter]
			counter = dest
		else:
			no += abs(d[counter] - d[dest])
			counter = dest
	elif d['z'] - d[counter] + d[dest] < abs(d[counter] - d[dest]):
		no += d['z'] - d[counter] + d[dest]
		counter = dest
	else:
		no += abs(d[counter] - d[dest])
		counter = dest
print(no)


x = input()
start = 'a'

def check_range(element, start, end):
	if start < end:
		if element >= start and element <= end:
			return True
		else:
			return False
	elif element <= end and element <= start or (element >= end and element >= start):
		return True
	else:
		return False
counter = 0
for i in range(len(x)):
	if start >= 'a' and start <= 'n':
		opp = chr(ord(start) + 13)
	else:
		opp = chr(ord(start) - 13)
	if check_range(x[i], start, opp):
		test = 0
		test2 = start
		for j in range(13):
			if test2 == x[i]:
				break
			elif test2 == 'z':
				test2 = 'a'
			else:
				test2 = chr(ord(test2) + 1)
			test += 1
	else:
		test = 0
		test2 = start
		for j in range(13):
			if test2 == x[i]:
				break
			elif test2 == 'a':
				test2 = 'z'
			else:
				test2 = chr(ord(test2) - 1)
			test += 1
	counter += test
	start = x[i]
print(counter)


word = ''
result = 0
length = 0
pointer = 'a'
word = str(input())
for i in range(len(word)):
	length = abs(ord(word[i]) - ord(pointer))
	pointer = word[i]
	if length < 13:
		result += length
	else:
		result += 26 - length
print(result)


word = list(input())
letters = 'abcdefghijklmnopqrstuvwxyz'
pos = 'a'
count = 0
for char in word:
	if letters.index(char) > letters.index(pos):
		fw = letters.index(char) - letters.index(pos)
		bw = 26 - letters.index(char) + letters.index(pos)
	elif letters.index(char) < letters.index(pos):
		fw = 26 - letters.index(pos) + letters.index(char)
		bw = letters.index(pos) - letters.index(char)
	else:
		fw = bw = 0
	if fw <= bw:
		count += fw
	else:
		count += bw
	pos = char
print(count)


word = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
inital = 0
total = 0
for c in word:
	pos = alpha.find(c)
	total += min(abs(pos - inital), 26 - abs(pos - inital))
	inital = pos
print(total)


str = input()
count = 0
startPoint = 97
subs = 24
for letter in str:
	tempLetter = ord(letter)
	startPoint = abs(startPoint - tempLetter)
	counter = min(startPoint, abs(startPoint - 26))
	count += min(startPoint, abs(startPoint - 26))
	startPoint = tempLetter
print(count)


word = input()
cnt = 0
cur = 97
for i in word:
	i = ord(i)
	if abs(i - cur) > 13:
		cnt += 13 - (abs(cur - i) - 13)
	elif abs(i - cur) <= 13:
		cnt += abs(i - cur)
	cur = i
print(cnt)


import sys
import math
name = sys.stdin.readline()
total = 0
prev = 0
for c in name:
	curr = ord(c) - 97
	if curr != -87:
		forward = math.fabs(curr - prev)
		if prev < 13:
			abs_prev = prev
		else:
			abs_prev = 26 - prev
		if curr < 13:
			abs_curr = curr
		else:
			abs_curr = 26 - curr
		backward = abs_prev + abs_curr
		if forward > backward:
			total += backward
		elif backward >= forward:
			total += forward
	prev = curr
print(int(total))


import math
s = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
p = 'a'
m = 0
toprint = 0
for c in s:
	d = alpha.index(p)
	d2 = alpha.index(c)
	dis = abs(d2 - d)
	if dis <= 13:
		toprint = toprint + dis
	else:
		toprint = toprint + 25 - dis + 1
	p = c
print(toprint)


str_in = input()
sum_n = 0
first = 97
for i in range(len(str_in)):
	if ord(str_in[i]) >= first:
		sum_n += min(abs(ord(str_in[i]) - first), abs(first - 97) + abs(123 - ord(str_in[i])))
	else:
		sum_n += min(abs(ord(str_in[i]) - first), abs(first - 122) + abs(96 - ord(str_in[i])))
	first = ord(str_in[i])
print(sum_n)


s = input()
current = 1
ans = 0
for x in s:
	ans += min(abs(ord(x) - 96 - current), 26 - abs(ord(x) - 96 - current))
	current = ord(x) - 96
print(ans)


x = input()
i = 0
e = 'a'
p = 0
while i < len(x):
	d = abs(ord(x[i]) - ord(e))
	if d > 13:
		d = 26 - d
	p += d
	e = x[i]
	i += 1
print(p)


import string
name = [x for x in input()]
abcAsc = list(string.ascii_lowercase)
abcDsc = abcAsc[::-1]
currentChar = 'a'
indexToRight = abcAsc.index(currentChar)
indexToLeft = abcDsc.index(currentChar)
abcAsc = abcAsc[indexToRight:] + abcAsc[:indexToRight]
abcDsc = abcDsc[indexToLeft:] + abcDsc[:indexToLeft]
totalMovs = 0
for char in name:
	indexToRight = abcAsc.index(char)
	indexToLeft = abcDsc.index(char)
	abcAsc = abcAsc[indexToRight:] + abcAsc[:indexToRight]
	abcDsc = abcDsc[indexToLeft:] + abcDsc[:indexToLeft]
	currentMovs = min(indexToRight, indexToLeft)
	totalMovs += currentMovs
print(totalMovs)


sd = 0
pc = 0
for c in input().strip():
	cc = ord(c) - ord('a')
	d1 = pc - cc
	if d1 < 0:
		d1 = 26 + d1
	d2 = cc - pc
	if d2 < 0:
		d2 = 26 + d2
	sd += min(d1, d2)
	pc = cc
print(sd)


n = list(input())
k = ord('a')
count = 0
for i in n:
	x = min(abs(k - ord(i)), 26 - abs(k - ord(i)))
	count += x
	k = ord(i)
print(count)


alphabet = 'abcdefghijklmnopqrstuvwxyz'

def clockwise(start, end):
	count = 0
	i = alphabet.index(start)
	while alphabet[i] != end:
		count += 1
		i = (i + 1) % len(alphabet)
	return count

def anti_clockwise(start, end):
	count = 0
	i = alphabet.index(start)
	while alphabet[i] != end:
		count += 1
		i = (i - 1) % len(alphabet)
	return count
word = input()
rotations = 0
start = 'a'
for i in word:
	end = i
	rotations += min(clockwise(start, end), anti_clockwise(start, end))
	start = end
print(rotations)


def main():
	try:
		while True:
			s = input()
			cur = 0
			result = 0
			for c in s:
				c = ord(c) - 97
				result += min((c - cur) % 26, (cur - c) % 26)
				cur = c
			print(result)
	except EOFError:
		pass
main()


x = input()
p = 'a'
result = 0
for i in x:
	l_1 = abs(ord(p) - ord(i))
	l_2 = 26 - abs(l_1)
	result += min(l_1, l_2)
	p = i
print(result)


s = input()
n = len(s)
cnt = min(abs(ord('a') - ord(s[0])), 26 - abs(ord('a') - ord(s[0])))
for i in range(1, n):
	fasele = abs(ord(s[i]) - ord(s[i - 1]))
	cnt += min(fasele, 26 - fasele)
print(cnt)


Dict = {}
Alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in Alpha:
	Dict[i] = ord(i)
S = input()
Pointer = 'a'
R = 0
for i in S:
	N1 = abs(Dict[Pointer] - Dict[i])
	N2 = 26 - abs(Dict[Pointer] - Dict[i])
	R += min(N1, N2)
	Pointer = i
print(R)


from sys import stdin
w = stdin.readline()[:-1]
res = 0
ch = 'a'
for i in w:
	m = abs(ord(i) - ord(ch))
	if m < 13:
		res += m
	else:
		res += 26 - m
	ch = i
print(res)


(m, count) = (97, 0)
for i in map(ord, input()):
	v = abs(i - m)
	count += min(v, 26 - v)
	m = i
print(count)


from sys import stdin
s = input()
a = []
n = len(s)
flag = 97
c = 0
for i in range(n):
	dif = abs(flag - ord(s[i]))
	if dif > 13:
		dif = 26 - dif
	c += dif
	flag = ord(s[i])
print(c)


word = input()
x = abs(ord(word[0]) - ord('a'))
y = abs(ord('z') - ord(word[0])) + 1
z = 0
k = min(x, y)
for i in range(1, len(word)):
	x = abs(ord(word[i]) - ord(word[i - 1]))
	y = abs(ord('z') - ord(word[i - 1])) + abs(ord(word[i]) - ord('a')) + 1
	z = abs(ord('a') - ord(word[i - 1])) + abs(ord(word[i]) - ord('z')) + 1
	k += min(x, y, z)
print(k)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = str(input())
count = 0
cur = 0
for i in s:
	pos = alphabet.find(i)
	count += abs(pos - cur) if abs(pos - cur) <= 26 - abs(pos - cur) else 26 - abs(pos - cur)
	cur = alphabet.find(i)
print(count)


ch = input()

def decalage(a, b):
	k = (ord(a) - ord(b)) % 26
	if k > 13:
		k = 26 - k
	return k
s = 0
a = 'a'
for i in range(len(ch)):
	b = ch[i]
	s += decalage(a, b)
	a = b
print(s)


import sys
s = input()
ans = abs(ord(s[0]) - ord('a'))
ans = min(ans, 26 - ans)
for i in range(1, len(s)):
	now = abs(ord(s[i]) - ord(s[i - 1]))
	ans += min(now, abs(26 - now))
print(ans)


s = input()
S = 'abcdefghijklmnopqrstuvwxyz'
ind = 0
ans = 0
for item in s:
	index = ind
	ans1 = 0
	while S[index] != item:
		index = (index + 1) % 26
		ans1 += 1
	index = ind
	ans2 = 0
	while S[index] != item:
		index = (index - 1 + 26) % 26
		ans2 += 1
	ans += min(ans1, ans2)
	ind = index
print(ans)


def read_input():
	return input()

def do_rotate(a):
	rotations = 0
	a = 'a' + a
	for i in range(1, len(a)):
		af = max(ord(a[i]), ord(a[i - 1]))
		be = min(ord(a[i]), ord(a[i - 1]))
		rotations += min(af - be, ord('z') - af + be - ord('a') + 1)
	return rotations

def main():
	print(do_rotate(read_input()))
main()


s = input()
s = 'a' + s
x = 0
for a in range(len(s) - 1):
	res = ord(s[a]) - ord(s[a + 1])
	x = x + min(abs(res), 26 - abs(res))
print(x)


c = 0
cur = 1
s = input()
for i in s:
	a = ord(i) - 96
	b = min(cur - 1 + (27 - a), abs(cur - a), 27 - cur + (a - 1))
	c += b
	cur = a
print(c)


string_input = input()
list_of_ascii = [ord(c) for c in string_input]
list_of_ascii.insert(0, ord('a'))
sum = 0
target = list_of_ascii[0]
for x in range(1, len(list_of_ascii)):
	sum += min(abs(target - list_of_ascii[x]), 26 - abs(target - list_of_ascii[x]))
	target = list_of_ascii[x]
print(sum)


def clock_generator():
	position = 1
	dict = {}
	for i in range(97, 123):
		dict[chr(i)] = position
		position = position + 1
	return dict

def move_counter(string):
	point = 1
	moves = 0
	dict = clock_generator()
	for char in string:
		cd = abs(dict[char] - point)
		acd = 26 - abs(dict[char] - point)
		moves += min(cd, acd)
		point = dict[char]
	return moves
x = input()
print(move_counter(x))


a_ord = ord('a')

def getMinDiff(c1, c2):
	i1 = ord(c1) - a_ord
	i2 = ord(c2) - a_ord
	i1_i2 = i1 - i2
	if i1_i2 < 0:
		i1_i2 += 26
	i2_i1 = i2 - i1
	if i2_i1 < 0:
		i2_i1 += 26
	return i1_i2 if i1_i2 < i2_i1 else i2_i1
s = input()
cur_ch = 'a'
cnt = 0
for c in s:
	cnt += getMinDiff(cur_ch, c)
	cur_ch = c
print(cnt)


from copy import copy
s = list(map(str, input()))
h = 'a'
sum = 0
for x in s:
	step = abs(ord(x) - ord(h))
	h = copy(x)
	if step > 13:
		step = 26 - step
	sum += step
print(sum)


a = input()
j = 'a'
f = 0
for i in a:
	d = abs(abs(ord(i) - ord(j)) - 26)
	e = abs(ord(i) - ord(j))
	j = i
	if d < e:
		f = f + d
	else:
		f = f + e
print(f)


def main():
	s = input()
	pointer = ord('a')
	distance = 0
	for c in s:
		next_char = ord(c)
		dis = abs(next_char - pointer)
		dis = 26 - dis if dis > 13 else dis
		distance += dis
		pointer = next_char
	print(distance)
main()


a = input()
(s, t) = (0, 0)
for i in range(len(a)):
	b = ord(a[i]) - 97
	if abs(b - t) <= 13:
		s = s + abs(b - t)
	else:
		s = s + (27 - abs(b - t) - 1)
	t = b
print(s)


name = list('a' + input())
total = 0
for i in range(len(name) - 1):
	forward = abs(ord(name[i]) - ord(name[i + 1]))
	backword = abs(ord('z') - max(ord(name[i]), ord(name[i + 1]))) + abs(min(ord(name[i]), ord(name[i + 1])) - ord('a')) + 1
	total += forward if forward < backword else backword
print(total)


def dist(a, b):
	s = 'abcdefghijklmnopqrstuvwxyz'
	i = 0
	j = 0
	while a != s[i]:
		i += 1
	while b != s[j]:
		j += 1
	if 26 - abs(j - i) < abs(j - i):
		return 26 - abs(j - i)
	else:
		return abs(j - i)
word = input()
ans = dist('a', word[0])
i = 0
while i != len(word) - 1:
	ans += dist(word[i], word[i + 1])
	i += 1
print(ans)


z = 'abcdefghijklmnopqrstuvwxyz'
s = input()
c = 0
s = s + 'a'
for i in range(len(s) - 1):
	ind = z.index(s[i])
	n = z.index(s[i - 1])
	(m, mm) = (min(ind, n), max(ind, n))
	c += min(abs(ind - n), 26 - mm + m)
print(c)


r = 0
p = 'a'
wrd = str(input())
for i in range(len(wrd)):
	c = abs(ord(wrd[i]) - ord(p))
	a = 26 - c
	r += min(a, c)
	p = wrd[i]
print(r)


x = input()
s1 = 'a'
n = 0
for i in range(len(x)):
	if abs(ord(x[i]) - ord(s1)) <= 13:
		n += abs(ord(x[i]) - ord(s1))
		s1 = x[i]
	else:
		n += 26 - abs(ord(x[i]) - ord(s1))
		s1 = x[i]
print(n)


s = input()
s = map(ord, s)
p = 97
m = 0
for i in s:
	x = abs(i - p)
	m += min(x, 26 - x)
	p = i
print(m)


s = input()
c = int(0)
a = int(1)
for i in range(len(s)):
	z = ord(s[i]) - 96
	p = abs(z - a)
	o = abs(26 - p)
	a = z
	c += min(p, o)
print(c)


def letters_diff(a, b):
	lo = min(ord(a), ord(b))
	hi = max(ord(a), ord(b))
	return min(hi - lo, ord('z') - hi + lo - ord('a') + 1)
word = input()
res = 0
prev_letter = 'a'
for letter in word:
	res += letters_diff(letter, prev_letter)
	prev_letter = letter
print(res)


name = input()
characters = 'abcdefghijklmnopqrstuvwxyz'
length = len(characters)
total = 0
current_index = 0
for c in name:
	index_c = characters.find(c)
	step_from_current_to_c = abs(current_index - index_c)
	counterclockwise = length + current_index - index_c
	if counterclockwise > length:
		counterclockwise -= length * 2
		counterclockwise = abs(counterclockwise)
	total += min(step_from_current_to_c, counterclockwise)
	current_index = index_c
print(total)


import string

def dist_clock(start, end, alpha):
	cnt = 0
	cur_index = ord(start) - ord('a')
	cur = start
	while cur != end:
		cur_index = (cur_index + 1) % 26
		cur = alpha[cur_index]
		cnt += 1
	return cnt

def dist_clock1(start, end, alpha):
	cnt = 0
	cur_index = 25 - (ord(start) - ord('a'))
	cur = start
	while cur != end:
		cur_index = (cur_index + 1) % 26
		cur = alpha[cur_index]
		cnt += 1
	return cnt
s = input()
ordered_case = list(string.ascii_lowercase)
inv_case = list(string.ascii_lowercase)[::-1]
cnt = min(dist_clock('a', s[0], ordered_case), dist_clock1('a', s[0], inv_case))
for i in range(1, len(s)):
	cnt += min(dist_clock(s[i - 1], s[i], ordered_case), dist_clock1(s[i - 1], s[i], inv_case))
print(cnt)


def getMin(first, second):
	result = abs(first - second)
	if result > 13:
		result = 26 - abs(first - second)
	return result

def miniSteps(name_string):
	first = 'a'
	sum = 0
	for i in name_string:
		second = i
		sum = sum + getMin(ord(first), ord(second))
		first = second
	return sum
n = input()
print(miniSteps(n))


import sys

def ans(word):
	word = 'a' + word
	distance = 0
	for i in range(len(word) - 1):
		fr = word[i]
		to = word[i + 1]
		distance += min(abs(ord(to) - ord(fr)), 26 - abs(ord(to) - ord(fr)))
	return distance
for word in sys.stdin:
	word = word.rstrip('\r').rstrip('\n')
	print(ans(word))


s = input()
curr = 97
ans = 0
for i in s:
	k = (ord(i) - curr + 26) % 26
	ans += min(k, 26 - k)
	curr = ord(i)
print(ans)


word = input()
ORD = [0] + [ord(x) - 97 for x in word]
cost = 0
for i in range(1, len(ORD)):
	dif = abs(ORD[i - 1] - ORD[i])
	if dif < 26 - dif:
		cost += dif
	else:
		cost += 26 - dif
print(cost)


n = input()
t = len(n)
n = n.lower()
p = 'a'
m = 0
for i in n:
	x = abs(ord(i) - ord(p))
	y = 26 - x
	z = min(x, y)
	m = m + z
	p = i
print(m)


import string
alpha = [i for i in string.ascii_lowercase]
word = input()
fgj = 'a' + word
res = 0
for i in range(len(fgj) - 1):
	abc = alpha.index(fgj[i]) - alpha.index(fgj[i + 1])
	ghi = alpha.index(fgj[i + 1]) - alpha.index(fgj[i])
	res += min(abc % 26, ghi % 26)
print(res)


word = str(input())
max_moves = 0
position = 0
for i in range(len(word)):
	index = list(bytes(word[i], 'utf8'))[0] - 97
	walk = abs(position - index)
	if walk < 13:
		max_moves += walk
	else:
		max_moves += 26 - walk
	position = index
print(max_moves)


import math
s = input()
f = 97
count = 0
for j in s:
	i = ord(j)
	if i > f:
		q = i - 26
	else:
		q = i + 26
	count += min(abs(i - f), abs(q - f))
	f = i
print(count)


def dis(c, v):
	d = abs(ord(c) - ord(v))
	return d if d < 13 else 26 - d
s = input()
count = dis('a', s[0])
for i in range(len(s) - 1):
	count += dis(s[i], s[i + 1])
print(count)


def distance(len_list, idx_1, idx_2):
	i1 = (idx_1 - idx_2) % len_list
	j = (idx_2 - idx_1) % len_list
	return min(i1, j)
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
inp = input()
i = ans = 0
lst = list(inp)
while i < len(lst) - 1:
	(indx1, indx2) = (alphabet.index(lst[i]), alphabet.index(lst[i + 1]))
	cnt = distance(26, indx1, indx2)
	ans += cnt
	i += 1
indx3 = alphabet.index(lst[0])
indx4 = distance(26, 0, indx3)
print(ans + indx4)


alph = 'abcdefghijklmnopqrstuvwxyz'
k = 0
pos = 0
s = str(input())
for i in s:
	r = alph.index(i)
	if r < pos:
		k += min(pos - r, 26 - pos + r)
	else:
		k += min(r - pos, 1 + pos + 25 - r)
	pos = r
print(k)


st = str(input().strip())
pointer = 'a'
rotations = 0
for i in range(len(st)):
	v = min(abs(ord(st[i]) - ord(pointer)), 26 - abs(ord(st[i]) - ord(pointer)))
	pointer = st[i]
	rotations += v
print(rotations)


def main():
	word = input()
	moves = 0
	pointerAt = 'a'
	for letter in word:
		c = abs(ord(pointerAt) - ord(letter))
		ac = 26 - abs(ord(letter) - ord(pointerAt))
		moves += min(c, ac)
		pointerAt = letter
	print(moves)
main()


word = input()
count = 0
ran = abs(97 - ord(word[0]))
n1 = ran
n2 = 26 - ran
count += n1 if n1 <= n2 else n2
for i in range(len(word) - 1):
	ran = abs(ord(word[i]) - ord(word[i + 1]))
	n1 = ran
	n2 = 26 - ran
	count += n1 if n1 <= n2 else n2
print(count)


s = input()
pointer = 'a'
num = 0
for i in s:
	step1 = abs(ord(pointer) - ord(i))
	step2 = 26 - abs(ord(pointer) - ord(i))
	num = num + min(step1, step2)
	pointer = i
print(num)


s = list(map(lambda l: ord(l) - ord('a'), 'a' + input()))
print(sum((min(abs(s[i] - s[i - 1]), 26 - abs(s[i] - s[i - 1])) for i in range(1, len(s)))))


s = input()
count = 0
last = 'a'
for i in range(len(s)):
	turn = abs(ord(last) - ord(s[i]))
	if turn > 26 - turn:
		turn = 26 - turn
	count += turn
	last = s[i]
print(count)


import string
alph = {c: i for (i, c) in enumerate(string.ascii_lowercase)}
n = input()
ans = 0
current = 'a'
for i in n:
	ans += min(abs(alph[i] - alph[current]), 26 - abs(alph[i] - alph[current]))
	current = i
print(ans)


text = str(input())
pointer = 'a'
count = 0
for i in range(len(text)):
	dist = abs(ord(pointer) - ord(text[i]))
	if dist < 13:
		count += dist
	else:
		count += 26 - dist
	pointer = text[i]
print(count)


s = input()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
last = 'a'
ans = 0
for elem in s:
	last_ind = a.index(last)
	ind = a.index(elem)
	ans += min(abs(ind - last_ind), abs((ind + 26 - last_ind) % 26), abs((last_ind + 26 - ind) % 26))
	last = elem
print(ans)


word = input()
count = 0
last_letter = 'a'
for letter in word:
	gap = abs(ord(letter) - ord(last_letter))
	count = count + min(gap, 26 - gap)
	last_letter = letter
print(count)


def get_hole_path(word):
	word = 'a' + word
	i = hole_path = 0
	while i < len(word) - 1:
		length = ord(word[i]) - ord(word[i + 1]) if ord(word[i]) > ord(word[i + 1]) else ord(word[i + 1]) - ord(word[i])
		length = length if length < 13 else 26 - length
		hole_path += length
		i += 1
	return hole_path
print(get_hole_path(input()))


s = input()
sum = 0
x = 'a'
for i in range(0, len(s)):
	t = ord(s[i]) - ord(x)
	if t > 0:
		g = t - 26
	else:
		g = t + 26
	x = s[i]
	sum += min(abs(t), abs(g))
print(sum)


l = input()
start = 'a'
t = 0
for i in range(len(l)):
	x = abs(ord(start) - ord(l[i]))
	t += min(x, 26 - x)
	start = l[i]
print(t)


import string
arr = [i for i in string.ascii_lowercase]
current = 'a'
s = str(input())
count = 0
for i in s:
	if i != current:
		count += min(abs(arr.index(i) - arr.index(current)), 26 - abs(arr.index(i) - arr.index(current)))
		current = i
print(count)


str = input()
previous = 'a'
movement = 0
for i in str:
	x = 1000000
	y = 1000000
	z = 1000000
	x = abs(ord(i) - ord(previous))
	if ord(previous) < ord(i):
		y = 123 - ord(i) + (ord(previous) - 97)
	if ord(previous) > ord(i):
		z = abs(123 - ord(previous) + (ord(i) - 97))
	minn = min(x, y, z)
	movement += minn
	previous = i
print(movement)


exhibit = list(input())
current = 1
rotation = 0
for i in exhibit:
	a = ord(i) - 96
	if abs(a - current) > 26 - abs(a - current):
		rotation += 26 - abs(a - current)
	else:
		rotation += abs(a - current)
	current = a
print(rotation)


exhibit = input()
import string
values = dict()
for (index, letter) in enumerate(string.ascii_lowercase):
	values[letter] = index

def myfunc(x, y):
	if x <= y:
		return x
	else:
		return y
totalrotations = [myfunc(26 - values[exhibit[0]], values[exhibit[0]])]
for i in range(len(exhibit) - 1):
	rotation = myfunc(26 - abs(values[exhibit[i + 1]] - values[exhibit[i]]), abs(values[exhibit[i + 1]] - values[exhibit[i]]))
	totalrotations.append(rotation)
print(sum(totalrotations))


s = input()
c = 'a'
total = 0
for new_c in s:
	move1 = abs(ord(new_c) - ord(c))
	move2 = 26 - abs(ord(new_c) - ord(c))
	total += min(move1, move2)
	c = new_c
print(total)


import sys
name = sys.stdin.readline()[:-1]
name = 'a' + name
output = 0
for i in range(0, len(name) - 1):
	suggested = abs(ord(name[i]) - ord(name[i + 1]))
	if suggested > 13:
		output += 26 - suggested
	else:
		output += suggested
print(output)


from string import ascii_lowercase
letters_dict = {char: index + 1 for (index, char) in enumerate(ascii_lowercase)}
word = input()
current = 'a'
result = 0
for char in word:
	result += min(abs(26 - letters_dict[char] + letters_dict[current]), abs(letters_dict[char] - letters_dict[current]), abs(26 - letters_dict[current] + letters_dict[char]))
	current = char
print(result)


keys = list(map(chr, range(97, 123)))
values = list(range(1, 27))
dictionary = dict(zip(keys, values))
count = 0
word = str(input())
start = 1
for symbol in word:
	position = dictionary[symbol]
	if position > start:
		variant_1 = 26 - position + start
		variant_2 = position - start
	else:
		variant_1 = start - position
		variant_2 = 26 - start + position
	if variant_1 > variant_2:
		diff = variant_2
	else:
		diff = variant_1
	start = position
	count += diff
print(count)


a = input()
alfabet = 'abcdefghijklmnopqrstuvwxyz'
letter = 'a'
res = 0
for i in a:
	h = alfabet.find(i)
	q = alfabet.find(letter)
	x = abs(h - q)
	y = 26 - x
	res += min(x, y)
	letter = i
print(res)


string = input()
alphabets = 'abcdefghijklmnopqrstuvwxyz'
pointer = 0
front = rear = pointer
ans = 0
steps = 0
for i in string:
	while True:
		if alphabets[front] == i:
			ans += steps
			steps = 0
			pointer = alphabets.find(i)
			break
		elif alphabets[rear] == i:
			ans += steps
			steps = 0
			pointer = alphabets.find(i)
			break
		else:
			front = front + 1
			front = front % 26
			rear -= 1
			steps += 1
	front = rear = pointer
print(ans)


str = input()
ch = 'a'
total = 0
for i in str:
	dis = abs(ord(ch) - ord(i))
	if dis < 13:
		total += dis
	else:
		total = total + (26 - dis)
	ch = i
print(total)


n = input()
ini = 'a'
sum = 0
for i in n:
	c1 = abs(ord(ini) - ord(i))
	if c1 >= 13:
		c1 = abs(26 - c1)
	sum += c1
	ini = i
print(sum)


line = 'a' + str(input())
res = 0
size = len(line)
for i in range(1, size):
	res += min(abs(ord(line[i]) - ord(line[i - 1])), 26 - abs(ord(line[i]) - ord(line[i - 1])))
print(res)


name = input()
current = 'a'
moves = 0
for x in name:
	diff = abs(ord(current) - ord(x))
	if diff > 13:
		moves += 26 - diff
	else:
		moves += diff
	current = x
print(moves)


a = input()
su = 'abcdefghijklmnopqrstuvwxyz'
fl2 = 'a'
ll2 = ''
k = 0
for i in a:
	ll1 = su.find(i)
	fl1 = su.find(fl2)
	k += min(abs(ll1 - fl1), 26 - abs(fl1 - ll1))
	fl2 = i
print(k)


s = input()
b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
j = 0
cad = 0
for i in range(len(s)):
	count = 0
	while b[j % 26] != s[i]:
		count = count + 1
		j = j + 1
	j = b.index(s[i])
	if count > 13:
		add = count - 13
		bad = 13 - add
		cad = cad + bad
	else:
		cad = cad + count
print(cad)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

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

def sip():
	return input()

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

def mips():
	return map(str, sys.stdin.readline().split())

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
s = sip()
val = min(ord(s[0]) - ord('a'), 26 - (ord(s[0]) - 96) + (ord('a') - 96))
for i in range(1, len(s)):
	x = ord(s[i - 1]) - 96
	y = ord(s[i]) - 96
	if y == x:
		val += 0
	elif y > x:
		val += min(y - x, x + 26 - y)
	else:
		val += min(x - y, y + 26 - x)
print(val)


alphabet = 'abcdefghijklmnopqrstuvwxyz'

def num_of_rotation(now_pos, target_pos):
	if alphabet.index(target_pos) > alphabet.index(now_pos):
		clockwise_rotation = alphabet.index(target_pos) - alphabet.index(now_pos)
		counterclockwise_rotation = alphabet.index(now_pos) - alphabet.index(target_pos) + 26
	elif alphabet.index(target_pos) < alphabet.index(now_pos):
		clockwise_rotation = alphabet.index(target_pos) - alphabet.index(now_pos) + 26
		counterclockwise_rotation = alphabet.index(now_pos) - alphabet.index(target_pos)
	else:
		return 0
	return min(clockwise_rotation, counterclockwise_rotation)
input_string = input()
ans = 0
ans += num_of_rotation('a', input_string[0])
for i in range(len(input_string) - 1):
	ans += num_of_rotation(input_string[i], input_string[i + 1])
print(ans)