#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  if (n == 1) {
    cout << 1 << '\n';
    return 0;
  }
  ll l = 1, r = n - 2;
  while (s[l] == s[0]) l++;
  while (s[r] == s[n - 1]) r--;
  r++, l--;
  l += 1;
  r = n - r;
  if (s[0] == s[n - 1]) {
    cout << ((l * r) + 1 + l + r) % mod << '\n';
  } else {
    cout << ((l + r) + 1) % mod << '\n';
  }
  return 0;
}
