#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
string s;
vector<long long> v;
char cp;
long long cnt, n;
int main() {
  cin >> n >> s;
  cp = s[0];
  for (int i = 0; i < n; i++) {
    if (s[i] == cp)
      cnt++;
    else
      v.push_back(cnt), cnt = 1, cp = s[i];
  }
  v.push_back(cnt);
  if (v.size() == 1)
    cout << ((1ll * (n + 1) * n) / 2) % mod;
  else if (v.size() == 2)
    cout << (v[0] + 1 + v[v.size() - 1]) % mod;
  else if (s[0] == s[n - 1])
    cout << (1ll * (v[0] + 1) * (v[v.size() - 1] + 1)) % mod;
  else
    cout << ((v[0] + 1) + (v[v.size() - 1])) % mod;
  return 0;
}
