https://codeforc.es/contest/1096/problem/B
题意:删除一个子串使得其剩下的字符相同;可以全部删除;
思路:记录连续等于s[0]和后到前等于s[n-1]的,如果他们相同则可以删除他们中间的任意长度;否则就只能删除得只剩s[0]或s[n-1]
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<string>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-16
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=1e6+9;
const int mod=1e9+7;
inline ll read()
{
ll f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9')
{
if(ss=='-')f=-1;ss=getchar();
}
while(ss>='0'&&ss<='9')
{
x=x*10+ss-'0';ss=getchar();
} return f*x;
}
ll power(ll x,ll n)
{
ll ans=1;
while(n)
{
if(n&1) ans=ans*x;
x=x*x;
n>>=1;
}
return ans;
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int n;
cin>>n;
string s;
cin>>s;
int l=0;
int r=n-1;
ll cntl=0,cntr=0;
while(s[l]==s[0]) l++,cntl++;
while(s[r]==s[n-1]) r--,cntr++;
if(s[0]==s[n-1])
{
cout<<(cntl+1)*(cntr+1)%998244353<<endl;
}
else
{
cout<<(cntl+cntr+1)%998244353<<endl;
}
return 0;
}