#include #include #include using namespace std; int dist(int a, int b, int c, int d) { return abs(a - c) + abs(b - d); } pair < int, int > v[300]; char c[105], n; int ans = 0, xs, ys, xd, yd; int main() { v['Q'] = {1, 1}; v['W'] = {1, 2}; v['E'] = {1, 3}; v['R'] = {1, 4}; v['T'] = {1, 5}; v['Y'] = {1, 6}; v['U'] = {1, 7}; v['I'] = {1, 8}; v['O'] = {1, 9}; v['P'] = {1, 10}; v['A'] = {2, 1}; v['S'] = {2, 2}; v['D'] = {2, 3}; v['F'] = {2, 4}; xs = 2; ys = 4; v['G'] = {2, 5}; v['H'] = {2, 6}; v['J'] = {2, 7}; xd = 2; yd = 7; v['K'] = {2, 8}; v['L'] = {2, 9}; v['Z'] = {3, 1}; v['X'] = {3, 2}; v['C'] = {3, 3}; v['V'] = {3, 4}; v['B'] = {3, 5}; v['N'] = {3, 6}; v['M'] = {3, 7}; cin.getline(c, 103); n = strlen(c); for (int i = 0; i < n; ++ i) if (dist(xs, ys, v[c[i]].first, v[c[i]].second) < dist(xd, yd, v[c[i]].first, v[c[i]].second)) { ans += dist(xs, ys, v[c[i]].first, v[c[i]].second); xs = v[c[i]].first; ys = v[c[i]].second; } else if (dist(xs, ys, v[c[i]].first, v[c[i]].second) >= dist(xd, yd, v[c[i]].first, v[c[i]].second)) { ans += dist(xd, yd, v[c[i]].first, v[c[i]].second); xd = v[c[i]].first; yd = v[c[i]].second; } cout << ans; return 0; }