#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#define int long long

#define fi first

#define tc int t; cin >> t; while(t--)

#define se second

#define pb push_back

#define vi vector<int>

#define pii pair<int, int>

#define piii pair<int, pii>

#define vii vector<pii>

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define debug cout<<"\ndebug\n";

typedef long long ll;

const int mxn = 1e5+20;

const int MOD = 1e9+7;

const int INF = LLONG_MAX;

int tot(int a, int b){return (a+b)%MOD;}

// int sub(int a, int b){return (a-b)%mod;}

// int mul(int a, int b){return (a*b)%mod;}

// int chmx(int &a, int b){ return max(a, b);}

// int chmn(int &a, int b){ return min(a, b);}

void solve(){

    int n, s=-1,p=-1; cin >> n;

    string ss; cin >> ss;

    if(ss[0] == 's')ss[0] = '.';

    if(ss[n-1]=='p')ss[n-1] = '.';

    bool foundp=0,founds=0;

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

        if(ss[i] == 'p')foundp=1;

        if(ss[i] == 's') founds=1;

    }

    cout << (foundp&&founds ? "NO":"YES")<<endl;

}

int32_t main(){

    fastio;

    int t = 1;

    cin >> t;

    while(t--){

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#define int long long

#define fi first

#define tc int t; cin >> t; while(t--)

#define se second

#define pb push_back

#define vi vector<int>

#define pii pair<int, int>

#define piii pair<int, pii>

#define vii vector<pii>

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define debug cout<<"\ndebug\n";

typedef long long ll;

const int mxn = 1e5+20;

const int MOD = 1e9+7;

const int INF = LLONG_MAX;

int tot(int a, int b){return (a+b)%MOD;}

// int sub(int a, int b){return (a-b)%mod;}

// int mul(int a, int b){return (a*b)%mod;}

// int chmx(int &a, int b){ return max(a, b);}

// int chmn(int &a, int b){ return min(a, b);}

void solve(){

    int n, s=-1,p=-1; cin >> n;

    string ss; cin >> ss;

    bool ok = 0;

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

        if(ss[i]=='p' && p==-1){

            p=i;

        }

        else if(ss[i] == 's'){

            s = i;

        } else ok = 1;

    }

    if(s > p && p!=-1)cout<<"NO"<<endl;

    else{

        if(n-s==p+1 && ok) cout << "NO" << endl;

        else cout << "YES"<<endl;

    }

}

int32_t main(){

    fastio;

    int t = 1;

    cin >> t;

    while(t--){

        solve();

    }

    return 0;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

ll answer(int n){

    string st; cin>>st;

    bool s=0,p=0;

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

        if(st[i]=='s' ) s=1;

        if(st[i]=='p') p=1;

    }

    if(s && p) return 0;

    if(st[0]=='p'){

        if(s || st[n-1]=='s') return 0;

    }

    return 1;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        int n; cin>>n;

        //cout<<answer(n)<<endl;

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

    }

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

ll answer(int n){

    string st; cin>>st;

    bool s=0,p=0;

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

        if(st[i]=='s' ) s=1;

        if(st[i]=='p') p=1;

    }

    if(s && p|| p && st[n-1]=='s') return 0;

    if(st[0]=='p'){

        if(s || st[n-1]=='s') return 0;

        else return 1;

    }

    return 1;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        int n; cin>>n;

        //cout<<answer(n)<<endl;

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

    }

}

Answer: 2


#include <bits/stdc++.h>

#ifdef LOCAL

#include "debug.h"

#else

#define dbg(x...)

void dbgEndl() {}

#endif

#if __cplusplus <= 201703L || defined(LOCAL)

#include <bits/extc++.h>

namespace pbds = __gnu_pbds;

#endif

using namespace std;

using u32 = unsigned;

using u64 = unsigned long long;

using i64 = long long;

#if __cplusplus >= 202002L

using i128 = __int128;

#endif

using f64 = long double;

constexpr int N = 1000010;

constexpr f64 eps = 1e-9; // !!!

constexpr int inf32 = 1e9;

constexpr i64 inf64 = 1e18;

inline void YES(void) { cout << "YES\n"; }

inline void Yes(void) { cout << "Yes\n"; }

inline void NO(void) { cout << "NO\n"; }

inline void No(void) { cout << "No\n"; }

inline void YES_NO(bool cond) { cond ? YES() : NO(); }

inline void Yes_No(bool cond) { cond ? Yes() : No(); }

int n, m;

inline void solve(void) {

    string s;

    cin >> n >> s;

    if (count(s.begin() + 1, s.end(), 's') == 0) {

        return YES();

    }

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

        if (s[i] == 'p') return NO();

        if (i > 0 && s[i] == 's') {

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

                if (s[j] == 'p') return NO();

            }

            return YES();

        }

    }

    YES();

}

inline void optimizeIO(void) {

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

}

int main(int argc, char const *argv[]) {

    int t = 1;

    optimizeIO(), cin >> t;

    while (t--) solve();

    return 0;

}

#include <bits/stdc++.h>

#ifdef LOCAL

#include "debug.h"

#else

#define dbg(x...)

void dbgEndl() {}

#endif

#if __cplusplus <= 201703L || defined(LOCAL)

#include <bits/extc++.h>

namespace pbds = __gnu_pbds;

#endif

using namespace std;

using u32 = unsigned;

using u64 = unsigned long long;

using i64 = long long;

#if __cplusplus >= 202002L

using i128 = __int128;

#endif

using f64 = long double;

constexpr int N = 1000010;

constexpr f64 eps = 1e-9; // !!!

constexpr int inf32 = 1e9;

constexpr i64 inf64 = 1e18;

inline void YES(void) { cout << "YES\n"; }

inline void Yes(void) { cout << "Yes\n"; }

inline void NO(void) { cout << "NO\n"; }

inline void No(void) { cout << "No\n"; }

inline void YES_NO(bool cond) { cond ? YES() : NO(); }

inline void Yes_No(bool cond) { cond ? Yes() : No(); }

int n, m;

inline void solve(void) {

    string s;

    cin >> n >> s;

    if (count(s.begin(), s.end(), 's') == 0) {

        return YES();

    }

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

        if (s[i] == 'p') return NO();

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

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

                if (s[j] == 'p') return NO();

            }

            return YES();

        }

    }

    YES();

}

inline void optimizeIO(void) {

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

}

int main(int argc, char const *argv[]) {

    int t = 1;

    optimizeIO(), cin >> t;

    while (t--) solve();

    return 0;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

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

        if(s.substr(i,2)=="ps"){

            cout<<"NO\n";

            return;

        }

        if(i>0 && i<n-2 && s.substr(i,2)=="sp"){

             cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin>>t;

    while(t--){

        solve();

    };

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

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

        s[0]='.';

    }

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

        s[n-1]='.';

    }

    int cd1=0,cd2=0;

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

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

            cd1=1;

        }

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

            cd2=1;

        }

    }

    if(cd1 && cd2){

        cout<<"NO\n";

        return;

    }

    cout<<"YES\n";

}

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin>>t;

    while(t--){

        solve();

    };

    return 0;

}

Answer: 2


// Online C++ compiler to run C++ program online

#include <bits/stdc++.h>

using namespace std;

bool solve(string &s,int n){

  int s1=0,p1=0,d1=0;

  for(auto &r:s){

    if(r=='s')

    s1++;

    if(r=='p')

    p1++;

    if(r=='.')

    d1++;

  }

  if(p1==n||s1==n||d1==n||s1+d1==n||p1+d1==n)

  return 1;

  if(s[0]=='s'&&s1==1)

  return 1;

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

  return 1;

  return 0;

}

int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        if(solve(s,n))

        cout<<"YES";

        else

        cout<<"NO";

        cout<<endl;

    }

    return 0;

}

// Online C++ compiler to run C++ program online

#include <bits/stdc++.h>

using namespace std;

bool solve(string &s,int n){

  int s1=0,p1=0,d1=0;

  for(auto &r:s){

    if(r=='s')

    s1++;

    if(r=='p')

    p1++;

    if(r=='.')

    d1++;

  }

  if(p1==n||s1==n||d1==n)

  return 1;

  if(s[0]=='s'&&s1==1)

  return 1;

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

  return 1;

  return 0;

}

int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        if(solve(s,n))

        cout<<"YES";

        else

        cout<<"NO";

        cout<<endl;

    }

    return 0;

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

#define int long long

signed main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);  cout.tie(NULL);

    int t; cin>>t;

    while(t--){

        int n,ss=0,si=-1,pp=0,pi=-1; cin>>n;

        string s; cin>>s;

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

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

                ss++;

                si=i;

            }

            else if(s[i]=='p'){

                pp++;

                pi=i;

            }

        }

        if(!ss || !pp) cout<<"YES"<<endl;

        else if((ss==1 && si==0) || (pp==1 && pi==n-1)) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

        // cout<<ss<<" "<<pp<<" "<<si<<" "<<pi<<endl;

    }

}

#include<bits/stdc++.h>

using namespace std;

#define int long long

signed main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);  cout.tie(NULL);

    int t; cin>>t;

    while(t--){

        int n,ss=0,si=-1,pp=0,pi=-1; cin>>n;

        string s; cin>>s;

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

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

                ss++;

                si=i;

            }

            else if(s[i]=='p'){

                pp++;

                pi=i;

            }

        }

        if(!ss || !pp) cout<<"YES"<<endl;

        else if(si==0 || pi==n-1) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

        // cout<<ss<<" "<<pp<<" "<<si<<" "<<pi<<endl;

    }

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pair pair<ll,ll>

ll n,m,say1,say2,cem=0;

int main()

{

    cin>>n;

    string s;

    while(n--)

    {

      cin>>m;

      cin>>s;

      say1=0;

      say2=0;

      bool b=1;

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

      {

        cout<<"yes"<<endl;

        continue;

      }

      for(int i=0;i<s.size();i++)

      {

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

        say1++;

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

        say2++;

        if(i!=0 and s[i]=='s' and s[i-1]=='p')

        b=0;

      }

      if(say2==0)

      {

        cout<<"yes"<<endl;

        continue;

      }

      if(s[0]=='.' and say1==0)

      {

        cout<<"yes"<<endl;

        continue;

      }

      if(b)

      {

        cout<<"yes"<<endl;

        continue;

      }

     else

      cout<<"no"<<endl;

    }

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pair pair<ll,ll>

ll n,m,say1,say2,cem=0;

int main()

{

    cin>>n;

    string s;

    while(n--)

    {

      cin>>m;

      cin>>s;

      say1=0;

      say2=0;

      bool b=0,b1=0;

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

      {

        s[0]='.';

      }

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

      s[m-1]='.';

      for(int i=0;i<s.size();i++)

      {

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

        b=1;

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

        b1=1;

      }

      if(b1 and b)

      cout<<"no"<<endl;

      else cout<<"yes"<<endl;

    }

}

Answer: 2


// **************** MBRAHUL ***************

#include<bits/stdc++.h>

#define ll long long

#define pn cout<<"NO"<<endl

#define py cout<<"YES"<<endl

#define vll vector<long long>

#define vi vector<int>

#define vb vector<bool>

#define u_map unordered_map

#define pll pair<long long,long long>

#define pii pair<int,int>

#define inf INT_MAX

#define pb push_back

#define mod 998244353

#define MOD 1000000007

#define ld long double

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define loop(i,n) for(int i=0;i<n;i++)

#define rloop(i, n) for(int i=n-1;i>=0;i--)

using namespace std;

void input(vector<ll>&arr,ll n){

for(ll i =0;i<n;i++)cin>>arr[i];

}

void printArr(vector<ll>&arr, ll i,ll j){

for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";

cout<<endl;

}

void find(){

  int n;

  string str;

  cin>>n>>str;

  set<char>s;

  for(auto c:str)s.insert(c);

  if(s.size()==1){

    py;

    return;

  }

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

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

    else{

      pn;

      return;

    }

  }

  py;

}

int main(){

ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

ll test=1;

cin>>test;

while(test--){

find();

}

return 0;

}

// **************** MBRAHUL ***************

#include<bits/stdc++.h>

#define ll long long

#define pn cout<<"NO"<<endl

#define py cout<<"YES"<<endl

#define vll vector<long long>

#define vi vector<int>

#define vb vector<bool>

#define u_map unordered_map

#define pll pair<long long,long long>

#define pii pair<int,int>

#define inf INT_MAX

#define pb push_back

#define mod 998244353

#define MOD 1000000007

#define ld long double

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define loop(i,n) for(int i=0;i<n;i++)

#define rloop(i, n) for(int i=n-1;i>=0;i--)

using namespace std;

void input(vector<ll>&arr,ll n){

for(ll i =0;i<n;i++)cin>>arr[i];

}

void printArr(vector<ll>&arr, ll i,ll j){

for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";

cout<<endl;

}

void find(){

  int n;

  string str;

  cin>>n>>str;

  set<char>st;

  for(auto c:str)if(c!='.')st.insert(c);

  if(st.size()<=1){

    py;

    return;

  }

  int s=0,p=0;

  for(auto c:str){

    if(c=='s')s++;

    else if(c=='p')p++;

  }

  if(s==1 || p==1){

    if(s==1 && p==1){

      if(str.back()=='p' || str[0]=='s')py;

      else pn;

    }

    else if(s==1){

      if(str[0]=='s')py;

      else pn;

    }

    else{

      if(str.back()=='p')py;

      else pn;

    }

  }

  else pn;

}

int main(){

ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

ll test=1;

cin>>test;

while(test--){

find();

}

return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    bool seen_s = false;

    bool seen_p = false;

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

        seen_s = true;

    }

    else if(s[0] == 'p'){

        seen_p = true;

    }

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

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

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

        else if(s[i] == 'p'){

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }

    }

    cout << "yes\n";

}

int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    bool seen_s = false;

    bool seen_p = false;

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

        seen_p = true;

    }

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

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

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

        else if(s[i] == 'p'){

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }

    }

    if(s[n-1] == 's' && seen_p){

        cout << "no\n";

        return;

    }

    cout << "yes\n";

}

int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

}

Answer: 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;

    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;

}

#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


#include<iostream>

#include<string>

using namespace std;

void solve()

{

	int n,jump=1;

	string s;

	cin>>n>>s;

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

	{

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

		{

			jump++;

			continue;

		}

		if(s[i]=='s'&&s[i-jump]=='p')

		{

			cout<<"NO"<<endl;

			return;

		}

		if(s[i]=='p'&&s[i-jump]=='s'&&i!=n-1&&i-jump!=0)

		{

			cout<<"NO"<<endl;

			return;

		}

		jump=1;

	}

	cout<<"YES"<<endl;

}

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

#include<iostream>

#include<string>

using namespace std;

void solve()

{

	int n;

	string s;

	cin>>n>>s;

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

	{

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

		{

			cout<<"NO"<<endl;

			return;

		}

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

		{

			cout<<"NO"<<endl;

			return;

		}

	}

	cout<<"YES"<<endl;

}

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

using ll=long long;

ll n,a[1000010],q[1000010];

string s;

void solve()

{

	cin>>n;

	cin>>s;

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

	{

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

		{

			if(s[i]=='p'&&s[j]=='s'&&i!=n-1&&j!=0)

			{

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

				return;

			}

		}

	}

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

	return;

}

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

#include<bits/stdc++.h>

using namespace std;

using ll=long long;

ll n,a[1000010],q[1000010];

string s;

void solve()

{

	cin>>n;

	cin>>s;

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

	{

		if(s[i]=='p') q[i]=1;

		else if(s[i]=='s') q[i]=2;

		else if(s[i]=='.') q[i]=0;

	}

	bool flag=false;

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

	{

		if(q[i]) flag=true;

	}

	if(!flag)

	{

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

		return;

	}

	if(q[0]==0&&q[n-1]==0&&flag)

	{

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

		return;

	}

	flag=false;

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

	{

		if(q[i]==1)

		{

			flag=true;

		}

		if(flag&&q[i]==2)

		{

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

			return;

		}

	}

	flag=false;

	for(int i=n-1;i>=0;i--)

	{

		if(q[i]==2) flag=true;

		if(flag&&q[i]==1)

		{

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

			return;

		}

	}

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

	return;

}

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

const int N=6000;

char a[N];

int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		int n;

		cin>>n;

		int b1=0,b2=0;

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

		{

			cin>>a[i];

			if(i==1 or i==n)continue;

			if(a[i]=='p')b1++;

			if(a[i]=='s')b2++;

		}

		if(b1>0 and b2>0)cout<<"NO"<<endl;

		else if(b1==b2 and (a[1]!='p' or a[n]!='s'))cout<<"YES"<<endl;

		else if(b2>0 and a[1]!='p')cout<<"YES"<<endl;

		else if(b1>0 and a[n]!='s')cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

	}

}

#include<bits/stdc++.h>

using namespace std;

const int N=6000;

char a[N];

int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		int n;

		cin>>n;

		int b1=0,b2=0;

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

		{

			cin>>a[i];

			if(a[i]=='p')b1++;

			if(a[i]=='s')b2++;

		}

		if(b1==0 or b2==0)cout<<"YES"<<endl;

		else if(b1>1 and b2>1)cout<<"NO"<<endl;

		else if(a[1]=='p' or a[n]=='s')cout<<"NO"<<endl;

		else if((b1==1 and a[n]=='p') or (b2==1 and a[1]=='s'))cout<<"YES"<<endl;

		else cout<<"NO";

	}

}

Answer: 1


#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;

void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

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

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }

    if(mp.size()==1){

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

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"/n";

    }

    else if(mp['s']==1 && s[0]=='s'){

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

    }

    else if(mp['p']==1 && s[n-1]=='p'){

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

    }

    else{

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

    }

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;

void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

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

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }

    if(mp.size()==1){

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

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

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

    }

    else if(mp['s']==1 && s[0]=='s'){

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

    }

    else if(mp['p']==1 && s[n-1]=='p'){

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

    }

    else{

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

    }

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

Answer: 2


import java.util.*;

import java.io.*;

public class B_pspspsps {

    static final int MAX = 10_000_000;

    static final int MOD = 1_000_000_007;

    static boolean[] isPrime = new boolean[MAX + 1];

    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    public static void solve() {

        FastIO sc = new FastIO();

        int testCases = sc.nextInt();

        while (testCases-- != 0) {

            int n = sc.nextInt();

            String s = sc.next();

            boolean f = false;

            boolean isS=false;

            boolean isP=false;

            char arr[] = s.toCharArray();

            if(arr[0]=='s')arr[0]='.';

            if(arr[n-1]=='p')arr[n-1]='.';

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

                if(arr[i]=='p')isP=true;

                if(arr[i]=='s')isS=true;

            }

            if(isP&&isS)out.println("NO");

            else

            out.println("YES");

        }

        out.flush();

    }

    public static void debugArray(int[] arr) {

        out.println(Arrays.toString(arr));

    }

    public static void debugList(List<Integer> list) {

        out.println(list);

    }

    public static long modAdd(long a, long b, int mod) {

        return (a + b) % mod;

    }

    public static long modMul(long a, long b, int mod) {

        return (a * b) % mod;

    }

    public static long modExp(long base, long exp, int mod) {

        long result = 1;

        while (exp > 0) {

            if ((exp & 1) == 1) result = (result * base) % mod;

            base = (base * base) % mod;

            exp >>= 1;

        }

        return result;

    }

    public static void precomputePrimes() {

        Arrays.fill(isPrime, true);

        isPrime[0] = isPrime[1] = false;

        for (int i = 2; i * i <= MAX; i++) {

            if (isPrime[i]) {

                for (int j = i * i; j <= MAX; j += i) {

                    isPrime[j] = false;

                }

            }

        }

    }

    public static boolean isPrime(int n) {

        return n >= 0 && n <= MAX && isPrime[n];

    }

    public static void bfs(int start, List<Integer>[] graph, boolean[] visited) {

        Queue<Integer> queue = new LinkedList<>();

        queue.add(start);

        visited[start] = true;

        while (!queue.isEmpty()) {

            int node = queue.poll();

            for (int neighbor : graph[node]) {

                if (!visited[neighbor]) {

                    queue.add(neighbor);

                    visited[neighbor] = true;

                }

            }

        }

    }

    static class DSU {

        int[] parent, rank;

        DSU(int n) {

            parent = new int[n];

            rank = new int[n];

            for (int i = 0; i < n; i++) parent[i] = i;

        }

        int find(int x) {

            if (x != parent[x]) parent[x] = find(parent[x]);

            return parent[x];

        }

        void union(int x, int y) {

            int rootX = find(x), rootY = find(y);

            if (rootX != rootY) {

                if (rank[rootX] > rank[rootY]) parent[rootY] = rootX;

                else if (rank[rootX] < rank[rootY]) parent[rootX] = rootY;

                else {

                    parent[rootY] = rootX;

                    rank[rootX]++;

                }

            }

        }

    }

    static class FastIO {

        BufferedReader br;

        StringTokenizer st;

        public FastIO() {

            br = new BufferedReader(new InputStreamReader(System.in));

        }

        String next() {

            while (st == null || !st.hasMoreElements()) {

                try {

                    st = new StringTokenizer(br.readLine());

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }

        int nextInt() {

            return Integer.parseInt(next());

        }

        long nextLong() {

            return Long.parseLong(next());

        }

        double nextDouble() {

            return Double.parseDouble(next());

        }

        String nextLine() {

            String str = "";

            try {

                str = br.readLine();

            } catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }

    }

    public static void main(String[] args) {

        precomputePrimes();

        solve();

    }

}

import java.util.*;

import java.io.*;

public class B_pspspsps {

    static final int MAX = 10_000_000;

    static final int MOD = 1_000_000_007;

    static boolean[] isPrime = new boolean[MAX + 1];

    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    public static void solve() {

        FastIO sc = new FastIO();

        int testCases = sc.nextInt();

        while (testCases-- != 0) {

            int n = sc.nextInt();

            String s = sc.next();

            boolean f = false;

            boolean isS=false;

            char arr[] = s.toCharArray();

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

                if(arr[i]=='p')isS=true;

                else if(arr[i]=='s' && isS){

                    f = true;

                    break;

                }

            }

            if(s.contains("ps") || s.contains(".sp."))f= true;

            if(f)out.println("NO");

            else

            out.println("YES");

        }

        out.flush();

    }

    public static void debugArray(int[] arr) {

        out.println(Arrays.toString(arr));

    }

    public static void debugList(List<Integer> list) {

        out.println(list);

    }

    public static long modAdd(long a, long b, int mod) {

        return (a + b) % mod;

    }

    public static long modMul(long a, long b, int mod) {

        return (a * b) % mod;

    }

    public static long modExp(long base, long exp, int mod) {

        long result = 1;

        while (exp > 0) {

            if ((exp & 1) == 1) result = (result * base) % mod;

            base = (base * base) % mod;

            exp >>= 1;

        }

        return result;

    }

    public static void precomputePrimes() {

        Arrays.fill(isPrime, true);

        isPrime[0] = isPrime[1] = false;

        for (int i = 2; i * i <= MAX; i++) {

            if (isPrime[i]) {

                for (int j = i * i; j <= MAX; j += i) {

                    isPrime[j] = false;

                }

            }

        }

    }

    public static boolean isPrime(int n) {

        return n >= 0 && n <= MAX && isPrime[n];

    }

    public static void bfs(int start, List<Integer>[] graph, boolean[] visited) {

        Queue<Integer> queue = new LinkedList<>();

        queue.add(start);

        visited[start] = true;

        while (!queue.isEmpty()) {

            int node = queue.poll();

            for (int neighbor : graph[node]) {

                if (!visited[neighbor]) {

                    queue.add(neighbor);

                    visited[neighbor] = true;

                }

            }

        }

    }

    static class DSU {

        int[] parent, rank;

        DSU(int n) {

            parent = new int[n];

            rank = new int[n];

            for (int i = 0; i < n; i++) parent[i] = i;

        }

        int find(int x) {

            if (x != parent[x]) parent[x] = find(parent[x]);

            return parent[x];

        }

        void union(int x, int y) {

            int rootX = find(x), rootY = find(y);

            if (rootX != rootY) {

                if (rank[rootX] > rank[rootY]) parent[rootY] = rootX;

                else if (rank[rootX] < rank[rootY]) parent[rootX] = rootY;

                else {

                    parent[rootY] = rootX;

                    rank[rootX]++;

                }

            }

        }

    }

    static class FastIO {

        BufferedReader br;

        StringTokenizer st;

        public FastIO() {

            br = new BufferedReader(new InputStreamReader(System.in));

        }

        String next() {

            while (st == null || !st.hasMoreElements()) {

                try {

                    st = new StringTokenizer(br.readLine());

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }

        int nextInt() {

            return Integer.parseInt(next());

        }

        long nextLong() {

            return Long.parseLong(next());

        }

        double nextDouble() {

            return Double.parseDouble(next());

        }

        String nextLine() {

            String str = "";

            try {

                str = br.readLine();

            } catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }

    }

    public static void main(String[] args) {

        precomputePrimes();

        solve();

    }

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

int n;

char s[505];

void solve(){

    cin>>n;

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

    	cin>>s[i];

	}

	int a=0,b=0;

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

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

		if(s[i]=='p')b++;

	}

	if(a[1]=='p'){

		if(a[n]!='s'){

			if(a==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(a[n]=='s'){

		if(a[1]!='p'){

			if(b==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

	}

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int TTT=1;

    cin>>TTT;

    while(TTT--)solve();

}

#include<bits/stdc++.h>

using namespace std;

int n;

char s[505];

void solve(){

    cin>>n;

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

    	cin>>s[i];

	}

	int a=0,b=0;

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

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

		if(s[i]=='p')b++;

	}

	if(s[1]=='p'){

		if(s[n]!='s'){

			if(a==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(s[n]=='s'){

		if(s[1]!='p'){

			if(b==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(a==0||b==0)cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int TTT=1;

    cin>>TTT;

    while(TTT--)solve();

}

Answer: 2


#pragma region usual_defs
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

// this is the only reason I like C++ (sorry, java, try to be more fun next time):
#define meow cin
#define murr cout
#define lol long long
#define lmao unsigned long long
#define el '\n'
#define none \
    {        \
    }
#define kaput return
#define kill break
#define nah continue
using namespace std;
#pragma endregion usual_defs
// #define SYNC
#define i_like_cats

int n;
string str;
bool l, _s, _p;
void cat()
{
    meow >> n;
    meow.ignore();
    getline(meow, str);
    _s = false;
    _p = false;
    for (int i = 0; i < n; i++)
    {
        if (str[i] == 's')
            _s = true;
        else if (str[i] == 'p')
            _p = true;
    }
    if (!(_s && _p))
    {
        murr << "YES\n";
        kaput;
    }

    _p = true;
    for (int i = 0; i < n - 1; i++)
    {
        if (str[i] == 'p')
        {
            _p = false;
            kill;
        }
    }
    if (_p)
    {
        murr << "YES\n";
        kaput;
    }

    _s = true;
    for (int i = 1; i < n; i++)
    {
        if (str[i] == 's')
        {
            _s = false;
            kill;
        }
    }
    if (_s)
    {
        murr << "YES\n";
        kaput;
    }
    murr << "NO\n";
}

#pragma region main
#ifdef i_like_cats
int INPUT_SETS_COUNT;
#endif
int main()
{
    ios_base::sync_with_stdio(false);
#ifndef SYNC
    meow.tie(NULL);
#endif
#ifdef i_like_cats
    meow >> INPUT_SETS_COUNT;
    meow.ignore();
    while (INPUT_SETS_COUNT--)
        cat();
#endif
#ifndef i_like_cats
    cat();
#endif
}
#pragma endregion main

#pragma region usual_defs
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

// this is the only reason I like C++ (sorry, java, try to be more fun next time):
#define meow cin
#define murr cout
#define lol long long
#define lmao unsigned long long
#define el '\n'
#define none \
    {        \
    }
#define kaput return
#define kill break
#define nah continue
using namespace std;
#pragma endregion usual_defs
// #define SYNC
#define i_like_cats

int n;
string str;
bool l, _s, _p;
void cat()
{
    meow >> n;
    meow.ignore();
    getline(meow, str);
    _s = false;
    _p = false;
    for (int i = 0; i < n; i++)
    {
        if (str[i] == 's')
            _s = true;
        else if (str[i] == 'p')
            _p = true;
    }
    if (!(_s && _p))
    {
        murr << "YES\n";
        kaput;
    }

    if (str[0] != '.' || str[n - 1] != '.')
    {
        l = false;
        for (int i = 0; i < n; i++)
        {
            if (str[i] != '.')
            {
                if (str[i] == 's')
                {
                    if (l)
                    {
                        murr << "NO\n";
                        kaput;
                    }
                }
                else
                    l = true;
            }
        }
        murr << "YES\n";
    }
    else
        murr << "NO\n";
}

#pragma region main
#ifdef i_like_cats
int INPUT_SETS_COUNT;
#endif
int main()
{
    ios_base::sync_with_stdio(false);
#ifndef SYNC
    meow.tie(NULL);
#endif
#ifdef i_like_cats
    meow >> INPUT_SETS_COUNT;
    meow.ignore();
    while (INPUT_SETS_COUNT--)
        cat();
#endif
#ifndef i_like_cats
    cat();
#endif
}
#pragma endregion main

Answer: 1


#include"bits/stdc++.h"
using namespace std;

#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

typedef long long ll;
const int MOD = 1000000007;
const int Nmax = 2e5+5;

void akibify(){

      int n ;cin>>n ;
      string s ;
      cin>>s;bool f = 1;
      map<char,int>m ;
      int slast = 0;
      int pfirst = -1 ;
       for(int i = 0 ; i < n ; i++){
            m[s[i]]++;
            if(s[i] == 's'){
                slast = i ;
            }
            if(s[i] == 'p' && pfirst == -1){
                pfirst = i ;
            }
       }
       if(m['p'] == 0 || m['s'] == 0){
        YES;
        return;
       }
       if(slast == 0 || pfirst == n-1){
        YES;
        return;
       }
       NO;

      }

int main(){
   fast_io;
    int t ;
    cin>>t ;
    while(t--){
      akibify();

    }

    return 0;
}

#include"bits/stdc++.h"
using namespace std;

#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

typedef long long ll;
const int MOD = 1000000007;
const int Nmax = 2e5+5;

void akibify(){

      int n ;cin>>n ;
      string s ;
      cin>>s;bool f = 1;

      for(int i = 1 ; i < n ; i++){
           char c1 = s[i-1];
           int l1,r1 ;
           if(c1 == 'p') {
            l1 = 0 ;
            r1 = i-1;
           }
           else if(c1 == 's') {
            l1 = i-1;
            r1 = n-1;
           }
           else {
            l1 = 0 ;
            r1 = n-1;
           }
           char c2 = s[i];
            int l2,r2 ;
             if(c2 == 'p') {
            l2 = 0 ;
            r2 = i;
           }
           else if(c2 == 's') {
            l2 = i;
            r2 = n-1;
           }
           else {
            l2= 0 ;
            r2 = n-1;
           }
           if(c1 == 'p' && c2 == 's' && r1 < l2 ){
              f = 0 ;
              NO;
              return ;
           }
           if(c1 == 's' && c2 == 'p' && l2 < l1 && r2 <r1){
               f = 0;
               NO;
               return;
           }

      }
    //   int l = 0 , r = n-1;
    //   while(l < r){
    //     if(s[l] )
    //   }
      YES;

}

int main(){
   fast_io;
    int t ;
    cin>>t ;
    while(t--){
      akibify();

    }

    return 0;
}

Answer: 1


#include <bits/stdc++.h>

#define int long long

const int mod = 1e9 + 7;

const int inf = 1e18;

using namespace std;

void solve()

{

    int n;

    string a;

    cin >> n >> a;

    int cnt1=0,cnt2=0;

    for(auto &i:a){

        if(i=='s') cnt1++;

        if(i=='p') cnt2++;

    }

    if(cnt1==0 || cnt2==0 || cnt1==1 && a[a.size()-1]=='s' || cnt2==1 && a[a.size()-1]=='p') cout << "YES";

    else cout << "NO";

}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

#ifdef Timur

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

        cout << "\n";

    }

    return 0;

}

#include <bits/stdc++.h>

#define int long long

const int mod = 1e9 + 7;

const int inf = 1e18;

using namespace std;

void solve()

{

    int n;

    string a;

    cin >> n >> a;

    int cnt1=0,cnt2=0;

    for(auto &i:a){

        if(i=='s') cnt1++;

        if(i=='p') cnt2++;

    }

    if(cnt1==0 || cnt2==0 || cnt2==1 && a[a.size()-1]=='p') cout << "YES";

    else cout << "NO";

}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

#ifdef Timur

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

        cout << "\n";

    }

    return 0;

}

Answer: 2


import java.util.HashSet;

import java.util.Scanner;

public class PSPS {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int testCase=sc.nextInt();

        while (testCase-- >0){

            int n=sc.nextInt();

            String s=sc.next();

            int pidx=s.indexOf('p');

            int sidx=s.lastIndexOf('s');

            HashSet<Character> hs=new HashSet<>();

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

                if(s.charAt(i)!='.') hs.add(s.charAt(i));

            }

            if(hs.size()>1 || (pidx<sidx && pidx!=-1)) System.out.println("NO");

            else System.out.println("YES");

        }

    }

}

import java.util.HashSet;

import java.util.Scanner;

public class PSPS {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int testCase=sc.nextInt();

        while (testCase-- >0){

            int n=sc.nextInt();

            String s=sc.next();

            int pidx=s.indexOf('p');

            int sidx=s.lastIndexOf('s');

            HashSet<Character> hs=new HashSet<>();

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

                if(s.charAt(i)!='.') hs.add(s.charAt(i));

            }

            if(hs.size()>1 || pidx<sidx) System.out.println("NO");

            else System.out.println("YES");

        }

    }

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+7;

#define int long long

#define endl '\n'

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    s='0'+s;

    if(s[1]=='s'){

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

            if(s[i]=='p'&&i!=n){

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    else if(s[1]=='p'){

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

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

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    else{

        int cnts=0,cntp=0,ix=0,ip=0;

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

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

                cnts++;

                ix=i;

            }

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

                cntp++;

                ip=i;

            }

            if(ip<ix){

                cout<<"NO"<<endl;

                return;

            }

        }

    }

    cout<<"YES"<<endl;

}

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    //freopen("in.txt", "rt", stdin);

    //freopen("out.txt", "wt", stdout);

    int T=1;

    cin>>T;

    while(T--){

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+7;

#define int long long

#define endl '\n'

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    s='0'+s;

    int l=-1,r=n+1;

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

        if(s[i]=='s') l=i;

    }

    for(int i=n;i>=0;i--){

        if(s[i]=='p')r=i;

    }

    if(r<l){

        cout<<"NO"<<endl;

        return;

    }

    else{

        if(l==-1||r==n+1||l==1||r==n){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }

}

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    //freopen("in.txt", "rt", stdin);

    //freopen("out.txt", "wt", stdout);

    int T=1;

    cin>>T;

    while(T--){

        solve();

    }

    return 0;

}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

#define int long long

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

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.size()==1){

		cout<<"YES\n";

	}

	else if(m.size()==2){

		if(m.find('.')!=m.end()){

			cout<<"YES\n";

		}

		else{

			int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

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

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";

			}

		}

		}

	}

	else{

		int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

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

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";

			}

		}

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

#include<bits/stdc++.h>

using namespace std;

#define int long long

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

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

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

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

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		cout<<"NO\n";

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

Answer: 2


#include<iostream>

#include<map>

#include<algorithm>

using namespace std;

typedef long long LL;

const int N = 200010, MOD = 1e9 + 7;

int T;

LL n, m;

int a[N], b[N];

int main() {

    cin >> T;

    while (T--) {

        cin >> n;

        string s;

        cin >> s;

        int f = 1;

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

            if (s[i] != s[0]) f = 0;

        }

        if (f) puts("YES");

        else {

            f = 1;

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

                if (s[i] == 's') f = 0;

            }

            if (f) puts("YES");

            else{

                if (s[0] == 'p') puts("NO");

                else {

                    f = 1;

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

                        if (s[i] == 'p' && i != n - 1) {

                            f = 0;

                            break;

                        }

                    }

                    if (f) puts("YES");

                    else puts("NO");

                }

            }

        }

    }

    return 0;

}

#include<iostream>

#include<map>

#include<algorithm>

using namespace std;

typedef long long LL;

const int N = 200010, MOD = 1e9 + 7;

int T;

LL n, m;

int a[N], b[N];

int main() {

    cin >> T;

    while (T--) {

        cin >> n;

        string s;

        cin >> s;

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

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

        int f1 = 0, f2 = 0;

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

            if(s[i] == 's') f1 = 1;

            else if(s[i] == 'p') f2 = 1;

        }

        if(f1 && f2) puts("NO");

        else puts("YES");

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")

#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#define int long long

int mod=1e9+7;

void sort(vector<int> &vct){ sort(vct.begin(),vct.end());}

void invct(vector<int> &vct,int n){vct.resize(n);for(int i=0;i<n;i++)cin>>vct[i];}

int accumulate(vector<int> &vct){int sum=0;for(int i=0;i<vct.size();i++)sum+=vct[i];return sum;}

void Solve()

{

    string str,str1,str2;

    vector<int> vct,vct1,vct2;

    unordered_map<int,int> mp;

    vector<vector<int>> mat;

    int a,b,c,k,l,m,n,r;

    // cin>>n>>m;

    cin>>n;

    cin>>str;

    // no ps is

    int flag=0;

    int flag1=0;

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

    {

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

        {

            if(flag1==1 && i!=n-1)

            {

                cout<<"NO"<<endl;

                return ;

            }

            if(flag==0)flag=1;

        }

        else if(str[i]=='s')

        {

            if(flag1==0 && i!=0)flag1=1;

            if(flag==1)

            {

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    cout<<"YES"<<endl;

}

signed main()

{

    ios_base::sync_with_stdio(false);cin.tie(nullptr);

    int TC;cin>>TC;while(TC--) Solve();

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")

#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#define int long long

int mod=1e9+7;

void sort(vector<int> &vct){ sort(vct.begin(),vct.end());}

void invct(vector<int> &vct,int n){vct.resize(n);for(int i=0;i<n;i++)cin>>vct[i];}

int accumulate(vector<int> &vct){int sum=0;for(int i=0;i<vct.size();i++)sum+=vct[i];return sum;}

void Solve()

{

    string str,str1,str2;

    vector<int> vct,vct1,vct2;

    unordered_map<int,int> mp;

    vector<vector<int>> mat;

    int a,b,c,k,l,m,n,r;

    // cin>>n>>m;

    cin>>n;

    cin>>str;

    // no ps is

    int flag=0;

    int flag1=0;

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

    {

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

        {

            if(flag1==1 && i!=n-1)

            {

                cout<<"NO"<<endl;

                return ;

            }

            if(flag==0)flag=1;

        }

        else if(str[i]=='s')

        {

            if(flag1==0)flag1=1;

            if(flag==1)

            {

                cout<<"NO"<<endl;

                return ;

            }

        }

    }

    cout<<"YES"<<endl;

}

signed main()

{

    ios_base::sync_with_stdio(false);cin.tie(nullptr);

    int TC;cin>>TC;while(TC--) Solve();

    return 0;

}

Answer: 1


/*************************************************************************************************************

										⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠛⠋⠉⠈⠉⠉⠉⠉⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⡿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿

										⣿⣿⣿⣿⡏⣀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿

										⣿⣿⣿⢏⣴⣿⣷⠀⠀⠀⠀⠀⢾⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿

										⣿⣿⣟⣾⣿⡟⠁⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣷⢢⠀⠀⠀⠀⠀⠀⠀⢸⣿

										⣿⣿⣿⣿⣟⠀⡴⠄⠀⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⣿

										⣿⣿⣿⠟⠻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⢴⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⣿

										⣿⣁⡀⠀⠀⢰⢠⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⡄⠀⣴⣶⣿⡄⣿

										⣿⡋⠀⠀⠀⠎⢸⣿⡆⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⠗⢘⣿⣟⠛⠿⣼

										⣿⣿⠋⢀⡌⢰⣿⡿⢿⡀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣧⢀⣼

										⣿⣿⣷⢻⠄⠘⠛⠋⠛⠃⠀⠀⠀⠀⠀⢿⣧⠈⠉⠙⠛⠋⠀⠀⠀⣿⣿⣿⣿⣿

										⣿⣿⣧⠀⠈⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠟⠀⠀⠀⠀⢀⢃⠀⠀⢸⣿⣿⣿⣿

										⣿⣿⡿⠀⠴⢗⣠⣤⣴⡶⠶⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡸⠀⣿⣿⣿⣿

										⣿⣿⣿⡀⢠⣾⣿⠏⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠉⠀⣿⣿⣿⣿

										⣿⣿⣿⣧⠈⢹⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿

										⣿⣿⣿⣿⡄⠈⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣦⣄⣀⣀⣀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠙⣿⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠁⠀⠀⠹⣿⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⢐⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⠿⠛⠉⠉⠁⠀⢻⣿⡇⠀⠀⠀⠀⠀⠀⢀⠈⣿⣿⡿⠉⠛⠛⠛⠉⠉

										⣿⡿⠋⠁⠀⠀⢀⣀⣠⡴⣸⣿⣇⡄⠀⠀⠀⠀⢀⡿⠄⠙⠛⠀⣀⣠⣤⣤⠄

*************************************************************************************************************/

#include <set>

#include <map>

#include <queue>

#include <cmath>

#include <tuple>

#include <random>

#include <vector>

#include <bitset>

#include <chrono>

#include <iomanip>

#include <cassert>

#include <complex>

#include <fstream>

#include <sstream>

#include <iostream>

#include <algorithm>

#include <unordered_set>

#include <unordered_map>

using namespace std;

#define UwU cin.tie(0);ios_base::sync_with_stdio(0);

#define test int test_num;cin>>test_num;while(test_num--)

#define prec(k) cout<<fixed<<setprecision(k);

#define cl(n,k) (((n)+(k)-1)/(k))

#define f first

#define s second

using ll = long long;

using ld = long double;

using pii = pair<int,int>;

using pll = pair<ll,ll>;

using point = complex<double>;

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

ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

const int M = 1e9 + 7;

const int O = 998244353;

const ld EPS = 1e-10;

const ld PI = 3.14159265358979323846;

const ll INF = (ll)1e18 + 5;

const int N = 2e5 + 5;

int n;

string s;

int main(){

	UwU

	test{

		cin >> n >> s;

		if(!count(s.begin(),s.end(),'p') || !count(s.begin(),s.end(),'s')){

			cout << "YES\n";

		}

		else if(count(s.begin(),s.end(),'p') >= 2 && count(s.begin(),s.end(),'s') >= 2){

			cout << "NO\n";

		}

		else{

			if(count(s.begin(),s.end(),'s') >= 2){

				reverse(s.begin(),s.end());

				for(auto& c : s){

					if(c == 'p' || c == 's'){

						c = c ^ 'p' ^ 's';

					}

				}

			}

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

				cout << "NO\n";

			}

			else{

				cout << "YES\n";

			}

		}

	}

	return 0;

}

/*************************************************************************************************************

										⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠛⠋⠉⠈⠉⠉⠉⠉⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⡿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿

										⣿⣿⣿⣿⡏⣀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿

										⣿⣿⣿⢏⣴⣿⣷⠀⠀⠀⠀⠀⢾⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿

										⣿⣿⣟⣾⣿⡟⠁⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣷⢢⠀⠀⠀⠀⠀⠀⠀⢸⣿

										⣿⣿⣿⣿⣟⠀⡴⠄⠀⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⣿

										⣿⣿⣿⠟⠻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⢴⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⣿

										⣿⣁⡀⠀⠀⢰⢠⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⡄⠀⣴⣶⣿⡄⣿

										⣿⡋⠀⠀⠀⠎⢸⣿⡆⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⠗⢘⣿⣟⠛⠿⣼

										⣿⣿⠋⢀⡌⢰⣿⡿⢿⡀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣧⢀⣼

										⣿⣿⣷⢻⠄⠘⠛⠋⠛⠃⠀⠀⠀⠀⠀⢿⣧⠈⠉⠙⠛⠋⠀⠀⠀⣿⣿⣿⣿⣿

										⣿⣿⣧⠀⠈⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠟⠀⠀⠀⠀⢀⢃⠀⠀⢸⣿⣿⣿⣿

										⣿⣿⡿⠀⠴⢗⣠⣤⣴⡶⠶⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡸⠀⣿⣿⣿⣿

										⣿⣿⣿⡀⢠⣾⣿⠏⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠉⠀⣿⣿⣿⣿

										⣿⣿⣿⣧⠈⢹⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿

										⣿⣿⣿⣿⡄⠈⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣦⣄⣀⣀⣀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠙⣿⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠁⠀⠀⠹⣿⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⢐⣿⣿⣿⣿⣿⣿⣿⣿⣿

										⣿⣿⣿⣿⠿⠛⠉⠉⠁⠀⢻⣿⡇⠀⠀⠀⠀⠀⠀⢀⠈⣿⣿⡿⠉⠛⠛⠛⠉⠉

										⣿⡿⠋⠁⠀⠀⢀⣀⣠⡴⣸⣿⣇⡄⠀⠀⠀⠀⢀⡿⠄⠙⠛⠀⣀⣠⣤⣤⠄

*************************************************************************************************************/

#include <set>

#include <map>

#include <queue>

#include <cmath>

#include <tuple>

#include <random>

#include <vector>

#include <bitset>

#include <chrono>

#include <iomanip>

#include <cassert>

#include <complex>

#include <fstream>

#include <sstream>

#include <iostream>

#include <algorithm>

#include <unordered_set>

#include <unordered_map>

using namespace std;

#define UwU cin.tie(0);ios_base::sync_with_stdio(0);

#define test int test_num;cin>>test_num;while(test_num--)

#define prec(k) cout<<fixed<<setprecision(k);

#define cl(n,k) (((n)+(k)-1)/(k))

#define f first

#define s second

using ll = long long;

using ld = long double;

using pii = pair<int,int>;

using pll = pair<ll,ll>;

using point = complex<double>;

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

ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

const int M = 1e9 + 7;

const int O = 998244353;

const ld EPS = 1e-10;

const ld PI = 3.14159265358979323846;

const ll INF = (ll)1e18 + 5;

const int N = 2e5 + 5;

int n;

string s;

int main(){

	UwU

	test{

		cin >> n >> s;

		if(!count(s.begin(),s.end(),'p') || !count(s.begin(),s.end(),'s')){

			cout << "YES\n";

		} // git

		else if(count(s.begin(),s.end(),'p') >= 2 && count(s.begin(),s.end(),'s') >= 2){

			cout << "NO\n";

		} //

		else{

			if(count(s.begin(),s.end(),'s') >= 2){

				reverse(s.begin(),s.end());

				for(auto& c : s){

					if(c == 'p' || c == 's'){

						c = c ^ 'p' ^ 's';

					}

				}

			}

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

				cout << "YES\n";

			}

			else if(count(s.begin(),s.end(),'p') == 1 && s.back() == 'p'){

				cout << "YES\n";

			}

			else{

				cout << "NO\n";

			}

		}

	}

	return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

// Macros for shorthand

#define ll long long

#define ld long double

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

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

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

#define rep(i, a, b) for (int i = a; i < b; i++)

#define rrep(i, a, b) for (int i = a; i >= b; i--)

// Constants

const ll MOD = 1e9 + 7;

const ll INF = 1e18;

// Debugging utility (comment out in contests)

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

// Fast IO

void fast_io() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

}

// GCD and LCM

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// Modular arithmetic

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

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

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

ll mod_pow(ll a, ll b, ll m = MOD) {

    ll res = 1;

    while (b > 0) {

        if (b & 1) res = (res * a) % m;

        a = (a * a) % m;

        b >>= 1;

    }

    return res;

}

// Binary search example (can be modified)

int binary_search(vector<int>& v, int target) {

    int lo = 0, hi = sz(v) - 1;

    while (lo <= hi) {

        int mid = lo + (hi - lo) / 2;

        if (v[mid] == target) return mid;

        else if (v[mid] < target) lo = mid + 1;

        else hi = mid - 1;

    }

    return -1;

}

// Main function

int main() {

    fast_io();

    int t; // Number of test cases

    cin >> t;

    while (t--) {

        // Input and solve here

        int n;

        cin >> n;

        string s;

        cin>>s;

        int pidx=-1,sidx=-1;

        int flag=0;

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

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

                sidx = i;

                if(pidx!=-1){

                    if(pidx<sidx){

                        flag=1;

                        break;

                    }

                }

            }

            else if(s[i]=='p'){

                pidx=i;

                if(sidx!=-1){

                    if(sidx!=0 && pidx!=n-1){

                        flag=1;

                        break;

                    }

                }

            }

        }

        if(flag==1){

            cout<<"NO"<<endl;

        }

        else{

            cout<<"YES"<<endl;

        }

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

// Macros for shorthand

#define ll long long

#define ld long double

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

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

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

#define rep(i, a, b) for (int i = a; i < b; i++)

#define rrep(i, a, b) for (int i = a; i >= b; i--)

// Constants

const ll MOD = 1e9 + 7;

const ll INF = 1e18;

// Debugging utility (comment out in contests)

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

// Fast IO

void fast_io() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

}

// GCD and LCM

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// Modular arithmetic

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

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

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

ll mod_pow(ll a, ll b, ll m = MOD) {

    ll res = 1;

    while (b > 0) {

        if (b & 1) res = (res * a) % m;

        a = (a * a) % m;

        b >>= 1;

    }

    return res;

}

// Binary search example (can be modified)

int binary_search(vector<int>& v, int target) {

    int lo = 0, hi = sz(v) - 1;

    while (lo <= hi) {

        int mid = lo + (hi - lo) / 2;

        if (v[mid] == target) return mid;

        else if (v[mid] < target) lo = mid + 1;

        else hi = mid - 1;

    }

    return -1;

}

// Main function

int main() {

    fast_io();

    int t; // Number of test cases

    cin >> t;

    while (t--) {

        // Input and solve here

        int n;

        cin >> n;

        string s;

        cin>>s;

        int pidx=-1,sidx=-1;

        int flag=0;

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

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

                sidx = i;

            }

            else if(s[i]=='p'){

                pidx=i;

                if(sidx!=-1){

                    if(sidx!=0 && pidx!=n-1){

                        flag=1;

                        break;

                    }

                }

            }

        }

        if(flag==1){

            cout<<"NO"<<endl;

        }

        else{

            if(pidx!=-1 && sidx!=-1 && pidx<sidx){

                cout<<"NO"<<endl;

            }

            else{

                cout<<"YES"<<endl;

            }

        }

    }

    return 0;

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		int n;

		cin>>n;

		string s;

		cin>>s;

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

		{

			s[0]='.';

		}

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

		{

			s[n-1]='.';

		}

		int flag=0;

		int arr=0;

		for(int i=0;i<n&&flag*arr!=1;i++)

		{

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

			{

				flag=1;

			}

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

			{

				arr=1;

			}

		}

		if(arr*flag)

		{

			cout<<"NO"<<endl;

		}

		else

		{

			cout<<"YES"<<endl;

		}

	}

}

#include<bits/stdc++.h>

using namespace std;

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		int n;

		cin>>n;

		string s;

		cin>>s;

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

		{

			s[0]='.';

		}

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

		{

			s[n-1]='.';

		}

		int flag=0;

		int arr=0;

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

		{

			if(s[i]=='p'&&flag==0)

			{

				flag=1;

			}

			else if(s[i]=='s'&&flag)

			{

				arr=1;

				break;

			}

		}

		if(arr)

		{

			cout<<"NO"<<endl;

		}

		else

		{

			cout<<"YES"<<endl;

		}

	}

}

Answer: 1


// #include<bits/stdc++.h>

// #define int long long

#include <iostream>

#include <iostream>

#include <chrono>

#include <vector>

#include <math.h>

#include <cmath>

#include <unordered_map>

#include <map>

#include <numeric>

#include <vector>

#include <string>

#include <set>

#include <unordered_set>

#include <queue>

#include <algorithm>

#include <iomanip>

#include <stack>

#include <cstring>

using namespace std;

using namespace chrono;

// #define ll unsigned long long int

#define ll long long int

// ll mod = 1e9 + 7;

ll mod = 998244353;

// ll prime[1000009];

vector<bool> prime(100000000 + 1, true);

ll maxpoweroftwo(ll n)

{

  ll x = log2(n);

  return x;

}

ll maxpoweroffive(ll n)

{

  ll x = log(n) / log(5);

  return x;

}

ll maxpoweroften(ll n)

{

  ll x = log(n) / log(10);

  return x;

}

static ll gcd(ll a, ll b)

{

  ll r, i;

  while (b != 0)

  {

    r = a % b;

    a = b;

    b = r;

  }

  return a;

}

ll lcm(ll a, ll b)

{

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

}

vector<ll> decToBinary(ll n1)

{

  vector<ll> binaryNum(63);

  ll i = 0;

  while (n1 > 0)

  {

    binaryNum[i] = n1 % 2;

    // binaryNum.push_back(n1 % 2);

    n1 = n1 / 2;

    i++;

  }

  return binaryNum;

}

ll binaryToDecimal(vector<ll> v)

{

  ll dec_value = 0;

  // Initializing base value to 1, i.e 2^0

  ll base = 1;

  ll i = v.size() - 1;

  while (i >= 0)

  {

    ll last_digit = v[i];

    // temp = temp / 10;

    dec_value += last_digit * base;

    base = base * 2;

    i--;

  }

  return dec_value;

}

// k = upto k

vector<ll> sieveOfEratosthenes(ll k)

{

  // Create a boolean vector initialized to true

  std::vector<bool> isPrime(k + 1, true);

  isPrime[0] = isPrime[1] = false; // 0 and 1 are not primes

  for (ll i = 2; i * i <= k; ++i)

  {

    if (isPrime[i])

    {

      // Mark multiples of i as not prime

      for (ll j = i * i; j <= k; j += i)

      {

        isPrime[j] = false;

      }

    }

  }

  // Store all prime numbers in a vector

  std::vector<ll> primes;

  for (ll i = 2; i <= k; ++i)

  {

    if (isPrime[i])

    {

      primes.push_back(i);

    }

  }

  return primes;

}

vector<ll> primeFactorization(ll n)

{

  vector<ll> factors;

  for (ll i = 2; i * i <= n; i++)

  {

    ll cnt = 0;

    while (n % i == 0)

    {

      cnt++;

      n /= i;

      factors.push_back(i);

    }

  }

  if (n > 1)

    factors.push_back(n);

  return factors;

}

bool get_bit(ll a, ll i)

{

  return a & (1ll << i);

}

ll binpow(ll a, ll b)

{

  ll ans = 1;

  while (b > 0)

  {

    if ((b & 1) == 1)

      ans *= a;

    a *= a;

    b = b >> 1;

  }

  return ans;

}

ll binpowmod(ll a, ll b)

{

  ll ans = 1;

  while (b > 0)

  {

    if ((b & 1) == 1)

    {

      ans *= a;

      ans %= mod;

    }

    a *= a;

    a %= mod;

    b = b >> 1;

  }

  return ans;

}

const ll MAX = 2e5 + 7;

vector<ll> fact(MAX);

ll add(ll a, ll b)

{

  return (a + b) % mod;

}

ll sub(ll a, ll b)

{

  return ((a - b) % mod + mod) % mod;

}

ll mult(ll a, ll b)

{

  return ((a * b) % mod);

}

ll inv(ll a)

{

  return binpowmod(a, mod - 2);

}

ll divide(ll a, ll b)

{

  return mult(a, inv(b));

}

ll nCr(ll n, ll r)

{

  if (n < r)

    return 0;

  return divide(fact[n], mult(fact[r], fact[n - r]));

}

void preFactorial()

{

  fact[0] = 1;

  for (ll i = 1; i < MAX; i++)

    fact[i] = mult(i, fact[i - 1]);

}

void solve() {

  ll n;cin>>n;string s;cin>>s;

ll counts=0;

ll countp=0;

ll posp=-1;

ll poss=-1;

for (ll i = 0; i < n; i++)

{

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

    poss=i;

    counts++;

  }

  else if(s[i]=='p'){

    posp=i;

    countp++;

  }

}

if(counts==0 || countp==0){

  cout<<"YES";

}

else{

  if(counts>1 && countp>1){

    cout<<"NO";

  }

  else{

    if(counts==1 && countp==1){

      if(poss==0 || posp==n-1){

        cout<<"YES";

      }

      else{

        cout<<"NO";

      }

    }

    else{

    if(counts==1){

      if(poss==0){

        cout<<"YES";

      }

      else{

        cout<<"NO";

      }

    }

    else{

      if(posp==n-1){

        cout<<"YES";

      }

      else{

        cout<<"NO";

      }

    }

  }

  }

}

// sppp => 1234

// sp.p => 1234

// 123456

  cout<<endl;

}

// DIV2 => A -> 15 MIN , B->45MIN , C->1 HR

// BUT LOGIC TIME -> A-> 10 MIN , B-> 30MIN , C-> 30MIN

// DIV3=> A-> 10 MIN , B-> 15MIN , C->45MIN , D->1HR

// BUT LOGIC TIME -> A-> 5 MIN , B-> 10MIN , C-> 30MIN , D-> 30 MIN

// DIV3=> A-> 5 MIN , B-> 10MIN , C->20MIN , D->35MIN , E->45MIN

// BUT LOGIC TIME -> A-> 5 MIN , B-> 5MIN , C-> 15MIN , D-> 25 MIN , E->30MIN

// increase speed in 'a' within 5 min

int main()

{

  ios::sync_with_stdio(0);

  cin.tie(0);

  cout.tie(0);

  preFactorial();

  int T;

  cin >> T;

  auto start1 = high_resolution_clock::now();

  while (T--)

  {

    solve();

  }

  auto stop1 = high_resolution_clock::now();

  auto duration = duration_cast<microseconds>(stop1 - start1);

  cerr << "Time: " << duration.count() / 1000 << " ms" << endl;

  return 0;

}

// #include<bits/stdc++.h>

// #define int long long

#include <iostream>

#include <iostream>

#include <chrono>

#include <vector>

#include <math.h>

#include <cmath>

#include <unordered_map>

#include <map>

#include <numeric>

#include <vector>

#include <string>

#include <set>

#include <unordered_set>

#include <queue>

#include <algorithm>

#include <iomanip>

#include <stack>

#include <cstring>

using namespace std;

using namespace chrono;

// #define ll unsigned long long int

#define ll long long int

// ll mod = 1e9 + 7;

ll mod = 998244353;

// ll prime[1000009];

vector<bool> prime(100000000 + 1, true);

ll maxpoweroftwo(ll n)

{

  ll x = log2(n);

  return x;

}

ll maxpoweroffive(ll n)

{

  ll x = log(n) / log(5);

  return x;

}

ll maxpoweroften(ll n)

{

  ll x = log(n) / log(10);

  return x;

}

static ll gcd(ll a, ll b)

{

  ll r, i;

  while (b != 0)

  {

    r = a % b;

    a = b;

    b = r;

  }

  return a;

}

ll lcm(ll a, ll b)

{

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

}

vector<ll> decToBinary(ll n1)

{

  vector<ll> binaryNum(63);

  ll i = 0;

  while (n1 > 0)

  {

    binaryNum[i] = n1 % 2;

    // binaryNum.push_back(n1 % 2);

    n1 = n1 / 2;

    i++;

  }

  return binaryNum;

}

ll binaryToDecimal(vector<ll> v)

{

  ll dec_value = 0;

  // Initializing base value to 1, i.e 2^0

  ll base = 1;

  ll i = v.size() - 1;

  while (i >= 0)

  {

    ll last_digit = v[i];

    // temp = temp / 10;

    dec_value += last_digit * base;

    base = base * 2;

    i--;

  }

  return dec_value;

}

// k = upto k

vector<ll> sieveOfEratosthenes(ll k)

{

  // Create a boolean vector initialized to true

  std::vector<bool> isPrime(k + 1, true);

  isPrime[0] = isPrime[1] = false; // 0 and 1 are not primes

  for (ll i = 2; i * i <= k; ++i)

  {

    if (isPrime[i])

    {

      // Mark multiples of i as not prime

      for (ll j = i * i; j <= k; j += i)

      {

        isPrime[j] = false;

      }

    }

  }

  // Store all prime numbers in a vector

  std::vector<ll> primes;

  for (ll i = 2; i <= k; ++i)

  {

    if (isPrime[i])

    {

      primes.push_back(i);

    }

  }

  return primes;

}

vector<ll> primeFactorization(ll n)

{

  vector<ll> factors;

  for (ll i = 2; i * i <= n; i++)

  {

    ll cnt = 0;

    while (n % i == 0)

    {

      cnt++;

      n /= i;

      factors.push_back(i);

    }

  }

  if (n > 1)

    factors.push_back(n);

  return factors;

}

bool get_bit(ll a, ll i)

{

  return a & (1ll << i);

}

ll binpow(ll a, ll b)

{

  ll ans = 1;

  while (b > 0)

  {

    if ((b & 1) == 1)

      ans *= a;

    a *= a;

    b = b >> 1;

  }

  return ans;

}

ll binpowmod(ll a, ll b)

{

  ll ans = 1;

  while (b > 0)

  {

    if ((b & 1) == 1)

    {

      ans *= a;

      ans %= mod;

    }

    a *= a;

    a %= mod;

    b = b >> 1;

  }

  return ans;

}

const ll MAX = 2e5 + 7;

vector<ll> fact(MAX);

ll add(ll a, ll b)

{

  return (a + b) % mod;

}

ll sub(ll a, ll b)

{

  return ((a - b) % mod + mod) % mod;

}

ll mult(ll a, ll b)

{

  return ((a * b) % mod);

}

ll inv(ll a)

{

  return binpowmod(a, mod - 2);

}

ll divide(ll a, ll b)

{

  return mult(a, inv(b));

}

ll nCr(ll n, ll r)

{

  if (n < r)

    return 0;

  return divide(fact[n], mult(fact[r], fact[n - r]));

}

void preFactorial()

{

  fact[0] = 1;

  for (ll i = 1; i < MAX; i++)

    fact[i] = mult(i, fact[i - 1]);

}

void solve() {

  ll n;cin>>n;string s;cin>>s;

// pspspsps

// .sp.

// sssssss

// sspp

// 1234

// 4213

// 4321

// sps no

// spps no

// ppps no

// ssss ok

// pppp ok

// sssp ok

// spp  => 123

// .sss => 4321 ok

// .pppp => 12345 ok

// .spp => 1234 no

// .ppps => 12341 no

// .ssp => 4321 ok

// ss.pp=> 4321

// ristricted case =>

//  p ke bad s

// s ke bad p only one time

ll counts=0;

ll countp=0;

ll posp=-1;

ll poss=-1;

for (ll i = 0; i < n; i++)

{

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

    poss=i;

    counts++;

  }

  else if(s[i]=='p'){

    posp=i;

    countp++;

  }

}

if(counts==0 || countp==0){

  cout<<"YES";

}

else{

  if(countp>1){

    cout<<"NO";

  }

  else{

    if(posp<n-1){

      cout<<"NO";

    }

    else{

      cout<<"YES";

    }

  }

}

// p

  cout<<endl;

}

// DIV2 => A -> 15 MIN , B->45MIN , C->1 HR

// BUT LOGIC TIME -> A-> 10 MIN , B-> 30MIN , C-> 30MIN

// DIV3=> A-> 10 MIN , B-> 15MIN , C->45MIN , D->1HR

// BUT LOGIC TIME -> A-> 5 MIN , B-> 10MIN , C-> 30MIN , D-> 30 MIN

// DIV3=> A-> 5 MIN , B-> 10MIN , C->20MIN , D->35MIN , E->45MIN

// BUT LOGIC TIME -> A-> 5 MIN , B-> 5MIN , C-> 15MIN , D-> 25 MIN , E->30MIN

// increase speed in 'a' within 5 min

int main()

{

  ios::sync_with_stdio(0);

  cin.tie(0);

  cout.tie(0);

  preFactorial();

  int T;

  cin >> T;

  auto start1 = high_resolution_clock::now();

  while (T--)

  {

    solve();

  }

  auto stop1 = high_resolution_clock::now();

  auto duration = duration_cast<microseconds>(stop1 - start1);

  cerr << "Time: " << duration.count() / 1000 << " ms" << endl;

  return 0;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

#define YES cout << "YES\n";

#define NO cout << "NO\n";

const int N = 1e6 + 5;

signed main() // Road to red

{

    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

        int n,res{1}; cin >> n;

        string s; cin >> s;

        bool p = 0;

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

        {

            if(s[i] == 'p'){p = 1;}

            if(p && s[i] == 's'){res = 0; break;}

        }

        bool ss = 0;

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

        {

            if(i < n-2 && s[i] == 's'){ss = 1;}

            if(ss && s[i] == 'p'  && i < n-1){res = 0; break;}

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

#define YES cout << "YES\n";

#define NO cout << "NO\n";

const int N = 1e6 + 5;

signed main() // Road to red

{

    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

        int n,res{1}; cin >> n;

        string s; cin >> s;

        bool p = 0;

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

        {

            if(s[i] == 'p'){p = 1;}

            if(p && s[i] == 's'){res = 0; break;}

            // else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;}

        }

        bool ss = 0;

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

        {

            if(i < n-2 && s[i] == 's'){ss = 1;}

            if(ss && s[i] == 'p'){res = 0; break;}

            // else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;}

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        stack<char> sta;

        bool flag=false;

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

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

            if(sta.top()=='p' && s[i]=='s'){

                flag=true;

                break;

            }

            sta.push(s[i]);

        }

        if(flag){

            cout<<"NO"<<endl;

            continue;

        }

        s[0]='.';

        s[n-1]='.';

        unordered_set<char> st;

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

            if(s[i]!='.'){

                st.insert(s[i]);

            }

        }

        if(st.size()<=1){

        cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        string s;

        cin>>s;

        stack<char> sta;

        bool flag=false;

        sta.push(s[0]);

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

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

            if(sta.top()=='p' && s[i]=='s'){

                flag=true;

                break;

            }

            sta.push(s[i]);

        }

        if(flag){

            cout<<"NO"<<endl;

            continue;

        }

        s[0]='.';

        s[n-1]='.';

        unordered_set<char> st;

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

            if(s[i]!='.'){

                st.insert(s[i]);

            }

        }

        if(st.size()<=1){

        cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

#define fu(i,a,b) for(int i = a; i<b; i++)

#define f(i,a) for(int i = 0; i<a; i++)

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        string s;

        int t=0;

        cin >> s;

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

        {

            t=1;

        }

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

        {

            t=1;

        }

        else

        {

            t=1;

            f(i,n)

            {

                if(s[i]!= '.')

                {

                    t=0;

                }

            }

        }

        char m = '.';

        f(i,n)

        {

            if(s[i]=='s' && m == 'p')

            {

                t=0;

            }

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

            {

                m = 's';

            }

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

            {

                m = 'p';

            }

        }

        if(t==1)

        {

            cout << "YES" << endl;

        }

        else

        {

            cout << "NO" << endl;

        }

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

#define fu(i,a,b) for(int i = a; i<b; i++)

#define f(i,a) for(int i = 0; i<a; i++)

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        string s;

        int t=0;

        cin >> s;

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

        {

            s[0] = '.';

        }

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

        {

            s[n-1] = '.';

        }

        int g=0,h=0;

        f(i,n)

        {

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

            {

                g =1;

            }

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

            {

                h =1;

            }

        }

        if(g==1 && h==1)

        {

            cout << "NO" << endl;

        }

        else

        {

            cout << "YES" << endl;

        }

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

/* clang-format off */

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>

/* FUNCTIONS */
#define f(a,n) for(long long int i=a;i<n;i++)
#define cf(i,s,e) for(long long int i=s;i<e;i++)
#define rf(e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()

/* PRINTS */
template <class T>
void print_v(vector<T> &v) { cout << "{"; for (auto x : v) cout << x << ","; cout << "\b}"; }

/* UTILS */
#define M 1000000007
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()

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

string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }

string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }

bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }

#define yy cout<<"Yes\n"
#define nn cout<<"No\n"

/* -question intuitions:
- dp --compute next result from the previous result of the sequence
        -- you have a choice at each step and each choice can lead to answer

- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n))
or upper/lower bound of something in a sorted sample namespac
 --- where anwer space is sorted and in fixed range

-heap -- find lowest or largest of a segment -- k is given example kth largest or smallest
if k+smallest -- kth smallest--maxheap
if k+largest --kth largest--  minheap
complexity-- nlog(k)
*/

#define inputv(arr,n) {for(int i=0;i<n;i++)cin>>arr[i];}
#define printv(a) {for(auto u:a) cout<<u<<" "; cout<<endl;}
void solve(){
    ll n;
    cin>>n;

    string s;
    cin>>s;

    string temp = "";
    for(auto it: s)
        if(it=='.')continue;
        else temp+=it;
    if(n==1 || temp == "") {
        yy;
        return;
    }
    for(int i = 1; i<n;i++){
        string curr = "";
        curr+=s[i-1];
        curr+=s[i];

        if(i==1 || i==n-1) {
            if(curr=="ps"){
                nn;
                return;
            }
        }

        else if(curr=="sp" || curr=="ps"){
            nn;
            return;
        }
    }
    yy;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t; cin>>t;
    while(t--){

    solve();

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

/* clang-format off */

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>

/* FUNCTIONS */
#define f(a,n) for(long long int i=a;i<n;i++)
#define cf(i,s,e) for(long long int i=s;i<e;i++)
#define rf(e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()

/* PRINTS */
template <class T>
void print_v(vector<T> &v) { cout << "{"; for (auto x : v) cout << x << ","; cout << "\b}"; }

/* UTILS */
#define M 1000000007
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()

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

string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }

string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }

bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }

#define yy cout<<"Yes\n"
#define nn cout<<"No\n"

/* -question intuitions:
- dp --compute next result from the previous result of the sequence
        -- you have a choice at each step and each choice can lead to answer

- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n))
or upper/lower bound of something in a sorted sample namespac
 --- where anwer space is sorted and in fixed range

-heap -- find lowest or largest of a segment -- k is given example kth largest or smallest
if k+smallest -- kth smallest--maxheap
if k+largest --kth largest--  minheap
complexity-- nlog(k)
*/

#define inputv(arr,n) {for(int i=0;i<n;i++)cin>>arr[i];}
#define printv(a) {for(auto u:a) cout<<u<<" "; cout<<endl;}
void solve(){
    ll n;
    cin>>n;

    string s;
    cin>>s;

    if(n==1) {
        yy;
        return;
    }
    if(s[0]=='s') s[0] = '.';
    if(s[n-1] == 'p') s[n-1] = '.';

    char ch = ' ';
    for(auto it: s){
        if(it!='.'){
            if(ch == ' '){
                ch = it;
            }else{
                if(ch != it) {
                    nn;
                    return
                ;
                }
            }
        }
    }

    yy;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t; cin>>t;
    while(t--){

    solve();

    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    while(t --)

    {

        int n;

        string str;

        cin >> n >> str;

        int p = n, s = -1;

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

        {

            if(str[i] == 'p') p = min(p, i);

            if(str[i] == 's') s = max(s, i);

        }

        if(p < s) cout << "NO" << "\n";

    else if(s == 0 || s == -1 || p == n - 1 || p == n) cout << "YES" << "\n";

        else cout << "NO" << "\n";

    }

}

#include<bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    while(t --)

    {

        int n;

        string str;

        cin >> n >> str;

        int p = n, s = -1;

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

        {

            if(str[i] == 'p') p = min(p, i);

            if(str[i] == 's') s = max(s, i);

        }

        if(p < s) cout << "NO" << "\n";

    else if(str[0] == '.' && str[n - 1] == '.' && p != n && s != -1) cout << "NO" << "\n";

        else cout << "YES" << "\n";

    }

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

ifstream fin("input.txt");

ofstream fout("output.txt");

void solve(){

    int n; cin >> n;

    vector<char> v(n);

    for(auto &i: v) cin >> i;

    int imp = 0;

    int posSmx = -1;

    for(int i = 0; i < n; i++) if(v[i] == 's') posSmx = i;

    for(int i = 0; i < n; i++) if(v[i] == 'p' && i < posSmx) imp = 1;

    if(posSmx != -1){

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

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

                if(i != n - 1) imp = 1;

            }

        }

    }

    cout << ((imp == 1) ? "NO": "YES") << '\n';

}

int32_t main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int t = 1;

  cin >> t;

  while(t--) solve();

}

#include <bits/stdc++.h>

using namespace std;

ifstream fin("input.txt");

ofstream fout("output.txt");

void solve(){

    int n; cin >> n;

    vector<char> v(n);

    for(auto &i: v) cin >> i;

    int imp = 0;

    int posSmx = -1;

    for(int i = 0; i < n; i++) if(v[i] == 's') posSmx = i;

    for(int i = 0; i < n; i++) if(v[i] == 'p' && i < posSmx) imp = 1;

    if(posSmx > 0){

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

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

                if(i != n - 1) imp = 1;

            }

        }

    }

    cout << ((imp == 1) ? "NO": "YES") << '\n';

}

int32_t main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int t = 1;

  cin >> t;

  while(t--) solve();

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

#define YES cout << "YES\n";

#define NO cout << "NO\n";

const int N = 1e6 + 5;

signed main() // Road to red

{

    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

        int n,res{1}; cin >> n;

        string s; cin >> s;

        for(auto &x : s){if(x == '.'){x = 's';}}

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

        {

            if(s[i] == 'p' && s[i+1] == 's'){res = 0; break;}

            else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;}

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

#define YES cout << "YES\n";

#define NO cout << "NO\n";

const int N = 1e6 + 5;

signed main() // Road to red

{

    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

        int n,res{1}; cin >> n;

        string s; cin >> s;

        bool p = 0;

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

        {

            if(s[i] == 'p'){p = 1;}

            if(p && s[i] == 's'){res = 0; break;}

        }

        bool ss = 0;

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

        {

            if(i < n-2 && s[i] == 's'){ss = 1;}

            if(ss && s[i] == 'p'  && i < n-1){res = 0; break;}

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

Answer: 2