I recently solved this very interesting problem while practicing for the upcoming Usaco competition in two weeks. Here is a link to the problem if you would like to read it for yourself. In summary, the problem gives you a string s, and asks you to return the sum of the number of occurrences of…