func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 300010, K = 18;   char s[N];   bool sm[K * K][N], b[N], vis[N];   int n, p, tot, ans, ss, w[K][K], mp[K][K], a[N], cnt[K], q[N];   int cal(int S) {     int res = 0;     for (int i = (1); i <= (p); i++)       if (S & (1 << (i - 1))) res += cnt[i];     return res;   }   void work(int x, int y, int k) {     int tot = 0;     for (int i = (1); i <= (n); i++)       if (s[i] -  a  + 1 == x || s[i] -  a  + 1 == y) a[++tot] = i;     for (int i = (1); i <= (tot - 1); i++)       if ((s[a[i]] -  a  + 1 == x && s[a[i + 1]] -  a  + 1 == y) ||           (s[a[i]] -  a  + 1 == y && s[a[i + 1]] -  a  + 1 == x)) {         int S = 0;         for (int j = (a[i] + 1); j <= (a[i + 1] - 1); j++) S |= 1 << (s[j] -  a );         S ^= ss;         sm[k][S] = 1;       }   }   int main() {     scanf( %d%d%s , &n, &p, s + 1);     ans = n + 1;     ss = (1 << p) - 1;     for (int i = (1); i <= (n); i++) cnt[s[i] -  a  + 1]++;     for (int i = (1); i <= (p); i++)       for (int j = (1); j <= (p); j++) scanf( %d , &mp[i][j]);     for (int i = (1); i <= (p); i++)       for (int j = (i); j <= (p); j++)         if (!mp[i][j]) w[i][j] = ++tot, work(i, j, tot);     for (int x = (1); x <= (tot); x++) {       for (int i = 1; i <= ss; i <<= 1)         for (int j = (1); j <= (ss); j++)           if (j & i) sm[x][j ^ i] |= sm[x][j];     }     for (int S = (0); S <= (ss); S++) {       b[S] = 1;       for (int i = (1); i <= (p); i++)         for (int j = (i); j <= (p); j++)           if (S & (1 << (i - 1)) && S & (1 << (j - 1)) && !mp[i][j] &&               sm[w[i][j]][S]) {             b[S] = 0;             break;           }     }     q[1] = ss;     vis[ss] = 1;     for (int st = 0, ed = 1; st != ed;) {       int S = q[++st];       ans = min(ans, cal(S));       for (int i = (1); i <= (p); i++) {         int S1 = S ^ (1 << (i - 1));         if (S & (1 << (i - 1)) && !vis[S1] && b[S1]) vis[S1] = 1, q[++ed] = S1;       }     }     printf( %d n , ans);     return 0;   }   