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

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Combinatorics

Mathematics


Solutions:
n = int(input())
s = input()
st = 0
for i in s:
	if i == s[0]:
		st += 1
	else:
		break
en = 0
for i in s[::-1]:
	if i == s[-1]:
		en += 1
	else:
		break
if s[0] != s[-1]:
	print(en + st + 1)
else:
	t = (en + 1) * (st + 1)
	print(t % 998244353)


n = int(input())
s = input()
l = 0
r = n - 1
lc = None
rc = None
while not lc or (l < n and lc == s[l]):
	lc = s[l]
	l += 1
while not rc or (r > 0 and rc == s[r]):
	rc = s[r]
	r -= 1
mod = 998244353
if r == 0 and rc == s[r]:
	print(n * (n + 1) // 2 % mod)
elif lc != rc:
	print((l + n - r) % mod)
else:
	print((l + 1) * (n - r) % mod)


N = int(input())
inp = input()
ans = 1
first = 1
last = 1
ind = 0
while inp[ind] == inp[ind + 1]:
	ind += 1
	first += 1
ind = len(inp) - 1
while inp[ind] == inp[ind - 1]:
	ind -= 1
	last += 1
ans += first + last
if inp[0] == inp[-1]:
	ans += first * last
ans %= 998244353
print(ans)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
from collections import deque
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	s = str(input())
	group = [[k, len(list(g))] for (k, g) in itertools.groupby(s)]
	cnt = group[0][1] + group[-1][1]
	if group[0][0] == group[-1][0]:
		ans = (group[0][1] + 1) * (group[-1][1] + 1)
	else:
		ans = cnt + 1
	print(ans % 998244353)
main()


from sys import stdin

def from_start(string, n):
	char = string[0]
	i = 0
	while i < n - 1:
		if string[i] != char:
			break
		i += 1
	return i

def from_end(string, n):
	char = string[-1]
	i = n - 1
	while i > 0:
		if string[i] != char:
			break
		i -= 1
	return n - i - 1

def from_mid(string, first, second):
	if string[0] == string[-1] and len(string) > 2:
		start = first
		end = len(string) - second - 1
		if start <= end:
			third = start - 1
			third += n - 2 - end
			third += (start - 1) * (n - 2 - end)
			return third + 1
		else:
			return 0
	else:
		return 0
n = int(stdin.readline().strip())
string = list(stdin.readline().strip())
first = from_start(string, n)
second = from_end(string, n)
third = from_mid(string, first, second)
print((first + second + third + 1) % 998244353)


import sys
import math
import collections
inp = lambda : sys.stdin.readline()
m = 998244353

def pre(s):
	p = 1
	while p < len(s) and s[p - 1] == s[p]:
		p += 1
	return p

def suf(s):
	p = len(s) - 1
	ct = 0
	while p >= 0 and s[p] == s[-1]:
		p -= 1
		ct += 1
	return ct
n = int(input())
s = input()
c1 = pre(s)
c2 = suf([i for i in s])
if s[0] == s[-1]:
	print((c1 * c2 + c1 + c2 + 1) % m)
else:
	print((c1 + c2 + 1) % m)


n = int(input())
arr = list(input())
m = 998244353
t = 0
if n == 1:
	print(1)
while t < n - 1 and arr[t] == arr[t + 1]:
	t += 1
a = t + 1
t = n - 1
while t > 1 and arr[t - 1] == arr[t]:
	t -= 1
b = n - t
ans = 0
if a == n:
	ans = n * (1 + n) // 2
elif arr[0] == arr[n - 1]:
	ans = a * b + a + b + 1
else:
	ans = a + b + 1
print(ans % m)


n = int(input())
s = input()
prefix = 0
suffix = 0
mod = 998244353
for i in range(1, len(s)):
	if s[i] != s[0]:
		prefix = i
		break
for j in range(len(s) - 2, -1, -1):
	if s[j] != s[-1]:
		suffix = len(s) - 1 - j
		break
res = (prefix + 1 + suffix) % mod
if s[0] == s[-1]:
	res = (prefix + 1) * (suffix + 1) % mod
print(res)


n = int(input())
s = input()
i = j = 2
while s[i - 1] == s[0]:
	i += 1
while s[-j] == s[-1]:
	j += 1
if s[0] == s[-1]:
	print(i * j % 998244353)
else:
	print(i + j - 1 % 998244353)


n = int(input())
s = input()
mod = 998244353
s1 = ''
if s[0] == s[-1]:
	q1 = q2 = i = 1
	while i < n and s[i] == s[0]:
		q1 += 1
		i += 1
	i = n - 2
	while i > -1 and s[i] == s[0]:
		q2 += 1
		i -= 1
	print((q1 + 1) * (q2 + 1) % mod)
else:
	q1 = q2 = i = 1
	while i < n and s[i] == s[0]:
		q1 += 1
		i += 1
	i = n - 2
	while i > -1 and s[i] == s[-1]:
		q2 += 1
		i -= 1
	print((q1 + 1 + q2) % mod)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		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())
(N,) = getIntList()
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())
p = input()
(c1, c2) = (0, 0)
i = 0
while p[i] == p[0] and i < n:
	c1 += 1
	i += 1
i = n - 1
while p[i] == p[n - 1] and i >= 0:
	c2 += 1
	i -= 1
if c1 == n:
	print(n * (n - 1) // 2 % 998244353)
elif p[0] == p[n - 1]:
	print((c1 + 1) * (c2 + 1) % 998244353)
else:
	print((c1 + c2 + 1) % 998244353)


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)


import string
n = int(input())
s = input()
l = 0
for i in range(n):
	if s[i] != s[0]:
		break
	l += 1
r = 0
for i in range(n - 1, 0, -1):
	if s[i] != s[-1]:
		break
	r += 1
if s[0] == s[-1]:
	print((l + 1) * (r + 1) % 998244353)
else:
	print(l + r + 1)


n = int(input())
s = input()
ls = 0
rs = 0
for i in range(n):
	if s[i] == s[0]:
		ls += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if s[i] == s[n - 1]:
		rs += 1
	else:
		break
if s[0] == s[n - 1]:
	print((ls + 1) * (rs + 1) % 998244353)
else:
	print((ls + rs + 1) % 998244353)


n = int(input())
s = input()
cnt1 = 0
i = 0
while i + 1 < n:
	if s[i] == s[i + 1]:
		cnt1 += 1
		i += 1
	else:
		break
j = n - 1
cnt2 = 0
while j - 1 >= 0:
	if s[j] == s[j - 1]:
		cnt2 += 1
		j -= 1
	else:
		break
if s[0] == s[n - 1]:
	u = (cnt1 + 2) % 998244353 * ((cnt2 + 2) % 998244353) % 998244353
	print(u)
else:
	print((cnt2 + 1 + 1 + cnt1 + 1) % 998244353)


n = int(input())
s = str(input())
ans = 0
cntl = 0
cntr = 0
mod = 998244353
for i in range(n):
	if s[i] == s[0]:
		cntl += 1
	else:
		break
for i in range(n - 1, 0, -1):
	if s[n - 1] == s[i]:
		cntr += 1
	else:
		break
if s[0] == s[n - 1]:
	print((cntr + 1) * (cntl + 1) % mod)
else:
	print((cntr + cntl + 1) % mod)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	s = input()
	ans = 0
	if s[0] == s[-1]:
		(i, j) = (0, n - 1)
		while s[i] == s[0]:
			i += 1
		while s[j] == s[0]:
			j -= 1
		ans = (i + 1) * (n - j)
	else:
		(i, j) = (0, n - 1)
		while s[i] == s[0]:
			i += 1
		while s[j] == s[-1]:
			j -= 1
		ans += i + n - j
	print(ans % 998244353)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = input()
sf = s[0]
sl = s[-1]
f = 0
l = 0
ans = 0
if s.count(sf) != n:
	for i in range(n):
		if s[i] == sf:
			ans += 1
			f += 1
		else:
			ans += 1
			break
	for i in range(n)[::-1]:
		if s[i] == sl:
			ans += 1
			l += 1
		else:
			ans += 1
			break
	ans -= 1
	if sf == sl:
		ans += f * l
else:
	ans = n * (n + 1)
	ans //= 2
	ans += 1
print(ans % 998244353)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
s = input()
ans = 3
i = 1
while i < n and s[i] == s[i - 1]:
	i += 1
	ans += 1
s = s[::-1]
i = 1
while i < n and s[i] == s[i - 1]:
	i += 1
	ans += 1
left = 0
right = 0
s = s[::-1]
key = s[0]
i = 0
while s[i] == key:
	left += 1
	i += 1
s = s[::-1]
i = 0
while s[i] == key:
	right += 1
	i += 1
ans = ans % M + left % M * (right % M) % M
print(ans % M)


n = int(input())
s = input().strip()
m = 998244353
cnt1 = 0
tmp = 0
for i in range(n):
	if s[i] == s[0]:
		cnt1 += 1
	else:
		break
tail = s[n - 1]
cnt2 = 0
for i in range(n - 1, -1, -1):
	if s[i] == s[n - 1]:
		cnt2 += 1
	else:
		break
if s[0] != s[n - 1]:
	print((cnt1 + cnt2 + 1) % m)
elif cnt1 == n:
	print(int(n * (n + 1) / 2) % m)
else:
	print((cnt1 + 1) * (cnt2 + 1) % m)


n = int(input())
S = input()
(l, r) = (S[0], S[-1])
(x, y) = (0, n - 1)
while S[x] == l:
	x += 1
while S[y] == r:
	y -= 1
if l == r:
	print((x + 1) * (n - y) % 998244353)
else:
	print(x + n - y)


from sys import stdin, stdout
import math
MOD = 998244353
n = int(stdin.readline())
s = stdin.readline().strip()
n1 = 1
while n1 < len(s) and s[n1] == s[0]:
	n1 += 1
n2 = 1
while n2 < len(s) and s[-n2 - 1] == s[-1]:
	n2 += 1
if s[0] != s[-1]:
	stdout.write(str(1 + (n1 + n2) % MOD))
elif n1 == n:
	stdout.write(str((n * (n + 1) // 2 + 1) % MOD))
else:
	stdout.write(str((n1 + 1) * (n2 + 1) % MOD))


n = int(input())
s = input()
if s[0] == s[n - 1]:
	p = 0
	while p < n and s[p] == s[0]:
		p += 1
	q = 0
	while q < n and s[n - 1 - q] == s[n - 1]:
		q += 1
	res = (p + 1) * (q + 1) % 998244353
	print(res)
else:
	p = 0
	while p < n and s[p] == s[0]:
		p += 1
	res = p + 1
	if p < n:
		q = 0
		while q < n and s[n - 1 - q] == s[n - 1]:
			q += 1
		res += q + 1
	res -= 1
	print(res)


l = int(input())
word = input()
prefix_ct = 0
suffix_ct = 0
for i in range(0, l):
	if word[i] == word[0]:
		prefix_ct += 1
	else:
		break
for i in range(l - 1, -1, -1):
	if word[i] == word[-1]:
		suffix_ct += 1
	else:
		break
if prefix_ct + suffix_ct == 2 * l:
	print(l - 1)
if word[0] != word[-1]:
	print((suffix_ct + prefix_ct) % 998244353 + 1)
else:
	print((suffix_ct + 1) * (prefix_ct + 1) % 998244353)


n = int(input())
s = list(input())
ch = s[n - 1]
count1 = 0
count2 = 0
for i in range(n - 1, -1, -1):
	if ch == s[i]:
		count1 += 1
	else:
		break
ch = s[0]
for i in range(0, n):
	if ch == s[i]:
		count2 += 1
	else:
		break
mod = 998244353
if s[0] == s[n - 1]:
	ans = (count1 + 1) * (count2 + 1) % mod
else:
	ans = (count1 + count2 + 1) % mod
print(ans)


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


n = int(input())
st = input()
count = 0
count_right = 0
count_left = 0
for i in range(n):
	if st[i] != st[i + 1]:
		count_left += 1
		count += 1
		break
	else:
		count_left += 1
		count += 1
for i in reversed(range(n)):
	if st[i] != st[i - 1]:
		count += 1
		count_right += 1
		break
	else:
		count_right += 1
		count += 1
if st[0] != st[n - 1]:
	count += 1
else:
	count = (count_left + 1) * (count_right + 1)
print(count % 998244353)


import sys
n = int(input())
s = list(input())
count1 = 1
for i in range(0, n - 1, 1):
	if s[i] == s[i + 1]:
		count1 += 1
	else:
		break
if len(s) == count1:
	count = 0
	for i in range(1, n + 1):
		count += i
	print(count)
	print('!', count % 998244353)
	sys.exit()
count2 = 1
for i in range(n - 1, 0, -1):
	if s[i] == s[i - 1]:
		count2 += 1
	else:
		break
if s[0] == s[-1]:
	print((count1 + 1) * (count2 + 1) % 998244353)
elif s[0] != s[-1]:
	print((count1 + count2 + 1) % 998244353)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
n = int(input())
m = 998244353
s = input()[:-1]
x = 1
y = 1
for i in range(1, n):
	if s[i] == s[0]:
		x += 1
	else:
		break
for i in range(n - 2, -1, -1):
	if s[i] == s[-1]:
		y += 1
	else:
		break
if s[0] == s[-1]:
	print((x + y + x * y + 1) % m)
else:
	print((x + y + 1) % m)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		s = self.next()
		mod = 998244353
		l = 0
		while s[l] == s[0]:
			l += 1
		r = n - 1
		while s[r] == s[-1]:
			r -= 1
		if s[0] == s[-1]:
			print((l + 1) * (n - r) % mod)
		else:
			print(l + 1 + n - r - 1)
Main().solve()


def solve(n, s):
	l = 0
	r = 0
	left = s[0]
	right = s[-1]
	for i in range(n):
		if s[i] == left:
			l += 1
		else:
			break
	for j in range(n - 1, -1, -1):
		if s[j] == right:
			r += 1
		else:
			break
	if left == right:
		print((l + 1) * (r + 1) % 998244353)
	else:
		print((l + r + 1) % 998244353)
n = int(input())
s = input()
solve(n, s)


n = int(input())
s = input().strip()
lns = len(s)
rlel = [0, 0]
i = 0
back = s[i]
while back == s[i]:
	back == s[i]
	i += 1
rlel[0] = i
i = 0
s = s[::-1]
back = s[i]
while back == s[i]:
	back == s[i]
	i += 1
rlel[1] = i
sm = sum(rlel) + 1
if s[0] == s[-1]:
	sm += rlel[0] - 1 + rlel[-1] - 1
	sm += (rlel[0] - 1) * (rlel[1] - 1)
	sm += 1
print(sm % 998244353)


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()
l = 0
r = 0
tc = s[0]
s1 = ''
s2 = ''
for i in range(n):
	if s[i] == tc:
		l = i
		s1 += s[i]
	else:
		break
tc = s[n - 1]
for i in range(n - 1, -1, -1):
	if s[i] == tc:
		r = i
		s2 += s[i]
	else:
		break
l += 1
r = n - 1 - i
if s2[0] == s1[0]:
	ans = (l + 1) * (r + 1)
else:
	ans = l + r + 1
print(ans % 998244353)


import sys

def eprint(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def solve(s):
	start_len = 0
	end_len = 0
	s_char = s[0]
	for c in s:
		if c != s_char:
			break
		start_len += 1
	e_char = s[-1]
	for i in range(len(s) - 1, -1, -1):
		c = s[i]
		if c != e_char:
			break
		end_len += 1
	total = 0
	if s_char != e_char:
		total += start_len + 1
		total += end_len + 1
		total -= 1
	else:
		total += (start_len + 1) * (end_len + 1)
	return total

def main():
	N = int(input())
	s = input()
	print(solve(s) % 998244353)
main()


strLen = int(input())
string = input()
preLen = sufLen = 1
MODULO = 998244353
for i in range(1, strLen):
	if string[0] == string[i]:
		preLen += 1
	else:
		break
for i in range(2, strLen):
	if string[-1] == string[-i]:
		sufLen += 1
	else:
		break
if string[0] == string[-1]:
	solution = (preLen + 1) * (sufLen + 1)
else:
	solution = preLen + sufLen + 1
print(solution % MODULO)


n = int(input())
s = input()
start = s[0]
end = s[-1]
count_begin = 0
count_end = 0
for i in s:
	if i == start:
		count_begin += 1
	else:
		break
for i in reversed(s):
	if i == end:
		count_end += 1
	else:
		break
if start == end:
	print((count_end + 1 + count_begin * (count_end + 1)) % 998244353)
else:
	print((count_begin + count_end + 1) % 998244353)


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()
ans = 1
fi = s[0]
fil = 0
la = s[len(s) - 1]
lal = 0
for i in range(0, len(s)):
	if s[i] == fi:
		fil += 1
	else:
		break
for i in range(len(s) - 1, -1, -1):
	if s[i] == la:
		lal += 1
	else:
		break
ans += fil + lal
if fi == la:
	ans += fil * lal
ans %= 998244353
print(ans)


n = int(input())
s = list(input())
start_symbol = s[0]
start_k = 1
for i in range(1, n):
	if s[i] == start_symbol:
		start_k += 1
	else:
		break
if start_k == n:
	print((2 ** n - 1) % 998244353)
	exit()
else:
	end_symbol = s[n - 1]
	end_k = 1
	for i in range(n - 2, -1, -1):
		if s[i] == end_symbol:
			end_k += 1
		else:
			break
	if end_symbol != start_symbol:
		print((start_k + end_k + 1) % 998244353)
	else:
		print((start_k + 1) * (end_k + 1) % 998244353)


def check(a, b):
	if a < b:
		(a, b) = (b, a)
	ans = 0
	for i in range(2, a + b):
		if i <= b:
			ans += i - 1
		else:
			ans += min(b, a - (i - b) + 1)
	return ans
mod = 998244353
n = int(input())
s = input()
if n == 1:
	print(1)
elif len(set(s)) == 1:
	k = n * (n + 1) // 2
	print(k % mod)
else:
	f = 1
	r = 1
	for i in range(1, n):
		if s[i] != s[i - 1]:
			break
		f += 1
	for i in range(n - 2, -1, -1):
		if s[i] != s[i + 1]:
			break
		r += 1
	if s[0] != s[-1]:
		print((f + r + 1) % mod)
	else:
		print((f + r + 2 + check(f, r)) % mod)


import sys
input = sys.stdin.readline
n = int(input())
a = list(input().rstrip())
c = 0
s = set()
for i in range(n):
	s.add(a[i])
	if len(s) > 1:
		break
	c += 1
s = set()
flag = 0
d = 0
for i in range(n - 1, -1, -1):
	s.add(a[i])
	if len(s) > 1:
		flag = 1
		break
	d += 1
if flag == 0:
	print(n * (n - 1) // 2)
	exit(0)
s = list(s)
p = 0
if a[n - 1] == a[0] and c > 0 and (d > 0):
	p = c * d
print((c + d + p + 1) % 998244353)


n = int(input())
code = list(input())
frontnumber = 1
i = 0
while True:
	if i <= len(code) - 2 and code[i] == code[i + 1]:
		frontnumber += 1
		i += 1
	else:
		break
backnumber = 1
i = 0
while True:
	if i <= len(code) - 2 and code[-i - 1] == code[-i - 2]:
		backnumber += 1
		i += 1
	else:
		break
if not code[0] == code[-1]:
	total = frontnumber + backnumber + 1
else:
	total = (frontnumber + 1) * (backnumber + 1)
modtotal = total % 998244353
print(modtotal)


mod = 998244353
n = int(input())
s = input()
l = r = 1
for i in s:
	if i is s[0]:
		l += 1
	else:
		break
for i in reversed(s):
	if i is s[-1]:
		r += 1
	else:
		break
if s[0] is s[-1]:
	print(l * r % mod)
else:
	print((l + r - 1) % mod)


n = int(input())
s = input()
p = 1
for i in range(n):
	if s[i] != s[0]:
		p = 0
		break
if p == 1:
	print(n * (n + 1) // 2 % 998244353)
	exit(0)
l = 0
while s[l] == s[l + 1]:
	l += 1
g = 0
while s[n - g - 1] == s[n - g - 2]:
	g += 1
l += 1
g += 1
if s[0] == s[-1]:
	print((l + 1) * (g + 1) % 998244353)
else:
	print((l + 1 + g) % 998244353)


mod = 998244353
n = int(input())
s = list(input())
r = set(s)
if len(r) == 1:
	exit(print(n * (n + 1) // 2 % mod))
(i, j) = (1, n - 2)
while i < n and s[i] == s[i - 1]:
	i += 1
while j >= 0 and s[j] == s[j + 1]:
	j -= 1
j = n - 1 - j
if s[0] == s[-1]:
	ans = (i * j + i + j + 1) % mod
else:
	ans = (i + j + 1) % mod
print(ans)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
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)
	exit()
if s[0] == s[-1]:
	print((l_cnt + 1) * (r_cnt + 1) % 998244353)
	exit()
print(1 + r_cnt + l_cnt)


import os, sys, math
n = int(input())
s = sys.stdin.readline()[:-1]
mod = 998244353
i = 0
while i < len(s) and s[i] == s[0]:
	i += 1
j = len(s) - 1
while j >= 0 and s[j] == s[-1]:
	j -= 1
if s[0] == s[-1]:
	print((i + 1) * (len(s) - j) % mod)
else:
	print((i + len(s) - j) % mod)


n = int(input())
s = input().rstrip()
first_c = s[0]
first_n = 0
last_c = s[-1]
last_n = 0
for i in range(n):
	if s[i] == first_c:
		first_n += 1
	else:
		break
for i in reversed(range(n)):
	if s[i] == last_c:
		last_n += 1
	else:
		break
if first_c == last_c:
	ans = (first_n + 1) * (last_n + 1)
else:
	ans = first_n + 1 + (last_n + 1) - 1
print(ans % 998244353)


MOD = 998244353
I = lambda : list(map(int, input().split()))
(n,) = I()
s = input()
i = 1
ans = []
count = 1
while i < n:
	if s[i] == s[i - 1]:
		count += 1
	else:
		ans.append(count)
		count = 1
	i += 1
ans.append(count)
res = 0
res += ans[0] + ans[-1] + 1
if s[0] == s[-1]:
	x = min(ans[0], ans[-1])
	res += ans[0] * ans[-1]
print(res % MOD)


prime = 998244353
t = 1
from heapq import heappop, heappush
for test in range(t):
	n = int(input())
	s = input()
	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)
	elif grp[0] == grp[-1]:
		ans = (cnt[0] + 1) * (cnt[-1] + 1) % prime
		print(ans)
	else:
		ans = cnt[0] + 1 + cnt[-1]
		ans = ans % prime
		print(ans)


n = int(input())
s = input()
mod = int(998244353)

def total(k):
	k * (k + 1) // 2
if s[0] == s[n - 1]:
	(i, j) = (1, n - 2)
	while s[i] == s[0]:
		i += 1
	while s[j] == s[n - 1]:
		j -= 1
	if j >= i:
		print((1 + (n - 1 - j) + i + i * (n - 1 - j)) % mod)
	else:
		print(total(n) % mod)
else:
	(i, j) = (1, n - 2)
	while s[i] == s[0]:
		i += 1
	while s[j] == s[n - 1]:
		j -= 1
	if j >= i:
		ans = (2 + (n - 1 - j) + i - 1) % mod
		print(ans)
	else:
		ans = (2 + i + (n - 1 - j) - 1) % mod
		print(ans)


n = int(input())
s = str(input())
prefix = ''
suffix = ''
for i in range(0, n):
	if s[i] != s[0]:
		break
prefix = s[0:i]
for i in range(n - 1, -1, -1):
	if s[i] != s[n - 1]:
		break
suffix = s[i + 1:n]
if prefix == s:
	print(n * (n + 1) / 2 % 998244353)
elif s[0] == s[n - 1]:
	print((len(prefix) + 1) * (len(suffix) + 1) % 998244353)
else:
	print((len(prefix) + len(suffix) + 1) % 998244353)


import sys
input = sys.stdin.readline
n = int(input())
s = input().rstrip()
MOD = 998244353
i = 0
while i < n - 1 and s[i] == s[i + 1]:
	i += 1
left = i + 1
i = n - 1
while i > 0 and s[i] == s[i - 1]:
	i -= 1
right = n - i
if s[0] != s[-1]:
	print((left + 1 + (right + 1) - 1) % MOD)
else:
	print((left + 1) * (right + 1) % MOD)


mod = 998244353
n = int(input())
s = input()
(pc, sc) = (1, 1)
for i in range(1, n):
	if s[i] != s[i - 1]:
		break
	pc += 1
for i in range(n - 1, -1, -1):
	if s[i] != s[i - 1]:
		break
	sc += 1
if s[0] == s[-1]:
	print((pc + 1) * (sc + 1) % mod)
else:
	print((sc + pc + 1) % mod)


n = int(input())
s = input()
i = 0
c = 0
n = 0
d = 0
while s[i] == s[0]:
	c += 1
	i += 1
i = -1
while s[i] == s[-1]:
	n += 1
	i -= 1
if s[0] == s[-1]:
	d = 1
if d == 0:
	print((n + c + 1) % 998244353)
else:
	print((c * (n + 1) + (n + 1)) % 998244353)


n = int(input())
s = input()
current = s[0]
answer = 0
count = 0
for i in range(n):
	if s[i] == s[0]:
		count += 1
	else:
		break
answer += count
count2 = 0
for i in range(n - 1, -1, -1):
	if s[i] == s[-1]:
		count2 += 1
	else:
		break
answer += count2
if s[0] == s[-1]:
	answer += count2 * count
solution = (answer + 1) % 998244353
print(solution)


n = int(input())
k = input()
ans = 3
m = [0, 0]
if k[0] == k[1]:
	i = 1
	while k[0] == k[i]:
		m[0] += 1
		i += 1
		if i >= n:
			break
if k[n - 1] == k[n - 2]:
	i = 2
	while k[n - 1] == k[n - i]:
		m[1] += 1
		i += 1
		if i > n:
			break
if k[n - 1] == k[0]:
	ans += (m[1] + 1) * (m[0] + 1)
ans += m[0] + m[1]
ans = ans % 998244353
print(ans)


n = int(input())
s = input()
i = 0
j = 0
while s[i] == s[0]:
	i += 1
while s[n - 1 - j] == s[n - 1]:
	j += 1
ans = i + j + 1
if s[0] == s[n - 1]:
	ans += i * j
print(ans % 998244353)


(n, s) = (int(input()), input())
l = 1
while l < n:
	if s[l] != s[0]:
		break
	l += 1
ans = l + 1
r = n - 1
while r >= 0:
	if s[r] != s[n - 1]:
		break
	r -= 1
for i in range(r + 1, n):
	ch = s[i]
	if ch == s[0]:
		ans += l + 1
		ans = ans % 998244353
	else:
		ans += 1
		ans = ans % 998244353
print(ans)


n = int(input())
s = list(input())
c = [s[0]]
m = [s[-1]]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		c.append(s[i + 1])
	else:
		break
s.reverse()
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		m.append(s[i + 1])
	else:
		break
if s[0] != s[-1]:
	print((len(c) + len(m) + 1) % 998244353)
else:
	print((len(c) + 1) * (len(m) + 1) % 998244353)


n = int(input())
st = input()
l = 0
while st[l] == st[l + 1]:
	l += 1
r = n - 1
while st[r] == st[r - 1]:
	r -= 1
ans = l + 1 + (n - r) + 1
if st[r] == st[l]:
	ans += (l + 1) * (n - r)
print(ans % 998244353)


(n, s) = (int(input()), input())
l = 0
while l < n:
	if s[l] != s[0]:
		break
	l += 1
r = 0
while n - 1 - r >= 0:
	if s[n - 1 - r] != s[-1]:
		break
	r += 1
ans = l + r + 1
if s[0] == s[-1]:
	ans = (l + 1) * (r + 1) % 998244353
print(ans)


import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
left_count = 1
c = s[0]
for idx in range(1, n):
	if s[idx] != c:
		break
	else:
		left_count += 1
right_count = 1
c = s[-1]
for idx in range(n - 2, 0, -1):
	if s[idx] != c:
		break
	else:
		right_count += 1
c1 = left_count
c2 = right_count
if s[0] == s[-1]:
	c3 = left_count * right_count
else:
	c3 = 0
total = (1 + c1 + c2 + c3) % 998244353
print('{}'.format(total))


n = int(input())
str = input()
(s, e) = (str[0], str[-1])
cs = ce = 0
for c in str:
	if c != s:
		break
	cs += 1
for c in str[::-1]:
	if c != e:
		break
	ce += 1
if cs == ce == n and s == e:
	print(n)
elif s != e:
	print((cs + ce + 1) % 998244353)
else:
	print((cs + 1) * (ce + 1) % 998244353)


n = int(input())
s = input()
MOD = 998244353
if s == s[0] * n:
	print(n * (n + 1) // 2 % MOD)
	exit()
ans = 1
for i in range(1, n):
	if s[i] != s[0]:
		mark1 = i
		break
for i in range(n - 2, -1, -1):
	if s[i] != s[-1]:
		mark2 = i
		break
ans += mark1 + n - 1 - mark2
if s[0] == s[-1]:
	ans += mark1 * (n - 1 - mark2)
print(ans % MOD)


n = int(input())
a = input()
if len(set(a)) == 1:
	print((n * n + n) // 2)
else:
	start = 1
	end = 1
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			break
		else:
			start += 1
	for i in range(1, n):
		if a[-i] != a[-i - 1]:
			break
		else:
			end += 1
	if a[0] == a[-1]:
		print((start + 1) * (end + 1) % 998244353)
	else:
		print((start + end + 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()
mr = 0
fc = s[0]
ifc = 0
ml = n
lc = s[-1]
ilc = 0
for i in range(0, n):
	if s[i] == fc:
		ifc += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if s[i] == lc:
		ilc += 1
	else:
		break
if fc != lc:
	print((ilc + ifc + 1) % 998244353)
else:
	print((ilc + 1) * (ifc + 1) % 998244353)


n = int(input())
s = input()
pre = 0
suf = 0
while s[0] == s[pre]:
	pre += 1
while s[n - 1] == s[n - 1 - suf]:
	suf += 1
result = pre + suf + 1
if s[0] == s[n - 1]:
	result += pre * suf
result %= 998244353
print(result)


while True:
	try:
		n = int(input())
		s = input()
		fst = 1
		for i in range(1, n, 1):
			if s[i] == s[i - 1]:
				fst += 1
			else:
				break
		last = 1
		for i in range(n - 2, -1, -1):
			if s[i] == s[i + 1]:
				last += 1
			else:
				break
		if s[0] == s[-1]:
			print((fst + 1) * (last + 1) % 998244353)
		else:
			print((fst + last + 1) % 998244353)
	except EOFError:
		break


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)


l = int(input())
s = input()
s = list(s)
t = set(s)
if len(t) == len(s):
	print(3)
else:
	n = 1
	i = 0
	while i < l:
		if s[i] != s[0]:
			t1 = i
			n = n + t1
			break
		i = i + 1
	i = l - 1
	while i >= 0:
		if s[l - 1] != s[i]:
			t2 = l - i - 1
			n = (n + t2) % 998244353
			break
		i = i - 1
	if s[0] == s[-1]:
		n = (n + t1 * t2) % 998244353
	print(n % 998244353)


import sys
from itertools import groupby
from math import factorial
a = input()
s = input()
g = [(c, len(list(cgen))) for (c, cgen) in groupby(s)]
if g[0] is g[-1]:
	print(factorial(g[0][1]) % 998244353)
	sys.exit(0)
if g[0][0] == g[-1][0]:
	print((1 + g[0][1] * g[-1][1] + g[0][1] + g[-1][1]) % 998244353)
	sys.exit(0)
print((1 + g[0][1] + g[-1][1]) % 998244353)


n = int(input())
l = list(input())
mod = 998244353
pre = 1
post = 1
for i in range(n - 1):
	if l[i + 1] == l[i]:
		pre = (pre + 1) % mod
	else:
		break
for i in range(n - 1, 0, -1):
	if l[i] == l[i - 1]:
		post = (post + 1) % mod
	else:
		break
if l[0] == l[n - 1]:
	print((pre + 1) * (post + 1) % mod % mod)
else:
	print((pre % mod + post % mod + 1 % mod) % mod)


def tri(n):
	return n * (n + 1) // 2
from collections import Counter
input()
s = input()
ct = Counter(s)
ans = 0
if len(ct.most_common(3)) == 1:
	ans = tri(len(s))
else:
	left = 1
	right = 1
	lc = s[0]
	rc = s[-1]
	while s[left] == lc:
		left += 1
	while s[len(s) - 1 - right] == rc:
		right += 1
	if lc == rc:
		ans = (left + 1) * (right + 1)
	else:
		ans = left + right + 1
print(ans % 998244353)


n = int(input())
s = input()
if s[0] == s[-1]:
	col = 1
	cor = 1
	for i in range(n):
		if i + 1 < n and s[i] == s[i + 1]:
			col += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if i - 1 > -1 and s[i] == s[i - 1]:
			cor += 1
		else:
			break
	print((col + 1) * (cor + 1) % 998244353)
else:
	col = 1
	cor = 1
	for i in range(n):
		if i + 1 < n and s[i] == s[i + 1]:
			col += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if i - 1 > -1 and s[i] == s[i - 1]:
			cor += 1
		else:
			break
	print((col + cor + 1) % 998244353)


l = int(input())
s = input()
ans = 0
i = 1
while i < l:
	if s[i] != s[0]:
		break
	i += 1
j = l - 2
while j >= 0:
	if s[j] != s[-1]:
		break
	j -= 1
if s[0] != s[-1]:
	ans = i + 1 + l - j
	print((ans - 1) % 998244353)
else:
	ans = (i + 1) * (l - j)
	print(ans % 998244353)


modu = 998244353
n = int(input())
s = input()
fans = 0
for i in range(n):
	if s[i] == s[0]:
		fans = fans + 1
	else:
		break
s2 = s[::-1]
lans = 0
for i in range(n):
	if s2[i] == s2[0]:
		lans = lans + 1
	else:
		break
if s[0] == s2[0] and len(set(s)) > 1:
	print((fans * lans + lans + fans + 1) % modu)
elif len(set(s)) > 1:
	print((fans + lans + 1) % modu)
else:
	print(2 ** fans % modu)


import bisect
from itertools import accumulate, count
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
from sys import maxsize
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return sorted(fac)

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
n = int(input())
s = input()
start = 1
end = 1
ans = 0
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		start += 1
	else:
		break
s = s[::-1]
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		end += 1
	else:
		break
if s[0] == s[-1]:
	ans += (start + 1) * (end + 1)
else:
	ans += start + end + 1
print(ans % 998244353)


n = int(input())
s = str(input())
m = 998244353
if (s == s[::-1]) & (len(set(s)) == 1):
	print(n * (n + 1) // 2 % m)
else:
	i = 1
	while i < n:
		if s[0] != s[i]:
			break
		i = i + 1
	n1 = i
	s1 = s[::-1]
	i = 1
	while i < n:
		if s1[0] != s1[i]:
			break
		i = i + 1
	n2 = i
	if s[0] == s1[0]:
		n3 = min(n1, n2)
		print((n1 + n2 + n1 * n2 + 1) % m)
	else:
		print((n1 + n2 + 1) % m)


n = int(input())
s = input()
l = r = 1
while l < n and s[l] == s[l - 1]:
	l += 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)
print(ans % 998244353)


import math
import collections
import bisect
import heapq
import time
import itertools
import sys
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)


n = int(input())
s = input()
x1 = 1
x2 = 1
(i1, i2) = (1, -2)
while i1 < n and s[i1] == s[i1 - 1]:
	x1 += 1
	i1 += 1
while i2 * -1 < n + 1 and s[i2] == s[i2 + 1]:
	x2 += 1
	i2 -= 1
if s[0] != s[-1]:
	print(x1 + x2 + 1)
else:
	print((x1 + 1) * (x2 + 1) % 998244353)


mod = 998244353
n = int(input())
s = list(input())
if len(set(s)) == 1:
	ans = n * (n + 1) // 2
	print(ans % mod)
	exit()
pre = []
pre.append(s[0])
pr = i = po = 0
i = 1
while i < n and s[i - 1] == s[i]:
	pre.append(s[i])
	pr = i
	i += 1
i = n - 1
pos = []
pos.append(s[i])
while i > pr and s[i - 1] == s[i]:
	pos.append(s[i - 1])
	po = i
	i -= 1
if pos[0] == pre[0]:
	ans = (len(pre) + 1) * (len(pos) + 1)
else:
	ans = len(pre) + len(pos) + 1
print(ans % mod)


from itertools import *
from functools import *
from operator import *
input()
s = input()
i = 1
while s[i] == s[0]:
	i += 1
pref = i
i = len(s) - 1
while s[i] == s[-1]:
	i -= 1
suf = len(s) - i - 1
MOD = 998244353
print((pref + 1) * (suf + 1) % MOD if s[0] == s[-1] else (pref + suf + 1) % MOD)


import sys
data = sys.stdin.readlines()
n = data[0]
s = data[1]
s = list(s[:len(s) - 1])
diferente1 = -1
diferente2 = -1
for i in range(len(s)):
	if s[i] != s[0] and diferente1 == -1:
		diferente1 = i
	if s[-(i + 1)] != s[-1] and diferente2 == -1:
		diferente2 = i
	if diferente1 != -1 and diferente2 != -1:
		break
if s[0] == s[-1]:
	print((diferente1 + 1) * (diferente2 + 1) % 998244353)
else:
	print(diferente1 + diferente2 + 1)


n = int(input())
s = input()
starlen = 0
boo = s[0]
for char in s:
	if char == boo:
		starlen += 1
	else:
		break
boop = s[-1]
endlen = 0
for char in s[::-1]:
	if char == boop:
		endlen += 1
	else:
		break
if boo != boop:
	print(starlen + endlen + 1)
elif starlen == len(s):
	print(starlen * (starlen + 1) // 2 % 998244353)
else:
	print((starlen + 1) * (endlen + 1) % 998244353)


mod = 998244353
n = int(input())
a = list(input())
i = 1
j = n - 2
while a[i - 1] == a[i]:
	i += 1
while a[j + 1] == a[j]:
	j -= 1
j = n - j - 1
r = set(a)
if len(r) == 1:
	print((n * (n + 1) // 2 + 1) % mod)
else:
	if a[0] == a[-1]:
		ans = (i * j + i + j + 1) % mod
	else:
		ans = (i + j + 1) % mod
	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)


t = int(input())
str1 = input()
f1 = str1[0]
l1 = str1[-1]
i = 0
fin = 1
while str1[i] == f1 and i < len(str1):
	i += 1
maj = i
fin += i
i = len(str1) - 1
pro = 0
while str1[i] == l1 and i > 0:
	i -= 1
	pro += 1
fin += pro
if f1 == l1:
	fin += maj * pro
print(fin % 998244353)


n = int(input())
s = input()
mod = 998244353
(front, back) = (1, 1)
for i in range(n - 1):
	if s[i] == s[i + 1]:
		front += 1
	else:
		break
rev = s[::-1]
for i in range(n - 1):
	if rev[i] == rev[i + 1]:
		back += 1
	else:
		break
if s[0] != rev[0]:
	print((front + back + 1) % mod)
else:
	print((front + 1) % mod * (back + 1) % mod)


n = int(input())
s = input()
cl = 0
cr = 0
for i in range(n):
	if s[i] == s[0]:
		cl += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if s[i] == s[n - 1]:
		cr += 1
	else:
		break
if s[0] == s[n - 1]:
	print((cl + 1) * (cr + 1) % 998244353)
else:
	print((cl + cr + 1) % 998244353)


n = int(input())
ar = input()
ct = 1
for i in range(n - 1, 0, -1):
	if ar[i] != ar[i - 1]:
		break
	ct += 1
if ct == n:
	print(n * (n + 1) // 2 % 998244353)
else:
	kt = 1
	for i in range(n - 1):
		if ar[i] != ar[i + 1]:
			break
		kt += 1
	if ar[0] == ar[-1]:
		print((ct + 1) * (kt + 1) % 998244353)
	else:
		print((ct + 1 + kt) % 998244353)


from bisect import bisect_left, bisect_right
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque, defaultdict
import math
import heapq
import re

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
LOW = 'abcdefghijklmnopqrstuvwxyz'
UP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MAX = float('inf')
MIN = float('-inf')
MOD = 998244353

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def main():
	n = iin()
	s = sin()
	ans = 3
	c1 = 1
	c2 = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			c1 += 1
			ans += 1
		else:
			break
	for i in range(n - 2, -1, -1):
		if s[i] == s[i + 1]:
			c2 += 1
			ans += 1
		else:
			break
	ans = ans % MOD
	if n > 1:
		if s[0] == s[-1]:
			x = n - c1 - c2
			if x > 0:
				ans += 1
				c1 -= 1
				c2 -= 1
				ans += c1 + c2
				if c1 != 0 and c2 != 0:
					ans += c1 * c2
	print(ans % MOD)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = input()
l = 0
r = n - 1
c = 0
k = s[0]
m = s[-1]
for i in s:
	if i == k:
		c += 1
	else:
		break
f = c
g = 0
for i in s[::-1]:
	if i == m:
		c += 1
		if m == k:
			g += 1
	else:
		break
print((c + 1 + f * g) % 998244353)


n = int(input())
s = input()
pre = 1
suf = 1
for i in range(1, n):
	if s[i] == s[i - 1]:
		pre += 1
	else:
		break
for i in range(2, n + 1):
	if s[-i] == s[-i + 1]:
		suf += 1
	else:
		break
if s[0] == s[-1]:
	print((pre + 1) * (suf + 1) % 998244353)
else:
	print((suf + pre + 1) % 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)


from sys import stdin, stdout
n = int(stdin.readline())
st = stdin.readline()
cntl = 0
cntr = 0
for i in st:
	if st[0] == i:
		cntl += 1
	else:
		break
for j in range(n - 1, -1, -1):
	if st[j] == st[n - 1]:
		cntr += 1
	else:
		break
if st[0] == st[n - 1]:
	print((cntl + 1) * (cntr + 1) % 998244353)
else:
	print((cntl + cntr + 1) % 998244353)


import copy
n = int(input())
s = input()
di = {}
MOD = 998244353
for ch in s:
	if ch not in di:
		di[ch] = 1
	else:
		di[ch] += 1
l = len(di)
i = 0
count = 0
if l == 1:
	count = n * (n + 1) // 2
else:
	(cnta, cntb) = (1, 1)
	s1 = s[::-1]
	for i in range(n):
		if s[i] == s[i + 1]:
			cnta += 1
		else:
			break
	for i in range(n):
		if s1[i] == s1[i + 1]:
			cntb += 1
		else:
			break
	if s[0] == s1[0]:
		count = (cnta + 1) * (cntb + 1)
	else:
		count = cnta + cntb + 1
print(count % MOD)


n = int(input())
s = list(input())
x = s[0]
y = s[-1]
count1 = 0
count2 = 0
i = 0
while s[i] == x:
	count1 += 1
	i += 1
j = 1
while s[-j] == y:
	count2 += 1
	j += 1
if x != y:
	ans = count1 + count2 + 1
	print(ans % 998244353)
else:
	ans = count1 + count2 + 1 + count1 * count2
	print(ans % 998244353)


danger = 998244353
n = int(input())
s = list(input())
if len(s) == 2:
	print(3)
else:
	fs = s[0]
	ls = s[-1]
	fso = 0
	lso = 0
	for i in s:
		if i == fs:
			fso += 1
		else:
			break
	for i in s[::-1]:
		if i == ls:
			lso += 1
		else:
			break
	if fs == ls:
		ans = (fso + 1) * (lso + 1)
	else:
		ans = 1 + fso + lso
	print(ans % danger)


n = int(input())
s = input()
f = 0
b = len(s) - 1
ans = 0
for i in range(len(s)):
	c = s[i]
	if c != s[0]:
		break
	else:
		f = i
for i in range(len(s) - 1, 0, -1):
	c = s[i]
	if c != s[len(s) - 1]:
		break
	else:
		b = i
if s[f] == s[b]:
	ans += (f + 1 + 1) * (len(s) - b + 1)
else:
	ans += f + 1
	ans += len(s) - b
	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, s) = (int(input()), input())
(fl, ll) = (s[0], s[-1])
if fl != ll:
	i = 0
	while s[i] == fl:
		i += 1
	j = n - 1
	while s[j] == ll:
		j -= 1
	print((i + (n - j)) % 998244353)
else:
	i = 0
	while i < n and s[i] == fl:
		i += 1
	assert i < n, 'no 2 different characters found in the string'
	j = n - 1
	while s[j] == ll:
		j -= 1
	print((i + 1) * (n - j) % 998244353)


n = int(input())
s = input()
for i in range(n - 1):
	if s[i + 1] == s[i]:
		pass
	else:
		l = i + 1
		break
for i in range(n - 1):
	if s[n - 1 - (i + 1)] == s[n - 1 - i]:
		pass
	else:
		r = n - 1 - i - 1
		break
ans = 0
temp = 0
inf = 998244353
if s[0] == s[-1]:
	ans = ans + n % inf - r % inf
	ans = ans % inf
	temp = temp + n % inf - r % inf
	temp = temp % inf
	temp = temp * (l % inf)
	temp = temp % inf
	ans = ans + temp
	ans = ans % inf
else:
	ans = ans + l % inf + n % inf - r % inf
	ans = ans % inf
print(ans)


import sys
from math import factorial
inf = float('inf')
mod = 998244353

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	n = int(input())
	s = input().strip()
	d = {}
	for i in s:
		d[i] = 1
	if len(d) == 1:
		count = 2 * (n - 1) % mod
		x = factorial(n - 2)
		count = (count + x) % mod
		print(count)
		return
	x = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			x += 1
		else:
			break
	y = 0
	for i in range(n - 1, 0, -1):
		if s[i] == s[i - 1]:
			y += 1
		else:
			break
	count = 3
	count = (count + x) % mod
	count = (count + y) % mod
	if s[0] == s[-1]:
		count += 1
		count = (count + x) % mod
		count = (count + y) % mod
		count = (count + x * y) % mod
	print(count)
main()


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


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)


def B():
	mod = 998244353
	n = int(input())
	word = input()
	countFirst = 0
	countLast = 0
	while word[0] == word[countFirst]:
		countFirst += 1
	while word[-1] == word[n - countLast - 1]:
		countLast += 1
	if word[0] == word[-1]:
		print((countLast + 1) * (countFirst + 1) % mod)
		return
	print((countFirst + countLast + 1) % mod)
B()


n = int(input())
s = str(input())
(a, b) = (0, 0)
while s[a] == s[0]:
	a += 1
while s[n - 1 - b] == s[n - 1]:
	b += 1
ans = a + b + 1
if s[0] == s[n - 1]:
	ans += a * b
print(ans % 998244353)


n = int(input())
s = input()
mod = 998244353
ans = 0
if s[0] == s[-1]:
	l = 0
	r = n - 1
	while s[0] == s[l]:
		l += 1
	while s[n - 1] == s[r]:
		r -= 1
	print((l + 1) * (n - r) % mod)
else:
	l = 0
	while s[l] == s[0]:
		l += 1
	r = n - 1
	while s[r] == s[n - 1]:
		r -= 1
	print(l + n - r)


n = int(input())
MAX = 998244353
s = input()
k1 = 0
km = 0
for i in range(n):
	if s[i] == s[0]:
		k1 += 1
	else:
		break
for i in range(1, n + 1):
	if s[-1 * i] == s[-1]:
		km += 1
	else:
		break
if k1 == n:
	res = k1 * (k1 + 1) // 2
	print(res % MAX)
elif s[0] == s[-1]:
	res = (k1 + 1) * (km + 1)
	print(res % MAX)
else:
	print(k1 + km + 1)


n = int(input())
s = input()
l = len(s)
count = 0
p = 998244353
for i in range(len(s)):
	if s[i] == s[0]:
		count += 1
if count == l:
	count = l * (l + 1) // 2
	print(count % p)
else:
	count = 0
	if s[0] == s[-1]:
		start = 1
		end = 1
		for i in range(1, len(s)):
			if s[i] == s[0]:
				start += 1
			else:
				break
		for i in range(len(s) - 2, -1, -1):
			if s[i] == s[-1]:
				end += 1
			else:
				break
		rem = l - start - end
		count += (start + 1) * (end + 1)
	else:
		start = 1
		end = 1
		for i in range(1, len(s)):
			if s[i] == s[0]:
				start += 1
			else:
				break
		for i in range(len(s) - 2, -1, -1):
			if s[i] == s[-1]:
				end += 1
			else:
				break
		count += start + end
		count += 1
	print(count % p)


d = input()
a = input()
for i in range(len(a)):
	if a[i] != a[0]:
		l = i
		break
for i in range(len(a) - 1, -1, -1):
	if a[i] != a[-1]:
		r = len(a) - i - 1
		break
if a[-1] != a[0]:
	print(r + l + 1)
else:
	print((r + l + 1 + r * l) % 998244353)


(a, b) = (int(input()), input())
i = 0
j = a - 1
(r, r1) = (1, 1)
while i <= j:
	if b[0] == b[i] and r:
		i += 1
	else:
		r = 0
	if b[-1] == b[j] and r1:
		j -= 1
	else:
		r1 = 0
	if r == 0 and r1 == 0:
		break
if b[0] != b[-1]:
	exit(print(i + a - j))
print((i + 1) * (a - j) % 998244353)


y = int(input())
str1 = input()
count1 = 0
count2 = 0

def one(str1, n, z):
	if n == z:
		if len(str1) == 0:
			return True
		if len(str1) == 1:
			return True
		else:
			first = str1[0]
			for i in str1:
				if i != first:
					return False
			return True
for i in range(0, y):
	if str1[0] == str1[i]:
		count1 += 1
	else:
		break
for i in range(y - 1, 0, -1):
	if str1[y - 1] == str1[i]:
		count2 += 1
	else:
		break
if one(str1, 0, 0):
	count = y * (y - 1) // 2 + y
	print((count + 1) % 998244353)
elif str1[0] != str1[y - 1]:
	print((count1 + count2 + 1) % 998244353)
else:
	print((count1 + 1) * (count2 + 1) % 998244353)


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	if n == 1:
		return 0
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=None):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
n = int(input())
s = input()
(a, b) = (s[0], s[n - 1])
(l, r) = (1, 1)
for i in range(n):
	if s[i] == a:
		l += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if s[i] == b:
		r += 1
	else:
		break
if a == b:
	print(l * r % 998244353)
else:
	print((l + r - 1) % 998244353)


n = int(input())
s = input()
len_pref = len_suf = 1
i = 1
while s[i] == s[0]:
	len_pref += 1
	i += 1
i = 2
while s[-i] == s[-i + 1]:
	len_suf += 1
	i += 1
if s[0] == s[-1]:
	print((max(len_pref, len_suf) + 1) * (min(len_pref, len_suf) + 1) % 998244353)
else:
	print(len_pref + len_suf + 1)


n = int(input())
s = input()
total = 1
if n == 2:
	total = 2
	print(3)
else:
	x = 1
	y = 1
	if s[0] != s[n - 1]:
		for i in range(0, n - 1):
			if s[i] == s[i + 1]:
				x += 1
			else:
				break
		for i in range(n - 1, 1, -1):
			if s[i] == s[i - 1]:
				y += 1
			else:
				break
		if x + y <= n:
			total = x + y + 1
	else:
		for i in range(0, n - 1):
			if s[i] == s[i + 1]:
				x += 1
			else:
				break
		for i in range(n - 1, 1, -1):
			if s[i] == s[i - 1]:
				y += 1
			else:
				break
		total = total + (x + 1) * (y + 1) - 1
	print(total % 998244353)


n = int(input())
s = input()
revs = s[::-1]
l = 0
r = 0
ls = s[0]
rs = revs[0]
for i in s:
	if i != ls:
		break
	l += 1
for i in revs:
	if i != rs:
		break
	r += 1
ans = 0
maxi = 998244353
if s[0] != s[-1]:
	ans = (l % maxi + (r + 1) % maxi) % maxi
else:
	ans = (l + 1) % maxi * ((r + 1) % maxi) % maxi
print(ans)


n = int(input())
st = input()
mod = 998244353
(frnt_idx, back_idx) = (0, n - 1)
while frnt_idx < n and st[frnt_idx] == st[0]:
	frnt_idx += 1
while back_idx >= 0 and st[back_idx] == st[-1]:
	back_idx -= 1
if st[0] == st[-1]:
	print((frnt_idx + 1) * (n - back_idx) % mod)
else:
	print((frnt_idx + n - back_idx) % mod)


mod = 998244353
n = int(input())
s = input()
i = 1
while s[i] == s[i - 1]:
	i += 1
c = i
i = n - 2
c2 = 1
while s[i] == s[-1]:
	i -= 1
	c2 += 1
if s[0] == s[-1]:
	print(((c + c2) % mod + c % mod * (c2 % mod) % mod % mod + 1) % mod)
else:
	print((c + c2 + 1) % mod)


mod = 1000000007
MOD = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
it = lambda : tuple(map(int, input().split()))
ls = lambda : list(input())
n = ii()
s = si()
c1 = 0
for i in s:
	if i == s[0]:
		c1 += 1
	else:
		break
c2 = 0
for i in s[::-1]:
	if i == s[-1]:
		c2 += 1
	else:
		break
if s[0] == s[-1]:
	print((c1 + 1) * (c2 + 1) % MOD)
else:
	print((c1 + c2 + 1) % MOD)


input()
s = input()
t = s[0]
k = 1
for i in s:
	if t != i:
		break
	else:
		k += 1
t2 = s[-1]
k2 = 1
for i in s[::-1]:
	if t2 != i:
		break
	else:
		k2 += 1
ans = k * k2 % 998244353 if t2 == t else (k + k2 - 1) % 998244353
print(ans)


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


n = int(input())
s = input()
first_letter = s[0]
last_letter = s[-1]
total = 1
i = 0
while s[i] == first_letter and i < len(s):
	i += 1
total += i
p = i
j = 0
i = len(s) - 1
while s[i] == last_letter and 0 <= i:
	i -= 1
	j += 1
total += j
if first_letter == last_letter:
	total += p * j
print(total % 998244353)


from itertools import groupby
p = 998244353
n = int(input())
s = input()
a = len(list(next(groupby(s))[1]))
b = len(list(next(groupby(s[::-1]))[1]))
if s[0] != s[-1]:
	print((1 + a + b) % p)
else:
	print((1 + a + b + a * b) % p)


n = int(input())
ss = input()
s = list(ss)
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)


n = int(input())
s = str(input())
f = s[0]
l = s[-1]
fc = lc = 0
for i in range(0, n):
	if s[i] == f:
		fc += 1
	else:
		break
for i in range(0, n):
	if s[n - i - 1] == l:
		lc += 1
	else:
		break
if l != f:
	print(int(fc + lc + 1) % 998244353)
else:
	ans = fc + lc + 1
	ans += fc * lc
	print(int(ans) % 998244353)


n = int(input())
letters = input()
startingletter = letters[0]
endingletter = letters[n - 1]
left = 1
right = 1
if startingletter != endingletter:
	index = 1
	while startingletter == letters[index]:
		left += 1
		index += 1
	index = n - 2
	while endingletter == letters[index]:
		right += 1
		index -= 1
	total = 1 + right + left
	newtotal = total % 998244353
	print(newtotal)
else:
	index = 1
	while startingletter == letters[index]:
		left += 1
		index += 1
	index = n - 2
	while endingletter == letters[index]:
		right += 1
		index -= 1
	total = (left + 1) * (right + 1)
	newtotal = total % 998244353
	print(newtotal)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
M = 998244353
for _ in range(1):
	n = nmbr()
	s = input()
	ans = 0
	if s[0] == s[-1]:
		(l, r) = (0, n - 1)
		while l < n and s[l] == s[0]:
			l += 1
		while r >= 0 and s[r] == s[0]:
			r -= 1
		if l <= r:
			ans = (l + 1) * (n - r)
		else:
			ans = n * (n + 1) // 2
	else:
		l = 0
		while l < n and s[l] == s[0]:
			l += 1
		ans += l
		r = n - 1
		c = 0
		while r >= 0 and s[r] == s[-1]:
			r -= 1
			c += 1
		ans += c
		ans += 1
	print(ans % M)


def substring(s):
	firstc = s[0]
	score = 1
	l = 1
	for i in s[1:]:
		if i == firstc:
			score += 1
			l += 1
		else:
			break
	lastc = s[-1]
	score += 1
	r = 1
	for i in s[len(s) - 2::-1]:
		if i == lastc:
			score += 1
			r += 1
		else:
			break
	if lastc == firstc:
		return (r + 1) * (l + 1) % 998244353
	else:
		return (score + 1) % 998244353
a = input()
print(substring(input()))


n = int(input())
s = input()
left = right = 0
cleft = cright = 'a'
for i in range(1, n):
	if s[i] != s[i - 1]:
		left = i - 1
		cl = s[i - 1]
		break
for j in range(1, n):
	i = n - 1 - j
	if s[i] != s[i + 1]:
		right = i + 1
		cr = s[i + 1]
		break
if cl != cr:
	print(left + 2 + n - right)
elif right <= left:
	print(n * (n + 1) // 2 % 998244353)
else:
	print((left + 2) * (n - right + 1) % 998244353)


length = input()
length = int(length)
a = input()
a = str(a)
first = a[0]
last = a[length - 1]

def thefirst(string):
	counter = 0
	while counter < length:
		if first == string[counter]:
			counter += 1
		else:
			break
	return counter

def thelast(string):
	counter = length - 1
	while counter > -1:
		if last == string[counter]:
			counter -= 1
		else:
			break
	return length - (counter + 1)
if first == last:
	print((thefirst(a) + 1) * (thelast(a) + 1) % 998244353)
else:
	print((thefirst(a) + thelast(a) + 1) % 998244353)


from sys import stdin, exit
MOD = 998244353
_ = stdin.readline().rstrip()
string = stdin.readline().rstrip()
(left, right) = (None, None)
for (i, c) in enumerate(string):
	if c != string[0]:
		left = i - 1
		break
for (i, c) in reversed(list(enumerate(string))):
	if c != string[-1]:
		right = i + 1
		break
on_left = left + 1
on_right = len(string) - right
in_middle = len(string) - on_left - on_right
if in_middle == 0 and string[0] == string[-1]:
	print(len(string) ** 2 % MOD)
	exit(0)
sum = 1 + on_left + on_right % MOD
if string[0] == string[-1]:
	sum = (sum + on_left * on_right) % MOD
print(sum % MOD)


import os
import sys
import math
import collections
import cmath

def mp():
	return map(int, input().split())

def inp():
	return input()
n = int(inp())
s = inp()
r = 1
l = 1
for i in range(1, n):
	if s[0] == s[i]:
		l += 1
	else:
		break
for i in range(2, n):
	if s[-1] == s[-i]:
		r += 1
	else:
		break
if s[0] == s[-1]:
	print((l + 1) * (r + 1) % 998244353)
else:
	print((l + r + 1) % 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(ANS)


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()
cntl = 1
cntr = 1
for i in range(1, len(s)):
	if s[0] == s[i]:
		cntl += 1
	else:
		break
for i in range(n - 2, -1, -1):
	if s[n - 1] == s[i]:
		cntr += 1
	else:
		break
if s[0] != s[n - 1]:
	ans = (cntl + cntr + 1) % 998244353
	print(ans)
else:
	ans = (cntl + 1) * (cntr + 1) % 998244353
	print(ans)


n = int(input())
s = input()
x = []
ans = 0
for i in range(1, n):
	a = s[i]
	if a != s[i - 1]:
		x.append(i)
p = x[0]
q = x[-1] - 1
if s[0] == s[-1]:
	ans = p + (n - q - 1) + p * (n - q - 1) + 1
else:
	ans = p + n - q - 1 + 1
ans = ans % 998244353
print(ans)


n = int(input())
s = input()
d = {chr(97 + i): 0 for i in range(26)}
mod = 998244353
for i in range(n):
	d[s[i]] += 1
sum = 1
b = []
e = {chr(97 + i): 0 for i in range(26)}
f = []
g = 1
r = []
k = []
for i in range(0, n):
	if s[i] not in r:
		r.append(s[i])
		b.append([s[i], i])
	if s[n - 1 - i] not in k:
		f.append([s[n - 1 - i], n - 1 - i])
		k.append(s[n - 1 - i])
	if len(b) == 1:
		sum += 1
	if len(f) == 1:
		sum += 1
if b[0][0] == f[0][0]:
	if b[1][1] <= f[0][1]:
		sum += b[1][1] % mod * (n - 1 - f[1][1]) % mod
print(sum % mod)


def main():
	n = int(input())
	s = input()
	(first, last) = (s[0], s[-1])
	nf = 0
	nl = 0
	for l in s:
		if l != first:
			break
		nf += 1
	else:
		print(n * (n + 1) // 2 % 998244353)
		return 0
	for l in s[::-1]:
		if l != last:
			break
		nl += 1
	if first == last:
		print((nl + 1) * (nf + 1) % 998244353)
	else:
		print(nl + nf + 1)
main()


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


m = 998244353
n = int(input())
s = str(input())
c = 1
co = 1
lo = 1
for i in range(n - 1):
	if s[i] == s[i + 1]:
		co = co + 1
	else:
		break
for i in range(n - 1):
	if s[n - 1 - i] == s[n - 1 - i - 1]:
		lo = lo + 1
	else:
		break
if s[0] == s[n - 1]:
	if co == n:
		res = co * (co + 1) // 2
	else:
		res = 1 + lo + co + lo * co
	print(res % m)
else:
	res = lo + co + 1
	print(res % m)


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


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


m = 998244353
n = int(input())
s = list(input())
a = 1
f = s[0]
while s[a] == f:
	a += 1
b = -2
l = s[-1]
while s[b] == l:
	b -= 1
b *= -1
b -= 1
res = a + b + 1
if s[0] == s[-1]:
	res += a * b
print(res % m)


t = int(input())
a = input()
value = 998244353
count = 0
diff = 0
temp = a[0]
only_one = 1
for i in range(1, len(a)):
	if a[i] != temp:
		first_index = i
		only_one = -1
		break
temp = a[t - 1]
count = 0
for i in range(len(a) - 1, -1, -1):
	count += 1
	if a[i] != temp:
		break
if only_one == 1:
	print(t * (t + 1) / 2 % value)
elif a[0] != a[t - 1]:
	print((first_index + count) % value)
else:
	print((first_index + 1) * count % value)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph():
	d = {}
	(v, e) = mi()
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(l, n):
	d = {}
	for i in range(1, n + 1):
		if i not in d.keys():
			d[i] = l[i]
		else:
			d[i].append(l[i])
	return d
n = ii()
s = si()
r = 1
l = 1
for i in range(1, n):
	if s[0] == s[i]:
		l += 1
	else:
		break
for i in range(2, n):
	if s[-1] == s[-i]:
		r += 1
	else:
		break
if s[0] == s[-1]:
	print((l + 1) * (r + 1) % 998244353)
else:
	print((l + r + 1) % 998244353)


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


import sys
inf = float('inf')
ip = lambda : sys.stdin.readline().rstrip()
split = lambda : ip().split(' ')
ip1 = lambda : map(int, split())
arr = lambda : list(ip1())
arr1 = lambda n: [arr() for _ in range(n)]
mod = 998244353
n = int(ip())
s = ip()
a = 1
i = 1
while i < n and s[i - 1] == s[i]:
	i += 1
a = i
b = 0
i = n - 1
while i >= 0 and s[i] == s[-1]:
	b += 1
	i -= 1
if s[0] == s[-1]:
	ans = a * b + a + b + 1
else:
	ans = a + b + 1
print(ans % mod)


n = int(input())
s = str(input())
mod = 998244353
if s[0] != s[-1]:
	for i in range(n):
		if s[i] != s[0]:
			break
	for j in reversed(range(n)):
		if s[j] != s[-1]:
			break
	k = n - 1 - j
	ans = 0
	if i + k < n:
		ans += k + 1 + (i - 1)
		ans += 1
	if i + k == n:
		ans = i - 1 + (k - 1) + 3
	print(ans % mod)
else:
	for i in range(n):
		if s[i] != s[0]:
			break
	for j in reversed(range(n)):
		if s[j] != s[-1]:
			break
	k = n - 1 - j
	ans = (i + 1) * (k + 1)
	print(ans % mod)


Mod = 998244353
n = int(input())
string = input()
front = 1
i = 1
while i < n:
	if string[i] == string[0]:
		front += 1
	else:
		break
	i += 1
rear = 1
i = n - 2
while i >= 0:
	if string[i] == string[n - 1]:
		rear += 1
	else:
		break
	i -= 1
if front + rear > n:
	n = n % Mod
	ans = n * (n + 1) % Mod
elif string[0] != string[n - 1]:
	ans = front % Mod + rear % Mod
	ans = (ans + 1) % Mod
else:
	Mid = n - (front + rear)
	front = front % Mod
	rear = rear % Mod
	ans = (front + rear + 1) % Mod
	temp = front * rear % Mod
	ans = (ans + temp) % Mod
print(ans)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def si():
	return input()

def ii():
	return int(input())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
t = 1
for _ in range(t):
	n = ii()
	s = list(si())
	mod = 998244353
	if len(set(s)) == 1:
		print(ncr(n, 2, mod))
		continue
	if s[0] == s[-1]:
		i = 0
		while 1:
			if s[i] != s[i + 1]:
				break
			i += 1
		j = n - 1
		while 1:
			if s[j] != s[j - 1]:
				break
			j -= 1
		res = (i + 2) * (n - j + 1)
		res %= mod
		print(res)
	else:
		i = 0
		while 1:
			if s[i] != s[i + 1]:
				break
			i += 1
		j = n - 1
		while 1:
			if s[j] != s[j - 1]:
				break
			j -= 1
		res = i + 1 + n - j + 1
		res %= mod
		print(res)


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)


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


MOD = 998244353
(n, s) = (int(input()), input())
i = 1
while s[i] == s[i - 1]:
	i += 1
prefix = i
i = len(s) - 1
while s[i] == s[i - 1]:
	i -= 1
suffix = len(s) - i
if s[0] != s[-1]:
	ans = prefix + suffix + 1
else:
	ans = (prefix + 1) * (suffix + 1)
print(ans % MOD)


input()
s = input()
(h, a) = (s[0], 0)
(t, b) = (s[-1], 0)
for i in range(len(s)):
	if s[i] == h:
		a += 1
	else:
		break
for i in range(len(s) - 1, -1, -1):
	if s[i] == t:
		b += 1
	else:
		break
a %= 998244353
b %= 998244353
if a == len(s):
	print(a * (a + 1) / 2 % 998244353)
elif h == t:
	print((a + b + 1 + a * b) % 998244353)
else:
	print((a + b + 1) % 998244353)


n = int(input().strip())
s = input().strip()
f = s[0]
l = s[-1]
fc = 0
while fc < n and s[fc] == f:
	fc += 1
lc = 0
rs = list(reversed(s))
while lc < n and rs[lc] == l:
	lc += 1

def f1(n):
	return n * (n + 1) // 2
mod = 998244353
if lc == fc == len(s):
	print(f1(n) % mod)
elif f == l:
	print((lc + 1) * (fc + 1) % mod)
else:
	print((lc + fc + 1) % mod)


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 998244353

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
import heapq, string
n = int(input())
s = input()
cnt = 0
if n == 2:
	print(3)
else:
	pref = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			pref += 1
		else:
			break
	suff = 1
	for i in range(n - 2, -1, -1):
		if s[i] == s[i + 1]:
			suff += 1
		else:
			break
	if s[0] == s[-1]:
		print((suff + 1 + pref + suff * pref) % mod)
	else:
		print((suff + pref + 1) % mod)


import math
MODULO = 998244353
n = input()
n = int(n)
s = input()
beg = s[0]
end = s[n - 1]
length_beg = 0
begpos = 0
while s[begpos] == beg and begpos < n:
	begpos += 1
endpos = n - 1
while s[endpos] == end and endpos >= 0:
	endpos -= 1
netbeg = begpos
netend = n - 1 - endpos
total = 1
total += netbeg
total += netend
if beg == end:
	total += netbeg * netend
print(total % MODULO)


N = int(input())
S = input()
a = b = 1
for c in S[1:]:
	if c != S[0]:
		break
	a += 1
for c in reversed(S[:-1]):
	if c != S[-1]:
		break
	b += 1
MOD = 998244353
if S[0] == S[-1]:
	print((a + 1) * (b + 1) % MOD)
else:
	print(a + b + 1)


n = int(input())
s = input()
modulo = 998244353
if s[0] != s[-1]:
	counter = 1
	ind = 1
	while s[0] == s[ind]:
		counter += 1
		ind += 1
	counter += 1
	ind = -2
	while s[-1] == s[ind]:
		counter += 1
		ind -= 1
	counter += 1
elif len(s) == s.count(s[0]):
	counter = n * (n + 1) // 2
else:
	counter = 1
	left = 1
	while s[0] == s[left]:
		counter += 1
		left += 1
	counter += 1
	right = n - 2
	while s[-1] == s[right]:
		counter += 1
		right -= 1
	counter += 1
	counter += left * (n - 1 - right)
print(counter % modulo)


n = int(input())
s = input()
(L, R) = (0, 0)
while s[L] == s[0]:
	L += 1
while s[-1] == s[n - 1 - R]:
	R += 1
ans = L + R + 1
if s[0] == s[-1]:
	ans += L * R
print(ans % 998244353)


n = int(input())
c = input()
d = []
p = c[0]
k = 0
for i in c:
	if p == i:
		k += 1
	else:
		d.append((p, k))
		(p, k) = (i, 1)
d.append((p, k))
if d[0][0] != d[-1][0]:
	print((d[0][1] + d[-1][1] + 1) % 998244353)
else:
	print((d[0][1] * d[-1][1] + d[0][1] + d[-1][1] + 1) % 998244353)


def mi():
	return list(map(int, input().split()))
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)
elif c1 == n:
	print(n * (n + 1) // 2 % 998244353)
else:
	print((c1 + 1) * (c2 + 1) % 998244353)


import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
i = 0
v = 1
j = n - 1
w = 0
start = s[0]
end = s[-1]
for k in range(0, n):
	if v == 1:
		if s[k] == start:
			i = k
		else:
			v = 0
	if s[k] != end:
		j = n - 1
		w = 0
	elif w == 0:
		j = k
		w = 1
if i >= j:
	print(n * (n + 1) // 2)
elif start != end:
	print((i + n - j + 2) % 998244353)
else:
	print((i + 2) * (n + 1 - j) % 998244353)


m = 998244353
n = int(input())
s = input()
(sc, ec) = (s[0], s[-1])
start = 1
end = 1
for i in range(1, n):
	if s[i] != sc:
		break
	start += 1
for i in range(n - 2, -1, -1):
	if s[i] != ec:
		break
	end += 1
if sc != ec:
	print((start + end + 1) % m)
else:
	print((start + 1) * (end + 1) % m)


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)


input()
a = input()
x = 0
b = 0
for i in range(len(a)):
	if a[i] != a[0]:
		x = i
		break
a = a[::-1]
for j in range(len(a)):
	if a[j] != a[0]:
		b = j
		break
if a[0] != a[-1]:
	print((x + b + 1) % 998244353)
else:
	print((x * b + x + b + 1) % 998244353)


R = lambda : map(int, input().split())
n = int(input())
s = list(input())
(c1, c2) = (1, n - 1)
mod = 998244353
while c1 < n:
	if s[c1] != s[c1 - 1]:
		break
	c1 += 1
while c2 >= 0:
	if s[c2] != s[c2 - 1]:
		break
	c2 -= 1
if c1 == c2:
	print((c1 + (n - c2) + 1) % mod)
elif s[0] != s[n - 1]:
	print((c1 + (n - c2) + 1) % mod)
else:
	c2 = n - c2
	print((c1 * (c2 + 1) + c2 + 1) % mod)


n = int(input())
a = [0] + list(input())
if a[1] == a[-1]:
	uk1 = 1
	uk2 = n
	while a[uk1] == a[1] or a[uk2] == a[-1]:
		if a[uk1] == a[1]:
			uk1 += 1
		if a[uk2] == a[-1]:
			uk2 -= 1
	print(uk1 * (n - uk2 + 1) % 998244353)
else:
	uk1 = 1
	uk2 = n
	while a[uk1] == a[1] or a[uk2] == a[-1]:
		if a[uk1] == a[1]:
			uk1 += 1
		if a[uk2] == a[-1]:
			uk2 -= 1
	print(uk1 + (n - uk2 - 1) + 1)


n = int(input())
my = input()
count = 1
my_ = my[::-1]
temp1 = my_[0]
b = 0
temp = my[0]
a = 0
for i in range(1, n + 1):
	if my[i - 1] == my[0]:
		a += 1
	else:
		break
for i in range(1, n + 1):
	if my_[i - 1] == my_[0]:
		b += 1
	else:
		break
if my[0] == my[-1]:
	print((a * b + a + b + 1) % 998244353)
else:
	print((a + b + 1) % 998244353)


def get_occurrences(s):
	res = []
	cur_char = s[0]
	cur_count = 1
	for c in s[1:]:
		if c == cur_char:
			cur_count += 1
		else:
			res.append((cur_char, cur_count))
			cur_char = c
			cur_count = 1
	res.append((cur_char, cur_count))
	return res

def main():
	n = int(input())
	s = input()
	occurrences = get_occurrences(s)
	if occurrences[0][0] != occurrences[-1][0]:
		res = 1 + occurrences[0][1] + occurrences[-1][1]
	else:
		res = (occurrences[0][1] + 1) * (occurrences[-1][1] + 1)
	print(res % 998244353)
main()


import sys

def main():
	n = 0
	mod = 998244353
	for line in sys.stdin:
		if not n:
			n = int(line.strip())
		else:
			string = line.strip()
			pre = post = 0
			i = 0
			while string[0] == string[i]:
				pre += 1
				i += 1
			i = len(string) - 1
			while string[-1] == string[i]:
				post += 1
				i -= 1
			if string[0] == string[-1]:
				print((pre + 1) % mod * ((post + 1) % mod) % mod)
			else:
				print(((pre + post) % mod + 1) % mod)
main()


input()
s = input()
(i, j) = (2, 2)
while s[i - 1] == s[0]:
	i += 1
while s[-j] == s[-1]:
	j += 1
print((i + j - 1, i * j % 998244353)[s[0] == s[-1]])


n = int(input())
ch = input()
popqu = set(ch)
cnt = 0
for b in popqu:
	if ch[0] == b and ch[-1] == b:
		cnt2 = 0
		cnt3 = 0
		for y in ch:
			if y != b:
				break
			cnt2 += 1
		for y in range(len(ch) - 1, -1, -1):
			if ch[y] != b:
				break
			cnt3 += 1
		cnt += cnt2 + cnt3 + cnt2 * cnt3
	elif ch[0] == b and ch[-1] != b:
		ans = 0
		for y in ch:
			if y != b:
				break
			ans += 1
		cnt += ans
	elif ch[0] != b and ch[-1] == b:
		ans = 0
		for y in range(len(ch) - 1, -1, -1):
			if ch[y] != b:
				break
			ans += 1
		cnt += ans
print((cnt + 1) % 998244353)


n = int(input())
string = input()
left = 0
right = n - 1
flag1 = 0
flag2 = 0
while left < right:
	flag1 = 0
	flag2 = 0
	if string[left] == string[left + 1]:
		left += 1
		flag1 = 1
	if string[right] == string[right - 1]:
		right -= 1
		flag2 = 1
	if flag1 == 0 and flag2 == 0:
		break
if left >= right:
	print(n * (n + 1) // 2 % 998244353)
elif string[0] != string[n - 1]:
	print((left + 1 + (n - right) + 1) % 998244353)
else:
	tot = left + 1 + (n - right) + 1
	tot += (left + 1) * (n - right)
	print(tot % 998244353)


n = int(input())
s = input()
fs = s[0]
indf = 0
for i in range(n):
	if s[i] != fs:
		break
	indf += 1
ls = s[-1]
indl = 0
for i in range(-1, -n, -1):
	if s[i] != ls:
		break
	indl += 1
mas = []
for i in range(n):
	if s[i] not in mas:
		mas.append(s[i])
if s == s[0] * n:
	ans = n * (n + 1) // 2
elif s[0] == s[-1]:
	ans = (indf + 1) * (indl + 1)
else:
	ans = indf + indl + 1
print(ans % 998244353)


n = int(input())
s = input()
l = 1
r = 1
for x in range(1, n):
	if s[x] != s[x - 1]:
		break
	else:
		l = l + 1
for x in range(n - 2, 0, -1):
	if s[x] != s[x + 1]:
		break
	else:
		r = r + 1
if s[0] != s[-1]:
	print((l + r + 1) % 998244353)
else:
	print((l + 1) % 998244353 * ((r + 1) % 998244353) % 998244353)


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


n = int(input())
c = input()
ar = [k for k in c]
i = 0
count1 = 1
count2 = 1
c1 = ar[0]
c2 = ar[n - 1]
while i < n - 1 and ar[i] == ar[i + 1]:
	count1 += 1
	i += 1
i = n - 1
while i > 0 and ar[i] == ar[i - 1]:
	count2 += 1
	i -= 1
MOD = 998244353
if c1 == c2:
	ans = 0
	seen = set(ar[0])
	i = 0
	while len(seen) < 2:
		if i >= n:
			break
		if ar[i] in seen:
			ans += count2 + 1
		else:
			ans += count2 + 1
			seen.add(ar[i])
			break
		i += 1
	print(ans % MOD)
else:
	print((1 + count1 + count2) % MOD)


a = int(input())
b = input()
c = b[::-1]
d = 1
e = 1
gg = 1
for i in range(1, a):
	if b[i] == b[i - 1]:
		d += 1
	else:
		break
for i in range(1, a):
	if c[i] == c[i - 1]:
		e += 1
	else:
		break
gg += d + e
if b[0] == b[a - 1]:
	gg += e * d
print(gg % 998244353)


MOD = 998244353
n = int(input())
s = input()
pref = s[0]
suff = s[-1]
lpref = 0
lsuff = 0
for i in range(len(s)):
	if s[i] == pref:
		lpref = lpref + 1
	else:
		break
for i in range(len(s)):
	if s[len(s) - 1 - i] == suff:
		lsuff = lsuff + 1
	else:
		break
if pref == suff:
	res = (lpref + 1) % MOD * ((lsuff + 1) % MOD) % MOD
else:
	res = (lpref + lsuff + 1) % MOD
print(res)


(n, s, L, M) = (int(input()), input(), 0, 998244353)
for ch in s:
	if ch != s[0]:
		break
	L += 1
if L < n:
	R = 0
	for ch in s[::-1]:
		if ch != s[-1]:
			break
		R += 1
	print((L + 1) * (R + 1) % M if s[0] == s[-1] else L + R + 1)
else:
	print(n * (n + 1) // 2 % M)


def read(type=1):
	if type:
		file = open('input.dat', 'r')
		n = int(file.readline())
		line = file.readline()
		file.close()
	else:
		n = int(input().strip())
		line = input().strip()
	return (n, line)

def solve():
	MOD = 998244353
	st = 0
	while s[0] == s[st]:
		st += 1
		if st == len(s):
			return (st - 1) * st % MOD
	en = 0
	while s[len(s) - 1] == s[len(s) - 1 - en]:
		en += 1
	if s[0] != s[len(s) - 1]:
		return (st + en + 1) % MOD
	else:
		return (st + 1) * (en + 1) % MOD
(n, s) = read(0)
sol = solve()
print(sol)


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return 998244353

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
n = INI()
S = INS()
s = S[0]
for _ in range(1, n):
	if s != S[_]:
		x = _
		break
e = S[n - 1]
for _ in range(n - 2, -1, -1):
	if e != S[_]:
		y = n - _ - 1
		break
if S[0] == S[n - 1]:
	OPS((x + 1) * (y + 1) % MOD())
else:
	OPS(x + y + 1)


characters = int(input())
word = input()
answer = 1
ans = 0
if word[0] != word[len(word) - 1]:
	x = word[0]
	y = word[len(word) - 1]
	z = 0
	while word[z] == x:
		answer = answer + 1
		z = z + 1
	z = len(word) - 1
	while word[z] == y:
		answer = answer + 1
		z = z - 1
	print(answer)
else:
	z = 0
	num = 0
	x = word[0]
	while word[z] == x:
		num = num + 1
		z = z + 1
	beg = z + 1
	z = len(word) - 1
	while word[z] == x:
		num = num + 1
		z = z - 1
	end = len(word) - z
	print(end * beg % 998244353)
	term = 2
	ans = 3
	while num > 2:
		num = num - 1
		ans = ans + term
		term = term + 1


n = int(input())
s = str(input())
answ = 0
x = y = 0
for i in s[0:]:
	if i == s[0]:
		x += 1
	else:
		break
for j in s[-1:0:-1]:
	if j == s[-1]:
		y += 1
	else:
		break
if s[0] == s[-1]:
	print((x + y + x * y + 1) % 998244353)
else:
	print((x + y + 1) % 998244353)


n = int(input())
s = input()
total = 0
l = 0
r = 0
for c in s:
	if c == s[0]:
		l += 1
	else:
		break
for c in s[::-1]:
	if c == s[-1]:
		r += 1
	else:
		break
if s[0] == s[-1]:
	while True:
		total += l + r + 1
		l -= 1
		r -= 1
		if l == -1 or r == -1:
			break
else:
	total += 1 + l + r
print(total % 998244353)


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


n = int(input())
s = input()
start = 0
for i in range(n):
	if s[i] == s[0]:
		start += 1
	else:
		break
end = 0
for j in range(n - 1, -1, -1):
	if s[j] == s[-1]:
		end += 1
	else:
		break
if s[0] == s[-1]:
	print((start + 1) * (end + 1) % 998244353)
else:
	print(start + end + 1)


n = int(input())
s = input()
first_let = s[0]
final_let = s[n - 1]
Ind = 1
while s[Ind] == first_let:
	Ind += 1
num_first_let = Ind
Ind = 1
Jnd = n - 2
while s[Jnd] == final_let:
	Ind += 1
	Jnd -= 1
num_final_let = Ind
if first_let != final_let:
	print((1 + num_first_let + num_final_let) % 998244353)
else:
	print((1 + num_first_let + num_final_let + num_first_let * num_final_let) % 998244353)


MOD = 998244353
_ = input()
s = input()
c = s[0]
for i in range(len(s)):
	if s[i] != c:
		break
len_prefix = i
c = s[-1]
for i in range(len(s) - 1, -1, -1):
	if s[i] != c:
		break
len_suffix = len(s) - i - 1
if s[0] != s[-1]:
	ans = len_prefix + len_suffix + 1
else:
	ans = (len_prefix + 1) * (len_suffix + 1)
print(ans % MOD)


input()
st = input()
for (i, c) in enumerate(st[1:]):
	if c != st[0]:
		break
lenFirst = i + 1
for (i, c) in enumerate(st[-2::-1]):
	if c != st[-1]:
		break
lenLast = i + 1
if st[0] == st[-1]:
	ans = (lenFirst + 1) * lenLast + lenFirst + 1
else:
	ans = lenLast + lenFirst + 1
print(ans % 998244353)


n = int(input())
s = str(input())
count1 = 0
count2 = 0
res = 0
for x in range(n):
	if s[x] == s[0]:
		count1 = count1 + 1
	else:
		break
for x in range(n - 1, 0, -1):
	if s[x] == s[n - 1]:
		count2 = count2 + 1
	else:
		break
if s[0] == s[n - 1]:
	res = (count2 + 1) * (count1 + 1)
else:
	res = count2 + 1 + count1
print(res % 998244353)


n = int(input())
s = list(input())
hell = 998244353
x = 0
for i in range(1, n):
	if s[i] == s[i - 1]:
		x = i
	else:
		break
y = n - 1
t = n - 1
while y > 0:
	if s[y - 1] == s[y]:
		t = y - 1
	else:
		break
	y -= 1
if len(list(set(s))) == 1:
	print(n * (n + 1) // 2 % hell)
	exit(0)
elif s[0] == s[-1]:
	l = t - x - 1
	l1 = x + 1
	l2 = n - l - l1
	ab = min(l1, l2) + 1
	print((1 + l1 * (l2 + 1) % hell + l2) % hell)
else:
	l = t - x - 1
	l1 = x + 1
	l2 = n - l - l1
	print((1 + l1 + l2) % hell)


n = int(input())
s = input()
cntl = 0
cntr = 0
for i in s:
	if i == s[0]:
		cntl += 1
	else:
		break
revs = s[::-1]
for i in revs:
	if i == revs[0]:
		cntr += 1
	else:
		break
if s[0] == s[n - 1]:
	print((cntl + 1) * (cntr + 1) % 998244353)
else:
	print((cntl + cntr + 1) % 998244353)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 5 * 10 ** 5 + 7
mod = 998244353

def mat(s):
	cnt = 0
	p = s[0]
	for i in s:
		if i == p:
			cnt += 1
		else:
			break
	return cnt
n = I()
s = S()
lef = mat(s)
rig = mat(s[::-1])
if s[0] != s[-1]:
	print((rig + lef + 1) % mod)
else:
	ans = (lef + 1) * (rig + 1)
	print(ans % mod)


n = int(input())
a = list(input())
front = 1
back = 1
for i in range(n - 1):
	if a[i] == a[i + 1]:
		front += 1
	else:
		break
for i in range(n - 1, 0, -1):
	if a[i] == a[i - 1]:
		back += 1
	else:
		break
if len(set(a)) == 1:
	print(n * (n + 1) // 2 % 998244353)
elif a[0] == a[-1]:
	print((front + 1) * (back + 1) % 998244353)
else:
	print((front + back + 1) % 998244353)


from math import floor
n = int(input())
s = input()
r = 1
l = 1
for i in range(1, n):
	if s[0] == s[i]:
		l += 1
	else:
		break
for i in range(2, n):
	if s[-1] == s[-i]:
		r += 1
	else:
		break
if s[0] == s[-1]:
	print((l + 1) * (r + 1) % 998244353)
else:
	print((l + r + 1) % 998244353)


t = int(input())
s = str(input())
start = s[0]
last = s[len(s) - 1]
l = 0
r = 0
c = 0
for i in s:
	if i == start:
		l += 1
	else:
		break
for i in range(len(s) - 1, -1, -1):
	if s[i] == last:
		r += 1
	else:
		break
c = t - (l + r)
if start == last:
	print((l + r + l * r + 1) % 998244353)
else:
	print((l + r + 1) % 998244353)


n = int(input())
arr = input()
mod = 998244353
left = 0
right = 0
l = arr[0]
r = arr[-1]
for c in arr:
	if l == c:
		left += 1
	else:
		break
if left != n:
	for c in arr[::-1]:
		if r == c:
			right += 1
		else:
			break
ans = left + right + 1
if left == n:
	ans = n * (n + 1) // 2
elif left + right == n:
	ans = left + right + 1
elif l == r:
	ans = left + right + left * right + 1
else:
	ans = left + right + 1
print(ans % mod)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	n = int(stdin.readline())
	s = stdin.readline()
	res = 1
	l = 0
	while s[l + 1] == s[0]:
		l = l + 1
	r = n - 1
	while s[r - 1] == s[n - 1]:
		r = r - 1
	if s[0] != s[n - 1]:
		res = l + 2 + (n - r + 1) - 1
	else:
		res = (l + 2) * (n - r + 1)
	stdout.write(str(res % 998244353))
	return 0
main()


n = int(input())
s = input()
cnt1 = cnt2 = 1
c1 = c2 = ''
for c in s:
	if c1 == '':
		c1 = c
	elif c1 == c:
		cnt1 += 1
	else:
		break
if cnt1 == n:
	cnt = n * (n + 1) // 2
else:
	for c in s[::-1]:
		if c2 == '':
			c2 = c
		elif c2 == c:
			cnt2 += 1
		else:
			break
	if c1 == c2:
		cnt = (cnt1 + 1) * (cnt2 + 1)
	else:
		cnt = cnt1 + cnt2 + 1
print(cnt % 998244353)


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


x = int(input())
s = input()
last = s[0]
cnt = 0
cntb = 1
for i in s:
	if last != i:
		break
	else:
		cnt += 1
cnt1 = 0
for i in s[::-1]:
	if s[-1] != i:
		break
	else:
		cnt1 += 1
if s[-1] == s[0]:
	print((cnt + 1) * (cnt1 + 1) % 998244353)
else:
	print((cnt + cnt1 + 1) % 998244353)


n = int(input())
s = input()
l = r = 0
while l < n and s[l] == s[0]:
	l += 1
while r < n and s[n - 1 - r] == s[-1]:
	r += 1
res = 0
if s[0] == s[-1]:
	res = (l + 1) * (r + 1)
else:
	res = l + r + 1
print(res % 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)


n = int(input())
s = input()
previ = s[0]
x = 0
for i in s:
	if previ == i:
		x += 1
		continue
	break
starting = (previ, x)
previ = s[-1]
x = 0
for i in s[::-1]:
	if previ == i:
		x += 1
		continue
	break
mod = 998244353
ending = (previ, x)
if starting[0] != ending[0]:
	print((starting[1] + ending[1] + 1) % mod)
else:
	print((starting[1] + 1) * (ending[1] + 1) % mod)


n = int(input())
s = list(input())
MOD = 998244353
l = n - 1
for i in range(n - 1):
	if s[i] != s[i + 1]:
		l = i
		break
r = 0
for i in range(n - 1, 0, -1):
	if s[i] != s[i - 1]:
		r = i
		break
ans = 0
if s[0] == s[-1]:
	if l < r:
		ans = (l + 2) * (n - r + 1)
	else:
		ans = n * (n + 1) // 2
else:
	ans = l + 1 + (n - r) + 1
ans %= MOD
print(ans)


P = 998244353
_ = input()
s = input()
num_first_chars = 0
num_last_chars = 0
for idx in range(len(s)):
	if s[idx] != s[0]:
		break
num_first_chars = idx
for idx in range(len(s) - 1, -1, -1):
	if s[idx] != s[-1]:
		break
num_last_chars = len(s) - 1 - idx
num_total_ways = 0
if s[0] != s[-1]:
	num_total_ways += 1 + num_first_chars + num_last_chars
else:
	num_total_ways += 1 + num_first_chars + num_last_chars + num_first_chars * num_last_chars
print(num_total_ways % P)


n = int(input())
s = input()
len1 = 1
len2 = 1
while s[len1] == s[len1 - 1]:
	len1 += 1
while s[n - len2 - 1] == s[n - len2]:
	len2 += 1
ans = 0
if s[0] == s[n - 1]:
	ans = (len1 + 1) * (len2 + 1)
else:
	ans = len1 + 1 + len2
print(ans % 998244353)


tam = input()
tudo = input()
listapal = []
listanum = []
ant = '-1'
x = -1
for i in tudo:
	if i == ant:
		listanum[x] += 1
	else:
		listapal.append(i)
		listanum.append(1)
		x += 1
	ant = i
cont = 0
if listapal[0] == listapal[len(listapal) - 1]:
	cont += listanum[0] * listanum[len(listanum) - 1]
cont += listanum[0] + listanum[len(listanum) - 1] + 1
print(cont % 998244353)


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


n = int(input())
l = list(input())
cpt = 1
cs = l[0]
ls = 1
while l[ls] == cs:
	ls += 1
ce = l[-1]
le = 1
while l[-le - 1] == ce:
	le += 1
cpt += ls
cpt += le
if cs == ce:
	cpt += ls * le
print(cpt % 998244353)


n = int(input())
s = input()
r = 1
l = len(s)
if l == 1:
	r = 1
elif l == 2:
	r = 3
else:
	a = s[0]
	b = s[-1]
	index = 0
	while True:
		if s[index] == a:
			index += 1
		else:
			break
	la = index
	index = -1
	while True:
		if s[index] == b:
			index -= 1
		else:
			break
	lb = abs(index + 1)
	r = la + lb + 1
	if a == b:
		r += la * lb
	r = r % 998244353
print(r)


n = int(input())
s = input()
st = 0
while s[st] == s[0]:
	st += 1
en = 0
while s[-en - 1] == s[-1]:
	en += 1
print((st + en + 1 + (st * en if s[0] == s[-1] else 0)) % 998244353)


n = int(input())
l = list(input())
r = 0
r += 1
if len(set(l)) == 1:
	print(int(n * (n + 1) / 2) % 998244353)
else:
	if l[0] != l[-1]:
		t = l[0]
		flag = True
		flag2 = False
		ll = []
		for i in range(n):
			if flag and l[i] != t:
				ll.append(i)
				flag = False
				flag2 = True
			if flag2 and l[i] != t:
				try:
					ll[1] = i
				except:
					ll.append(i)
		start = ll[0]
		end = ll[1 % len(ll)]
		start2 = start
		t = l[-1]
		flag = True
		flag2 = False
		ll = []
		for i in range(n):
			if flag and l[i] != t:
				ll.append(i)
				flag = False
				flag2 = True
			if flag2 and l[i] != t:
				try:
					ll[1] = i
				except:
					ll.append(i)
		start = ll[0]
		end = ll[1 % len(ll)]
		end2 = len(l) - 1 - end
		r += end2 + start2
		r %= 998244353
	else:
		t = l[0]
		flag = True
		flag2 = False
		ll = []
		for i in range(n):
			if flag and l[i] != t:
				ll.append(i)
				flag = False
				flag2 = True
			if flag2 and l[i] != t:
				try:
					ll[1] = i
				except:
					ll.append(i)
		start = ll[0]
		start2 = start - 0 + 1
		end = ll[1 % len(ll)]
		end2 = len(l) - 1 - end + 1
		r += end2 * start2 - 1
		r %= 998244353
	print(r % 998244353)


n = int(input())
s = input()
l = 0
kl = 1
kr = 1
r = len(s) - 1
i = 0
while l < n - 1 and s[l + 1] == s[l]:
	l += 1
	kl += 1
while r > 0 and s[r - 1] == s[r]:
	r -= 1
	kr += 1
if s[0] != s[n - 1]:
	i += kl + 1 + kr
	print(i % 998244353)
else:
	i += (kl + 1) * (kr + 1)
	print(i % 998244353)


n = int(input())
s = input()
first = s[0]
last = s[n - 1]
count_first = 1
count_last = 1
for char in s:
	if char == first:
		count_first += 1
	else:
		break
for char in s[::-1]:
	if char == last:
		count_last += 1
	else:
		break
if first == last:
	print(count_last * count_first % 998244353)
else:
	print((count_last + count_first - 1) % 998244353)


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


from collections import Counter, defaultdict, deque
n = int(input())
s = input()
m = 998244353
start = s[0]
end = s[-1]
startl = 1
endl = 1
p = 1
while p < n:
	if s[p] == start:
		startl += 1
	else:
		break
	p += 1
p = n - 2
while p >= 0:
	if s[p] == end:
		endl += 1
	else:
		break
	p -= 1
if start != end:
	print((startl + endl + 1) % m)
else:
	print((startl + endl + 1 + startl * endl) % m)


n = int(input())
s = input()
mod = 998244353
left = s[0]
right = s[-1]
ans = 1
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)


a = int(input())
b = input()
c1 = 0
c2 = 0
for i in range(a):
	if b[i] == b[0]:
		c1 += 1
	else:
		break
for j in range(a - 1, -1, -1):
	if b[j] == b[a - 1]:
		c2 += 1
	else:
		break
if b[0] == b[a - 1]:
	print((c1 + 1) * (c2 + 1) % 998244353)
else:
	print((c1 + c2 + 1) % 998244353)


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


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

def func(s):
	letter = s[0]
	for i in range(1, n):
		if s[i] != letter:
			f = i - 1
			break
	return f + 1
if len(s) == 2:
	print(3)
else:
	a = func(s)
	b = func(s[::-1])
	if s[0] == s[-1]:
		print((a + 1) * (b + 1) % 998244353)
	else:
		print((a + b + 1) % 998244353)


import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
counter = {}
lower = 0
for i in range(n):
	counter[s[i]] = 1
	if len(counter) > 1:
		lower = i
		break
counter = {}
upper = n - 1
for i in reversed(range(n)):
	counter[s[i]] = 1
	if len(counter) > 1:
		upper = i
		break
mod = 998244353
if s[0] == s[-1]:
	ans = (lower + 1) % mod * ((n - upper) % mod) % mod
else:
	ans = ((lower + 1) % mod + (n - upper) % mod - 1) % mod
print(ans)


import sys
MOD = 998244353

def solve(io):
	N = io.read_int()
	S = io.read_line()
	(fc, fl) = get_prefix(S)
	(bc, bl) = get_prefix(S[::-1])
	if fl == N:
		io.println(N * (N + 1) // 2 % MOD)
		return
	if fc == bc:
		io.println((fl + 1) * (bl + 1) % MOD)
		return
	io.println((fl + bl + 1) % MOD)

def get_prefix(S):
	for i in range(1, len(S)):
		if S[0] != S[i]:
			return (S[0], i)
	return (S[0], len(S))

class IO:
	in_stream = None
	out_stream = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, input_stream, output_stream):
		self.in_stream = input_stream
		self.out_stream = output_stream

	def read_to_buffer(self):
		self.raw = self.in_stream.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def read_string(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def read_int(self):
		return int(self.read_string())

	def read_float(self):
		return float(self.read_string())

	def read_string_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_string())
		return arr

	def read_int_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_int())
		return arr

	def read_float_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_float())
		return arr

	def read_line(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		if self.pos > 0:
			raise ValueError('Cannot call read_line in the middle of a line.')
		self.pos = len(self.buf)
		return self.raw

	def print(self, *args):
		self.out_stream.write(' '.join([str(x) for x in args]))

	def println(self, *args):
		self.print(*args)
		self.print('\n')

	def println_array(self, arr, sep=' '):
		self.println(sep.join((str(x) for x in arr)))

	def flush_output(self):
		self.out_stream.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flush_output()


import sys

def ab(s):
	for i in range(1, len(s)):
		if s[i] != s[0]:
			break
	return i

def main():
	l = int(sys.stdin.readline().strip())
	s = sys.stdin.readline().strip()
	a = ab(s)
	b = l + 1 - ab(s[::-1])
	if s[l - 1] != s[0]:
		print((l + a - b + 2) % 998244353)
	else:
		print((l + a - b + 2 + a * (l - b + 1)) % 998244353)
main()


input()
s = str(input())
n = len(s)
count_left = 0
count_right = 0
for i in range(0, n, 1):
	if s[i] == s[0]:
		count_left += 1
	else:
		break
i = n - 1
while i >= 0:
	if s[i] == s[n - 1]:
		count_right += 1
	else:
		break
	i -= 1
if s[0] == s[n - 1]:
	print((count_left + 1) * (count_right + 1) % 998244353)
else:
	print((count_left + count_right + 1) % 998244353)


import math
n = int(input())
s = input()
(i, j) = (0, n - 1)
while i < n and s[i] == s[0]:
	i += 1
while j >= 0 and s[j] == s[-1]:
	j -= 1
r = 0
if i == n:
	r = n * (n - 1) // 2 + n
elif s[0] == s[-1]:
	r = (i + 1) * (n - j)
else:
	r = i + n - j
print(r % 998244353)


n = int(input())
s = input()
pre = 0
suf = 0
while pre < n and s[pre] == s[0]:
	pre += 1
index = n - 1
while index >= 0 and s[index] == s[-1]:
	suf += 1
	index -= 1
if s[0] == s[-1]:
	ans = (pre + 1) * (suf + 1)
else:
	ans = 1 + pre + suf
print(ans % 998244353)


n = int(input())
s = input()
k = 0
l = 0
while s[0] == s[k]:
	k += 1
while s[n - 1] == s[n - 1 - l]:
	l += 1
result = k + l + 1
if s[0] == s[n - 1]:
	result += k * l
result = result % 998244353
print(result)


n = int(input())
s = input()
begin = s[0]
num_begin = 0
end = s[-1]
num_end = 0
for i in s:
	if begin == i:
		num_begin += 1
	else:
		break
for i in reversed(s):
	if end == i:
		num_end += 1
	else:
		break
if begin == end:
	print((num_begin + 1) * (num_end + 1) % 998244353)
else:
	print((num_begin + num_end + 1) % 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)