human
I found an interesting problem on https://codeforces.com/problemset/problem/1096/B:
You are given a string $s$ of length $n$ consisting only of lowercase Latin letters.

A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.

Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).

It is guaranteed that there is at least two different characters in $s$.

Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.

Since the answer can be rather large (not very large though) print it modulo $998244353$.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

-----Input-----

The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the string $s$.

The second line of the input contains the string $s$ of length $n$ consisting only of lowercase Latin letters.

It is guaranteed that there is at least two different characters in $s$.

-----Output-----

Print one integer — the number of ways modulo $998244353$ to remove exactly one substring from $s$ in such way that all remaining characters are equal.

-----Examples-----
Input
4
abaa

Output
6

Input
7
aacdeee

Output
6
Input
2
az

Output
3

-----Note-----

Let $s[l.
r]$ be the substring of $s$ from the position $l$ to the position $r$ inclusive.

Then in the first example you can remove the following substrings:   $s[1.
2]$.
 $s[1.
3]$.
 $s[1.
4]$.
 $s[2.
2]$.
 $s[2.
3]$.
 $s[2.
4]$. 

In the second example you can remove the following substrings:   $s[1.
4]$.
 $s[1.
5]$.
 $s[1.
6]$.
 $s[1.
7]$.
 $s[2.
7]$.
 $s[3.
7]$. 

In the third example you can remove the following substrings:   $s[1.
1]$.
 $s[1.
2]$.
 $s[2.
2]$.

I tried it in Python, but could not do it. Can you solve it?

 Give me a Python code to print one integer — the number of ways modulo $998244353$ to remove exactly one substring from $s$ in such way that all remaining characters are equal?
assistant
#Here is Python code to print one integer — the number of ways modulo $998244353$ to remove exactly one substring from $s$ in such way that all remaining characters are equal.

#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass


inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)
s = input()

for a in range(1,1000000):
    if s[a] !=s[0]:
        break
    
for b in range(N-2,-1,-1):
    if s[b] !=s[N-1]:
        break
dprint(a,b)
base = 998244353
if s[0] != s[N-1]:
    print( a + N - b )
else:
    print( (a+1) * (N-b) % base )