#include <bits/stdc++.h>
using namespace std;
const long long p = 998244353;
long long n, l, r, ans;
char s[201000];
long long work(int x) {
  l = 1;
  r = n;
  long long cnt = 0;
  while (s[l] == s[1]) l++;
  l--;
  while (s[r] == s[n]) r--;
  r++;
  if (l > r) {
    cnt = (n + 1) * n / 2;
    return cnt % p;
  }
  if (x) {
    cnt = cnt + l - 1 + 2;
    cnt = cnt + n - r + 2;
    cnt--;
    return cnt;
  }
  cnt = (n - r + 2) * (l + 1) % p;
  return cnt;
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  if (s[1] == s[n])
    ans = work(0);
  else
    ans = work(1);
  printf("%I64d", ans);
  return 0;
}
