func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   inline void chmin(A &a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A &a, B b) {     if (a < b) a = b;   }   long long N, M;   string S;   signed main() {     cin >> N >> M >> S;     long long ans = 0;     vector<long long> cnt(M);     for (long long i = N - 1; i >= 0; i--) {       long long c = S[i] -  a ;       if (i + 1 < N && S[i] != S[i + 1]) {         ans += N - i - 1 - cnt[c];         ans += cnt[c] * (M - 1);         ans += (N - i - 1 - cnt[c]) * (M - 2);       }       cnt[c]++;     }     fill((cnt).begin(), (cnt).end(), 0ll);     vector<long long> st(N);     for (long long i = 0; i < N; i++) {       long long c = S[i] -  a ;       if (i && S[i - 1] != S[i]) {         st[i] = 1;         if (i >= 3 && S[i - 3] == S[i - 1] && S[i - 2] == S[i])           st[i] += st[i - 2];         ans += i - cnt[c] - st[i];         ans += cnt[c] * (M - 1);         ans += (i - cnt[c]) * (M - 2);         long long tmp = st[i] - 1;         if (i - st[i] * 2 >= 0 && S[i - st[i] * 2] == S[i]) tmp++;         ans -= tmp;       }       cnt[c]++;     }     ans += (M - 1) * N;     cout << ans << endl;     return 0;   }   