#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const long long INFll = 1e18;   const int INFint = 1e9;   const long long MOD = 1e9 + 7;   void needForSpeed() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool isPrime(long long a) {     if (a < 2) return 0;     for (long long i = 2; i <= sqrt(a); i++)       if (a % i == 0) return 0;     return 1;   }   long long binpow(long long base, long long pow, long long mod = INFll) {     if (pow == 0)       return 1;     else if (pow % 2)       return base * binpow(base, pow - 1, mod) % mod;     else {       long long p = binpow(base, pow / 2LL, mod);       return p * p % mod;     }   }   template <class T>   void PR_VEC(const vector<T> &vec) {     cout <<  size(  << vec.size() <<  ):[   ;     if (vec.size() == 0) {       cout <<  !EMPTY!  ] n ;       return;     }     cout << vec[0] <<    ;     for (int i = 1; i < vec.size(); ++i) cout <<   ,    << vec[i] <<    ;     cout <<   ] n ;   }   int solve() {     long long n, m, ans;     cin >> n >> m;     string s;     cin >> s;     ans = n * (m - 1LL);     for (int i = 1; i < n; ++i) {       if (s[i] != s[i - 1]) ans += n * (m - 1LL);     }     int len = 1;     for (int i = 1; i < n; ++i) {       if (len == 1) {         if (s[i] != s[i - 1]) {           len = 2;         } else {           continue;         }       } else {         if (s[i] != s[i - 2]) {           ans -= (len * (len - 1LL)) / 2LL;           if (s[i] == s[i - 1])             len = 1;           else             len = 2;         } else {           ++len;         }       }     }     ans -= (len * (len - 1LL)) / 2LL;     cout << ans;     return 0;   }   int main() {     needForSpeed();     int tests = 1;     while (tests--) {       solve();     }     return 0;   }   