#include <bits/stdc++.h>
using namespace std;
void read(vector<long long> &v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i];
}
void print(vector<long long> v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
}
long long n, m, a, b, temp, x, y;
string str;
set<long long> s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  cin >> str;
  long long ans = 1;
  set<char> pr;
  set<char> su;
  pr.insert(str[0]);
  su.insert(str[n - 1]);
  vector<long long> push_back(n, 0);
  vector<long long> sb(n, 0);
  push_back[0] = 1;
  sb[n - 1] = 1;
  for (int i = 1; i < n; i++) {
    pr.insert(str[i]);
    if (pr.size() == 1)
      push_back[i] = 1;
    else
      break;
  }
  for (int i = n - 2; i >= 0; i--) {
    su.insert(str[i]);
    if (su.size() == 1)
      sb[i] = 1;
    else
      break;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      for (int j = 1; j < n; j++)
        if (sb[j] == 1) {
          ans += n - j;
          break;
        }
      continue;
    }
    if (push_back[i - 1] != 1) break;
    int index = lower_bound(sb.begin() + i + 1, sb.end(), 1) - sb.begin();
    ans++;
    if (index == n) continue;
    if (str[index] == str[i - 1]) ans += (n - index) % 998244353;
  }
  cout << ans % 998244353;
}
