f='qwertyuiopasdfghjkl zxcvbnm'.find
g=lambda i:sum(abs(f(x)%10-f(y)%10)+2*abs(f(x)/10-f(y)/10)for x,y in zip(i,i[1:]))
def main():
print "qwer =>",g("qwer")
print "qsx =>",g("qsx")
print "qmq =>",g("qmq")
print "tttt =>",g("tttt")
if __name__ == '__main__':
main()
Zj0ncXdlcnR5dWlvcGFzZGZnaGprbCB6eGN2Ym5tJy5maW5kCmc9bGFtYmRhIGk6c3VtKGFicyhmKHgpJTEwLWYoeSklMTApKzIqYWJzKGYoeCkvMTAtZih5KS8xMClmb3IgeCx5IGluIHppcChpLGlbMTpdKSkKCmRlZiBtYWluKCk6CglwcmludCAicXdlciA9PiIsZygicXdlciIpCglwcmludCAicXN4ICA9PiIsZygicXN4IikKCXByaW50ICJxbXEgID0+IixnKCJxbXEiKQoJcHJpbnQgInR0dHQgPT4iLGcoInR0dHQiKQoJCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CgltYWluKCk=