//https://www.nowcoder.com/questionTerminal/20082c12f1ec43b29cd27c805cd476cd

#include <map>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    map<char,int> inputTime = {     //字母按几次
            {'a',1},{'b',2},{'c',3},
            {'d',1},{'e',2},{'f',3},
            {'g',1},{'h',2},{'i',3},
            {'j',1},{'k',2},{'l',3},
            {'m',1},{'n',2},{'o',3},
            {'p',1},{'q',2},{'r',3},{'s',4},
            {'t',1},{'u',2},{'v',3},
            {'w',1},{'x',2},{'y',3},{'z',4}
        };
    map<char,int> keyMap = {        //字母在哪个按键上
        {'a',2},{'b',2},{'c',2},
        {'d',3},{'e',3},{'f',3},
        {'g',4},{'h',4},{'i',4},
        {'j',5},{'k',5},{'l',5},
        {'m',6},{'n',6},{'o',6},
        {'p',7},{'q',7},{'r',7},{'s',7},
        {'t',8},{'u',8},{'v',8},
        {'w',9},{'x',9},{'y',9},{'z',9}
    };
    string str;
    while (cin>>str)
    {
        int lastinput=1;                //记录上次的按键
        int time=0;
        for (int i = 0; i < str.size(); i++)//遍历字符串
        {
            //判断是否要等待
            if (lastinput==keyMap[str[i]])
            {
                time+=2;//等待2s
            }
            time+=inputTime[str[i]];//输入一个字母用时
            lastinput=keyMap[str[i]];//记录按键
        }
        cout<<time<<endl;
    }
    return 0;
} 

王道的思路