#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 9;
const int MAX = 100007;
const int H = 1 << 9;
int n;
int letter[MAX][N];
int dist[N][N];
int ch[MAX];
vector<int> l[N];
bool checked[N];
int mask[MAX];
int cnt[N][H];
void BFS(int x) {
  vector<int> vis(n, 0);
  queue<int> bfs;
  for (int i = 0; i < 8; ++i) {
    checked[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    letter[i][x] = (int)1e9 + 7;
    if (ch[i] == x) {
      vis[i] = 1;
      bfs.push(i);
      letter[i][x] = 0;
    }
  }
  while (!bfs.empty()) {
    int v = bfs.front();
    bfs.pop();
    if (v && !vis[v - 1]) {
      vis[v - 1] = 1;
      letter[v - 1][x] = letter[v][x] + 1;
      bfs.push(v - 1);
    }
    if (v + 1 < n && !vis[v + 1]) {
      vis[v + 1] = 1;
      letter[v + 1][x] = letter[v][x] + 1;
      bfs.push(v + 1);
    }
    if (!checked[ch[v]]) {
      checked[ch[v]] = 1;
      for (auto& u : l[ch[v]]) {
        if (!vis[u]) {
          vis[u] = 1;
          letter[u][x] = letter[v][x] + 1;
          bfs.push(u);
        }
      }
    }
  }
}
int FindDist(int x, int y) {
  int res = abs(x - y);
  for (int i = 0; i < 8; ++i) {
    res = min(res, 1 + letter[x][i] + letter[y][i]);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    ch[i] = s[i] - 'a';
  }
  for (int i = 0; i < 8; ++i) {
    for (int j = 0; j < n; ++j) {
      if (ch[j] == i) {
        l[i].push_back(j);
      }
    }
  }
  for (int i = 0; i < 8; ++i) {
    BFS(i);
  }
  for (int i = 0; i < 8; ++i) {
    for (int j = 0; j < 8; ++j) {
      dist[i][j] = (int)1e9 + 7;
      for (auto& v : l[i]) {
        dist[i][j] = min(dist[i][j], letter[v][j]);
      }
    }
  }
  int maxxx = 2 * 8 - 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 8; ++j) {
      int temp = letter[i][j] - dist[ch[i]][j];
      assert(temp < 2);
      mask[i] |= temp << j;
    }
  }
  pair<long long, long long> result = make_pair(0, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = max(0, i - maxxx); j < i; ++j) {
      int d = FindDist(i, j);
      if (d > result.first) {
        result.first = d;
        result.second = 1;
      } else if (d == result.first) {
        result.second++;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int c = 0; c < 8; ++c) {
      for (int m = 0; m < 1 << 8; ++m) {
        if (cnt[c][m]) {
          int temp = (int)1e9 + 7;
          for (int d = 0; d < 8; ++d) {
            temp = min(temp, 1 + dist[c][d] + ((m >> d) & 1) + dist[ch[i]][d] +
                                 ((mask[i] >> d) & 1));
          }
          if (temp > result.first) {
            result.first = temp;
            result.second = cnt[c][m];
          } else if (temp == result.first) {
            result.second += cnt[c][m];
          }
        }
      }
    }
    if (i - maxxx >= 0) {
      int z = i - maxxx;
      cnt[ch[z]][mask[z]]++;
    }
  }
  cout << result.first << " " << result.second;
  return 0;
}
