#include <bits/stdc++.h>
using namespace std;
long long INF = (long long)1e15;
const int maxn = (long long)2e6;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
int power(int x, unsigned int y, unsigned int m) {
  if (y == 0) return 1;
  int p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
void solve() {
  int n;
  cin >> n;
  string s1;
  cin >> s1;
  long long l = 1, r = 1;
  long long ways = 1;
  int i;
  for (i = 1; i < n; ++i) {
    if (s1[i] == s1[i - 1])
      l++;
    else
      break;
  }
  ways += l;
  int j;
  for (j = n - 2; j >= 1; --j) {
    if (s1[j] == s1[j + 1])
      r++;
    else
      break;
  }
  ways += r;
  ways %= 998244353;
  if (s1[0] == s1[n - 1]) {
    ways += ((r - 1) * l);
    ways %= 998244353;
    ways += l;
  }
  ways %= 998244353;
  cout << ways << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int t = 1;
  while (t--) {
    solve();
    cout << endl;
  }
}
