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

Code 1:
#include"bits/stdc++.h"
using namespace std;
 
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
 
typedef long long ll;
const int MOD = 1000000007;
const int Nmax = 2e5+5;

void akibify(){ 

      int n ;cin>>n ;
      string s ;
      cin>>s;bool f = 1;
      map<char,int>m ;
      int slast = 0;
      int pfirst = -1 ;
       for(int i = 0 ; i < n ; i++){
            m[s[i]]++;
            if(s[i] == 's'){
                slast = i ;
            }
            if(s[i] == 'p' && pfirst == -1){
                pfirst = i ;  
            }
       }
       if(m['p'] == 0 || m['s'] == 0){
        YES;
        return;
       }
       if(slast == 0 || pfirst == n-1){
        YES;
        return;
       }
       NO;
      

      }

    



int main(){
   fast_io;
    int t ;
    cin>>t ;
    while(t--){
      akibify();
        
    }
 
 
    return 0;
}

Code 2:
#include"bits/stdc++.h"
using namespace std;
 
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
 
typedef long long ll;
const int MOD = 1000000007;
const int Nmax = 2e5+5;

void akibify(){ 

      int n ;cin>>n ;
      string s ;
      cin>>s;bool f = 1;

      for(int i = 1 ; i < n ; i++){
           char c1 = s[i-1];
           int l1,r1 ;
           if(c1 == 'p') {
            l1 = 0 ;
            r1 = i-1;
           }
           else if(c1 == 's') {
            l1 = i-1;
            r1 = n-1;
           }
           else {
            l1 = 0 ;
            r1 = n-1;
           }
           char c2 = s[i];
            int l2,r2 ;
             if(c2 == 'p') {
            l2 = 0 ;
            r2 = i;
           }
           else if(c2 == 's') {
            l2 = i;
            r2 = n-1;
           }
           else {
            l2= 0 ;
            r2 = n-1;
           }
           if(c1 == 'p' && c2 == 's' && r1 < l2 ){
              f = 0 ;
              NO;
              return ;
           }
           if(c1 == 's' && c2 == 'p' && l2 < l1 && r2 <r1){
               f = 0;
               NO;
               return;
           }

      }
    //   int l = 0 , r = n-1;
    //   while(l < r){
    //     if(s[l] )
    //   }
      YES;

}

int main(){
   fast_io;
    int t ;
    cin>>t ;
    while(t--){
      akibify();
        
    }
 
 
    return 0;
}

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

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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve()

{

    int n;

    string a;

    cin >> n >> a;

    int cnt1=0,cnt2=0;

    for(auto &i:a){

        if(i=='s') cnt1++;

        if(i=='p') cnt2++;

    }

    if(cnt1==0 || cnt2==0 || cnt1==1 && a[a.size()-1]=='s' || cnt2==1 && a[a.size()-1]=='p') cout << "YES";

    else cout << "NO";

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

#ifdef Timur

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

        cout << "\n";

    }

    return 0;

}

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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve()

{

    int n;

    string a;

    cin >> n >> a;

    int cnt1=0,cnt2=0;

    for(auto &i:a){

        if(i=='s') cnt1++;

        if(i=='p') cnt2++;

    }

    if(cnt1==0 || cnt2==0 || cnt2==1 && a[a.size()-1]=='p') cout << "YES";

    else cout << "NO";

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

#ifdef Timur

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

        cout << "\n";

    }

    return 0;

}

Answer: 2
Problem: 2049B - pspspsps
Language: java

Code 1:
import java.util.HashSet;

import java.util.Scanner;



public class PSPS {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int testCase=sc.nextInt();

        while (testCase-- >0){

            int n=sc.nextInt();

            String s=sc.next();

            int pidx=s.indexOf('p');

            int sidx=s.lastIndexOf('s');

            HashSet<Character> hs=new HashSet<>();

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

                if(s.charAt(i)!='.') hs.add(s.charAt(i));

            }

            if(hs.size()>1 || (pidx<sidx && pidx!=-1)) System.out.println("NO");

            else System.out.println("YES");

        }

    }

}

Code 2:
import java.util.HashSet;

import java.util.Scanner;



public class PSPS {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int testCase=sc.nextInt();

        while (testCase-- >0){

            int n=sc.nextInt();

            String s=sc.next();

            int pidx=s.indexOf('p');

            int sidx=s.lastIndexOf('s');

            HashSet<Character> hs=new HashSet<>();

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

                if(s.charAt(i)!='.') hs.add(s.charAt(i));

            }

            if(hs.size()>1 || pidx<sidx) System.out.println("NO");

            else System.out.println("YES");

        }

    }

}



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

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

using namespace std;

const int N = 1e6+7;

#define int long long

#define endl '\n'







void solve(){



    int n;

    cin>>n;

    string s;

    cin>>s;

    s='0'+s;



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

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

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

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

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

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

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

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    else{

        int cnts=0,cntp=0,ix=0,ip=0;

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

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

                cnts++;

                ix=i;

            }

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

                cntp++;

                ip=i;

            }

            if(ip<ix){

                cout<<"NO"<<endl;

                return;

            }

        }

    }



    cout<<"YES"<<endl;

}



signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    //freopen("in.txt", "rt", stdin);

    //freopen("out.txt", "wt", stdout);



    int T=1;

    cin>>T;

    while(T--){



        solve();



    }

    

    

    

    return 0;

}

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

using namespace std;

const int N = 1e6+7;

#define int long long

#define endl '\n'







void solve(){



    int n;

    cin>>n;

    string s;

    cin>>s;

    s='0'+s;

    

    int l=-1,r=n+1;

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

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

    }

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

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

    }

    if(r<l){

        cout<<"NO"<<endl;

        return;

    }

    else{

        if(l==-1||r==n+1||l==1||r==n){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }

}



signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    //freopen("in.txt", "rt", stdin);

    //freopen("out.txt", "wt", stdout);



    int T=1;

    cin>>T;

    while(T--){



        solve();



    }

    

    

    

    return 0;

}

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

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

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

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

		cout<<"YES\n";

	}

	else if(m.size()==2){

		if(m.find('.')!=m.end()){

			cout<<"YES\n";

		}

		else{

			int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

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

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";	

			}

		}

		}

	}

	else{

		int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

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

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";	

			}

		}

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

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

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

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

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

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		cout<<"NO\n";

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

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

Code 1:
#include<iostream>

#include<map>

#include<algorithm>



using namespace std;



typedef long long LL;



const int N = 200010, MOD = 1e9 + 7;



int T;

LL n, m;

int a[N], b[N];



int main() {

    cin >> T;



    while (T--) {

        cin >> n;



        string s;

        cin >> s;



        int f = 1;

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

            if (s[i] != s[0]) f = 0;

        }



        if (f) puts("YES");

        else {

            f = 1;

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

                if (s[i] == 's') f = 0;

            }



            if (f) puts("YES");

            else{

                if (s[0] == 'p') puts("NO");

                else {

                    f = 1;

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

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

                            f = 0;

                            break;

                        }

                    }

                    if (f) puts("YES");

                    else puts("NO");

                }

            }

        }



    }



    return 0;

}



Code 2:
#include<iostream>

#include<map>

#include<algorithm>



using namespace std;



typedef long long LL;



const int N = 200010, MOD = 1e9 + 7;



int T;

LL n, m;

int a[N], b[N];



int main() {

    cin >> T;



    while (T--) {

        cin >> n;



        string s;

        cin >> s;



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

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



        int f1 = 0, f2 = 0;

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

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

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

        } 



        if(f1 && f2) puts("NO");

        else puts("YES");



    }



    return 0;

}



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

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

using namespace std;

#pragma GCC optimize("O3,unroll-loops")

#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#define int long long

int mod=1e9+7;

void sort(vector<int> &vct){ sort(vct.begin(),vct.end());}

void invct(vector<int> &vct,int n){vct.resize(n);for(int i=0;i<n;i++)cin>>vct[i];}

int accumulate(vector<int> &vct){int sum=0;for(int i=0;i<vct.size();i++)sum+=vct[i];return sum;}





void Solve()

{

    string str,str1,str2;

    vector<int> vct,vct1,vct2;

    unordered_map<int,int> mp;

    vector<vector<int>> mat;

    int a,b,c,k,l,m,n,r;



    // cin>>n>>m;

    cin>>n;

    cin>>str;

    // no ps is 

    int flag=0;

    int flag1=0;

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

    {

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

        {

            if(flag1==1 && i!=n-1)

            {

                cout<<"NO"<<endl;

                return ;

            }

            if(flag==0)flag=1;

        } 

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

        {

            if(flag1==0 && i!=0)flag1=1;

            if(flag==1)

            {

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    cout<<"YES"<<endl;



    

    

}



signed main()

{

    ios_base::sync_with_stdio(false);cin.tie(nullptr);

    int TC;cin>>TC;while(TC--) Solve();

    return 0;

}

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

using namespace std;

#pragma GCC optimize("O3,unroll-loops")

#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#define int long long

int mod=1e9+7;

void sort(vector<int> &vct){ sort(vct.begin(),vct.end());}

void invct(vector<int> &vct,int n){vct.resize(n);for(int i=0;i<n;i++)cin>>vct[i];}

int accumulate(vector<int> &vct){int sum=0;for(int i=0;i<vct.size();i++)sum+=vct[i];return sum;}





void Solve()

{

    string str,str1,str2;

    vector<int> vct,vct1,vct2;

    unordered_map<int,int> mp;

    vector<vector<int>> mat;

    int a,b,c,k,l,m,n,r;



    // cin>>n>>m;

    cin>>n;

    cin>>str;

    // no ps is 

    int flag=0;

    int flag1=0;

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

    {

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

        {

            if(flag1==1 && i!=n-1)

            {

                cout<<"NO"<<endl;

                return ;

            }

            if(flag==0)flag=1;

        } 

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

        {

            if(flag1==0)flag1=1;

            if(flag==1)

            {

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    cout<<"YES"<<endl;



    

    

}



signed main()

{

    ios_base::sync_with_stdio(false);cin.tie(nullptr);

    int TC;cin>>TC;while(TC--) Solve();

    return 0;

}

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

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

using namespace std;

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		int n;

		cin>>n;

		string s;

		cin>>s;

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

		{

			s[0]='.';

		}

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

		{

			s[n-1]='.';

		}

		int flag=0;

		int arr=0;

		for(int i=0;i<n&&flag*arr!=1;i++)

		{

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

			{

				flag=1;

			}

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

			{

				arr=1;

			}

		}

		if(arr*flag)

		{

			cout<<"NO"<<endl;

		}

		else

		{

			cout<<"YES"<<endl;

		}

	}

}

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

using namespace std;

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		int n;

		cin>>n;

		string s;

		cin>>s;

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

		{

			s[0]='.';

		}

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

		{

			s[n-1]='.';

		}

		int flag=0;

		int arr=0;

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

		{

			if(s[i]=='p'&&flag==0)

			{

				flag=1;

			}

			else if(s[i]=='s'&&flag)

			{

				arr=1;

				break;

			}

		}

		if(arr)

		{

			cout<<"NO"<<endl;

		}

		else

		{

			cout<<"YES"<<endl;

		}

	}

}

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

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

using namespace std;

#define int long long

#define endl '\n'

#define YES cout << "YES\n";

#define NO cout << "NO\n";



const int N = 1e6 + 5;



signed main() // Road to red

{

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

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

        int n,res{1}; cin >> n;

        string s; cin >> s;

        bool p = 0;

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

        {

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

            if(p && s[i] == 's'){res = 0; break;}

        }

        bool ss = 0;

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

        {

            if(i < n-2 && s[i] == 's'){ss = 1;}

            if(ss && s[i] == 'p'  && i < n-1){res = 0; break;}

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

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

using namespace std;

#define int long long

#define endl '\n'

#define YES cout << "YES\n";

#define NO cout << "NO\n";



const int N = 1e6 + 5;



signed main() // Road to red

{

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

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

        int n,res{1}; cin >> n;

        string s; cin >> s;

        bool p = 0;

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

        {

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

            if(p && s[i] == 's'){res = 0; break;}

            // else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;}

        }

        bool ss = 0;

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

        {

            if(i < n-2 && s[i] == 's'){ss = 1;}

            if(ss && s[i] == 'p'){res = 0; break;}

            // else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;}

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

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

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        stack<char> sta;

        bool flag=false;

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

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

            if(sta.top()=='p' && s[i]=='s'){

                flag=true;

                break;

            }

            sta.push(s[i]);

        }

        if(flag){

            cout<<"NO"<<endl;

            continue;

        }

        s[0]='.';

        s[n-1]='.';

        unordered_set<char> st;

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

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

                st.insert(s[i]);

            }

        }

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

        cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }



    }

    return 0;

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        stack<char> sta;

        bool flag=false;

        sta.push(s[0]);

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

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

            if(sta.top()=='p' && s[i]=='s'){

                flag=true;

                break;

            }

            sta.push(s[i]);

        }

        if(flag){

            cout<<"NO"<<endl;

            continue;

        }

        s[0]='.';

        s[n-1]='.';

        unordered_set<char> st;

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

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

                st.insert(s[i]);

            }

        }

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

        cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }



    }

    return 0;

}

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

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

using namespace std;

typedef long long ll;

typedef long double ld;

#define fu(i,a,b) for(int i = a; i<b; i++)

#define f(i,a) for(int i = 0; i<a; i++)

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;







int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

  



    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        

        string s;



        int t=0;



        cin >> s;



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

        {

            t=1;

        }

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

        {

            t=1;

        }

        else

        {

            t=1;

            f(i,n)

            {

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

                {

                    t=0;

                }

            }

        }



        char m = '.';





        f(i,n)

        {





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

            {

                t=0;

            }







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

            {

                m = 's';

            }

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

            {

                m = 'p';

            }



        }



        if(t==1)

        {

            cout << "YES" << endl;

        }

        else

        {

            cout << "NO" << endl;

        }







    }



    return 0;

}



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

using namespace std;

typedef long long ll;

typedef long double ld;

#define fu(i,a,b) for(int i = a; i<b; i++)

#define f(i,a) for(int i = 0; i<a; i++)

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;







int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

  



    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        

        string s;



        int t=0;



        cin >> s;



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

        {

            s[0] = '.';

        }

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

        {

            s[n-1] = '.';

        }



        int g=0,h=0;



        f(i,n)

        {



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

            {

                g =1;

            }

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

            {

                h =1;

            }



        }



        if(g==1 && h==1)

        {

            cout << "NO" << endl;

        }

        else

        {

            cout << "YES" << endl;

        }





    }



    return 0;

}



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

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

using namespace std;



int main()

{

    int t;

    cin >> t;



    while(t --)

    {

        int n;

        string str;

        cin >> n >> str;

        int p = n, s = -1;

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

        {

            if(str[i] == 'p') p = min(p, i);

            if(str[i] == 's') s = max(s, i); 

        }

        if(p < s) cout << "NO" << "\n";

    else if(s == 0 || s == -1 || p == n - 1 || p == n) cout << "YES" << "\n";

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



    }

}

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

using namespace std;



int main()

{

    int t;

    cin >> t;



    while(t --)

    {

        int n;

        string str;

        cin >> n >> str;

        int p = n, s = -1;

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

        {

            if(str[i] == 'p') p = min(p, i);

            if(str[i] == 's') s = max(s, i); 

        }

        if(p < s) cout << "NO" << "\n";

    else if(str[0] == '.' && str[n - 1] == '.' && p != n && s != -1) cout << "NO" << "\n";

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



    }

}

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

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

using namespace std;

ifstream fin("input.txt");

ofstream fout("output.txt");







void solve(){

    int n; cin >> n; 

    vector<char> v(n);

    for(auto &i: v) cin >> i;



    int imp = 0; 

    int posSmx = -1; 

    for(int i = 0; i < n; i++) if(v[i] == 's') posSmx = i; 

    for(int i = 0; i < n; i++) if(v[i] == 'p' && i < posSmx) imp = 1;   



    if(posSmx != -1){

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

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

                if(i != n - 1) imp = 1; 

            }

        }

    }

    cout << ((imp == 1) ? "NO": "YES") << '\n'; 

}



int32_t main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



  int t = 1;

  cin >> t;

  while(t--) solve();

}

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

using namespace std;

ifstream fin("input.txt");

ofstream fout("output.txt");







void solve(){

    int n; cin >> n; 

    vector<char> v(n);

    for(auto &i: v) cin >> i;



    int imp = 0; 

    int posSmx = -1; 

    for(int i = 0; i < n; i++) if(v[i] == 's') posSmx = i; 

    for(int i = 0; i < n; i++) if(v[i] == 'p' && i < posSmx) imp = 1;   



    if(posSmx > 0){

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

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

                if(i != n - 1) imp = 1; 

            }

        }

    }

    cout << ((imp == 1) ? "NO": "YES") << '\n'; 

}



int32_t main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



  int t = 1;

  cin >> t;

  while(t--) solve();

}

Answer: 2