#include <bits/stdc++.h>
using namespace std;
using pl = pair<long long, long long>;
using vll = vector<long long>;
using mll = map<long long, long long>;
using vpl = vector<pl>;
long long mod = 998244353;
void solve() {
  long long n, flag = 0, leftans, rightans, ans;
  string s;
  cin >> n >> s;
  char start = s[0], end = s[n - 1];
  long long firstdiff = -1;
  long long lastdiff = n + 1;
  for (long long i = 0; i < n; i++) {
    if (s[i] != start) {
      firstdiff = i;
      break;
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (s[n - 1] != start) {
      flag = 1;
    }
    if (s[n - 1] != s[i]) {
      lastdiff = i;
      break;
    }
  }
  if (flag) {
    if (lastdiff != n + 1) rightans = (n - 1 - lastdiff) % mod;
    if (firstdiff != -1) leftans = (firstdiff) % mod;
    ans = leftans + rightans + 1;
  } else {
    if (firstdiff != -1) ans = ((firstdiff + 1) * (n - lastdiff)) % mod;
  }
  if (firstdiff == -1) {
    cout << ((n * (n + 1)) / 2) % mod << "\n";
  } else {
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
