#include <bits/stdc++.h>
long long int mod = 998244353;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, c = 1, n;
  cin >> t;
  n = t;
  string s;
  cin >> s;
  if (t == 2) {
    cout << "3";
    return 0;
  }
  while (s[t - 1] == s[t - 2]) {
    c++;
    t = t - 1;
  }
  long long j = 0, d = 1;
  while (s[j] == s[j + 1]) {
    d++;
    j++;
  }
  if (s[0] != s[t - 1]) {
    cout << (c + d) + 1;
  } else if (d != n) {
    cout << (c + 1) * (d + 1) % mod;
  } else {
    cout << n * (n + 1) / 2;
  }
  return 0;
}
