Advertisement
erfanul007

CF Edu 57 B

Dec 29th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long int n,i,cnf=0,cnl=0,cnt=0;
  6. string a;
  7. cin>>n;
  8. cin>>a;
  9. char prev=a[0];
  10. for(i=0;i<n;i++){
  11. if(a[i]==prev)
  12. cnf++;
  13. else
  14. break;
  15. }
  16. char last=a[n-1];
  17. for(i=n-1;i>=0;i--){
  18. if(a[i]==last)
  19. cnl++;
  20. else
  21. break;
  22. }
  23. cnt=cnf+cnl;
  24. if(cnt==n)
  25. cout<<cnt+1<<endl;
  26. else{
  27. if(prev==last){
  28. cnt=((cnf+cnl)+(cnf*cnl)+1)%998244353;
  29. cout<<cnt<<endl;
  30. }
  31. else
  32. cout<<cnt+1<<endl;
  33. }
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement