#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MAXN = 500005;
template <typename T>
void read(T &x) {
  T flag = 1;
  char ch = getchar();
  for (; '0' > ch || ch > '9'; ch = getchar())
    if (ch == '-') flag = -1;
  for (x = 0; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  x *= flag;
}
int n;
char s[MAXN];
int dis[MAXN][8];
int Dis[8][8];
bool vis[MAXN];
vector<int> vec[MAXN];
bool mark[MAXN];
int lst[MAXN];
int msk[MAXN];
int ans;
int cnt[8][1 << 8];
queue<int> q;
int main() {
  memset(dis, 0x3f, sizeof(dis));
  memset(Dis, 0x3f, sizeof(Dis));
  read(n);
  scanf("%s", s + 1);
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) vec[j].clear(), mark[j] = false;
    for (int j = 1; j <= n; j++) {
      vis[j] = false;
      if (s[j] - 'a' == i) {
        vis[j] = true;
        q.push(j);
        dis[j][i] = 0;
        mark[i] = true;
      } else {
        lst[s[j] - 'a'] = 0;
        vec[s[j] - 'a'].push_back(j);
      }
    }
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      if (x > 1 && !vis[x - 1]) {
        vis[x - 1] = true;
        dis[x - 1][i] = dis[x][i] + 1;
        q.push(x - 1);
      }
      if (x < n && !vis[x + 1]) {
        vis[x + 1] = true;
        dis[x + 1][i] = dis[x][i] + 1;
        q.push(x + 1);
      }
      if (!mark[s[x] - 'a']) {
        mark[s[x] - 'a'] = true;
        for (auto y : vec[s[x] - 'a']) {
          if (!vis[y]) {
            vis[y] = true;
            dis[y][i] = dis[x][i] + 1;
            q.push(y);
          }
        }
      }
    }
  }
  for (int i = 0; i < 8; i++) {
    for (int j = 1; j <= n; j++) {
      if (s[j] == i + 'a') {
        for (int k = 0; k < 8; k++) {
          Dis[i][k] = min(Dis[i][k], dis[j][k]);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 8; j++) {
      msk[i] += ((dis[i][j] - Dis[s[i] - 'a'][j]) << j);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = max(i - 16, 1); j < i; j++) {
      int now = i - j;
      for (int k = 0; k < 8; k++) {
        now = min(now, dis[i][k] + dis[j][k] + 1);
      }
      ans = max(ans, now);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i > 17) {
      cnt[s[i - 17] - 'a'][msk[i - 17]]++;
      for (int j = 0; j < 8; j++) {
        for (int k = 0; k < (1 << 8); k++) {
          if (cnt[j][k]) {
            int now = 0x3f3f3f3f;
            for (int l = 0; l < 8; l++) {
              now = min(now, dis[i][l] + Dis[j][l] + ((k >> l) & 1) + 1);
            }
            ans = max(ans, now);
          }
        }
      }
    }
  }
  printf("%d ", ans);
  long long num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = max(i - 16, 1); j < i; j++) {
      int now = i - j;
      for (int k = 0; k < 8; k++) {
        now = min(now, dis[i][k] + dis[j][k] + 1);
      }
      if (ans == now) num++;
    }
  }
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    if (i > 17) {
      cnt[s[i - 17] - 'a'][msk[i - 17]]++;
      for (int j = 0; j < 8; j++) {
        for (int k = 0; k < (1 << 8); k++) {
          if (cnt[j][k]) {
            int now = 0x3f3f3f3f;
            for (int l = 0; l < 8; l++) {
              now = min(now, dis[i][l] + Dis[j][l] + ((k >> l) & 1) + 1);
            }
            if (now == ans) num += cnt[j][k];
          }
        }
      }
    }
  }
  printf("%lld\n", num);
  return 0;
}
