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

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

using namespace std;



#define int long long

using pii = pair<int,int>;



signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";



        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if(countp>0 and (s[i]=='s'))

                ans = "NO";

            if(counts>1 && countp>1)

                ans = "NO";

        }

        if((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')

            ans = "NO";

        if((counts>1 && countp>0) && s[n-1]=='.')

            ans = "NO";

        if((countp>1 && counts>0) && s[0]=='.')

            ans="NO";

        cout<<ans<<endl;

    }

}

/*

..sp

4321

sp..

1234



.spp

3124

spp.

3214



ssp.

4213

.ssp

4321



*/

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

using namespace std;



#define int long long

using pii = pair<int,int>;



signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        // cout<<s<<endl;

        // n=s.size();

        string ans = "YES";



        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if(countp>0 and (s[i]=='s'))

                ans = "NO";

            if(counts>1 && countp>1)

                ans = "NO";

        }

        if(s[0] == '.' && s[n-1]=='.' && counts>0 && countp>0)

            ans = "NO";

        cout<<ans<<endl;

    }

}

/*

sspp

4321

123456

*/

Answer: 1
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] == '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;

}

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] == '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;

        }       

    }

    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: 1
Problem: 2049B - pspspsps
Language: c++20 

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



using namespace std;



#define ll long long



void I_Will_Give_It_a_Try() {

    int n;

    cin >> n;

    string s;

    cin >> s;

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

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

    bool f1{}, f2{};

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

        if (s[i] == 'p') f1 = true;

        if (s[i] == 's') f2 = true;



    }

    cout << (f1 && f2 ? "NO\n" : "YES\n");

}



int32_t main() {

    ios::sync_with_stdio(0);

    cout.tie(0);

    cin.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

    int t{1};

    cin >> t;

    while (t--)

        I_Will_Give_It_a_Try();

    /*

        IT'S AN ABSOLUTE MESS UP THERE.

    */

}

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



using namespace std;



#define ll long long



void I_Will_Give_It_a_Try() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int Ss{}, Ps{}, idxP{-1}, idxS{-1};

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

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

            Ss++, idxS = i;

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

            Ps++;

            if (idxP == -1)

                idxP = i;

        }

    }

    if (!Ss || !Ps) return void(cout << "YES\n");

    if (Ss > 1 && Ps > 1 || idxP < idxS) return void(cout << "NO\n");

    if (s.back() == s.front() && s.front() == '.') return void(cout << "NO\n");

    cout << "YES\n";

}



int32_t main() {

    ios::sync_with_stdio(0);

    cout.tie(0);

    cin.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

    int t{1};

    cin >> t;

    while (t--)

        I_Will_Give_It_a_Try();

    /*

        IT'S AN ABSOLUTE MESS UP THERE.

    */

}

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

Code 1:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<vector>

#include<map>

#include <numeric>

#define ll long long

#define ull unsigned long long

using namespace std;



void solve()

{

    ll n;

    bool fs = false, fp = false;

    string s;

    cin >> n >> s;

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

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

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

        if(s[i] == 's') fs = true;

        if(s[i] == 'p') fp = true;

    }

    if(fs && fp) cout << "NO" << endl;

    else cout << "YES" << endl;

    return;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}

Code 2:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<vector>

#include<map>

#include <numeric>

#define ll long long

#define ull unsigned long long

using namespace std;



void solve()

{

    ll n;

    string s;

    cin >> n >> s;

    ll ns = 0, np = 0;

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

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

            ns++;

            if(np > 0) {

                cout << " NO" << endl;

                return;

            }

        }

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

    }

    if(ns == n || np == n) {

        cout << "YES" << endl;

        return;

    }

    if(ns == 0 && np == 0) {

        cout << "YES" << endl;

        return;

    }

    s = ' ' + s;

    map<ll,ll> mp;

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

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

            mp[n-i+1]++;

        }

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

            mp[i]++;

        }

    }

    for(auto x : mp) {

        if(x.second > 1) {

            cout << " NO" << endl;

            return;

        }

    }

    cout << "YES" << endl;

    return;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}

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

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

using namespace std;



#define int long long

using pii = pair<int,int>;



signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";



        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if((countp>0 and (s[i]=='s'))||(counts>1 && countp>1))

                ans = "NO";

        }

        if(((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')||

        ((counts>1 && countp>0) && s[n-1]=='.')||

        ((countp>1 && counts>0) && s[0]=='.'))

            ans = "NO";

        cout<<ans<<endl;

    }

}



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

using namespace std;



#define int long long

using pii = pair<int,int>;



signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";

        bool pflag = false;

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

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

                pflag = true;

            if(pflag and (s[i]=='s'||s[i]=='.'))

                ans = "NO";

        }

        cout<<ans<<endl;

    }

}

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

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

using namespace std;

void solve(void)

{

	int n;cin>>n;

	string s;cin>>s;

	int snum=0,pnum=0;

	bool pj=1;int posp,poss;

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

	{

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

		{

			posp=i;

			pj=0;

		}

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

		{

			snum++;

			poss=i;

		}

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

			pnum++;

	} 

	if(snum!=0&&pnum!=0&&posp<poss)

	{

		cout<<"NO\n";

		return ;

	}

	if(snum>1&&pnum>1)

	{

		cout<<"NO\n";

		return;

	}

	if(snum==1&&pnum==1&&(s[0]=='s'||s[n-1]=='p'))

	{

		cout<<"YES\n";

		return;

	}

	if(snum==1&&pnum!=0&&s[0]!='s')

	{

		cout<<"NO\n";

		return;

	}

	if(pnum==1&&snum!=0&&s[n-1]!='p')

	{

		cout<<"NO\n";

		return;

	}

//	cout<<posp<<" "<<poss<<endl;

	cout<<"YES\n";

}

signed main(void)

{

	ios::sync_with_stdio(0);

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

	int t;cin>>t;

	while(t--)

	{

		solve();

	}

}

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

using namespace std;

void solve(void)

{

	int n;cin>>n;

	string s;cin>>s;

	int snum=0,pnum=0;

	bool pj=1;int posp,poss;

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

	{

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

		{

			posp=i;

			pj=0;

		}

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

		{

			snum++;

			poss=i;

		}

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

			pnum++;

	} 

	if(snum!=0&&pnum!=0&&posp<poss)

	{

		cout<<"NO\n";

		return ;

	}

	if(snum>1&&pnum>1)

	{

		cout<<"NO\n";

		return;

	}

	if(snum!=0&&pnum!=0&&s[0]!='s'&&s[n-1]!='p')

	{

		cout<<"NO\n";

		return;

	}

//	cout<<posp<<" "<<poss<<endl;

	cout<<"YES\n";

}

signed main(void)

{

	ios::sync_with_stdio(0);

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

	int t;cin>>t;

	while(t--)

	{

		solve();

	}

}

Answer: 1
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;

//         cin>>n;

//         vector<int> v;

//         map<int,int> mp;

//         int x,y;

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

//             cin>>x>>y;

//             mp[x] = y;

//             v.push_back(y);

//         }

//         sort(v.begin(),v.end());

//         long total = 0;

//         for(auto &j : mp){

//             auto p = lower_bound(v.begin(),v.end(),j.second);

//             total+=p-v.begin();

//             v.erase(p);

//         }

//         cout<<total<<endl;

//     }

//     return 0;

// }



#include <bits/stdc++.h>

using namespace std;

 

int main(){

	int t;

	cin>>t;

	while (t--)

	{

		int n;

		string s;

		cin>>n>>s;

		bool is_poss=true,is_p=false,is_s=false;

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

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

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

			if(s[i]=='p') is_p = true;

			if(s[i]=='s') is_s = true;

		}

		if(is_s && is_p == true){

			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;

//         vector<int> v;

//         map<int,int> mp;

//         int x,y;

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

//             cin>>x>>y;

//             mp[x] = y;

//             v.push_back(y);

//         }

//         sort(v.begin(),v.end());

//         long total = 0;

//         for(auto &j : mp){

//             auto p = lower_bound(v.begin(),v.end(),j.second);

//             total+=p-v.begin();

//             v.erase(p);

//         }

//         cout<<total<<endl;

//     }

//     return 0;

// }



#include <bits/stdc++.h>

using namespace std;

 

int main(){

	int t;

	cin>>t;

	while (t--)

	{

		int n;

		string s;

		cin>>n>>s;

		bool is_poss=true,is_p=false,is_s=false;

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

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

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

			if(s[i]=='p') is_p = true;

			if(s[i]=='s') is_s = true;

		}

		if(is_s && is_p){

			cout<<"NO"<<endl;

		}else{

			cout<<"YES"<<endl;

		}

	}

}

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

Code 1:
#include <iostream>

#include <string>

#include <unordered_map>



#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);

using ll = long long;





void solve()

{

    int n;

    std::cin >> n;



    std::string str;

    std::cin >> str;



    // sp.... -> possible

    // ....sp -> possible

    // ps impossible in any case



    // basically p should be leading and only one p is allowed

    std::unordered_map<char, int> map;

    for (char e : str) map[e]++;

    bool p = false, s = false, oneP = false, oneS = false;

    for (const auto& [first, second] : map)

    {

        if (first == 'p' && second > 1) p = true;

        if (first == 's' && second > 1) s = true;

        if (first == 's' && second == 1) oneS = true;

        if (first == 'p' && second == 1) oneP = true;

    }



    if ((p && s) || (oneS && p)) {std::cout << "NO\n"; return;}

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



    p = false; s = false;

    for (char e : str)

    {

        if (e == 'p') p = true;

        if (e == 's') s = true;

    }

    (p && s) ? std::cout << "NO\n" : std::cout << "YES\n";

}



int main()

{

    inout;

    int t = 1;

    std::cin >> t;



    while (t--) solve();

}



Code 2:
#include <iostream>

#include <string>

#include <unordered_map>



#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);

using ll = long long;





void solve()

{

    int n;

    std::cin >> n;



    std::string str;

    std::cin >> str;



    // sp.... -> possible

    // ....sp -> possible

    // ps impossible in any case



    // basically p should be leading and only one p is allowed 

    bool p = false, s = false; 

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



    for (char e : str)

    {

        if (e == 'p') p = true;

        if (e == 's') s = true;

    }

    (p && s) ? std::cout << "NO\n" : std::cout << "YES\n";

}



int main()

{

    inout;

    int t = 1;

    std::cin >> t;



    while (t--) solve();

}



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

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



using namespace std;



int n;

string s;

void solve() {

    cin >> n >> s;

    

    int l = n - 1, r = 0;

    while(l >= 0 && s[l] != 's') l--;

    while(r < n && s[r] != 'p') r++;

    if(l > r) {

        cout << "No" << '\n';

        return;

    }



    if(l < 1 || n - r < 2) {

        cout << "Yes" << '\n';

    } else {

        // cout << l << ' ' << r << '\n';

        cout << "No" << '\n';

    }

}



int main() {

    int t;  cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}



/*

sspp

4312

*/

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



using namespace std;



int n;

string s;

void solve() {

    cin >> n >> s;

    

    bool f1 = false, f2 = false;

    for(char c : s) {

        if(c == 'p') f1 = true;

        else if(c == 's') f2 = true;

    }

    if(!f1 || !f2) {

        cout << "Yes" << "\n";

        return;

    }

    

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

        cout << "Yes" << "\n"; 

    }

    else cout << "No" << "\n";

}



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;



int main(){

    int t;

    cin >> t;

    while(t--){

        int n;

        cin >> n;

        string h;

        cin >> h;

        int i = 0;

        int j = n - 1;

        if(h[0] == h[n - 1]){

            i++;

            j--;

            goto abc;

        }

        if(h[0] == 's' || h[0] == '.'){

            i++;

        }

        if(h[n - 1] == 'p' || h[n - 1] == '.'){

            j--;

        }

        abc : //skip statement

        bool flag1 = 0;

        bool flag2 = 0;

        for(int p = i; p <= j; p++){

            if(h[p] == '.') continue;

            if(h[p] == 's') flag1 = 1;

            if(h[p] == 'p') flag2 = 1;

        }

        if(flag1 && flag2){

            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 h;

        cin >> h;

        int i = 0;

        int j = n - 1;

        if(h[0] == 's' || h[0] == '.'){

            i++;

        }

        if(h[n - 1] == 'p' || h[n - 1] == '.'){

            j--;

        }

        bool flag1 = 0;

        bool flag2 = 0;

        for(int p = i; p <= j; p++){

            if(h[p] == '.') continue;

            if(h[p] == 's') flag1 = 1;

            if(h[p] == 'p') flag2 = 1;

        }

        if(flag1 && flag2){

            cout << "NO" << endl;

        } else {

            cout << "YES" << endl;

        }

    }

}

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

Code 1:
a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  k = 0

  for z in range(b):

    if c[z] == "p" and k == 0:

      k = 1

      

    elif k == 1 and c[z] == "s":

      k = -1

      break

    

    

  

  if "s" in c and "p" in c:

    if c[-1] != "p":

      print("No")

      

    elif k == -1:

      print("No")

      

    else:

      print("Yes")

      

  elif k == -1:

    print("No")

    

  else:

    print("Yes")

Code 2:
a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  

  if j[0] == "s":

    j[0] = "."

    

  if j[-1] == "p":

    j[-1] = "."

    

  l = 0

  if "s" in j and "p" in j:

    l = -1

    

    

  print("Yes") if l == 0 else print("No")

    

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

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

using namespace std;



#define int long long int



void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    bool f = false;

    int cnts = 0;

    int cntp = 0;

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

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

        else if(s[i]=='s') cnts++;

    }

    if(cntp<=1 || cnts<=1){

        if(cntp==0 || cnts==0){

            cout<<"YES\n";

            return;

        }

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

            cout<<"YES\n";

            return;

        }

        else{

            cout<<"NO\n";

            return;

        }

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

            cout<<"YES\n";

            return;

        }

        else{

            cout<<"NO\n";

            return;

        }

    }

    else{

        cout<<"NO\n";

        return;

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int tt = 1;

    cin>>tt;



    while(tt--){

        solve();

    }

    return 0;

}

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

using namespace std;



#define int long long int



void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    bool f = false;

    int cnts = 0;

    int cntp = 0;

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

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

        else if(s[i]=='s') cnts++;

    }

    if(cntp<=1 || cnts<=1){

        if(cntp==0 || cnts==0){

            cout<<"YES\n";

            return;

        }

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

            cout<<"YES\n";

            return;

        }

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

            cout<<"YES\n";

            return;

        }

        else{

            cout<<"NO\n";

            return;

        }

    }

    else{

        cout<<"NO\n";

        return;

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int tt = 1;

    cin>>tt;



    while(tt--){

        solve();

    }

    return 0;

}

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

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

using namespace std;



int main(){

    ios::sync_with_stdio(false);

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

    int t;

    cin >> t;

    while(t --){

        int n;

        cin >> n;

        string s;

        cin >> s;

        int s_cnt = 0 , p_cnt = 0 , wzs = -1 , wzp = -1 , cs = -1;

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

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

                s_cnt ++;

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

                p_cnt ++;

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

                wzs = i;

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

                wzp = i;

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

                cs = i;

        }

        if(s_cnt && p_cnt){

            if(wzs > wzp || cs != 0)

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

            else

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

        }else

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

    }

    return 0;

}

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

using namespace std;



int main(){

    ios::sync_with_stdio(false);

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

    int t;

    cin >> t;

    while(t --){

        int n;

        cin >> n;

        string s;

        cin >> s;

        int wzs = -1 , wzp = -1;

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

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

                wzs = i;

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

                wzp = i;

        }

        if((wzs >= -1 && (wzp == n - 1 || wzp == -1)) || (wzs == -1 || wzs == 0) && wzp >= -1)

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

        else

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

    }

    return 0;

}

Answer: 2