#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
const int MOD = 998244353;
int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  int cnt = 1, cnt2 = 1, cur = n - 2;
  while (s[cnt] == s[cnt - 1] && cnt < n) cnt++;
  if (cnt == n) cnt2 = 0;
  while (cur >= 0 && s[cur] == s[cur + 1] && cur >= cnt) cur--, cnt2++;
  long long ans = cnt + 1 + cnt2;
  ans %= MOD;
  if (s[0] == s[n - 1]) {
    int idx = -1, idx2 = -1;
    for (int i = 0; i < n; i++) {
      if (s[i] != s[n - 1] && idx == -1) idx = i + 1;
      if (s[i] != s[n - 1]) idx2 = i + 1;
    }
    if (idx != -1) {
      ans += cnt2;
      ans %= MOD;
      for (int i = 1; i < n; i++) {
        if (s[i] != s[0]) break;
        ans += cnt2;
        ans %= MOD;
      }
    } else
      ans = (n * (n + 1)) / 2, ans %= MOD;
  }
  cout << ans << endl;
}
