#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  char end = s[n - 1], start = s[0];
  long long int count1 = 0, count2 = 0;
  while (s[count1] == start) {
    count1++;
  }
  int ptr = n - 1;
  while (s[ptr--] == end) {
    count2++;
  }
  if (s[0] == s[n - 1]) {
    count1++;
    count2++;
    long long int ans =
        (((count1) % 998244353) * ((count2) % 998244353) % 998244353);
    cout << ans;
    return (0);
  } else {
    long long int ans = count1 + count2 + 1;
    ans = ans % 998244353;
    cout << ans;
  }
}
