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

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

using namespace std;



template <typename A, typename B>

ostream &operator<<(ostream &os, const pair<A, B> &p) {

    return os << '(' << p.first << ", " << p.second << ')';

}



template <typename T_container, typename T = typename enable_if<

                                    !is_same<T_container, string>::value,

                                    typename T_container::value_type>::type>

ostream &operator<<(ostream &os, const T_container &v) {

    os << '{';

    string sep;

    for (const T &x : v)

        os << sep << x, sep = ", ";

    return os << '}';

}



void dbg_out() { cerr << endl; }



template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {

    cerr << ' ' << H;

    dbg_out(T...);

}



#ifdef LOCAL

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)

#else

#define debug(...)

#endif



int main() {

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        int N;

        cin >> N;

        string S;

        cin >> S;

        bool ok = true;

        int p = 0, s = 0;

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

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

                s++;

            if (S[i] == 'p') {

                p++;

                int j = i + 1;

                while (j < N && S[j] == '.')

                    j++;

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

                    ok = false;

                j = i;

            }

        }

        if (!ok || (s > 0 && p > 0 && S != "sp" && S != ".sp" && S != "sp.")) {

            cout << "NO" << '\n';

        } else {

            cout << "YES" << '\n';

        }

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed =

        std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    cerr << "time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

    return 0;

}



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

using namespace std;



template <typename A, typename B>

ostream &operator<<(ostream &os, const pair<A, B> &p) {

    return os << '(' << p.first << ", " << p.second << ')';

}



template <typename T_container, typename T = typename enable_if<

                                    !is_same<T_container, string>::value,

                                    typename T_container::value_type>::type>

ostream &operator<<(ostream &os, const T_container &v) {

    os << '{';

    string sep;

    for (const T &x : v)

        os << sep << x, sep = ", ";

    return os << '}';

}



void dbg_out() { cerr << endl; }



template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {

    cerr << ' ' << H;

    dbg_out(T...);

}



#ifdef LOCAL

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)

#else

#define debug(...)

#endif



int main() {

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        int N;

        cin >> N;

        string S;

        cin >> S;

        bool ok = true;

        int p = 0, s = 0;

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

            S[0] = '.';

        if (S[N - 1] == 'p')

            S[N - 1] = '.';

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

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

                s++;

            if (S[i] == 'p') {

                p++;

                int j = i + 1;

                while (j < N && S[j] == '.')

                    j++;

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

                    ok = false;

                j = i;

            }

        }

        if (!ok || (s > 0 && p > 0 && S != "sp" && S != ".sp" && S != "sp.")) {

            cout << "NO" << '\n';

        } else {

            cout << "YES" << '\n';

        }

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed =

        std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    cerr << "time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

    return 0;

}



Answer: 2