Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long int n,i,cnf=0,cnl=0,cnt=0;
- string a;
- cin>>n;
- cin>>a;
- char prev=a[0];
- for(i=0;i<n;i++){
- if(a[i]==prev)
- cnf++;
- else
- break;
- }
- char last=a[n-1];
- for(i=n-1;i>=0;i--){
- if(a[i]==last)
- cnl++;
- else
- break;
- }
- cnt=cnf+cnl;
- if(cnt==n)
- cout<<cnt+1<<endl;
- else{
- if(prev==last){
- cnt=((cnf+cnl)+(cnf*cnl)+1)%998244353;
- cout<<cnt<<endl;
- }
- else
- cout<<cnt+1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement