Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define fastio() ios::sync_with_stdio(false);cin.tie(nullptr);

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

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

#define pb push_back

#define fi first

#define se second

#define ll long long

const long long LINF = 1e18;

const int MOD = 1000000007;  

#define debug(x) cerr << #x << '=';_print(x);cerr << endl;

void _print(int x) { cerr << x; }

void _print(long long x) { cerr << x; }

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

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

void _print(const string &x) { cerr << x; }

void _print(bool x) { cerr << (x ? '1' : '0'); }

template <typename T>

void _print(const vector<T> &v)

{cerr << '[';for (const auto &i : v){_print(i);cerr << ' ';}cerr << ']';}

template <typename T>

void _print(const set<T> &s){cerr << '{';for (const auto &i : s){_print(i);cerr << ' ';}cerr << '}';}

template <typename K, typename V>

void _print(const map<K, V> &m){cerr << '{'<<endl;for (const auto &p : m){cerr << '(';_print(p.first);cerr << ':';_print(p.second);cerr << ')';}cerr << endl<<'}';}

template <typename T1, typename T2>

void _print(const pair<T1, T2> &p){cerr << '(';_print(p.first);cerr << ',';_print(p.second);cerr << ')';}

ll mod_add(ll&a,ll&b,ll m) {return (a+b)%m;}

ll mod_mul(ll&a,ll&b, ll m) {return (a*b)%m;}

ll mod_sub(ll&a,ll&b,ll m) {return ((a-b)%m+m)%m;}

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

ll binExpo(ll a,ll n) {ll res=1;while(n) {if(n&1) {res=(res*a)%MOD;}a=(a*a)%MOD; n>>=1;}return res;}

ll modInv(ll a,ll mod) {return binExpo(a,mod-2);}

int N;

vector<ll>fact(N+2,0);

void calcFact() {fact[0]=1;fact[1]=1;for(ll i=2;i<=N;i++){fact[i]=mod_mul(fact[i-1],i,MOD);}}

ll ncr(ll n,ll r) {ll numr=fact[n];ll den=mod_mul(fact[n-r],fact[r],MOD);ll ans=(modInv(den,MOD)*numr)%MOD;return ans;}

/*<------------------------------------------------------------------------>*/

void solve() {

    ll n;

    cin>>n;

    string s;

    cin>>s;

    bool ok=1;

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

        if(s[i]=='.') continue;

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

            if(s[i]=='p' and  s[j]=='s') {

                ok=0;

                cout<<"NO"<<endl;

                return ;

            }

            if(s[j]=='p' and  s[i]=='s') {

                if(n-i+1 >= j+1) {

                    if(i>0) {

                        cout<<"NO"<<endl;

                        return ;

                    }

                }

            }



        }

    }

    cout<<"YES"<<endl;



}

int main()

{

    fastio()

    ll int t;

    cin >> t;

    while(t--) solve();

    return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define fastio() ios::sync_with_stdio(false);cin.tie(nullptr);

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

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

#define pb push_back

#define fi first

#define se second

#define ll long long

const long long LINF = 1e18;

const int MOD = 1000000007;  

#define debug(x) cerr << #x << '=';_print(x);cerr << endl;

void _print(int x) { cerr << x; }

void _print(long long x) { cerr << x; }

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

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

void _print(const string &x) { cerr << x; }

void _print(bool x) { cerr << (x ? '1' : '0'); }

template <typename T>

void _print(const vector<T> &v)

{cerr << '[';for (const auto &i : v){_print(i);cerr << ' ';}cerr << ']';}

template <typename T>

void _print(const set<T> &s){cerr << '{';for (const auto &i : s){_print(i);cerr << ' ';}cerr << '}';}

template <typename K, typename V>

void _print(const map<K, V> &m){cerr << '{'<<endl;for (const auto &p : m){cerr << '(';_print(p.first);cerr << ':';_print(p.second);cerr << ')';}cerr << endl<<'}';}

template <typename T1, typename T2>

void _print(const pair<T1, T2> &p){cerr << '(';_print(p.first);cerr << ',';_print(p.second);cerr << ')';}

ll mod_add(ll&a,ll&b,ll m) {return (a+b)%m;}

ll mod_mul(ll&a,ll&b, ll m) {return (a*b)%m;}

ll mod_sub(ll&a,ll&b,ll m) {return ((a-b)%m+m)%m;}

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

ll binExpo(ll a,ll n) {ll res=1;while(n) {if(n&1) {res=(res*a)%MOD;}a=(a*a)%MOD; n>>=1;}return res;}

ll modInv(ll a,ll mod) {return binExpo(a,mod-2);}

int N;

vector<ll>fact(N+2,0);

void calcFact() {fact[0]=1;fact[1]=1;for(ll i=2;i<=N;i++){fact[i]=mod_mul(fact[i-1],i,MOD);}}

ll ncr(ll n,ll r) {ll numr=fact[n];ll den=mod_mul(fact[n-r],fact[r],MOD);ll ans=(modInv(den,MOD)*numr)%MOD;return ans;}

/*<------------------------------------------------------------------------>*/

void solve() {

    ll n;

    cin>>n;

    string s;

    cin>>s;

    bool ok=1;

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

        if(s[i]=='s' and i==0) continue;

        if(s[i]=='.') continue;

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

            if(s[i]=='p' and  s[j]=='s') {

                ok=0;

                cout<<"NO"<<endl;

                return ;

            }

            if(s[j]=='p' and  s[i]=='s') {

                if(n-i >= j+1) {

                    if(i>0) {

                        cout<<"NO"<<endl;

                        return ;

                    }

                }

            }



        }

    }

    cout<<"YES"<<endl;



}

int main()

{

    fastio()

    ll int t;

    cin >> t;

    while(t--) solve();

    return 0;

}