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