pre to store the count of two-character prefixes (XY) before each index.suf to store the count of two-character suffixes (YX) after each index.cnts to store the count of each digit in the string.pre array with the count of prefixes before each index.suf array with the count of suffixes after each index.pre and suf arrays for each combination and add to the result.