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]$.

Difficulty: interview

Starter code:

Solutions:
input()
s = input()
r1 = 1
f = s[0]
for c in s:
	if c != f:
		break
	r1 += 1
r2 = 1
p = s[-1]
for c in s[::-1]:
	if c != p:
		break
	r2 += 1
if f == p:
	print((r1 * r2) % 998244353)
else:
	print((r1 + r2 - 1) % 998244353)


n = int(input())
s = input()
a = s[0]
b = s[-1]
x = 0
while s[x] == a:
    x+=1
y = n-1
while s[y] == b:
    y-=1
x+=1
y = n-y
if a == b:
    print(x*y%998244353)
else:
    print(x+y-1)

def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())

n = ii()
s = input().strip()

x = 0
while s[0] == s[x]:
    x += 1
y = 0
while s[-1] == s[n - 1 - y]:
    y += 1

if s[0] == s[-1]:
    ans = (x + 1) * (y + 1)
else:
    ans = x + y + 1
print(ans % 998244353)


n = int(input())
s = input()

count_begin = 0
count_end = 0
i = 0
while(s[i] == s[0]):
    count_begin += 1
    i += 1
i = -1
while(s[i] == s[-1]):
    count_end += 1
    i -= 1
if s[0] == s[-1]:
    print((count_begin+1)*(count_end+1)%998244353 )
else:
    print((count_begin+count_end+1)%998244353)


#      
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 )





n = int(input())
s = input()
l = 1
while l < n and s[l] == s[l - 1]:
    l += 1
r = 1
while l < n and s[-r - 1] == s[- r]:
    r += 1
ans = 0
if s[0] != s[-1]:
    ans = l + r + 1
elif l == n:
    ans = n * (n + 1) // 2
else:
    ans = (l + 1) * (r + 1)
ans %= 998244353
print(ans)

n = int(input())
s = input()
k = 0
ans = 0
if s[n-1] != s[0]:
    while k < n and s[k] == s[0]:
        k += 1
    ans = k
    k = 0
    while n-1-k >= 0 and s[n-1-k] == s[n-1]:
        k += 1
    ans += k
else:
    kl ,kr = 0, 0
    while kl < n and s[kl] == s[0]:
        kl += 1
    while n-1-kr >= 0 and s[n-1-kr] == s[0]:
        kr += 1
    if kl == n:
        ans = n*(n+1)//2
    else:
        ans = kl * kr + kl + kr
print((ans+1) % 998244353)
        


n=int(input())
s=input()
ans=0
k1,k2=0,-1
for i in range(1,n):
	if s[i]!=s[0]:
		k1=i
		break
for i in range(n-2,-1,-1):
	if s[i]!=s[-1]:
		k2=i
		break
if s[0]==s[-1]:
	ans=(k1+1)*(n-k2)
else:
	ans+=k1+n-k2-1
	ans+=1
print(ans%998244353)


n=int(input())
s=list(input())
prev=s[0]
counter=0
for item in s:
    if item==prev:
        counter+=1
        
    else:
        break
s.reverse()
counter1=0
prev1=s[0]
for item in s:
    if item==prev1:
        counter1+=1
        
    else:
        break
if prev==prev1:
    print((counter+1)*(counter1+1)%998244353)
else:
    print(counter+counter1+1%998244353)


n = int(input())
s = input()
MOD = 998244353
pre = s[0]
num1, num2 = 1, 1
for i in range(1, n):
    if pre != s[i]:
        break
    num1 += 1

sur = s[-1]
for i in range(n - 2, -1, -1):
    if sur != s[i]:
        break
    num2 += 1

num1, num2 = num1 + 1, num2
if pre == sur:
    print(num1 * (num2 + 1) % MOD)
else:
    print((num1 + num2) % MOD)

n=int(input())
s=input()
a=1
x=s[0]
for i in range(1,n):
    if s[i]==x:a+=1
    else: break
b=1
x=s[-1]
for i in range(n-2,-1,-1):
    if s[i]==x:b+=1
    else: break
o=a+b+1
if s[0]==s[-1]:o+=a*b
print(o%998244353)

import sys

input = sys.stdin.readline
mod=998244353

n=int(input())
S=input().strip()

ANS=1
for s in ("abcdefghijklmnopqrstuvwxyz"):
    if s==S[0] or s==S[-1]:
        for i in range(n):
            if S[i]!=s:
                break
        l=i

        for i in range(n-1,-1,-1):
            if S[i]!=s:
                break
        r=i
        ANS=(ANS+(l+1)*(n-r)-1)%mod

    #print(s,l,r,ANS)

print(ANS)
            




def mi():
    return list(map(int, input().split()))
'''
7
aacdeee
'''
n = int(input())
s = list(input())

i,c1 = 0,1
while i+1<n and s[i+1]==s[i]:
    c1+=1
    i+=1

i = n-1
c2 = 1
while i-1>=0 and s[i-1]==s[i]:
    c2+=1
    i-=1

if s[0]!=s[-1]:
    print(c1+c2+1)
else:
    if c1==n:
        print((n*(n+1)//2)%998244353)
    else:
        print(((c1+1)*(c2+1))%998244353)


n = int(input())
s = input()
MOD = 998244353
left = 0
right = 0
right_1 = 0
a, b, c = True, True, True
i = 0
while (a or b or c) and i < n:
    if a and s[i] == s[0]:
        left += 1
    else:
        a = False
    if b and s[-i-1] == s[0]:
        right += 1
    else:
        b = False
    if c and s[-i-1] == s[-1]:
        right_1 += 1
    else:
        c = False
    i += 1
if right != 0:
    print((1+left*right+left+right) % MOD)
else:
    print((1+left+right_1) % MOD)


n = int(input())
S = input()

n = 0
m = 0
p = 998244353

for s in S:
    if s != S[0]:
        break
    n += 1

for s in S[::-1]:
    if s != S[-1]:
        break
    m += 1

ans = (n+1) * (m+1) if S[0] == S[-1] else n + m + 1
print(ans % 998244353)

n=int(input())
s=input()
left=0
right=len(s)-1
itog=0
while (left<n-1) and (s[left+1]==s[left]):
    left+=1
while (right>0) and s[right-1]==s[right]:
    right-=1
if (left<right) and (s[0]!=s[n-1]):
    itog+=(left+1)+1+(len(s)-right)
    print(itog%998244353)
elif (left<right) and (s[0]==s[n-1]):
    itog+=((left+1)+1)*(n-right+1)
    print(itog%998244353)
else:
    itog=n*(n-1)//2+n
    print(itog%998244353)

mod = 998244353

n = int(input())
a = list(input())

ans = 0

l = 1
while l < n and a[l] == a[0]:
    l += 1

r = n - 1
while r >= 0 and a[r] == a[-1]:
    r -= 1

if l == n:
    cur = 1
    for i in range(n):
        cur *= (n - i)
        cur //= i + 1
        ans += cur
        ans %= mod
    print(ans)
    return

r = n - r - 1
if a[0] == a[-1]:
    ans += (l + 1) * (r + 1) % mod
else:
    ans += l + r + 1
    ans %= mod
print(ans)


#!/usr/bin/env python3
import sys

def rint():
    return list(map(int, sys.stdin.readline().split()))
#lines = stdin.readlines()

n = int(input())

s = (input())

l_cnt = 1
for i in range(1, n):
    if s[i] == s[0]:
        l_cnt += 1
    else:
        break
r_cnt = 1
for i in range(n-2, -1, -1):
    if s[i] == s[-1]:
        r_cnt += 1
    else:
        break

if l_cnt == n:
    print((n*(n+1)//2)%998244353)
    return

if s[0] == s[-1]:
    print((l_cnt+1)*(r_cnt+1)%998244353)
    return

print(1 + r_cnt + l_cnt)


# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import itertools
import sys

"""
created by shhuan at 2018/12/28 22:46

"""

MOD = 998244353
N = int(input())
S = input()
rem = {S[0], S[-1]}

ans = 0
for v in rem:
    l, r = 0, N-1
    while l < N and S[l] == v:
        l += 1

    while r >= 0 and S[r] == v:
        r -= 1

    if l > r:
        ans += N*(N-1) // 2
        ans %= MOD
    else:
        ans += (l+1) * (N-r)
        ans %= MOD
ans = (ans + MOD - len(rem) + 1) % MOD
print(ans)

import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

mod = 998244353
n = int(input())
s = input()
if s == s[0]*n:
    print(n*(n+1)//2)
    return
g = gb(s)
gg = gb(s[::-1])
a = 0
a_c,b_c = '',''
b = 0
for k,v in g:
    a = len(list(v))
    a_c = k
    break
for k,v in gg:
    b = len(list(v))
    b_c = k
    break
res = 0
if a_c == b_c:
    res += a * b
res += a + b + 1
print(int(res)%mod)


length = int(input())
s = input()

i = 0
j = -1
while s[i] == s[0]:
    i += 1

while s[j] == s[-1]:
    j -= 1

j += 1
j = int(abs(j))

if s[0] == s[-1]:
    print(((i+1)*(j+1))%998244353)
else:
    print((i+j+1)%998244353)

n = int(input())
s = input()

mod = 998244353

left = s[0]
right = s[-1]

ans = 1  # include remove all

if left != right:
    lcount = 0
    for i in range(n):
        if s[i] == left:
            lcount += 1
        else:
            break
    rcount = 0
    for i in reversed(range(n)):
        if s[i] == right:
            rcount += 1
        else:
            break
    ans += lcount + rcount
    print(ans % mod)
else:
    lcount = 0
    for i in range(n):
        if s[i] == left:
            lcount += 1
        else:
            break
    rcount = 0
    for i in reversed(range(n)):
        if s[i] == right:
            rcount += 1
        else:
            break
    if lcount == len(s):
        print((n * (n - 1) // 2 + n)%mod)
    else:
        print((rcount + 1) * (lcount + 1) % mod)

n = int(input())
seq = input()

hurufdpn = seq[0]
hurufblkg = seq[-1]

jmldpn = 0
jmlblkg = 0

last = seq[0]
for s in seq:
    if s == last:
        jmldpn += 1
    else:
        break

last = seq[-1]
for s in seq[::-1]:
    if s == last:
        jmlblkg += 1
    else:
        break

tengah = n - jmldpn - jmlblkg
if tengah < 0:
    print(((1 + n) * n // 2) % 998244353)
else:
    ans = jmldpn + jmlblkg + 1
    if hurufdpn == hurufblkg:
        ans += 1 + (jmlblkg - 1) + (jmldpn - 1) + (jmldpn - 1) * (jmlblkg - 1)
    print(ans % 998244353)


n = int(input())
s = input()

curr_left = s[0]
curr_right = s[-1]
s_left = 0
s_right = 0
i = 0
while curr_left == s[i]:
    s_left +=1
    i+=1
i = len(s)-1
while curr_right == s[i]:
    s_right +=1
    i+=-1

if curr_left == curr_right:
    print((s_left+1)*(s_right+1)%998244353)
else:
    print((s_left + s_right + 1)%998244353)

# alpha = "abcdefghijklmnopqrstuvwxyz"
prime = 998244353
t = 1#int(input())
from heapq import heappop, heappush
for test in range(t):
    n = int(input())
    # n,m = (map(int, input().split()))
    s = input()
    # ans = 1
    # start = 1
    # cur = s[0]
    # tmp = 0
    # while s[start]==cur:
    #     start+=1
    #     tmp+=1
    # end = n-1
    # tmp = 1
    # while s[end]==cur:
    #     end-=1
    #     tmp+=1
    grp = []
    cnt = []
    tmp = 0
    cur = s[0]
    for i in s:
        if i==cur:
            tmp+=1
        else:
            grp.append(cur)
            cnt.append(tmp)
            cur = i
            tmp = 1
    grp.append(cur)
    cnt.append(tmp)
    if len(grp)==1:
        print(((n*(n+1))//2)%prime)
    else:
        if grp[0]==grp[-1]:
            ans = ((cnt[0]+1)*(cnt[-1]+1))%prime
            # print("here", ans)
            # if cnt[0]+cnt[-1]==n-1:
            #     ans-=1
            #     ans = ans%prime
            print(ans)
        else:
            ans = cnt[0]+1+cnt[-1]
            ans = ans%prime
            # if cnt[0]+cnt[-1]==n-1:
            #     ans-=1
            #     ans = ans%prime
            print(ans)