#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long l = s.length();
  bool visit[256];
  memset(visit, false, sizeof(visit));
  int dis = 0, i;
  for (i = 0; i < l; i++) {
    if (!visit[s[i]]) {
      visit[s[i]] = true;
      dis++;
    }
  }
  if (dis == 1) {
    cout << ((l * (l + 1)) / 2) % 998244353;
    return 0;
  }
  int s_cnt = 1, e_cnt = 1;
  i = 1;
  int j = l - 2;
  for (; i < l; i++) {
    if (s[i] == s[0])
      s_cnt++;
    else
      break;
  }
  for (; j >= 0; j--) {
    if (s[j] == s[n - 1])
      e_cnt++;
    else
      break;
  }
  if (s[0] != s[l - 1]) {
    cout << (e_cnt + s_cnt + 1) % 998244353;
  } else {
    cout << (long long)((long long)(s_cnt + 1) % 998244353 *
                        (long long)(e_cnt + 1) % 998244353) %
                998244353;
  }
  return 0;
}
