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

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

using namespace std;



// Macros for shorthand

#define ll long long

#define ld long double

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

#define rall(v) v.rbegin(), v.rend()

#define sz(x) ((int)(x).size())

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

#define rrep(i, a, b) for (int i = a; i >= b; i--)



// Constants

const ll MOD = 1e9 + 7;

const ll INF = 1e18;



// Debugging utility (comment out in contests)

#define debug(x) cerr << #x << " = " << (x) << endl;



// Fast IO

void fast_io() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

}



// GCD and LCM

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }



// Modular arithmetic

ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }

ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }

ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

ll mod_pow(ll a, ll b, ll m = MOD) {

    ll res = 1;

    while (b > 0) {

        if (b & 1) res = (res * a) % m;

        a = (a * a) % m;

        b >>= 1;

    }

    return res;

}



// Binary search example (can be modified)

int binary_search(vector<int>& v, int target) {

    int lo = 0, hi = sz(v) - 1;

    while (lo <= hi) {

        int mid = lo + (hi - lo) / 2;

        if (v[mid] == target) return mid;

        else if (v[mid] < target) lo = mid + 1;

        else hi = mid - 1;

    }

    return -1;

}



// Main function

int main() {

    fast_io();



    int t; // Number of test cases

    cin >> t;

    while (t--) {

        // Input and solve here

        int n;

        cin >> n;

        string s;

        cin>>s;

        int pidx=-1,sidx=-1;

        int flag=0;

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

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

                sidx = i;

                if(pidx!=-1){

                    if(pidx<sidx){

                        flag=1;

                        break;

                    }

                }

            }

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

                pidx=i;

                if(sidx!=-1){

                    if(sidx!=0 && pidx!=n-1){

                        flag=1;

                        break;

                    }

                }

            }

        }

        if(flag==1){

            cout<<"NO"<<endl;

        }

        else{

            cout<<"YES"<<endl;

        }

        

    }



    return 0;

}



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

using namespace std;



// Macros for shorthand

#define ll long long

#define ld long double

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

#define rall(v) v.rbegin(), v.rend()

#define sz(x) ((int)(x).size())

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

#define rrep(i, a, b) for (int i = a; i >= b; i--)



// Constants

const ll MOD = 1e9 + 7;

const ll INF = 1e18;



// Debugging utility (comment out in contests)

#define debug(x) cerr << #x << " = " << (x) << endl;



// Fast IO

void fast_io() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

}



// GCD and LCM

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }



// Modular arithmetic

ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }

ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }

ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

ll mod_pow(ll a, ll b, ll m = MOD) {

    ll res = 1;

    while (b > 0) {

        if (b & 1) res = (res * a) % m;

        a = (a * a) % m;

        b >>= 1;

    }

    return res;

}



// Binary search example (can be modified)

int binary_search(vector<int>& v, int target) {

    int lo = 0, hi = sz(v) - 1;

    while (lo <= hi) {

        int mid = lo + (hi - lo) / 2;

        if (v[mid] == target) return mid;

        else if (v[mid] < target) lo = mid + 1;

        else hi = mid - 1;

    }

    return -1;

}



// Main function

int main() {

    fast_io();



    int t; // Number of test cases

    cin >> t;

    while (t--) {

        // Input and solve here

        int n;

        cin >> n;

        string s;

        cin>>s;

        int pidx=-1,sidx=-1;

        int flag=0;

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

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

                sidx = i;

            }

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

                pidx=i;

                if(sidx!=-1){

                    if(sidx!=0 && pidx!=n-1){

                        flag=1;

                        break;

                    }

                }

            }

        }

        if(flag==1){

            cout<<"NO"<<endl;

        }

        else{

            if(pidx!=-1 && sidx!=-1 && pidx<sidx){

                cout<<"NO"<<endl;

            }

            else{

                cout<<"YES"<<endl;

            }

        }

        

    }



    return 0;

}



Answer: 1