#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353LL;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, r = 0LL;
  string s;
  cin >> n >> s;
  int i = 1, j = n - 2;
  while (i < n && s[i] == s[0]) i++;
  while (j >= 0 && s[j] == s[n - 1]) j--;
  if (i <= j || abs(i - j) == 1) {
    r = (long long)i + (long long)(n - j - 1);
    r %= mod;
    if (s[0] == s[n - 1]) {
      r += (long long)i * (long long)(n - j - 1);
    }
    r++;
    r %= mod;
  } else {
    r = 1LL + n + n * (n - 1) / 2;
    r %= mod;
  }
  cout << r;
  return 0;
}
