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

Code 1:
#include<iostream>

#include<iomanip>

#include<algorithm>

#include<vector>

#include<utility>

#include<set>

#include<unordered_set>

#include<list>

#include<iterator>

#include<deque>

#include<queue>

#include<stack>

#include<set>

#include<bitset>

#include<random>

#include<map>

#include<unordered_map>

#include<stdio.h>

#include<complex>

#include<math.h>

#include<cstring>

#include<chrono>

#include<string>

using namespace std;

 

#define int long long

#define input(v) for(auto &it:v)cin>>it

#define output(v) for(auto &it:v)cout<<it<<" "; cout << "\n"

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

#define vb vector<bool>

#define tzll(x) __builtin_ctzll(x)

#define lzll(x) __builtin_clzll(x)

#define lz(x) __builtin_clz(x)

#define tz(x) __builtin_ctz(x)

#define popc(x) __builtin_popcount(x)

#define popcll(x) __builtin_popcountll(x)

#define pi pair<long long, long long>

#define vi vector<long long>

#define vvi vector<vector<long long> >

#define vpi vector<pair<long long,long long> >

#define si set<long long>

#define spi set<pair<long,long> >

#define qi queue<long long>

#define qpi queue<pair<long,long> >

#define msi multiset<long long>

#define MOD 1000000007

#define MOD1 998244353

#define INF 1e18

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define ff first

#define ss second

typedef long long ll;

typedef unsigned long long ull;

typedef long double lld;



#ifndef ONLINE_JUDGE

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

#else

#define debug(x)

#endif



void _print(ll t) {cerr << t;}

void _print(string t) {cerr << t;}

void _print(char t) {cerr << t;}

void _print(lld t) {cerr << t;}

void _print(double t) {cerr << t;}

void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T, class V> void _print(map <T, V> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}



int gcd (int a, int b) {

    if (b == 0) return a;

    return gcd (b, a % b);

}

int lcm (int a, int b) {

    return a / gcd(a, b) * b;

}

long long binpow(long long a, long long b) {

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a;

        a = a * a;

        b >>= 1;

    }

    return res;

}

long long binpow(long long a, long long b, long long m) {

    a %= m;

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a % m;

        a = a * a % m;

        b >>= 1;

    }

    return res;

}

/*

    

*/



bool solve()

{

    int n;

    cin>>n;

    string s;

    cin>>s;

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

    {

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

        return 0;

        else if(s[i]=='s' && s[i+1]=='p' && i!=n-2)

        return 0;

    }

    return 1;

}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int t = 1; 

    cin >> t;

    for(int i = 1; i <= t; i++){

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

        (solve())?cout<<"YES\n":cout<<"NO\n";

    }

    return 0;

}

Code 2:
#include<iostream>

#include<iomanip>

#include<algorithm>

#include<vector>

#include<utility>

#include<set>

#include<unordered_set>

#include<list>

#include<iterator>

#include<deque>

#include<queue>

#include<stack>

#include<set>

#include<bitset>

#include<random>

#include<map>

#include<unordered_map>

#include<stdio.h>

#include<complex>

#include<math.h>

#include<cstring>

#include<chrono>

#include<string>

using namespace std;

 

#define int long long

#define input(v) for(auto &it:v)cin>>it

#define output(v) for(auto &it:v)cout<<it<<" "; cout << "\n"

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

#define vb vector<bool>

#define tzll(x) __builtin_ctzll(x)

#define lzll(x) __builtin_clzll(x)

#define lz(x) __builtin_clz(x)

#define tz(x) __builtin_ctz(x)

#define popc(x) __builtin_popcount(x)

#define popcll(x) __builtin_popcountll(x)

#define pi pair<long long, long long>

#define vi vector<long long>

#define vvi vector<vector<long long> >

#define vpi vector<pair<long long,long long> >

#define si set<long long>

#define spi set<pair<long,long> >

#define qi queue<long long>

#define qpi queue<pair<long,long> >

#define msi multiset<long long>

#define MOD 1000000007

#define MOD1 998244353

#define INF 1e18

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define ff first

#define ss second

typedef long long ll;

typedef unsigned long long ull;

typedef long double lld;



#ifndef ONLINE_JUDGE

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

#else

#define debug(x)

#endif



void _print(ll t) {cerr << t;}

void _print(string t) {cerr << t;}

void _print(char t) {cerr << t;}

void _print(lld t) {cerr << t;}

void _print(double t) {cerr << t;}

void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T, class V> void _print(map <T, V> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}



int gcd (int a, int b) {

    if (b == 0) return a;

    return gcd (b, a % b);

}

int lcm (int a, int b) {

    return a / gcd(a, b) * b;

}

long long binpow(long long a, long long b) {

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a;

        a = a * a;

        b >>= 1;

    }

    return res;

}

long long binpow(long long a, long long b, long long m) {

    a %= m;

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a % m;

        a = a * a % m;

        b >>= 1;

    }

    return res;

}

/*

    

*/



bool solve()

{

    int n;

    cin>>n;

    string s;

    cin>>s;

    int pmin=n,pmax=-1,smin=n,smax=-1;

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

    s[0]='.';

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

    s[n-1]='.';

    int sct=0,pct=0;

    for(auto it:s)

    {

        if(it=='s')

        sct++;

        if(it=='p')

        pct++;

    }

    if(sct==0 || pct==0)

    return 1;



    return 0;

}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int t = 1; 

    cin >> t;

    for(int i = 1; i <= t; i++){

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

        (solve())?cout<<"YES\n":cout<<"NO\n";

    }

    return 0;

}

Answer: 2