#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long inf = 1e17;
const long long N = 1e5 + 5;
bool prime[N];
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long cf = 1;
  long long cl = 1;
  for (long long i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      cf++;
    } else
      break;
  }
  for (long long i = n - 1; i >= 1; i--) {
    if (s[i] == s[i - 1])
      cl++;
    else
      break;
  }
  if (cf == n) {
    cout << ((n * (n - 1)) / 2 + 1) % mod << endl;
  } else {
    if (s[0] == s[n - 1]) {
      cout << ((cf + cl + 1 + (cf * cl))) % mod << endl;
    } else {
      cout << cf + cl + 1 << endl;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return (0);
}
