Rotary Dial

Interview

Time limit1sMemory limit128 MB

Summary
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 11 takes 22 seconds. Dialing a digit larger than 11 takes more time: each position further along adds 11 second. In other words, dialing digit nn takes n+1n+1 seconds, and 00 sits one position past 99, so it takes 1111 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.

DigitLetters
2A, B, C
3D, E, F
4G, H, I
5J, K, L
6M, N, O
7P, Q, R, S
8T, U, V
9W, X, Y, Z

To dial a word, you dial the digit for each letter in order. For example, UNUCIC corresponds to 868242868242.

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 22 and 1515, inclusive.

Output

Print the minimum time, in seconds, needed to dial the phone number for the given word.

Examples2

  1. Example 1

    Input
    WA
    
    Expected output
    13
    
  2. Example 2

    Input
    UNUCIC
    
    Expected output
    36