"""
z o
zoac
"""
left = [['q', 'w', 'e', 'r', 't'],
['a', 's', 'd', 'f', 'g'],
['z', 'x', 'c', 'v']]
right = [['', '', '', '', '', 'y', 'u', 'i', 'o', 'p'],
['', '', '', '', '', 'h', 'j', 'k', 'l'],
['', '', '', '', 'b', 'n', 'm']]
sl, sr = 'z', 'o'
alpha = list('l')
def return_left_location(string):
answer_return = -1
for i in range(len(left)):
for j in range(len(left[i])):
if left[i][j] == string:
answer_return = [i, j]
return answer_return
def return_right_location(string):
answer_return = -1
for i in range(len(right)):
for j in range(len(right[i])):
if right[i][j] == string:
answer_return = [i, j]
return answer_return
sl = return_left_location(sl)
sr = return_right_location(sr)
answer = 0
for value in alpha:
if return_left_location(value) == -1:
value_location = return_right_location(value)
sr_cha = abs(sr[0] - value_location[0]) + abs(sr[1] - value_location[1])
sr = value_location
answer += sr_cha + 1
elif return_right_location(value) == -1:
value_location = return_left_location(value)
sl_cha = abs(sl[0] - value_location[0]) + abs(sl[1] - value_location[1])
sl = value_location
answer += sl_cha + 1
print(answer)