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

Code 1:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pll pair<ll, ll>
#define vll vector<ll>
#define vii vector<int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define isON(n, k) (((n) >> (k)) & 1)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fb(i, a, b) for (ll i = a; i > b; i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
// int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
// int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
using namespace std;
const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;
ll t = 1;

void solve()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    // Check if the string contains 's' or 'p'
    if (s.find('s') == string::npos && s.find('p') == string::npos)
    {
        cout << "YES\n";
        return;
    }
    if (s[0] == 's') s[0] = '.';
    if (s.back() == 'p') s.back() = '.';
    bool fp = false, fs = false;
    f(i, 0, n)
    {
        switch (s[i])
        {
        case 's':
            fs = true;
            break;
        case 'p':
            fp = true;
            break;
        }
    }
    cout << (fs && fp ? "NO\n" : "YES\n");

    return;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Code 2:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pll pair<ll, ll>
#define vll vector<ll>
#define vii vector<int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define isON(n, k) (((n) >> (k)) & 1)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fb(i, a, b) for (ll i = a; i > b; i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
// int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
// int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
using namespace std;
const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;
ll t = 1;

void solve()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    // Check if the string contains 's' or 'p'
    if (s.find('s') == string::npos && s.find('p') == string::npos) {
        cout << "YES\n";
        return;
    }
    int l = -1, r = -1;
    f(i,0,n){
        switch (s[i])
        {
        case 'p':
            if (l == -1)
            {
                l = 1;
                r = i+1;
            }
            else {
                int ff = 1, ss = i+1;
                // Check if the new range [ff, ss] can contain the range [l, r] or vice versa
                if ((ff <= l && ss >= r) || (l <= ff && r >= ss))
                {
                    l = min(l, ff);
                    r = max(r, ss);
                }
                else
                {
                    cout << "NO\n";
                    return;
                }
            }
            break;
        case 's':
            if (l == -1)
            {
                l = i+1;
                r = n;
            }
            else {
                int ff = i+1, ss = n;
                // Check if the new range [ff, ss] can contain the range [l, r] or vice versa
                if ((ff <= l && ss >= r) || (l <= ff && r >= ss))
                {
                    l = min(l, ff);
                    r = max(r, ss);
                }
                else
                {
                    cout << "NO\n";
                    return;
                }
            }
            break;
        default:
            break;
        }
    }
    cout << "YES\n";

    return;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Answer: 1