Rotary Dial
InterviewTime limit1sMemory limit128 MB
Given an uppercase word, map each letter to its phone digit and sum the dial times, where digit d costs d+1 seconds and 0 costs 11.
- Level
Easy3 of 10
- Topics
- Implementation, String, Hash map
- Solved
- No attempts yet
Problem
Sang-geun's grandmother uses an old rotary dial telephone like the one shown below.

To dial a number, you press the digit you want and then turn the dial clockwise until it reaches the metal pin. Pressing a digit returns the dial to its starting position, so to dial the next digit you must turn it again from the start.
Dialing the digit takes seconds. Dialing a digit larger than takes more time: each position further along adds second. In other words, dialing digit takes seconds, and sits one position past , so it takes seconds.
Sang-geun's grandmother memorizes phone numbers as the letters that correspond to each digit. On the dial, letters map to digits as follows.
To dial a word, you dial the digit for each letter in order. For example, UNUCIC corresponds to .
Given the word your grandmother memorized, write a program that finds the minimum time needed to dial this phone number.
Input
The first line contains a word made up of uppercase letters only. The length of the word is between and , inclusive.
Output
Print the minimum time, in seconds, needed to dial the phone number for the given word.