There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'.

Each second, you may perform one of the following operations:


	Move the pointer one character counterclockwise or clockwise.
	Type the character the pointer is currently on.


Given a string word, return the minimum number of seconds to type out the characters in word.

&nbsp;
Example 1:

Input: word = "abc"
Output: 5
Explanation: 
The characters are printed as follows:
- Type the character 'a' in 1 second since the pointer is initially on 'a'.
- Move the pointer clockwise to 'b' in 1 second.
- Type the character 'b' in 1 second.
- Move the pointer clockwise to 'c' in 1 second.
- Type the character 'c' in 1 second.


Example 2:

Input: word = "bza"
Output: 7
Explanation:
The characters are printed as follows:
- Move the pointer clockwise to 'b' in 1 second.
- Type the character 'b' in 1 second.
- Move the pointer counterclockwise to 'z' in 2 seconds.
- Type the character 'z' in 1 second.
- Move the pointer clockwise to 'a' in 1 second.
- Type the character 'a' in 1 second.


Example 3:

Input: word = "zjpc"
Output: 34
Explanation:
The characters are printed as follows:
- Move the pointer counterclockwise to 'z' in 1 second.
- Type the character 'z' in 1 second.
- Move the pointer clockwise to 'j' in 10 seconds.
- Type the character 'j' in 1 second.
- Move the pointer clockwise to 'p' in 6 seconds.
- Type the character 'p' in 1 second.
- Move the pointer counterclockwise to 'c' in 13 seconds.
- Type the character 'c' in 1 second.


&nbsp;
Constraints:


	1 &lt;= word.length &lt;= 100
	word consists of lowercase English letters.


class Solution:
    def minTimeToType(self, word: str) -> int:
        prev = "a"
        res = 0
        for c in word:
            gap = abs(ord(c)-ord(prev))
            res += min(gap, 26 - gap)
            prev = c
        return res + len(word)
class Solution {
    public int minTimeToType(String word) {
        char prevChar = 'a';
        int totalTime = word.length();
        for(int i = 0; i < word.length(); i++){
            char currChar = word.charAt(i);
            int diff = Math.abs(currChar - prevChar);
            totalTime += Math.min(diff, 26 - diff);
            prevChar = currChar;
        }
        
        return totalTime;
    }
}
class Solution {
public:
    int minTimeToType(string word) {
        int res = word.size(), point = 'a';
        for (auto ch : word) {
            res += min(abs(ch - point), 26 - abs(point - ch));
            point = ch;
        }
        return res;
    }
};
var minTimeToType = function(word) {
  let ops = 0;
  let cur = 'a';
  
  for(const char of word) {
    const diff = Math.abs(cur.charCodeAt(0) - char.charCodeAt(0));
    if(diff > 13) {
      ops += 26 - diff + 1;
    } else {
      ops += diff + 1;
    }
    
    cur = char;
  }
  
  return ops;
};
Minimum Time to Type Word Using Special Typewriter