#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long cnt = 1;
  int j = 0;
  while (j + 1 < n && s[j + 1] == s[0]) {
    j++;
  }
  if (j == n - 1) {
    cout << (n * 1LL * (n + 1) / 2) % MOD;
    return;
  }
  cnt += j + 1;
  int k = n - 1;
  while (k > 0 && s[k - 1] == s[n - 1]) {
    k--;
  }
  cnt += n - k;
  if (s[0] == s[n - 1]) {
    cnt = (cnt + (j + 1) * 1LL * (n - k)) % MOD;
  }
  cout << cnt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  solve();
}
