#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, l = 0, r = 0;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    if (s[i] == s[0])
      ++l;
    else
      break;
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == s[n - 1])
      ++r;
    else
      break;
  }
  if (s[0] != s[n - 1])
    cout << (l + r + 1) % 998244353;
  else
    cout << (l + r + l * r + 1) % 998244353;
}
