func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long INFLL = 1e18 + 1;   const int MAX = 100001;   const long long MOD = 1000000007;   const int SZ = 300100;   const double PI = 3.14159265358979323846264338327;   long long inq(long long k, long long q, long long mod) {     if (q == 0) return 1;     long long l = inq(k, q / 2, mod);     if (q % 2 == 0)       return l * l % mod;     else       return l * l % mod * k % mod;   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   long long cubr(long long a) {     long long l = -1, r = 1e6 + 2;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (mid * mid * mid > a)         r = mid;       else         l = mid;     }     return l;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) { return -1 * max(-a, -b); }   long long possible(long long q) {     if (q == INF) return -1;     return q;   }   bool correct(int x, int xx) {     if (x < 0) return 0;     if (x >= xx) return 0;     return 1;   }   long long dsumm(long long x, long long k) {     long long y = 1;     long long z = 0;     for (int i = 0; y < 1e18; i += 1) {       z += x / y % k;       y *= k;     }     return z;   }   long long dcount(long long x) {     long long y = 1;     long long z = 0;     int c[100];     for (int i = 0; i < 10; i += 1) c[i] = 0;     for (int i = 0; x > 0; i += 1) {       if (c[x / y % 10] == 0) z++;       c[x / y % 10] = 1;       x /= 10;     }     return z;   }   long long lg10(long long x) {     if (10000 <= x && x < 100000) return 5;     if (x == 0) return 0;     return lg10(x / 10) + 1;   }   long long g(long long x, long long mod) {     if (x == 0) return 0;     return x / mod + g(x / mod, mod);   }   bool is_digit(char c) { return ( 0  <= c && c <=  9 ); }   string s;   int n, p;   int a[50][50];   int b[3000000];   int marks[(1 << 17)][20][20];   int r[3000000];   int dp[3000000];   int len[3000000];   int cnt[50];   void mark(int mask, int i, int j) {     if (marks[mask][i][j] == 0) return;     marks[mask][i][j] = 0;     for (int k = 0; k < p; k++) {       if (((1 << k) & mask) == 0 && k != i && k != j) {         int m2 = (mask + (1 << k));         if (marks[m2][i][j] == 1) mark(m2, i, j);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> p;     cin >> s;     for (int(i) = 0; (i) != (n); i += 1) b[i] = s[i] -  a ;     for (int(i) = 0; (i) != (n); i += 1) cnt[b[i]]++;     for (int i = 0; i < p; i++) {       for (int j = 0; j < p; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < (1 << p); i++) {       r[i] = 1;       for (int j = 0; j < p; j++) {         for (int k = 0; k < p; k++) {           marks[i][j][k] = 1;         }       }     }     for (int i = 0; i < p; i++) {       for (int j = 0; j < p; j++) {         if (a[i][j] == 0) {           long long calc = 0;           long long mask = 0;           for (int k = 0; k < n; k++) {             if (b[k] == j) {               if (calc == 1) {                 mark(mask, i, j);               }               calc = 0;               mask = 0;             }             if (b[k] == i) {               calc = 1;               mask = 0;             }             if (b[k] != i && b[k] != j && calc == 1) mask |= (1 << b[k]);           }         }       }     }     for (int i = 0; i < (1 << p); i++) {       r[i] = 1;       for (int j = 0; j < p; j++) {         for (int k = 0; k < p; k++) {           r[i] = min(r[i], marks[i][j][k]);         }       }     }     dp[0] = 1;     int ans = n;     for (int i = 1; i < (1 << p); i++) {       for (int j = 0; j < p; j++) {         if (i & (1 << j)) {           int ii = i - (1 << j);           if (dp[ii] && r[i]) {             dp[i] = 1;             int first = n;             for (int k = 0; k < p; k++) {               if ((1 << k) & i) {                 first -= cnt[k];               }             }             ans = min(first, ans);           }         }       }     }     cout << ans;   }   