you password type string s length n every character string m lowercase Latin lettersSince spend lot time typing want buy new keyboardA keyboard permutation m latin letter for example m 3 possible keyboard abc acb bac bca cab cbasince type password finger need spend time move finger password character the time character s_i character s_i1 equal distance character keyboard the total time spend type password keyboard call slowness keyboardmore formaly slowness keyboard equal sumlimits_i2n pos_s_i1 pos_s_i pos_x position letter x keyboardFor example s aacabc keyboard bac total time type password pos_a pos_a pos_a pos_c pos_c pos_a pos_a pos_b pos_b pos_c 2 2 2 3 3 2 2 1 1 3 0 1 1 1 2 5before buy new keyboard want know minimum possible slowness keyboard