#include <bits/stdc++.h>
using namespace std;
int n, l, r;
string s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  for (int i = n - 1; s[n - 1] == s[i]; --i) r = i;
  for (int i = 0; s[0] == s[i]; ++i) l = i;
  if (s[0] == s[n - 1])
    cout << (1LL * (l + 2) * (n - r + 1)) % 998244353 << '\n';
  else
    cout << (n - r + 1) + l + 1 << '\n';
  return 0;
}
