#include <bits/stdc++.h>
using namespace std;
const long long N = 200200;
const long long K = 26;
const long long Mod = 998244353;
char s[N];
vector<long long> v[K];
int main() {
  long long n;
  cin >> n;
  scanf("%s", s + 1);
  for (long long i = 1; i <= n; i++) s[i] -= 'a';
  for (long long i = 1; i <= n; i++) v[s[i]].push_back(i);
  long long Ans = 0;
  if (s[1] != s[n]) {
    for (long long i = 1; i <= n && s[i] == s[1]; i++) Ans++;
    for (long long i = n; i >= 1 && s[i] == s[n]; i--) Ans++;
    Ans++;
  } else {
    if (v[s[1]].size() == n) {
      Ans = n * (n + 1) / 2;
    } else {
      long long c1 = 1;
      long long c2 = 1;
      for (long long i = 1; i <= n && s[i] == s[1]; i++) c1++;
      for (long long i = n; i >= 1 && s[i] == s[n]; i--) c2++;
      Ans = c1 * c2;
    }
  }
  cout << Ans % Mod;
}
