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

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

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define all(x,a) x, x+a

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

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

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

#define ld long double

 

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}



bool s(ll a, ll b)

{

    return a>b;

}

 

void fun()

{

    lc(n);

    string a;

    cin >> a;

    f(i,0,n-1)

    {

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

        {

            f(j,i+1,n)

            {

                if ( a[j]=='s' )

                {

                    cout << "NO\n";

                    return;

                }

            }

        }

    }

    f(i,1,n-2)

    {

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

        {

            f(j,i+1,n-1)

            {

                if ( a[j]=='p' )

                {

                    cout << "NO\n";

                    return;

                }

            }

        }

    }

    cout << "YES\n";

    return;

}

 

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}

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

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define all(x,a) x, x+a

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

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

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

#define ld long double

 

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}



bool s(ll a, ll b)

{

    return a>b;

}

 

void fun()

{

    lc(n);

    string a;

    cin >> a;

    f(i,0,n-1)

    {

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

        {

            f(j,i+1,n)

            {

                if ( a[j]=='s' )

                {

                    cout << "NO\n";

                    return;

                }

            }

        }

    }

    f(i,1,n-2)

    {

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

        {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}

 

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}

Answer: 1