func_code_string: #include <bits/stdc++.h>   using namespace std;   int D[1 << 20], cnt[20][20];   bool chk[1 << 20];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int N, M;     queue<int> Q;     string s;     cin >> N >> M >> s;     for (int i = 1; i < N; i++)       if (s[i - 1] != s[i]) {         cnt[s[i - 1] -  a ][s[i] -  a ]++;         cnt[s[i] -  a ][s[i - 1] -  a ]++;       }     memset(D, 0x7f, sizeof(D));     chk[0] = true;     D[0] = 0;     Q.push(0);     while (!Q.empty()) {       int b = Q.front(), bc = __builtin_popcount(b) + 1;       Q.pop();       for (int i = 0; i < M; i++)         if (~b & (1 << i)) {           int diff = 0;           for (int j = 0; j < M; j++) {             if (b & (1 << j))               diff += bc * cnt[i][j];             else               diff -= bc * cnt[i][j];           }           D[b | (1 << i)] = min(D[b | (1 << i)], D[b] + diff);           if (!chk[b | (1 << i)]) {             chk[b | (1 << i)] = true;             Q.push(b | (1 << i));           }         }     }     cout << D[(1 << M) - 1] <<   n ;     return 0;   }   