Processing math: 100%

Problem #307

Eloquent

Alice is very confident about her Vocabulary, according to her lively words are those which contain only characters A,B,C and the frequency of each of them should be the same. Alice has a word \textit{S} of 1999998 characters (A,B,C each occur 666666 times). Now Bob has a word \textit{T} (which is lively as well) and he wants to know the minimum number of moves he needs to make in order to change the word from S to T in the worst case (irrespective of the words S and T). In a single move Bob can only swap neighboring letters. Report the answer divided 2 modulo 1000000007.

Contributed by Ashutosh Singh

Solved by 44 users

Log in to submit answers.

Is something wrong?

Maintaining a collection of high quality questions is our top priority. If, however, you do find an error, report the problem and we'll make sure it is reviewed soon.