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

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

using namespace std;



// Short forms

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

#define lli                 long long int

#define ll                  long long

#define ull                 unsigned long long

#define nl                  '\n'

#define ff                  first

#define ss                  second

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

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

#define pb                  push_back

#define mp                  make_pair



// Loops

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

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

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

#define llp(i,a,b)          for (ll i= (ll)(a); i < (ll)(ll)(b); ++i)



// STLs

#define pii                 pair<int, int>

#define vi                  vector<int>

#define vll                 vector<ll>

#define vvi                 vector<vector<int>>

#define vvl                 vector<vector<ll>>



// Outputs

#define yes                 cout<<"YES"<<nl

#define no                  cout<<"NO"<<nl

#define dbg(x)              cerr << #x <<" " << x << endl;



// Constants

#define PI                  3.141592653589793238

#define INF                 LONG_LONG_MAX

#define MOD                 1e9+7



// Faster Input Output

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));



// Maths

ll fact(ll n)          { if(n==0) return 1; ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; }

ll nPr(ll n, ll r)     { return fact(n) / fact(n - r); }

ll nCr(ll n, ll r)     { return fact(n) / (fact(r) * fact(n - r)); }

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

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

ll mypow(ll a, ll b)   { ll ans = 1; while(b){ if (b&1) ans = (ans*a) ; b /= 2; a = (a*a); } return ans; }

bool isPrime(ll n)     { if(n <= 1) return false; for(ll i = 2; i <= sqrt(n); i++) if(n % i == 0) return false; return true; }



int main() {

       int t;

       cin>>t;

       while(t--)

       {

              int n;

              cin>>n;

              string str;

              cin>>str;

              bool ans=true;

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

                     if(str[i]=='s' && str[i+1]=='p') ans=false;

                     if(str[i]=='p' && str[i+1]=='s') ans=false;

              }  

              int p=0;

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

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

                    if(str[i]=='s' && p>0) ans=false;

              }     

            if(ans) yes;

            else no;

       }

            

       return 0;

}

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

using namespace std;



// Short forms

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

#define lli                 long long int

#define ll                  long long

#define ull                 unsigned long long

#define nl                  '\n'

#define ff                  first

#define ss                  second

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

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

#define pb                  push_back

#define mp                  make_pair



// Loops

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

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

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

#define llp(i,a,b)          for (ll i= (ll)(a); i < (ll)(ll)(b); ++i)



// STLs

#define pii                 pair<int, int>

#define vi                  vector<int>

#define vll                 vector<ll>

#define vvi                 vector<vector<int>>

#define vvl                 vector<vector<ll>>



// Outputs

#define yes                 cout<<"YES"<<nl

#define no                  cout<<"NO"<<nl

#define dbg(x)              cerr << #x <<" " << x << endl;



// Constants

#define PI                  3.141592653589793238

#define INF                 LONG_LONG_MAX

#define MOD                 1e9+7



// Faster Input Output

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));



// Maths

ll fact(ll n)          { if(n==0) return 1; ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; }

ll nPr(ll n, ll r)     { return fact(n) / fact(n - r); }

ll nCr(ll n, ll r)     { return fact(n) / (fact(r) * fact(n - r)); }

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

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

ll mypow(ll a, ll b)   { ll ans = 1; while(b){ if (b&1) ans = (ans*a) ; b /= 2; a = (a*a); } return ans; }

bool isPrime(ll n)     { if(n <= 1) return false; for(ll i = 2; i <= sqrt(n); i++) if(n % i == 0) return false; return true; }



int main() {

       int t;

       cin>>t;

       while(t--)

       {

              int n;

              cin>>n;

              string str;

              cin>>str;

              bool ans=true;

              int s=0;

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

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

                    if(str[i]=='p' && s) ans=false;

              }  

              int p=0;

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

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

                    if(str[i]=='s' && p>0) ans=false;

              }     

            if(ans) yes;

            else no;

       }

            

       return 0;

}

Answer: 2