#include #define ll long long #define x first #define y second using namespace std; string s; int rs; string a[5] = {"QWERTYUIOP","ASDFGHJKL.","ZXCVBNM..."}; pair co[300]; bool u = 0; char c1, c2; int main() { for (int i = 0; i < 3; i++) for (int j = 0; j < a[i].size(); j++) co[a[i][j]] = {i, j}; c1 = 'F', c2 = 'J'; getline(cin, s); for (int i = 0; i < s.size(); i++) { u = 0; int minn = (abs(co[s[i]].x - co[c1].x) + abs(co[s[i]].y - co[c1].y)); if (abs(co[s[i]].x - co[c2].x) + abs(co[s[i]].y - co[c2].y) < minn) { u = 1; minn = abs(co[s[i]].x - co[c2].x) + abs(co[s[i]].y - co[c2].y); } if (!u) c1 = s[i]; else c2 = s[i]; rs += minn; } cout << rs; return 0; }