ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: c++23 

Code 1:
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#define int long long

#define fi first

#define tc int t; cin >> t; while(t--)

#define se second

#define pb push_back

#define vi vector<int>

#define pii pair<int, int>

#define piii pair<int, pii>

#define vii vector<pii>

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define debug cout<<"\ndebug\n";

typedef long long ll;

const int mxn = 1e5+20;

const int MOD = 1e9+7;

const int INF = LLONG_MAX;

int tot(int a, int b){return (a+b)%MOD;}

// int sub(int a, int b){return (a-b)%mod;}

// int mul(int a, int b){return (a*b)%mod;}

// int chmx(int &a, int b){ return max(a, b);}

// int chmn(int &a, int b){ return min(a, b);}



void solve(){

    int n, s=-1,p=-1; cin >> n;

    string ss; cin >> ss;

    if(ss[0] == 's')ss[0] = '.';

    if(ss[n-1]=='p')ss[n-1] = '.';

    bool foundp=0,founds=0;

    for(int i = 0; i < n; i++){

        if(ss[i] == 'p')foundp=1;

        if(ss[i] == 's') founds=1;

    }

    cout << (foundp&&founds ? "NO":"YES")<<endl;

}



int32_t main(){

    fastio; 

    int t = 1;

    cin >> t;

    while(t--){

        solve();

    }

    

    return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#define int long long

#define fi first

#define tc int t; cin >> t; while(t--)

#define se second

#define pb push_back

#define vi vector<int>

#define pii pair<int, int>

#define piii pair<int, pii>

#define vii vector<pii>

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define debug cout<<"\ndebug\n";

typedef long long ll;

const int mxn = 1e5+20;

const int MOD = 1e9+7;

const int INF = LLONG_MAX;

int tot(int a, int b){return (a+b)%MOD;}

// int sub(int a, int b){return (a-b)%mod;}

// int mul(int a, int b){return (a*b)%mod;}

// int chmx(int &a, int b){ return max(a, b);}

// int chmn(int &a, int b){ return min(a, b);}



void solve(){

    int n, s=-1,p=-1; cin >> n;

    string ss; cin >> ss;

    bool ok = 0;

    for(int i = 0; i < n; i++){

        if(ss[i]=='p' && p==-1){

            p=i;

        } 

        else if(ss[i] == 's'){

            s = i;

        } else ok = 1;

    }

    if(s > p && p!=-1)cout<<"NO"<<endl;

    else{

        if(n-s==p+1 && ok) cout << "NO" << endl;

        else cout << "YES"<<endl;

    }

}



int32_t main(){

    fastio; 

    int t = 1;

    cin >> t;

    while(t--){

        solve();

    }

    

    return 0;

}

Answer: 1
Problem: 2049B - pspspsps
Language: c++23 

Code 1:
#include <bits/stdc++.h>

using namespace std;

#define ll long long int

ll answer(int n){

    string st; cin>>st;

    bool s=0,p=0;

    for(int i=1;i<=n-2;i++) {

        if(st[i]=='s' ) s=1;

        if(st[i]=='p') p=1;

    }

    if(s && p) return 0;

    if(st[0]=='p'){

        if(s || st[n-1]=='s') return 0;

    }

    return 1;



}

int main(){

    int t;

    cin>>t;

    while(t--){

        int n; cin>>n;

        //cout<<answer(n)<<endl;

        cout<<(answer(n) ? "YES\n" : "NO\n" );

    }

}

Code 2:
#include <bits/stdc++.h>

using namespace std;

#define ll long long int

ll answer(int n){

    string st; cin>>st;

    bool s=0,p=0;

    for(int i=1;i<=n-2;i++) {

        if(st[i]=='s' ) s=1;

        if(st[i]=='p') p=1;

    }

    if(s && p|| p && st[n-1]=='s') return 0;

    if(st[0]=='p'){

        if(s || st[n-1]=='s') return 0;

        else return 1;

    }

    return 1;



}

int main(){

    int t;

    cin>>t;

    while(t--){

        int n; cin>>n;

        //cout<<answer(n)<<endl;

        cout<<(answer(n) ? "YES\n" : "NO\n" );

    }

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++20 

Code 1:
#include <bits/stdc++.h>

#ifdef LOCAL

#include "debug.h"

#else

#define dbg(x...)

void dbgEndl() {}

#endif

#if __cplusplus <= 201703L || defined(LOCAL)

#include <bits/extc++.h>

namespace pbds = __gnu_pbds;

#endif



using namespace std;

using u32 = unsigned;

using u64 = unsigned long long;

using i64 = long long;

#if __cplusplus >= 202002L

using i128 = __int128;

#endif

using f64 = long double;



constexpr int N = 1000010;

constexpr f64 eps = 1e-9; // !!!

constexpr int inf32 = 1e9;

constexpr i64 inf64 = 1e18;



inline void YES(void) { cout << "YES\n"; }

inline void Yes(void) { cout << "Yes\n"; }

inline void NO(void) { cout << "NO\n"; }

inline void No(void) { cout << "No\n"; }

inline void YES_NO(bool cond) { cond ? YES() : NO(); }

inline void Yes_No(bool cond) { cond ? Yes() : No(); }



int n, m;

inline void solve(void) {

    string s;

    cin >> n >> s;

    if (count(s.begin() + 1, s.end(), 's') == 0) {

        return YES();

    }

    for (int i = 0; i < n; i++) {

        if (s[i] == 'p') return NO();

        if (i > 0 && s[i] == 's') {

            for (int j = i + 1; j < n - 1; j++) {

                if (s[j] == 'p') return NO();

            }

            return YES();

        }

    }

    YES();

}



inline void optimizeIO(void) {

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

}

int main(int argc, char const *argv[]) {

    int t = 1;

    optimizeIO(), cin >> t;

    while (t--) solve();

    return 0;

}



Code 2:
#include <bits/stdc++.h>

#ifdef LOCAL

#include "debug.h"

#else

#define dbg(x...)

void dbgEndl() {}

#endif

#if __cplusplus <= 201703L || defined(LOCAL)

#include <bits/extc++.h>

namespace pbds = __gnu_pbds;

#endif



using namespace std;

using u32 = unsigned;

using u64 = unsigned long long;

using i64 = long long;

#if __cplusplus >= 202002L

using i128 = __int128;

#endif

using f64 = long double;



constexpr int N = 1000010;

constexpr f64 eps = 1e-9; // !!!

constexpr int inf32 = 1e9;

constexpr i64 inf64 = 1e18;



inline void YES(void) { cout << "YES\n"; }

inline void Yes(void) { cout << "Yes\n"; }

inline void NO(void) { cout << "NO\n"; }

inline void No(void) { cout << "No\n"; }

inline void YES_NO(bool cond) { cond ? YES() : NO(); }

inline void Yes_No(bool cond) { cond ? Yes() : No(); }



int n, m;

inline void solve(void) {

    string s;

    cin >> n >> s;

    if (count(s.begin(), s.end(), 's') == 0) {

        return YES();

    }

    for (int i = 0; i < n; i++) {

        if (s[i] == 'p') return NO();

        if (s[i] == 's') {

            for (int j = i + 1; j < n - 1; j++) {

                if (s[j] == 'p') return NO();

            }

            return YES();

        }

    }

    YES();

}



inline void optimizeIO(void) {

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

}

int main(int argc, char const *argv[]) {

    int t = 1;

    optimizeIO(), cin >> t;

    while (t--) solve();

    return 0;

}



Answer: 1
Problem: 2049B - pspspsps
Language: c++20 

Code 1:
#include <bits/stdc++.h>



using namespace std;



void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    for (int i=0; i<n; i++) {

        if(s.substr(i,2)=="ps"){

            cout<<"NO\n";

            return;

        }

        if(i>0 && i<n-2 && s.substr(i,2)=="sp"){

             cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}

 

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin>>t;

    while(t--){

        solve();

    };

    return 0;

}

Code 2:
#include <bits/stdc++.h>



using namespace std;



void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    if(s[0]=='s'){

        s[0]='.';

    }

    if(s[n-1]=='p'){

        s[n-1]='.';

    }

    int cd1=0,cd2=0;

    for (int i=0; i<n; i++) {

        if(s[i]=='s'){

            cd1=1;

        }

        if(s[i]=='p'){

            cd2=1;

        }

    }

    if(cd1 && cd2){

        cout<<"NO\n";

        return;

    }

    cout<<"YES\n";

}

 

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin>>t;

    while(t--){

        solve();

    };

    return 0;

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++20 

Code 1:
// Online C++ compiler to run C++ program online

#include <bits/stdc++.h>

using namespace std;



bool solve(string &s,int n){

  int s1=0,p1=0,d1=0;

  for(auto &r:s){

    if(r=='s')

    s1++;

    if(r=='p')

    p1++;

    if(r=='.')

    d1++;

  }

  if(p1==n||s1==n||d1==n||s1+d1==n||p1+d1==n)

  return 1;

  if(s[0]=='s'&&s1==1)

  return 1;

  if(s[n-1]=='p'&&p1==1)

  return 1;

  return 0;

}



int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        if(solve(s,n))

        cout<<"YES";

        else

        cout<<"NO";

        cout<<endl;

    }

    

    

    return 0;

}

Code 2:
// Online C++ compiler to run C++ program online

#include <bits/stdc++.h>

using namespace std;



bool solve(string &s,int n){

  int s1=0,p1=0,d1=0;

  for(auto &r:s){

    if(r=='s')

    s1++;

    if(r=='p')

    p1++;

    if(r=='.')

    d1++;

  }

  if(p1==n||s1==n||d1==n)

  return 1;

  if(s[0]=='s'&&s1==1)

  return 1;

  if(s[n-1]=='p'&&p1==1)

  return 1;

  return 0;

}



int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        if(solve(s,n))

        cout<<"YES";

        else

        cout<<"NO";

        cout<<endl;

    }

    

    

    return 0;

}

Answer: 1
Problem: 2049B - pspspsps
Language: c++23 

Code 1:
#include<bits/stdc++.h>

using namespace std;

#define int long long



signed main(){



    ios_base::sync_with_stdio(false);

    cin.tie(NULL);  cout.tie(NULL);



    int t; cin>>t;

    while(t--){

        int n,ss=0,si=-1,pp=0,pi=-1; cin>>n;

        string s; cin>>s;

        

        for(int i=0;i<n;i++){

            if(s[i]=='s'){

                ss++;

                si=i;

            }

            else if(s[i]=='p'){

                pp++;

                pi=i;

            }



        }

        if(!ss || !pp) cout<<"YES"<<endl;

        else if((ss==1 && si==0) || (pp==1 && pi==n-1)) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

        

        // cout<<ss<<" "<<pp<<" "<<si<<" "<<pi<<endl;

    }

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

#define int long long



signed main(){



    ios_base::sync_with_stdio(false);

    cin.tie(NULL);  cout.tie(NULL);



    int t; cin>>t;

    while(t--){

        int n,ss=0,si=-1,pp=0,pi=-1; cin>>n;

        string s; cin>>s;

        

        for(int i=0;i<n;i++){

            if(s[i]=='s'){

                ss++;

                si=i;

            }

            else if(s[i]=='p'){

                pp++;

                pi=i;

            }



        }

        if(!ss || !pp) cout<<"YES"<<endl;

        else if(si==0 || pi==n-1) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

        

        // cout<<ss<<" "<<pp<<" "<<si<<" "<<pi<<endl;

    }

}

Answer: 1
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pair pair<ll,ll>

ll n,m,say1,say2,cem=0;

int main()

{

    cin>>n;

    string s;

    while(n--)

    {

      cin>>m;

      cin>>s;

      say1=0;

      say2=0;

      bool b=1;

      if(s[0]=='s')

      {

        cout<<"yes"<<endl;

        continue;

      }

      for(int i=0;i<s.size();i++)

      {

        if(s[i]=='p')

        say1++;

        if(s[i]=='s')

        say2++;

        if(i!=0 and s[i]=='s' and s[i-1]=='p')

        b=0;

      }

      if(say2==0)

      {

        cout<<"yes"<<endl;

        continue;

      }

      if(s[0]=='.' and say1==0)

      {

        cout<<"yes"<<endl;

        continue;

      }

      if(b)

      {

        cout<<"yes"<<endl;

        continue;

      }

     else

      cout<<"no"<<endl;

    }

}

Code 2:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pair pair<ll,ll>

ll n,m,say1,say2,cem=0;

int main()

{

    cin>>n;

    string s;

    while(n--)

    {

      cin>>m;

      cin>>s;

      say1=0;

      say2=0;

      bool b=0,b1=0;

      if(s[0]=='s')

      {

        s[0]='.';

      }

      if(s[m-1]=='p')

      s[m-1]='.';

      for(int i=0;i<s.size();i++)

      {

        if(s[i]=='p')

        b=1;

        if(s[i]=='s')

        b1=1;

      }

      if(b1 and b)

      cout<<"no"<<endl;

      else cout<<"yes"<<endl;

    }

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
// **************** MBRAHUL *************** 

#include<bits/stdc++.h>

#define ll long long

#define pn cout<<"NO"<<endl

#define py cout<<"YES"<<endl

#define vll vector<long long>

#define vi vector<int>

#define vb vector<bool>

#define u_map unordered_map

#define pll pair<long long,long long>

#define pii pair<int,int>

#define inf INT_MAX

#define pb push_back

#define mod 998244353

#define MOD 1000000007

#define ld long double

#define ff first

#define ss second

#define all(v) v.begin(),v.end()

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define loop(i,n) for(int i=0;i<n;i++)

#define rloop(i, n) for(int i=n-1;i>=0;i--)

using namespace std;



void input(vector<ll>&arr,ll n){

for(ll i =0;i<n;i++)cin>>arr[i];

}



void printArr(vector<ll>&arr, ll i,ll j){

for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";

cout<<endl; 

}



void find(){

  int n;

  string str;

  cin>>n>>str;

  set<char>s;

  for(auto c:str)s.insert(c);

  if(s.size()==1){

    py;

    return;

  }

  for(int i = 0;i<n-1;i++){

    if(str[i]=='s' || str[i]=='.')continue;

    else{

      pn;

      return;

    }

  }

  py;

}



int main(){

ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

ll test=1;

cin>>test;

while(test--){

find();

}

return 0;

}

Code 2:
// **************** MBRAHUL *************** 

#include<bits/stdc++.h>

#define ll long long

#define pn cout<<"NO"<<endl

#define py cout<<"YES"<<endl

#define vll vector<long long>

#define vi vector<int>

#define vb vector<bool>

#define u_map unordered_map

#define pll pair<long long,long long>

#define pii pair<int,int>

#define inf INT_MAX

#define pb push_back

#define mod 998244353

#define MOD 1000000007

#define ld long double

#define ff first

#define ss second

#define all(v) v.begin(),v.end()

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define loop(i,n) for(int i=0;i<n;i++)

#define rloop(i, n) for(int i=n-1;i>=0;i--)

using namespace std;



void input(vector<ll>&arr,ll n){

for(ll i =0;i<n;i++)cin>>arr[i];

}



void printArr(vector<ll>&arr, ll i,ll j){

for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";

cout<<endl; 

}



void find(){

  int n;

  string str;

  cin>>n>>str;

  set<char>st;

  for(auto c:str)if(c!='.')st.insert(c);

  if(st.size()<=1){

    py;

    return;

  }

  int s=0,p=0;

  for(auto c:str){

    if(c=='s')s++;

    else if(c=='p')p++;

  }

  if(s==1 || p==1){

    if(s==1 && p==1){

      if(str.back()=='p' || str[0]=='s')py;

      else pn;

    }

    else if(s==1){

      if(str[0]=='s')py;

      else pn;

    }

    else{

      if(str.back()=='p')py;

      else pn;

    }

  }

  else pn;

}



int main(){

ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

ll test=1;

cin>>test;

while(test--){

find();

}

return 0;

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



    if(s[0] == 's'){

        seen_s = true;

    }

    else if(s[0] == 'p'){

        seen_p = true;

    }



    for(int i = 1; i < n-1; i++){

        if(s[i] == 's'){

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

        else if(s[i] == 'p'){

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



    if(s[0] == 'p'){

        seen_p = true;

    }

    

    for(int i = 1; i < n-1; i++){

        if(s[i] == 's'){

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

        else if(s[i] == 'p'){

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }

    if(s[n-1] == 's' && seen_p){

        cout << "no\n";

        return;

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#include<iostream>

#include<string>

using namespace std;

void solve()

{

	int n,jump=1;

	string s;

	cin>>n>>s;

	for(int i=1;i<n;i++)

	{

		if(s[i]=='.')

		{

			jump++;

			continue;

		}

		if(s[i]=='s'&&s[i-jump]=='p')

		{

			cout<<"NO"<<endl;

			return;

		}

		if(s[i]=='p'&&s[i-jump]=='s'&&i!=n-1&&i-jump!=0)

		{

			cout<<"NO"<<endl;

			return;

		}

		jump=1;

	}

	cout<<"YES"<<endl;

}

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0; 

} 

Code 2:
#include<iostream>

#include<string>

using namespace std;

void solve()

{

	int n;

	string s;

	cin>>n>>s;

	for(int i=1;i<n;i++)

	{

		if(s[i]=='s'&&s[i-1]=='p')

		{

			cout<<"NO"<<endl;

			return;

		}

		if(s[i]=='p'&&s[i-1]=='s'&&i!=n-1)

		{

			cout<<"NO"<<endl;

			return;

		}

	}

	cout<<"YES"<<endl;

}

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0; 

} 

Answer: 1
Problem: 2049B - pspspsps
Language: c++23 

Code 1:
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

ll n,a[1000010],q[1000010];

string s;



void solve()

{

	cin>>n;

	cin>>s;

	for(int i=0;i<=n-1;i++)

	{

		for(int j=0;j<=n-1;j++)

		{

			if(s[i]=='p'&&s[j]=='s'&&i!=n-1&&j!=0)

			{

				cout<<"NO"<<'\n';

				return;

			}

		}

	}

	cout<<"YES"<<'\n';

	return;

}



int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

ll n,a[1000010],q[1000010];

string s;



void solve()

{

	cin>>n;

	cin>>s;

	for(int i=0;i<n;i++)

	{

		if(s[i]=='p') q[i]=1;

		else if(s[i]=='s') q[i]=2;

		else if(s[i]=='.') q[i]=0;

	}

	bool flag=false;

	for(int i=0;i<n;i++)

	{

		if(q[i]) flag=true;

	}

	if(!flag)

	{

		cout<<"YES"<<'\n';

		return;

	}

	if(q[0]==0&&q[n-1]==0&&flag) 

	{

		cout<<"NO"<<'\n';

		return;

	}

	flag=false;

	for(int i=0;i<n;i++)

	{

		if(q[i]==1)

		{

			flag=true;

		}

		if(flag&&q[i]==2)

		{

			cout<<"NO"<<'\n';

			return;

		}

	}

	flag=false;

	for(int i=n-1;i>=0;i--)

	{

		if(q[i]==2) flag=true;

		if(flag&&q[i]==1)

		{

			cout<<"NO"<<'\n';

			return;

		}

	}

	cout<<"YES"<<'\n';

	return;

}



int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

Answer: 1
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

const int N=6000;

char a[N];

int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		int n;

		cin>>n;

		int b1=0,b2=0;

		for(int i=1;i<=n;i++)

		{

			cin>>a[i];

			if(i==1 or i==n)continue;

			if(a[i]=='p')b1++;

			if(a[i]=='s')b2++;

		}

		if(b1>0 and b2>0)cout<<"NO"<<endl;

		else if(b1==b2 and (a[1]!='p' or a[n]!='s'))cout<<"YES"<<endl;

		else if(b2>0 and a[1]!='p')cout<<"YES"<<endl;

		else if(b1>0 and a[n]!='s')cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

		

	}

} 

Code 2:
#include<bits/stdc++.h>

using namespace std;

const int N=6000;

char a[N];

int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		int n;

		cin>>n;

		int b1=0,b2=0;

		for(int i=1;i<=n;i++)

		{

			cin>>a[i];

			if(a[i]=='p')b1++;

			if(a[i]=='s')b2++;

		}

		if(b1==0 or b2==0)cout<<"YES"<<endl;

		else if(b1>1 and b2>1)cout<<"NO"<<endl;

		else if(a[1]=='p' or a[n]=='s')cout<<"NO"<<endl;

		else if((b1==1 and a[n]=='p') or (b2==1 and a[1]=='s'))cout<<"YES"<<endl;

		else cout<<"NO";

	}

} 

Answer: 1
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#include <bits/stdc++.h>

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

    for(ll i=0; i<n; i++){

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"/n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

Code 2:
#include <bits/stdc++.h>

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

    for(ll i=0; i<n; i++){

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"\n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

int n;

char s[505];

void solve(){

    cin>>n;

    for(int i=1;i<=n;i++){

    	cin>>s[i];

	}

	int a=0,b=0;

	for(int i=2;i<n;i++){

		if(s[i]=='s')a++;

		if(s[i]=='p')b++;

	}

	if(a[1]=='p'){

		if(a[n]!='s'){

			if(a==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(a[n]=='s'){

		if(a[1]!='p'){

			if(b==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

	}

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int TTT=1;

    cin>>TTT;

    while(TTT--)solve();

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

int n;

char s[505];

void solve(){

    cin>>n;

    for(int i=1;i<=n;i++){

    	cin>>s[i];

	}

	int a=0,b=0;

	for(int i=2;i<n;i++){

		if(s[i]=='s')a++;

		if(s[i]=='p')b++;

	}

	if(s[1]=='p'){

		if(s[n]!='s'){

			if(a==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(s[n]=='s'){

		if(s[1]!='p'){

			if(b==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(a==0||b==0)cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int TTT=1;

    cin>>TTT;

    while(TTT--)solve();

}

Answer: 2