Wrong output on input


#1

wrong output on input
INPUT : 2 ababba abba
expected output : 8
output : 21
ababba => babbaa => bbaaba => ababba => baabab => bbaaba => bbaaba => baabab => ababba
abba => bbaa => aabb => baab => baab => aabb => bbaa => abba => abba