func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, dist[8][8], dis[8][100010], lst[8], mask[100010], cnt[8][300], ans;   long long res;   char s[100010];   bool use[8];   queue<int> q;   int main() {     scanf( %d , &n);     scanf( %s , s);     for (int c = 0; c < 8; c++) lst[c] = -1;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) dist[i][j] = 0x3f3f3f3f;     for (int i = 0; i < n; i++) {       int now = s[i] -  a ;       lst[now] = i;       for (int c = 0; c < 8; c++)         if (lst[c] != -1)           dist[c][now] = dist[now][c] = min(dist[now][c], i - lst[c]);     }     for (int k = 0; k < 8; k++)       for (int i = 0; i < 8; i++)         for (int j = 0; j < 8; j++)           dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j] + 1);     for (int c = 0; c < 8; c++)       for (int i = 0; i < n; i++) dis[c][i] = 0x3f3f3f3f;     for (int c = 0; c < 8; c++) {       for (int i = 0; i < 8; i++) use[i] = false;       for (int i = 0; i < n; i++)         if (s[i] == c +  a ) q.push(i), dis[c][i] = 0;       while (!q.empty()) {         int u = q.front();         q.pop();         if (u > 0 && dis[c][u - 1] > dis[c][u] + 1) {           dis[c][u - 1] = dis[c][u] + 1;           q.push(u - 1);         }         if (u < n - 1 && dis[c][u + 1] > dis[c][u] + 1) {           dis[c][u + 1] = dis[c][u] + 1;           q.push(u + 1);         }         if (!use[s[u] -  a ]) {           for (int i = 0; i < n; i++)             if (s[i] == s[u] && dis[c][i] > dis[c][u] + 1) {               dis[c][i] = dis[c][u] + 1;               q.push(i);             }           use[s[u] -  a ] = true;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = max(i - 15, 0); j < i; j++) {         int p = i - j;         for (int c = 0; c < 8; c++) {           if (p > dis[c][i] + dis[c][j] + 1) p = dis[c][i] + dis[c][j] + 1;         }         if (p == ans) res++;         if (p > ans) ans = p, res = 1;       }       if (i >= 16) cnt[s[i - 16] -  a ][mask[i - 16]]++;       for (int c = 0; c < 8; c++) {         for (int opt = 0; opt < 256; opt++)           if (cnt[c][opt]) {             int p = 0x3f3f3f3f;             for (int j = 0; j < 8; j++) {               if (p > dis[j][i] + 1 + dist[j][c] + ((opt >> j) & 1))                 p = dis[j][i] + 1 + dist[j][c] + ((opt >> j) & 1);             }             if (p == ans) res += cnt[c][opt];             if (p > ans) ans = p, res = cnt[c][opt];           }       }       for (int c = 0; c < 8; c++)         mask[i] |= ((dis[c][i] - dist[c][s[i] -  a ]) << c);     }     cout << ans <<     << res << endl;     return 0;   }   