GPS Text Entry

No attempts yetTime limit1sMemory limit128 MB

Problem

For her birthday, Sandy received a Global Positioning System (GPS) unit, an electronic device she can use to track local hiking trails. Along the way she can mark waypoints and record them on a map once she gets home. A description of each waypoint can be entered into the unit, but the device has no keypad. Instead it has four cursor buttons (up, down, left, and right) and a button to accept the current letter.

The screen shows a grid of the letters and symbols used to "type out" a description. The grid is laid out as follows:

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 (space) . , (enter)

Here (space) is the space character and (enter) is the key that accepts the whole phrase.

When you enter a waypoint name, the cursor starts on the 'A'. You must move the cursor to the location of the next letter or symbol and then accept it. The cursor can only move to squares that are adjacent horizontally or vertically (never diagonally). Once every letter has been entered, you must move the cursor to 'enter' and accept the whole phrase.

Write a program that computes the number of cursor movements needed to "type in" a phrase. For example, to enter the word "GPS" starting from 'A', you move down 1 to select 'G', then right 3 and down 1 to select 'P', then down 1 and left 3 to select 'S', and finally down 1 and right 5 to select 'enter'. That is a total of 15 cursor movements. The total number of movements is the same whether you move vertically then horizontally or horizontally then vertically. Note also that you cannot move beyond the boundaries of the grid: you can neither move off the grid nor wrap around it.

Input

The input is a single string of at most 40 characters. You may assume that every character in the string appears somewhere in the grid.

Output

Output a single integer: the total number of cursor movements needed to enter the string using the given grid layout.