#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long i, j, k, ok, nr, n, m, el, min1, max1, x, y, a, b,xc1,xc2,yc1,yc2,cost; string s,tastatura[4]; pairv[30]; int main() { cin >> s; tastatura[1] = "qwertyuiop"; tastatura[2] = "asdfghjkl"; tastatura[3] = "zxcvbnm "; for (i = 1; i <= 3; i++) { for (j = 0; j <= 10 - 1; j++) { if (tastatura[i][j] != ' ') { v[tastatura[i][j] - 'a'].first = i; v[tastatura[i][j] - 'a'].second = j + 1; } } } xc1 = v['j' - 'a'].first; yc1 = v['j' - 'a'].second; xc2 = v['f' - 'a'].first; yc2 = v['f' - 'a'].second; for (i = 0; i <= s.size() - 1; i++) { s[i] += 32; x = v[s[i] - 'a'].first; y = v[s[i] - 'a'].second; if (abs(x - xc1) + abs(y - yc1) > abs(x - xc2) + abs(y - yc2)) { cost += abs(x - xc2) + abs(y - yc2); xc2 = x; yc2 = y; } else { cost += abs(x - xc1) + abs(y - yc1); xc1 = x; yc1 = y; } } cout << cost; return 0; }