Under construction

Still being built. Things may change

Cell-Phone Messaging

Interview

Time limit1sMemory limit128 MB

Summary
Given words, compute the typing time on a phone keypad where each press takes 1 second and switching between letters on the same key adds a 2-second pause.
Level

Easy3 of 10

Topics
Implementation, String, Simulation, Math
Solved
No attempts yet

Problem

To fit the 26 letters of the alphabet onto a cell-phone keypad, several letters share each numeric key:

KeyLetters
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 type a letter you press its key repeatedly: the first letter on a key takes one press, the second takes two presses, the third takes three, and so on. For example, a is one press of key 2, and dada is typed as 3232 (four presses).

When two consecutive letters are on the same key, you must wait for a time-out before entering the second one so the phone knows a new letter has started. For example, abba is entered as 2 pause 22 pause 22 pause 2, and www is entered as 9 pause 9 pause 9.

Each key press takes 1 second, and each time-out (pause) costs an additional 2 seconds. Given a word, compute the minimum number of seconds needed to type it.

Input

Each line contains one word made up of lowercase letters only; every word has at most 20 characters. Input stops when the word halt is read. The word halt is a sentinel and must not be processed.

Output

For each word that appears before halt, print on its own line the minimum number of seconds needed to type that word.

Examples1

  1. Example 1

    Input
    a
    dada
    bob
    abba
    cell
    www
    halt
    
    Expected output
    1
    4
    7
    12
    13
    7