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

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;



#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18



mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;



const int M=1e9+7;



// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }



void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0;

    rep(i,0,n){

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

        else if(s[i]=='s' && prevp){

            cout<<"NO\n";

            return;

        }

    }

    rep(i,1,n-2){

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

            cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}



int32_t main()

{

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    

    cin >> t;

    while(t--)

    {

        //cout << "Case #" << i << ": ";

        Solve();

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 

    return 0;

}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;



#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18



mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;



const int M=1e9+7;



// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }



void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0,prevs=0;

    rep(i,0,n){

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

            if(prevp==0) prevp=i+1;

        }

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

            prevs=i+1;

            if(prevp){

                cout<<"NO\n";

                return;

            }

        }

    }

    if(!prevs || !prevp) cout<<"YES\n";

    else if(prevs==1 || prevp==n) cout<<"YES\n";

    else cout<<"NO\n";

}



int32_t main()

{

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    

    cin >> t;

    while(t--)

    {

        //cout << "Case #" << i << ": ";

        Solve();

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 

    return 0;

}

Answer: 2