#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long a = 0;
  long long b = 0;
  for (long long i = 0; i < n; ++i) {
    if (s[i] == s[0])
      ++a;
    else
      break;
  }
  for (long long i = n - 1; i >= 0; --i) {
    if (s[i] == s[n - 1])
      ++b;
    else
      break;
  }
  long long x2 = n - 1;
  if (a == n) {
    cout << (n * (n - 1) / 2 + n) % 998244353;
    return 0;
  }
  if (s[0] == s[n - 1]) {
    cout << (a + 1) * (b + 1) % 998244353;
  } else {
    cout << (a + b + 1) % 998244353 << endl;
  }
  return 0;
}
