#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  char t;
  int front, back, i;
  for (i = 0; i < n; i++)
    if (s[i] != s[0]) break;
  front = i;
  if (front == n) {
    cout << ((long long)n) * (n - 1) / 2;
    exit(0);
  }
  t = s[n - 1];
  for (i = n - 2; i >= 0; i--)
    if (t != s[i]) break;
  back = n - i - 1;
  long long ans = 0;
  ans += (front) % 998244353;
  ans += ((back) % 998244353);
  ans += 1;
  if (s[0] == s[n - 1]) {
    ans += ((front * (long long)back) % 998244353);
  }
  cout << ans % 998244353 << endl;
}
