#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long a = 1, as = -1;
  for (long long i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      a++;
    else {
      as = i;
      break;
    }
  }
  if (as == -1) {
    long long ans = n * (n + 1);
    ans /= 2;
    cout << ans << endl;
    return 0;
  }
  long long b = 1, bs = -1;
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == s[i + 1])
      b++;
    else {
      bs = i;
      break;
    }
  }
  long long ans = a + b;
  if (s[0] != s[n - 1]) {
    if (a == 1 && b == 1) {
      cout << 3 << endl;
    } else {
      cout << a + b + 1 << endl;
    }
    return 0;
  } else {
    a++;
    b++;
    long long ans = a * b;
    ans %= mod;
    cout << ans << endl;
  }
  return 0;
}
