#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] == s[n - 1]) {
    char a = s[0];
    char b = s[n - 1];
    long long x = 0, y = 0;
    for (int i = 0; s[i] == a; i++) {
      x++;
    }
    for (int i = n - 1; s[i] == b; i--) {
      y++;
    }
    cout << ((x + 1) * (y + 1)) % mod;
  } else {
    char a = s[0];
    char b = s[n - 1];
    long long x = 0, y = 0;
    for (int i = 0; s[i] == a; i++) {
      x++;
    }
    for (int i = n - 1; s[i] == b; i--) {
      y++;
    }
    cout << (x + y + 1) % mod;
  }
  return 0;
}
