#include <bits/stdc++.h>
using namespace std;
int i,lu,dx[10]= {1,-1},dy[10]= {0,0,1,-1},co1,co2,ans,l,c,L,C,j,cst[5][20];
char a[5][20],st[200];
bool mrk[5][20];
queue<pair<int,int> >q;
pair<int,int> A,B,AA;
int main()
{
   /// ifstream f ("a.in");
  ///  ofstream g ("a.out");
    cin>>st;
    a[1][1]='Q';
    a[1][2]='W';
    a[1][3]='E';
    a[1][4]='R';
    a[1][5]='T';
    a[1][6]='Y';
    a[1][7]='U';
    a[1][8]='I';
    a[1][9]='O';
    a[1][10]='P';
    a[2][1]='A';
    a[2][2]='S';
    a[2][3]='D';
    a[2][4]='F';
    a[2][5]='G';
    a[2][6]='H';
    a[2][7]='J';
    a[2][8]='K';
    a[2][9]='L';
    a[3][1]='Z';
    a[3][2]='X';
    a[3][3]='C';
    a[3][4]='V';
    a[3][5]='B';
    a[3][6]='N';
    a[3][7]='M';
    lu=strlen(st);
    q.push({2,4});
    q.push({2,7});
    for(i=0; i<lu; ++i)
    {
        for(l=1; l<=3; ++l)
            for(c=1; c<=10; ++c)
                if(st[i]==a[l][c])
                {
                    L=l;
                    C=c;
                    break;
                }
        A=q.front();
        AA=A;
        q.pop();
        B=q.front();
        q.pop();
        q.push(A);
        while(!q.empty())
        {
            A=q.front();
            q.pop();
            for(j=0; j<4; ++j)
            {
                if(A.first+dx[j]==0||A.first+dx[j]==4||A.second+dy[j]==0||A.second+dy[j]==11)continue;
                if(!mrk[A.first+dx[j]][A.second+dy[j]])mrk[A.first+dx[j]][A.second+dy[j]]=true,cst[A.first+dx[j]][A.second+dy[j]]=cst[A.first][A.second]+1,q.push({A.first+dx[j],A.second+dy[j]});

            }
        }
        cst[AA.first][AA.second]=0;
        co1=cst[L][C];
        memset(cst,0,sizeof(cst));
        memset(mrk,0,sizeof(mrk));
        q.push(B);
        while(!q.empty())
        {
            A=q.front();
            q.pop();
            for(j=0; j<4; ++j)
            {
                if(A.first+dx[j]==0||A.first+dx[j]==4||A.second+dy[j]==0||A.second+dy[j]==11)continue;
                if(!mrk[A.first+dx[j]][A.second+dy[j]])mrk[A.first+dx[j]][A.second+dy[j]]=true,cst[A.first+dx[j]][A.second+dy[j]]=cst[A.first][A.second]+1,q.push({A.first+dx[j],A.second+dy[j]});

            }
        }
        cst[B.first][B.second]=0;
        co2=cst[L][C];
        memset(cst,0,sizeof(cst));
        memset(mrk,0,sizeof(mrk));
        if(co1<co2)q.push({L,C}),q.push(B),ans+=co1;
        else q.push(AA),q.push({L,C}),ans+=co2;
    }
    cout<<ans;
    return 0;}