def solve(self, cipher):
        N, M = cipher
        s = M
        if N > 1:
            s *= (M - 1)
        if N > 2:
            s *= pow(M - 2, N - 2, MOD)  # s *= self._exp(M-2, N-2)
            s %= MOD
        return s % MOD
Any palindrome, it has a sub-palindrome with length 2 or 3 pivoting at the center.
dataset/ETHPy150Open algorhythms/HackerRankAlgorithms/AntiPalindromic Strings.py/Solution.solve