Keyboard
Keyboard
It contains only one row of 26-keys, keys[], each key indicates a unique letter
in the alphabet from 'a' to 'z' in the given order.
NOTE: You need to press only one key at a time to type the word.
INPUT FORMAT:
-------------
Line-1: A string S, consists of order of the keys in the keyboard.
Line-2: A string W, the word to be typed.
OUTPUT FORMAT:
--------------
Print an integer result, the time taken to type the word.
SAMPLE INPUT-1:
---------------
abcdefghijklmnopqrstuvwxyz
SAMPLE OUTPUT-1:
----------------
code
EXPLANATION:
------------
Given word is "code"
- Time taken to type letter-c: from keys[0] to keys[2] => | 0 - 2 | = 2
- Time taken to type letter-o: from keys[2] to keys[14] => | 2 - 14 | = 12
- Time taken to type letter-d: from keys[14] to keys[3] => | 14 - 3 | = 11
- Time taken to type letter-e: from keys[3] to keys[4] => | 3 - 4 | = 1
Total time taken is : 26
SAMPLE INPUT-2:
---------------
poiuytrewqasdfghjklmnbvcxz
kmit
SAMPLE OUTPUT-2:
----------------
39
EXPLANATION:
------------
Given word is "kmit"
- Time taken to type letter-k: from keys[0] to keys[17] => | 0 - 17 | = 17
- Time taken to type letter-m: from keys[17] to keys[19] => | 17 - 19 | = 2
- Time taken to type letter-i: from keys[19] to keys[2] => | 20 - 2 | = 17
- Time taken to type letter-t: from keys[2] to keys[5] => | 2 - 5 | = 3
Total time taken is : 39
case =2
input =abcdefghijklmnopqrstuvwxyz
code
output =26
case =3
input =qazwsxedcrfvtgbyhnujmikolp
confirmation
output =117
case =4
input =qwertyuiopasdfghjklmnbvcxz
adobeconnect
output =154
case =5
input =mlpnkojibhuvgycftxdrzseawq
telescope
output =104
case =6
input =asdfghjklpoiuytrewqzxcvbnm
keshavmemorialinstituteoftechnology
output =289
case =7
input =mnbvcxzlkjhgfdsapoiuytrewq
tessellatorforngitandkmit
output =207
case =8
input =poiuytrewqzxcvbasdfghjnmkl
abcdefghijklmnopqrstuvwxyz
output =178
-----------------------------------------------------------
n=input()
x=input()
res=n.index(x[0])
for i in range(len(x)-1):
res=res+abs(n.index(x[i])-n.index(x[i+1]))
print(res)