#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

template <typename T>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;

using pi = pair<int, int>;

using pl = pair<long long, long long>;

using vi = vector<int>;

using vl = vector<long long>;

using vvi = vector<vector<int>>;

using vvl = vector<vector<long long>>;

using vpi = vector<pair<int, int>>;

using vpl = vector<pair<long long, long long>>;

using vvpi = vector<vector<pair<int, int>>>;

using vvpl = vector<vector<pair<long long, long long>>>;

using vb = vector<bool>;

using vs = vector<string>;

using si = set<int>;

using mpii = map<int, int>;

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

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

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

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

#define pb push_back

#define sc static_cast

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

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

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

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

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

#define approx(a) fixed << setprecision(a)

#define ff first

#define ss second

#define INF LONG_LONG_MAX

#define INFF LONG_LONG_MIN

#define inf INT_MAX

#define inff INT_MIN

#define nl '\n'

template <class T> void read(vector<T> &v);

template <class F, class S> void read(pair<F, S> &p);

template <class T, size_t Z> void read(array<T, Z> &a);

template <class T> void read(T &x) {

  cin >> x;

}

template <class R, class... T> void read(R &r, T &...t) {

  read(r);

  read(t...);

};

template <class T> void read(vector<T> &v) {

  for (auto &x : v)

    read(x);

}

template <class F, class S> void read(pair<F, S> &p) {

  read(p.ff, p.ss);

}

template <class T, size_t Z> void read(array<T, Z> &a) {

  for (auto &x : a)

    read(x);

}

template <class F, class S> void pr(const pair<F, S> &x);

template <class T> void pr(const T &x) {

  cout << x;

}

template <class R, class... T> void pr(const R &r, const T &...t) {

  pr(r);

  pr(t...);

}

template <class F, class S> void pr(const pair<F, S> &x) {

  pr("{", x.ff, ", ", x.ss, "}");

}

void ps() {

  pr("\n");

}

template <class T> void ps(const T &x) {

  pr(x);

  ps();

}

template <class T> void ps(vector<T> &v) {

  for (auto &x : v)

    pr(x, ' ');

  ps();

}

template <class T, size_t Z> void ps(const array<T, Z> &a) {

  for (auto &x : a)

    pr(x, ' ');

  ps();

}

template <class F, class S> void ps(const pair<F, S> &x) {

  pr(x.ff, ' ', x.ss);

  ps();

}

template <class R, class... T> void ps(const R &r, const T &...t) {

  pr(r, ' ');

  ps(t...);

}

#define definp()                                                               \

  int n;                                                                       \

  read(n);                                                                     \

  vl a(n);                                                                     \

  read(a);

#define int long long

// int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1};

#define MOD (long long)(1e9 + 7)

void exec_once() {

}

bool tc = 1;

void solve(int tn [[maybe_unused]]) {

    int n;read(n);

    string s;

    read(s);

    int cur = -1;

    bool p = 0;

    fori(i,0,n){

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

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

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

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

            if(i!=n-1) return ps("NO");

        }

    }

    ps("YES");

}

int32_t main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  exec_once();

  int t = 1;

  if (tc)

    cin >> t;

  fore(tn, 1, t) solve(tn);

  return 0;

}

#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

template <typename T>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;

using pi = pair<int, int>;

using pl = pair<long long, long long>;

using vi = vector<int>;

using vl = vector<long long>;

using vvi = vector<vector<int>>;

using vvl = vector<vector<long long>>;

using vpi = vector<pair<int, int>>;

using vpl = vector<pair<long long, long long>>;

using vvpi = vector<vector<pair<int, int>>>;

using vvpl = vector<vector<pair<long long, long long>>>;

using vb = vector<bool>;

using vs = vector<string>;

using si = set<int>;

using mpii = map<int, int>;

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

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

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

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

#define pb push_back

#define sc static_cast

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

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

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

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

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

#define approx(a) fixed << setprecision(a)

#define ff first

#define ss second

#define INF LONG_LONG_MAX

#define INFF LONG_LONG_MIN

#define inf INT_MAX

#define inff INT_MIN

#define nl '\n'

template <class T> void read(vector<T> &v);

template <class F, class S> void read(pair<F, S> &p);

template <class T, size_t Z> void read(array<T, Z> &a);

template <class T> void read(T &x) {

  cin >> x;

}

template <class R, class... T> void read(R &r, T &...t) {

  read(r);

  read(t...);

};

template <class T> void read(vector<T> &v) {

  for (auto &x : v)

    read(x);

}

template <class F, class S> void read(pair<F, S> &p) {

  read(p.ff, p.ss);

}

template <class T, size_t Z> void read(array<T, Z> &a) {

  for (auto &x : a)

    read(x);

}

template <class F, class S> void pr(const pair<F, S> &x);

template <class T> void pr(const T &x) {

  cout << x;

}

template <class R, class... T> void pr(const R &r, const T &...t) {

  pr(r);

  pr(t...);

}

template <class F, class S> void pr(const pair<F, S> &x) {

  pr("{", x.ff, ", ", x.ss, "}");

}

void ps() {

  pr("\n");

}

template <class T> void ps(const T &x) {

  pr(x);

  ps();

}

template <class T> void ps(vector<T> &v) {

  for (auto &x : v)

    pr(x, ' ');

  ps();

}

template <class T, size_t Z> void ps(const array<T, Z> &a) {

  for (auto &x : a)

    pr(x, ' ');

  ps();

}

template <class F, class S> void ps(const pair<F, S> &x) {

  pr(x.ff, ' ', x.ss);

  ps();

}

template <class R, class... T> void ps(const R &r, const T &...t) {

  pr(r, ' ');

  ps(t...);

}

#define definp()                                                               \

  int n;                                                                       \

  read(n);                                                                     \

  vl a(n);                                                                     \

  read(a);

#define int long long

// int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1};

#define MOD (long long)(1e9 + 7)

void exec_once() {

}

bool tc = 1;

void solve(int tn [[maybe_unused]]) {

    int n;read(n);

    string s;

    read(s);

    int cur = -1;

    bool p = 0;

    int cnt1 = 0, cnt2=0;

    fori(i,0,n){

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

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

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

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

    }

    if(cnt1==1 && (s[0] == 's' || s[n-1]=='s')) return ps("YES");

    if(cnt2==1 && (s[0] == 'p' || s[n-1]=='p')) return ps("YES");

    if(cnt1==0 || cnt2 == 0) return ps("YES");

    ps("NO");

}

int32_t main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  exec_once();

  int t = 1;

  if (tc)

    cin >> t;

  fore(tn, 1, t) solve(tn);

  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 = 0, s = 0;

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

        {

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

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

        }

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

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

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

    }

}

Answer: 1


a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  if j[0] == "s":

    j[0] = "."

  if j[-1] == "p":

    j[-1] = "."

  l = 0

  if "s" in j and "p" in j:

    l = -1

  print("Yes") if l == 0 else print("No")

a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  k = 0

  for z in range(b):

    if c[z] == "p" and k == 0:

      k = 1

    elif k == 1 and c[z] == "s":

      k = -1

      break

  if k != -1:

    n = c[0]

    for y in range(1,b):

      if c[y-1] != c[y]:

        n += c[y]

    if ".sp." in n:

      print("No")

    else:

      s = 0

      p = 0

      l = 0

      for y in range(b):

        if c[y] == ".":

          if (s > 1 and p > 0) or (s > 0 and p > 1):

            l = -1

            break

          s = 0

          p = 0

        else:

          if c[y] == "s":

            s += 1

          else:

            p += 1

      s = 0

      p = 0

      for y in range(b-1,-1,-1):

        if c[y] == ".":

          if (s > 1 and p > 0) or (s > 0 and p > 1):

            l = -1

            break

          s = 0

          p = 0

        else:

          if c[y] == "s":

            s += 1

          else:

            p += 1

      if l == -1:

        print("No")

      else:

        print("Yes")

  elif k == -1:

    print("No")

Answer: 1


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    char last = s[0];

    bool can = true;

    if (last == '.') {

        bool pf = false, sf = false;

        for (int i = 0; i < l1; i++) {  // Start from i = 0 to consider all characters

            if (s[i] == 'p') pf = true;

            if (s[i] == 's') sf = true;

        }

        if (sf && pf) can = false;

    } else {

        bool pf = false, sf = false;

        int countp = 0, counts = 0;

        for (auto x : s) {

            if (x == 'p') {

                pf = true;

                countp++;

            }

            if (x == 's') {

                sf = true;

                counts++;

                if (pf) {

                    can = false;

                    break;

                }

            }

        }

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

            can = false;

        }

    }

    if (can) {

        cout << "yes" << endl;

    } else {

        cout << "no" << endl;

    }

}

int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    bool can = true;

    bool pf=false;

    bool sf=false;

	int s_found=-1;

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

		char x=s[i];

		if(x=='s'){

			sf=true;

			s_found=i;

			if(pf){

				can=false;

				break;

				}

			}

		if(x=='p'){

			pf=true;

			if(sf){

				if(s_found!=0 && i!=l1-1){can=false;break;}

				}

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

}

int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}

Answer: 2


#include <bits/stdc++.h>

#define ll long long

using namespace std;

bool check(string s)

{

    bool did_come = false;

    ll l = s.length();

    ll index_last_p = l;

    for (ll i = 0; i < l - 1; i++)

    {

        if (s[i] == 's' && i != 0)

        {

            did_come = true;

        }

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

        {

            index_last_p = i;

            if (did_come)

            {

                return false;

            }

        }

    }

    for (ll i = index_last_p + 1; i < l; i++)

    {

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

            return false;

    }

    return true;

}

void solve()

{

    ll n;

    cin >> n;

    string s;

    cin >> s;

    if (check(s))

        cout << "YES" << endl;

    else

        cout << "NO" << endl;

}

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>

#define ll long long

using namespace std;

bool pisleft(string s)

{

    ll l = s.length();

    bool start = false;

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

    {

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

        {

            start = true;

        }

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

        {

            return true;

        }

    }

    return false;

}

void solve()

{

    ll n;

    cin >> n;

    string s;

    cin >> s;

    if (pisleft(s))

    {

        cout << "NO" << endl;

        return;

    }

    set<ll> perm;

    vector<ll> per_ct;

    ll ct_p = 0, ct_s = 0;

    for (ll i = 1; i < s.length() - 1; i++)

    {

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

        {

            ct_p++;

            per_ct.push_back(i + 1);

            perm.insert(i + 1);

        }

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

        {

            ct_s++;

            per_ct.push_back(s.length() - i);

            perm.insert(s.length() - i);

        }

    }

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

        ct_p++;

    if (s[s.length() - 1] == 's')

        ct_s++;

    if (s[0] == 'p' && ct_s != 0)

    {

        cout << "NO" << endl;

        return;

    }

    if (s[s.length() - 1] == 's' && ct_p != 0)

    {

        cout << "NO" << endl;

        return;

    }

    if (per_ct.size() != perm.size())

    {

        cout << "NO" << endl;

    }

    else

    {

        cout << "YES" << endl;

    }

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}

Answer: 1


#ifdef _MSC_VER

#  include <intrin.h>

#  define __builtin_popcount __popcnt

#endif

#include <bits/stdc++.h>

#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef long double ld;

#define MAX 3030

#define MAXS 20

#define BMAX 35

#define MOD 100'000'000

#define TC 1

#define ln '\n'

#define bb ' '

int A[MAX];

void solve() {

	int N;

	cin >> N;

	string s;

	cin >> s;

	int pc, sc;

	pc = sc = 0;

	int i;

	for (i = 0; i < N; i++) {

		if (s[i] == 'p' && i < N - 1) pc++;

		if (s[i] == 's' && i) sc++;

	}

	if (!pc || !sc) {

		cout << "YES" << ln;

		return;

	}

	else cout << "NO" << ln;

}

signed main() {

	ios::sync_with_stdio(false), cin.tie(0);

	int T = 1;

	if (TC) cin >> T;

	while (T--) solve();

}

#ifdef _MSC_VER

#  include <intrin.h>

#  define __builtin_popcount __popcnt

#endif

#include <bits/stdc++.h>

#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef long double ld;

#define MAX 3030

#define MAXS 20

#define BMAX 35

#define MOD 100'000'000

#define TC 1

#define ln '\n'

#define bb ' '

int A[MAX];

void solve() {

	int N;

	cin >> N;

	string s;

	cin >> s;

	int pc, sc;

	pc = sc = 0;

	for (auto c : s) {

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

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

	}

	if (pc > 1 && sc > 1) {

		cout << "NO" << ln;

		return;

	}

	if (!pc || !sc) {

		cout << "YES" << ln;

		return;

	}

	if (pc == 1) {

		if (s[N - 1] == 'p') cout << "YES" << ln;

		else cout << "NO" << ln;

	}

	else {

		if (s[0] == 's') cout << "YES" << ln;

		else cout << "NO" << ln;

	}

}

signed main() {

	ios::sync_with_stdio(false), cin.tie(0);

	int T = 1;

	if (TC) cin >> T;

	while (T--) solve();

}

Answer: 1


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

const int M=1e9+7;

// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }

void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0;

    rep(i,0,n){

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

        else if(prevp){

            cout<<"NO\n";

            return;

        }

    }

    rep(i,1,n-2){

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

            cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}

int32_t main()

{

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    cin >> t;

    while(t--)

    {

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

        Solve();

    }

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

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

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

    return 0;

}

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

const int M=1e9+7;

// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }

void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0,prevs=0;

    rep(i,0,n){

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

            if(prevp==0) prevp=i+1;

        }

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

            prevs=i+1;

            if(prevp){

                cout<<"NO\n";

                return;

            }

        }

    }

    if(!prevs || !prevp) cout<<"YES\n";

    else if(prevs==1 || prevp==n) cout<<"YES\n";

    else cout<<"NO\n";

}

int32_t main()

{

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    cin >> t;

    while(t--)

    {

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

        Solve();

    }

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

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

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

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define int long long

const ll N=1e9+7;

void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    int cs=count(s.begin(),s.end(),'s');

    int cp=count(s.begin(),s.end(),'p');

    int cd=count(s.begin(),s.end(),'.');

    if(cs==0||cp==0) {cout<<"YES\n"; return;}

    int i=n-1;

    bool found=true;

    while(i>=0){

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

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

            found=false;

            break;

        }

        else break;

    }

    if(!found) {cout<<"NO\n"; return;}

    i=0;

    while(i<n){

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

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

            found=false;

            break;

        }

        else break;

    }

    if(!found) {cout<<"NO\n"; return;}

    if(s[0]=='.' && s[n-1]=='.') {cout<<"NO\n"; return;}

    cout<<"YES\n";

    return;

}

int32_t main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    ll t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define int long long

const ll N=1e9+7;

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 cs=count(s.begin(),s.end(),'s');

    int cp=count(s.begin(),s.end(),'p');

    int cd=count(s.begin(),s.end(),'.');

    if(cs==0||cp==0) {cout<<"YES\n"; return;}

    cout<<"NO\n";

    return;

}

int32_t main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    ll t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	int l1=s.length();

	char last=s[0];

	bool can=true;

	if(last=='.'){

		bool pf=false;

		bool sf=false;

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

			if(s[i]=='p')pf=true;

			if(s[i]=='s')sf=true;

			}

		if(sf && pf)can=false;

		}

	else{

		bool pf=false;

		bool sf=false;

		int countp=0;

		int counts=0;

		for(auto x:s){

			if(x=='p'){pf=true;countp++;}

			if(x=='s'){

				sf=true;

				counts++;

				if(pf){can=false;break;}

				}

			}

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

			can=false;

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

	}

int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}

Answer: 2


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

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

    return;
}

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

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

    return 0;
}

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

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

    return;
}

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

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

    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>

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

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

}

template <typename T_container, typename T = typename enable_if<

                                    !is_same<T_container, string>::value,

                                    typename T_container::value_type>::type>

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

    os << '{';

    string sep;

    for (const T &x : v)

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

    return os << '}';

}

void dbg_out() { cerr << endl; }

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

    cerr << ' ' << H;

    dbg_out(T...);

}

#ifdef LOCAL

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

#else

#define debug(...)

#endif

int main() {

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

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        int N;

        cin >> N;

        string S;

        cin >> S;

        bool ok = true;

        int p = 0, s = 0;

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

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

                s++;

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

                p++;

                int j = i + 1;

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

                    j++;

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

                    ok = false;

                j = i;

            }

        }

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

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

        } else {

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

        }

    }

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

    auto elapsed =

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

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

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>

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

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

}

template <typename T_container, typename T = typename enable_if<

                                    !is_same<T_container, string>::value,

                                    typename T_container::value_type>::type>

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

    os << '{';

    string sep;

    for (const T &x : v)

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

    return os << '}';

}

void dbg_out() { cerr << endl; }

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

    cerr << ' ' << H;

    dbg_out(T...);

}

#ifdef LOCAL

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

#else

#define debug(...)

#endif

int main() {

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

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        int N;

        cin >> N;

        string S;

        cin >> S;

        bool ok = true;

        int p = 0, s = 0;

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

            S[0] = '.';

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

            S[N - 1] = '.';

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

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

                s++;

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

                p++;

                int j = i + 1;

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

                    j++;

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

                    ok = false;

                j = i;

            }

        }

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

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

        } else {

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

        }

    }

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

    auto elapsed =

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

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

    return 0;

}

Answer: 2


#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[n-1]=='p')

            cout<<"YES\n";

        else

        {

            bool b=true;

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

            {

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

                {

                    b=false;

                    break;

                }

            }

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

        }

    }

    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;

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

            s[0]='.';

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

            s[n-1]='.';

        bool f_s=false,f_p=false;

        for(char x:s)

        {

            if(x=='p')

                f_p=true;

            else if(x=='s')

                f_s=true;

        }

        cout<<((f_p && f_s)? "NO\n":"YES\n");

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int T,n;

string s;

int main() {

	ios::sync_with_stdio(0);

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

	cin>>T;

    while(T--){

	    cin>>n>>s;

	    bool f=0;

	    s=' '+s;

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

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

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

	                f=1;

	                break;

	            }

	        }

	        if(f) break;

	    }

	    if(f) cout<<"NO"<<"\n";

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

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int T,n;

string s;

int main() {

	ios::sync_with_stdio(0);

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

	cin>>T;

    while(T--){

	    cin>>n>>s;

	    bool f=0;

	    s=' '+s;

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

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

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

	                f=1;

	                break;

	            }

	        }

	        if(f) break;

	    }

	    if(f) cout<<"NO"<<"\n";

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

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

// Short forms

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

#define lli                 long long int

#define ll                  long long

#define ull                 unsigned long long

#define nl                  '\n'

#define ff                  first

#define ss                  second

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

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

#define pb                  push_back

#define mp                  make_pair

// Loops

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

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

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

#define llp(i,a,b)          for (ll i= (ll)(a); i < (ll)(ll)(b); ++i)

// STLs

#define pii                 pair<int, int>

#define vi                  vector<int>

#define vll                 vector<ll>

#define vvi                 vector<vector<int>>

#define vvl                 vector<vector<ll>>

// Outputs

#define yes                 cout<<"YES"<<nl

#define no                  cout<<"NO"<<nl

#define dbg(x)              cerr << #x <<" " << x << endl;

// Constants

#define PI                  3.141592653589793238

#define INF                 LONG_LONG_MAX

#define MOD                 1e9+7

// Faster Input Output

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));

// Maths

ll fact(ll n)          { if(n==0) return 1; ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; }

ll nPr(ll n, ll r)     { return fact(n) / fact(n - r); }

ll nCr(ll n, ll r)     { return fact(n) / (fact(r) * fact(n - r)); }

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

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

ll mypow(ll a, ll b)   { ll ans = 1; while(b){ if (b&1) ans = (ans*a) ; b /= 2; a = (a*a); } return ans; }

bool isPrime(ll n)     { if(n <= 1) return false; for(ll i = 2; i <= sqrt(n); i++) if(n % i == 0) return false; return true; }

int main() {

       int t;

       cin>>t;

       while(t--)

       {

              int n;

              cin>>n;

              string str;

              cin>>str;

              bool ans=true;

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

                     if(str[i]=='s' && str[i+1]=='p') ans=false;

                     if(str[i]=='p' && str[i+1]=='s') ans=false;

              }

              int p=0;

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

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

                    if(str[i]=='s' && p>0) ans=false;

              }

            if(ans) yes;

            else no;

       }

       return 0;

}

#include <bits/stdc++.h>

using namespace std;

// Short forms

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

#define lli                 long long int

#define ll                  long long

#define ull                 unsigned long long

#define nl                  '\n'

#define ff                  first

#define ss                  second

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

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

#define pb                  push_back

#define mp                  make_pair

// Loops

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

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

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

#define llp(i,a,b)          for (ll i= (ll)(a); i < (ll)(ll)(b); ++i)

// STLs

#define pii                 pair<int, int>

#define vi                  vector<int>

#define vll                 vector<ll>

#define vvi                 vector<vector<int>>

#define vvl                 vector<vector<ll>>

// Outputs

#define yes                 cout<<"YES"<<nl

#define no                  cout<<"NO"<<nl

#define dbg(x)              cerr << #x <<" " << x << endl;

// Constants

#define PI                  3.141592653589793238

#define INF                 LONG_LONG_MAX

#define MOD                 1e9+7

// Faster Input Output

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));

// Maths

ll fact(ll n)          { if(n==0) return 1; ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; }

ll nPr(ll n, ll r)     { return fact(n) / fact(n - r); }

ll nCr(ll n, ll r)     { return fact(n) / (fact(r) * fact(n - r)); }

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

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

ll mypow(ll a, ll b)   { ll ans = 1; while(b){ if (b&1) ans = (ans*a) ; b /= 2; a = (a*a); } return ans; }

bool isPrime(ll n)     { if(n <= 1) return false; for(ll i = 2; i <= sqrt(n); i++) if(n % i == 0) return false; return true; }

int main() {

       int t;

       cin>>t;

       while(t--)

       {

              int n;

              cin>>n;

              string str;

              cin>>str;

              bool ans=true;

              int s=0;

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

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

                    if(str[i]=='p' && s) ans=false;

              }

              int p=0;

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

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

                    if(str[i]=='s' && p>0) ans=false;

              }

            if(ans) yes;

            else no;

       }

       return 0;

}

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)if(c!='.')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;

#include<cctype>

typedef long long int ll;

typedef vector<ll> vll;

typedef vector<vector<ll>> vvll;

typedef vector<pair<ll, ll>> vpll;

typedef map<ll, ll> mll;

typedef map<char, ll> mcl;

typedef unordered_map<ll, ll> umll;

typedef unordered_map<char, ll> umcl;

typedef set<ll> sll;

typedef pair<ll, ll> pll;

typedef queue<ll> qll;

typedef deque<ll> dqll;

typedef priority_queue<ll> pqll;

#define Jay ios_base::sync_with_stdio(false);

#define Shree cin.tie(NULL);

#define Ram cout.tie(NULL);

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

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

#define nope cout<<-1<<"\n";

#define ZZ cout<<0<<"\n";

#define cspace cout<<"\n";

#define endl '\n'

#define inarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];

#define outarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

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

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

#define sz(v) (ll)(v.size())

#define fl(i, n) for(ll i=0; i<n; i++)

#define f(i, x, n) for(ll i=x; i<n; i++)

#define rf(i, n) for(ll i=n-1; i>=0; i--)

#define fr(e, x) for(auto &e:x)

#define RR return;

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

#define pf push_front

const ll MOD=1e9+7;

const ll N=1e7+7;

const ll PI=3.141592653589793238462643;

bool isPrime(ll n){if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5; i*i<=n; i+=6) {if(n%i==0 || n%(i+2)==0) return false;} return true;}

bool isPowerOfTwo(ll n){if(n==0)return false;return (ceil(log2(n))==floor(log2(n)));}

bool isPerfectSquare(ll x){if(x>=0){ll sr=sqrt(x);return (sr*sr==x);}}

bool isInteger(double n){return floor(n)==n;}

ll findMEX(const set<ll>&s){ll mex=0;while(s.find(mex)!=s.end()){mex++;}return mex;}

void solve()

{

    ll n;

    cin>>n;

    string s;

    cin>>s;

    ll p=count(all(s), 'p'), ss=count(all(s), 's'), d = count(all(s), '.');

    if(p+d==n || ss+d==n) yes

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

    else no

}

int main()

{

    Jay Shree Ram

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

#include<cctype>

typedef long long int ll;

typedef vector<ll> vll;

typedef vector<vector<ll>> vvll;

typedef vector<pair<ll, ll>> vpll;

typedef map<ll, ll> mll;

typedef map<char, ll> mcl;

typedef unordered_map<ll, ll> umll;

typedef unordered_map<char, ll> umcl;

typedef set<ll> sll;

typedef pair<ll, ll> pll;

typedef queue<ll> qll;

typedef deque<ll> dqll;

typedef priority_queue<ll> pqll;

#define Jay ios_base::sync_with_stdio(false);

#define Shree cin.tie(NULL);

#define Ram cout.tie(NULL);

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

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

#define nope cout<<-1<<"\n";

#define ZZ cout<<0<<"\n";

#define cspace cout<<"\n";

#define endl '\n'

#define inarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];

#define outarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

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

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

#define sz(v) (ll)(v.size())

#define fl(i, n) for(ll i=0; i<n; i++)

#define f(i, x, n) for(ll i=x; i<n; i++)

#define rf(i, n) for(ll i=n-1; i>=0; i--)

#define fr(e, x) for(auto &e:x)

#define RR return;

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

#define pf push_front

const ll MOD=1e9+7;

const ll N=1e7+7;

const ll PI=3.141592653589793238462643;

bool isPrime(ll n){if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5; i*i<=n; i+=6) {if(n%i==0 || n%(i+2)==0) return false;} return true;}

bool isPowerOfTwo(ll n){if(n==0)return false;return (ceil(log2(n))==floor(log2(n)));}

bool isPerfectSquare(ll x){if(x>=0){ll sr=sqrt(x);return (sr*sr==x);}}

bool isInteger(double n){return floor(n)==n;}

ll findMEX(const set<ll>&s){ll mex=0;while(s.find(mex)!=s.end()){mex++;}return mex;}

void solve()

{

    ll n;

    cin>>n;

    string s;

    cin>>s;

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

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

    if(count(all(s), 'p') && count(all(s), 's')) no

    else yes

}

int main()

{

    Jay Shree Ram

    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;

        cin >> n;

        string s;

        cin >> s;

        int lasts = -1, lastp = -1;

        bool ans = true;

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

        {

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

                lasts = i;

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

                lastp = i;

            if (lasts != -1 && lastp != -1)

            {

                if (lasts > lastp)

                {

                    ans = false;

                    break;

                }

                else if (lastp > lasts && lastp != n - 1)

                {

                    ans = false;

                    break;

                }

            }

        }

        if(ans==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;

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

            s[0] = '.';

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

            s[n - 1] = '.';

        bool fp=0, fs=0;

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

        {

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

            {

                fs=1;

            }

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

            {

                fp=1;

            }

        }

        if (fs==1 && fp==1)

            cout << "NO" << endl;

        else

            cout << "YES" << endl;

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int,int>;

signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        n=s.size();

        string ans = "YES";

        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if(countp>0 and (s[i]=='s'))

                ans = "NO";

            if(counts>1 && countp>1)

                ans = "NO";

        }

        if(s[0] == '.' && s[n-1]=='.' && counts>0 && countp>0)

            ans = "NO";

        cout<<ans<<endl;

    }

}

/*

ppss

1. s cannot come after p

.s.s.p

612345

s.s.p

54321

ssp

132

s..s..

654321

sp..p

12345

spp..

12345

ppp..

..pp..

123456

..sp..

654321

ssssp..

12345

* we can only have either one 's' or one 'p'

* if string can starts with '.' or 's'

* string cannot end with '.' if it has p in it

* if string has s and p then '.' can't come after 'p'

spp

123

ssspp

54321

*/

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int,int>;

signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";

        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if((countp>0 and (s[i]=='s'))||(counts>1 && countp>1))

                ans = "NO";

        }

        if(((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')||

        ((counts>1 && countp>0) && s[n-1]=='.')||

        ((countp>1 && counts>0) && s[0]=='.'))

            ans = "NO";

        cout<<ans<<endl;

    }

}

Answer: 2


def solve():

    n=int(input())

    s=input()

    cnt_s=0

    cnt_p=0

    cnt=0

    bol=False

    b=False

    for i in range(n):

        if s[i]=='s':

            cnt_s+=1

            if bol:

                b=True

        elif s[i]=='p':

            bol=True

            cnt_p+=1

        else:

            cnt+=1

    if b:

        print("NO")

        return

    if cnt_s==n or cnt_p==n or cnt==n or cnt+cnt_p==n or cnt+cnt_p==n:

        print("YES")

        return

    if s[n-1]=='.' and s[0]=='.':

        print("NO")

        return

    if cnt_p==1 and cnt_s==1:

        print("YES")

        return

    elif cnt_p==1:

        if s[n-1]=='p':

            print("YES")

        else:

            print("NO")

    elif cnt_s==1:

        if s[0]=='s':

            print("YES")

        else:

            print("NO")

    else:

        print("NO")

t=int(input())

for _ in range(t):

    solve()

def solve():

    n=int(input())

    s=input()

    cnt_s=0

    cnt_p=0

    cnt=0

    bol=False

    b=False

    for i in range(n):

        if s[i]=='s':

            cnt_s+=1

            if bol:

                b=True

        elif s[i]=='p':

            bol=True

            cnt_p+=1

        else:

            cnt+=1

    if b:

        print("NO")

        return

    if cnt_s==n or cnt_p==n or cnt==n or cnt+cnt_p==n or cnt+cnt_s==n:

        print("YES")

        return

    if s[n-1]=='.' and s[0]=='.':

        print("NO")

        return

    if cnt_p==1 and cnt_s==1:

        print("YES")

        return

    elif cnt_p==1:

        if s[n-1]=='p':

            print("YES")

        else:

            print("NO")

    elif cnt_s==1:

        if s[0]=='s':

            print("YES")

        else:

            print("NO")

    else:

        print("NO")

t=int(input())

for _ in range(t):

    solve()

Answer: 2


#include<bits/stdc++.h>

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=505;

char s[N];int n;

void work(){

    cin>>n;

    cin>>(s+1);

    int fl=0;int cs=0,cp=0;

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

        if(s[i]=='p'){if(fl==0);cp++;}

        if(s[i]=='s'){if(fl==1)fl++;cs++;}

    }

    if(fl==2){

        cout<<"NO"<<endl;

        return;

    }

    if(cs==0||cp==0||(cp==1&&s[n]=='p')||(cs==1&&s[1]=='s'))

        cout<<"YES"<<endl;

    else cout<<"NO"<<endl;

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}

#include<bits/stdc++.h>

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=505;

char s[N];int n;

void work(){

    cin>>n;

    cin>>(s+1);

    int fl=0;int cs=0,cp=0;

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

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

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

            if(fl==1)fl++;

            cs++;

        }

    }

    if(fl==2){

        cout<<"NO"<<endl;

        return;

    }

    if(cs==0||cp==0||(cp==1&&s[n]=='p')||(cs==1&&s[1]=='s')){

        cout<<"YES"<<endl;

    }else cout<<"NO"<<endl;

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}

Answer: 1


#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;

}

#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[i]=='.'){

            continue;

        }

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

            cout<<"NO\n";

            return;

        }

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

            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: 1


#include<bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

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

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

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

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

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

            if(i>0 && i<n-2 && s[i]=='s'){

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

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

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

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

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

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

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

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

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

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

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

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

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

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}

Answer: 2


#include<bits/stdc++.h>

#define ll long long

#define PII pair<int,int>

using namespace std;

void 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'){

            cout<<"NO\n";

            return;

        }

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

            cout<<"NO\n";

            return;

        }

    }

    cout<<"YES\n";

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

#include<bits/stdc++.h>

#define ll long long

#define PII pair<int,int>

using namespace std;

void solve()

{

    int n;

    cin>>n;

    string s;

    cin>>s;

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

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

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

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

                    cout<<"NO\n";

                    return;

                }

            }

        }

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

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

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

                    cout<<"NO\n";

                    return;

                }

            }

        }

    }

    cout<<"YES\n";

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

Answer: 2


#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;
      map<char,int>m ;
      int plast = -1;
      int sfirst = -1 ;
       for(int i = 0 ; i < n ; i++){
            m[s[i]]++;
            if(s[i] == 's' && sfirst == -1){
                sfirst = i ;
            }
            if(s[i] == 'p'){
                plast = i ;
            }
       }
       if(m['.'] == n || m['p'] == n || m['s'] == n){
        YES;
        return;
       }
       if(sfirst == 0 || plast == n-1){
        YES;
        return;
       }
       NO;

      }

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

    }

    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define all(x,a) x, x+a

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

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

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

#define ld long double

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}

bool s(ll a, ll b)

{

    return a>b;

}

void fun()

{

    lc(n);

    string a;

    cin >> a;

    f(i,0,n-1)

    {

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

        {

            f(j,i+1,n)

            {

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

                {

                    cout << "NO\n";

                    return;

                }

            }

        }

    }

    f(i,1,n-2)

    {

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

        {

            f(j,i+1,n-1)

            {

                if ( a[j]=='p' )

                {

                    cout << "NO\n";

                    return;

                }

            }

        }

    }

    cout << "YES\n";

    return;

}

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define all(x,a) x, x+a

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

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

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

#define ld long double

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}

bool s(ll a, ll b)

{

    return a>b;

}

void fun()

{

    lc(n);

    string a;

    cin >> a;

    f(i,0,n-1)

    {

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

        {

            f(j,i+1,n)

            {

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

                {

                    cout << "NO\n";

                    return;

                }

            }

        }

    }

    f(i,1,n-2)

    {

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

        {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}

Answer: 1


// DO NOT COPY AND PASTE CODE

// Be very sure of what you are doing before submitting

// Solve 1000+ problems of rating range 1300-1800 (400+ of 1300-1500 and 600+ for 1600-1800) before 31st December.

// Analyze the ratings of problems you are solving here https://cfviz.netlify.app/

// Dont look at test cases

#include<bits/stdc++.h>

using namespace    std;

#include <iostream>

#include <algorithm>

#include<numeric>

// typedef long ;

// #include <iostream>

// #include <cstdlib>

// #include <ctime>

// #include <thread>

// #include <chrono>

// #include <iostream>

// // Library effective with Windows

// #include <windows.h>

// // Library effective with Linux

// #include <unistd.h>

// const ll INF = 1e9+7;

#define ll                  long long

#define ull                 unsigned long long

// #define MOD                 1000000007 // 998244353

#define vi                  vector<int>

#define vb                  vector<bool>

#define vvi                 vector<vector<int> >

#define vll                 vector<long long>

#define pb                  push_back

#define eb                  emplace_back

#define mp(a, b)            make_pair(a, b)

#define pii                 pair<int, int>

#define vpii                vector<pair<int, int> >

#define mk(arr, n, type)    type *arr = new type[n];

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

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

#define FORALL(i, a)        for (auto& (i) : (a))

#define printall(a)         for (auto& (i) : (a)) cout << i << ' '

#define print(a)            cout << a << '\n'

#define rsort(a)            sort((a).rbegin(), (a).rend())

#define w(x)                int x; cin >> x; while(x--)

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

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

#define pqmx                priority_queue<int>

#define pqmn                priority_queue<int, vector<int>, greater<int> >

#define max3(a, b, c)       max((a), max((b), (c)))

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

#define mx_all(c)           *max_element((c).begin(), (c).end())

#define mn_all(c)           *min_element((c).begin(), (c).end())

#define lwr_b(c, a)         lower_bound((c).begin(), (c).end(), (a)) - ((c).begin())

#define upr_b(c, a)         upper_bound((c).begin(), (c).end(), (a)) - ((c).begin())

#define FIO                 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

// #define MAXN 100010

// int x[MAXN],y[MAXN],a[MAXN],degree[MAXN];

// const int MAX = 100'007;

const long long int MOD = 1000000007;

bool isprime(long long int N){

    if(N<2 || (!(N&1) && N!=2))

        return 0;

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

        if(!(N%i))

            return false;

    }

    return true;

}

long long int factorial(long long int n) {

    if (n <= 1) {

        return 1;

    } else {

        return (n * factorial(n - 1));

    }

}

void upd(int &a, int b) {

    a = (a * 1LL * b) % MOD;

}

// #define sz(a) int((a).size())

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

long long int gcd(long long int a, long long int b) {

    while (b != 0) {

        long long int temp = b;

        b = a % b;  // Get the remainder

        a = temp;   // Update a to the previous value of b

    }

    return a;

}

long long int powerMod(long long int base, long long int exponent, long long int mod) {

    long long int result = 1;

    base = base % mod;

    while (exponent > 0) {

        if (exponent % 2 == 1) {

            result = (result * base) % mod;

        }

        exponent = exponent >> 1;

        base = (base * base) % mod;

    }

    return result;

}

double roundToSixDecimalPlaces(double value) {

    return std::round(value * 1e6) / 1e6;

}

vector<ll> parent,component;

ll find(ll x){

    if(x==parent[x]) return x;

    return parent[x]=find(parent[x]);

}

void unite(ll a, ll b){

    a=find(a);

    b=find(b);

    if(a!=b){

        if(component[a]<component[b]){

            swap(a,b);

        }

        parent[b]=a;

        component[a]+=component[b];

    }

}

ull ull_abs(ull a, ull b) {

    return (a > b) ? (a - b) : (b - a);

}

const int MAXN = 200200;

void dfsRecursive(int vertex, vector<bool>& visited, const vector<vector<int>>& adjList) {

    visited[vertex] = true;

    for (int neighbor : adjList[vertex]) {

        if (!visited[neighbor]) {

            dfsRecursive(neighbor, visited, adjList);

        }

    }

}

long long power(long long a, long long b)

{

    long long res = 1;

    while (b > 0) {

        if (b%2==1) {

            res = (res * a);

        }

        a*=a;

        b >>= 1;

    }

    return res;

}

long long lcm(int a, int b) {

    return (1LL * a * b) / __gcd(a, b);

}

int pb, pc, ps;

int nb, nc, ns;

int lb, lc, ls;

ll fb, fc, fs;

ll price(ll x)

{

    fb = max(x*lb - nb, (ll)0);

    fc = max(x*lc - nc, (ll)0);

    fs = max(x*ls - ns, (ll)0);

    ll p = fb*pb + fc*pc + fs*ps;

    return p;

}

void solve() {

    int n;

    cin>>n;

    string s;

    cin>>s;

    if(n==1){

        cout<<"YES";

    }

    else{

        bool done=false;

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

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

                // done=true;

                // break;

                if((i+1)%2==0){

                    done=true;

                    break;

                }

            }

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

                if((i+1)%2==1){

                    done=true;

                    break;

                }

            }

        }

        if(done){

            cout<<"NO";

        }

        else{

            cout<<"YES";

        }

    }

    cout<<endl;

}

int main(){

   int t;

   cin>>t;

   while(t--){

    solve();

   }

   return 0;

}

;

// DO NOT COPY AND PASTE CODE

// Be very sure of what you are doing before submitting

// Solve 1000+ problems of rating range 1300-1800 (400+ of 1300-1500 and 600+ for 1600-1800) before 31st December.

// Analyze the ratings of problems you are solving here https://cfviz.netlify.app/

// Dont look at test cases

#include<bits/stdc++.h>

using namespace    std;

#include <iostream>

#include <algorithm>

#include<numeric>

// typedef long ;

// #include <iostream>

// #include <cstdlib>

// #include <ctime>

// #include <thread>

// #include <chrono>

// #include <iostream>

// // Library effective with Windows

// #include <windows.h>

// // Library effective with Linux

// #include <unistd.h>

// const ll INF = 1e9+7;

#define ll                  long long

#define ull                 unsigned long long

// #define MOD                 1000000007 // 998244353

#define vi                  vector<int>

#define vb                  vector<bool>

#define vvi                 vector<vector<int> >

#define vll                 vector<long long>

#define pb                  push_back

#define eb                  emplace_back

#define mp(a, b)            make_pair(a, b)

#define pii                 pair<int, int>

#define vpii                vector<pair<int, int> >

#define mk(arr, n, type)    type *arr = new type[n];

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

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

#define FORALL(i, a)        for (auto& (i) : (a))

#define printall(a)         for (auto& (i) : (a)) cout << i << ' '

#define print(a)            cout << a << '\n'

#define rsort(a)            sort((a).rbegin(), (a).rend())

#define w(x)                int x; cin >> x; while(x--)

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

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

#define pqmx                priority_queue<int>

#define pqmn                priority_queue<int, vector<int>, greater<int> >

#define max3(a, b, c)       max((a), max((b), (c)))

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

#define mx_all(c)           *max_element((c).begin(), (c).end())

#define mn_all(c)           *min_element((c).begin(), (c).end())

#define lwr_b(c, a)         lower_bound((c).begin(), (c).end(), (a)) - ((c).begin())

#define upr_b(c, a)         upper_bound((c).begin(), (c).end(), (a)) - ((c).begin())

#define FIO                 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

// #define MAXN 100010

// int x[MAXN],y[MAXN],a[MAXN],degree[MAXN];

// const int MAX = 100'007;

const long long int MOD = 1000000007;

bool isprime(long long int N){

    if(N<2 || (!(N&1) && N!=2))

        return 0;

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

        if(!(N%i))

            return false;

    }

    return true;

}

long long int factorial(long long int n) {

    if (n <= 1) {

        return 1;

    } else {

        return (n * factorial(n - 1));

    }

}

void upd(int &a, int b) {

    a = (a * 1LL * b) % MOD;

}

// #define sz(a) int((a).size())

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

long long int gcd(long long int a, long long int b) {

    while (b != 0) {

        long long int temp = b;

        b = a % b;  // Get the remainder

        a = temp;   // Update a to the previous value of b

    }

    return a;

}

long long int powerMod(long long int base, long long int exponent, long long int mod) {

    long long int result = 1;

    base = base % mod;

    while (exponent > 0) {

        if (exponent % 2 == 1) {

            result = (result * base) % mod;

        }

        exponent = exponent >> 1;

        base = (base * base) % mod;

    }

    return result;

}

double roundToSixDecimalPlaces(double value) {

    return std::round(value * 1e6) / 1e6;

}

vector<ll> parent,component;

ll find(ll x){

    if(x==parent[x]) return x;

    return parent[x]=find(parent[x]);

}

void unite(ll a, ll b){

    a=find(a);

    b=find(b);

    if(a!=b){

        if(component[a]<component[b]){

            swap(a,b);

        }

        parent[b]=a;

        component[a]+=component[b];

    }

}

ull ull_abs(ull a, ull b) {

    return (a > b) ? (a - b) : (b - a);

}

const int MAXN = 200200;

void dfsRecursive(int vertex, vector<bool>& visited, const vector<vector<int>>& adjList) {

    visited[vertex] = true;

    for (int neighbor : adjList[vertex]) {

        if (!visited[neighbor]) {

            dfsRecursive(neighbor, visited, adjList);

        }

    }

}

long long power(long long a, long long b)

{

    long long res = 1;

    while (b > 0) {

        if (b%2==1) {

            res = (res * a);

        }

        a*=a;

        b >>= 1;

    }

    return res;

}

long long lcm(int a, int b) {

    return (1LL * a * b) / __gcd(a, b);

}

int pb, pc, ps;

int nb, nc, ns;

int lb, lc, ls;

ll fb, fc, fs;

ll price(ll x)

{

    fb = max(x*lb - nb, (ll)0);

    fc = max(x*lc - nc, (ll)0);

    fs = max(x*ls - ns, (ll)0);

    ll p = fb*pb + fc*pc + fs*ps;

    return p;

}

void solve() {

    int n;

    cin>>n;

    string s;

    cin>>s;

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

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

    bool found_p=false;

    bool found_s=false;

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

        if(s[i]=='p') found_p=true;

        if(s[i]=='s') found_s=true;

    }

    if(found_p && found_s){

        cout<<"NO";

    }

    else{

        cout<<"YES";

    }

    cout<<endl;

}

int main(){

   int t;

   cin>>t;

   while(t--){

    solve();

   }

   return 0;

}

;

Answer: 2


#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;

      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(say2==0)

      {

        cout<<"yes"<<endl;

        continue;

      }

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

      {

        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


#include <bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	array<int, 2> cnt = {0, 0};
	for(int i = 0; i < n; i++){
		if(s[i] == 's') cnt[0]++;
		if(s[i] == 'p') cnt[1]++;
	}
	if(cnt[0] >= 2 && cnt[1] >= 2){
		cout << "No" << endl;
		return;
	}
	if(cnt[0] == 0 || cnt[1] == 0){
		cout << "Yes" << endl;
		return;
	}
	if(cnt[0] == 1 && s[0] == 's'){
		cout << "Yes" << endl;
		return;
	}
	if(cnt[1] == 1 && s[n - 1] == 'p'){
		cout << "Yes" << endl;
		return;
	}
	cout << "No" << endl;
}

int main(){
	int tt;
	cin >> tt;
	while(tt--){
		solve();
	}
}

#include <bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> a(n), b(n, n - 1);
	for(int i = 0; i < n; i++){
		if(i) a[i] = a[i - 1];
		if(s[i] == 's') a[i] = i;
	}
	for(int i = n - 1; i >= 0; i--){
		if(i + 1 < n) b[i] = b[i + 1];
		if(s[i] == 'p') b[i] = i;
	}
	bool ok = 1;
	for(int i = 0; i < n; i++){
		ok &= a[i] <= b[i];
	}
	cout << (ok ? "Yes" : "No") << endl;
}

int main(){
	int tt;
	cin >> tt;
	while(tt--){
		solve();
	}
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

int main() {

	// your code goes here

	int T;

	cin>>T;

	while(T--){

	    int n;

	    cin>>n;

	    string s;

	    cin>>s;

	    int cntp=0;

	    int cnts=0;

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

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

	        else if(s[i]=='s') cnts++;

	    }

	    if(cnts==0 || cntp==0){

	        cout<<"Yes"<<endl;

	        continue;

	    }

	    if(cntp>0 && cnts>0){

	        if(cntp==1 && s[s.size()-1]=='p'){

	            cout<<"Yes"<<endl;

	        }

	        else{

	            cout<<"No"<<endl;

	        }

	        continue;

	    }

	}

}

#include <bits/stdc++.h>

using namespace std;

int main() {

	// your code goes here

	int T;

	cin>>T;

	while(T--){

	    int n;

	    cin>>n;

	    string s;

	    cin>>s;

	    int cntp=0;

	    int cnts=0;

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

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

	        else if(s[i]=='s') cnts++;

	    }

	    if(cnts==0 || cntp==0){

	        cout<<"Yes"<<endl;

	        continue;

	    }

	    if(cntp>0 && cnts>0){

	        if(cntp==1 && s[s.size()-1]=='p'|| cnts==1 && s[0]=='s'){

	            cout<<"Yes"<<endl;

	        }

	        else{

	            cout<<"No"<<endl;

	        }

	        continue;

	    }

	}

}

Answer: 2


a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  k = 0

  for z in range(b):

    if c[z] == "p" and k == 0:

      k = 1

    elif k == 1 and c[z] == "s":

      k = -1

      break

  if k != -1:

    n = c[0]

    for y in range(1,b):

      if c[y-1] != c[y]:

        n += c[y]

    if ".sp." in n:

      print("No")

    else:

      print("Yes")

  elif k == -1:

    print("No")

a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  if j[0] == "s":

    j[0] = "."

  if j[-1] == "p":

    j[-1] = "."

  l = 0

  if "s" in j and "p" in j:

    l = -1

  print("Yes") if l == 0 else print("No")

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,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)

		{

			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;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ld long double

#define mp make_pair

#define F first

#define S second

#define pb push_back

#define upb upper_bound

#define lwb lower_bound

const int maxn = 512;

int n;

char s[maxn];

void clear_array() {

    fill(s, s + 3 + n, 0);

    n = 0;

}

void solve() {

    cin >> n;

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

        cin >> s[i];

    }

    int l = -1;

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

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

            l = i;

            break;

        }

    }

    int r = -1;

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

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

            r = i;

            break;

        }

    }

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

        cout << "YES\n";

        return;

    }

    if (l < r) {

        cout << "NO\n";

        return;

    }

    int pos1 = (n / 2);

    int pos2 = (n + 3) / 2;

    while (pos1 > 1 && pos2 < n) {

        if (s[pos1] == 's' && s[pos2] == 'p') {

            cout << "NO\n";

            return;

        }

        pos1--;

        pos2++;

    }

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

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

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

                cout << "NO\n";

                return;

            }

        }

    }

    cout << "YES\n";

}

void boost() {

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

    ios_base :: sync_with_stdio(false);

}

int main() {

    boost();

    int TT;

    cin >> TT;

    while (TT--) {

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ld long double

#define mp make_pair

#define F first

#define S second

#define pb push_back

#define upb upper_bound

#define lwb lower_bound

const int maxn = 512;

int n;

char s[maxn];

void clear_array() {

    fill(s, s + 3 + n, 0);

    n = 0;

}

void solve() {

    cin >> n;

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

        cin >> s[i];

    }

    int l = -1;

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

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

            l = i;

            break;

        }

    }

    int r = -1;

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

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

            r = i;

            break;

        }

    }

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

        cout << "YES\n";

        return;

    }

    if (l < r) {

        cout << "NO\n";

        return;

    }

    int pos1 = (n / 2);

    int pos2 = (n + 3) / 2;

    while (pos1 > 1 && pos2 < n) {

        if (s[pos1] == 's' && s[pos2] == 'p') {

            cout << "NO\n";

            return;

        }

        pos1--;

        pos2++;

    }

    cout << "YES\n";

}

void boost() {

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

    ios_base :: sync_with_stdio(false);

}

int main() {

    boost();

    int TT;

    cin >> TT;

    while (TT--) {

        solve();

    }

    return 0;

}

Answer: 1


from collections import defaultdict, deque
from bisect import bisect_right, bisect_left
from math import inf, isqrt, sqrt, gcd, factorial, ceil
from itertools import permutations

mod = 10**9 + 7

def main():
    for _ in range(int(input())):
        solve()

#     solve()
def solve():

    n = int(input())
    s = input()
    p_found = False
    for i in range(n):
        if s[i] == "p":
            p_found = True
        if p_found and s[i] == "s":
            print("NO")
            return
    a = 0
    while True:
        try:
            a = s.index("sp",a)
            if a-1>=0 and a+2<n:
                print("NO")
                return
            a+=1
        except:
            break
    print("YES")

main()

from collections import defaultdict, deque
from bisect import bisect_right, bisect_left
from math import inf, isqrt, sqrt, gcd, factorial, ceil
from itertools import permutations

mod = 10**9 + 7

def main():
    for _ in range(int(input())):
        solve()

#     solve()
def solve():

    n = int(input())
    s = list(input())

    s[0] = "." if s[0] == "s" else s[0]
    s[-1] = "." if s[-1] == "p" else s[-1]

    c1 = s.count("s")
    c2 = s.count("p")
    if c1 > 0 and c2 > 0:
        print("NO")
    else:
        print("YES")

main()

Answer: 2


a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  if j[0] == "s":

    j[0] = "."

  if j[-1] == "p":

    j[-1] = "."

  l = 0

  if "s" in j and "p" in j:

    l = -1

  print("Yes") if l == 0 else print("No")

a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  k = 0

  for z in range(b):

    if c[z] == "p" and k == 0:

      k = 1

    elif k == 1 and c[z] == "s":

      k = -1

      break

  if k != -1:

    n = c[0]

    for y in range(1,b):

      if c[y-1] != c[y]:

        n += c[y]

    if ".sp." in n:

      print("No")

    else:

      s = 0

      p = 0

      l = 0

      for y in range(b):

        if c[y] == ".":

          if (s > 1 and p > 0):

            l = -1

            break

          s = 0

          p = 0

        else:

          if c[y] == "s":

            s += 1

          else:

            p += 1

      s = 0

      p = 0

      for y in range(b-1,-1,-1):

        if c[y] == ".":

          if (p > 1 and s > 0):

            l = -1

            break

          s = 0

          p = 0

        else:

          if c[y] == "s":

            s += 1

          else:

            p += 1

      if l == -1:

        print("No")

      else:

        print("Yes")

  elif k == -1:

    print("No")

Answer: 1


#include <bits/stdc++.h>

#define endl "\n"

// #define int long long

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

constexpr int N = 2e5 + 1;

constexpr int P = 131;

constexpr int INF = 1e9;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    s = " " + s;

    int r = INF;

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

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

            r = i;

        }

    }

    bool ok = true;

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

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

            if (n > r) {

                ok = false;

                break;

            }

        }

    }

    if (ok) {

        cout << "YES\n";

    } else {

        cout << "NO\n";

    }

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        solve();

    }

}

#include <bits/stdc++.h>

#define endl "\n"

// #define int long long

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

constexpr int N = 2e5 + 1;

constexpr int P = 131;

constexpr int INF = 1e9;

void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    s = " " + s;

    int r = INF;

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

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

            r = i;

            break;

        }

    }

    bool ok = true;

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

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

            if (n > r) {

                ok = false;

                break;

            }

        }

    }

    if (ok) {

        cout << "YES\n";

    } else {

        cout << "NO\n";

    }

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        solve();

    }

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int,int>;

signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";

        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if(countp>0 and (s[i]=='s'))

                ans = "NO";

            if(counts>1 && countp>1)

                ans = "NO";

        }

        if((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')

            ans = "NO";

        if((counts>1 && countp>0) && s[n-1]=='.')

            ans = "NO";

        if((countp>1 && counts>0) && s[0]=='.')

            ans="NO";

        cout<<ans<<endl;

    }

}

/*

..sp

4321

sp..

1234

.spp

3124

spp.

3214

ssp.

4213

.ssp

4321

*/

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int,int>;

signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        // cout<<s<<endl;

        // n=s.size();

        string ans = "YES";

        int countp = 0, counts = 0;

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

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

                countp++;

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

                counts++;

            if(countp>0 and (s[i]=='s'))

                ans = "NO";

            if(counts>1 && countp>1)

                ans = "NO";

        }

        if(s[0] == '.' && s[n-1]=='.' && counts>0 && countp>0)

            ans = "NO";

        cout<<ans<<endl;

    }

}

/*

sspp

4321

123456

*/

Answer: 1


#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;

}

#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;

        }

    }

    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: 1


#include <bits/stdc++.h>

using namespace std;

#define ll long long

void I_Will_Give_It_a_Try() {

    int n;

    cin >> n;

    string s;

    cin >> s;

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

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

    bool f1{}, f2{};

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

        if (s[i] == 'p') f1 = true;

        if (s[i] == 's') f2 = true;

    }

    cout << (f1 && f2 ? "NO\n" : "YES\n");

}

int32_t main() {

    ios::sync_with_stdio(0);

    cout.tie(0);

    cin.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

    int t{1};

    cin >> t;

    while (t--)

        I_Will_Give_It_a_Try();

    /*

        IT'S AN ABSOLUTE MESS UP THERE.

    */

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void I_Will_Give_It_a_Try() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int Ss{}, Ps{}, idxP{-1}, idxS{-1};

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

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

            Ss++, idxS = i;

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

            Ps++;

            if (idxP == -1)

                idxP = i;

        }

    }

    if (!Ss || !Ps) return void(cout << "YES\n");

    if (Ss > 1 && Ps > 1 || idxP < idxS) return void(cout << "NO\n");

    if (s.back() == s.front() && s.front() == '.') return void(cout << "NO\n");

    cout << "YES\n";

}

int32_t main() {

    ios::sync_with_stdio(0);

    cout.tie(0);

    cin.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

    int t{1};

    cin >> t;

    while (t--)

        I_Will_Give_It_a_Try();

    /*

        IT'S AN ABSOLUTE MESS UP THERE.

    */

}

Answer: 1


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

const int M=1e9+7;

// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }

void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0,prevs=0;

    rep(i,0,n){

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

            if(prevp==0) prevp=i+1;

        }

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

            prevs=i+1;

            if(prevp){

                cout<<"NO\n";

                return;

            }

        }

    }

    if(!prevs || !prevp) cout<<"YES\n";

    else if(prevs==1 || prevp==n) cout<<"YES\n";

    else cout<<"NO\n";

}

int32_t main()

{

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    cin >> t;

    while(t--)

    {

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

        Solve();

    }

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

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

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

    return 0;

}

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long

#define rep(i, x, n) for (int i = x; i < n; i++)

#define rrep(i, x, n) for (int i = n; i >= x; i--)

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

#define fi first

#define se second

#define endl "\n"

#define pb push_back

#define pii pair<int, int>

#define vi vector<int>

#define vii vector<pair<int,int>>

#define vvi vector<vector<int>>

#define inf (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

const int M=1e9+7;

// Binary Exponentiation

int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; }

void Solve()

{

    int n,m,k,q;

    string s;

    cin>>n>>s;

    int prevp=0,prevs=0;

    rep(i,0,n){

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

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

            prevs=1;

            if(prevp){

                cout<<"NO\n";

                return;

            }

        }

    }

    if(!prevs || !prevp) cout<<"YES\n";

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

    else cout<<"NO\n";

}

int32_t main()

{

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;

    // freopen("in",  "r", stdin);

    // freopen("out", "w", stdout);

    cin >> t;

    while(t--)

    {

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

        Solve();

    }

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

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

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

    return 0;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define lc(t) ll t; cin >> t;

#define f(i,a,n) for (ll i=a; i<n; i++)

#define sp cout << " ";

#define nl cout << "\n";

#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]

#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "

#define pb push_back

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

#define all(x,a) x, x+a

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

#define vi vector<int>

#define vll vector<ll>

#define F first

#define S second

#define endl "\n"

#define mod 1000000007

#define inf 1000000000000000000

#define pi 3.141592653589793238462643383279502884197169399

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

#define ld long double

bool isprime (ll n)

{

    if (n<=1) return false;

    if(n==2 || n==3) return true;

    if(n%2==0 || n%3==0) return false;

    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;

    return true;

}

bool s(ll a, ll b)

{

    return a>b;

}

void fun()

{

    lc(n);

    string a;

    cin >> a;

    f(i,0,n-1)

    {

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

        {

            cout << "NO\n";

            return;

        }

    }

    f(i,1,n-2)

    {

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

        {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}

int main()

{

    krish;

    lc(t);

    // ll t = 1;

    while (t--) fun();

    return 0;

}

Answer: 1


#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<vector>

#include<map>

#include <numeric>

#define ll long long

#define ull unsigned long long

using namespace std;

void solve()

{

    ll n;

    bool fs = false, fp = false;

    string s;

    cin >> n >> s;

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

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

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

        if(s[i] == 's') fs = true;

        if(s[i] == 'p') fp = true;

    }

    if(fs && fp) cout << "NO" << endl;

    else cout << "YES" << endl;

    return;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}

#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<vector>

#include<map>

#include <numeric>

#define ll long long

#define ull unsigned long long

using namespace std;

void solve()

{

    ll n;

    string s;

    cin >> n >> s;

    ll ns = 0, np = 0;

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

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

            ns++;

            if(np > 0) {

                cout << " NO" << endl;

                return;

            }

        }

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

    }

    if(ns == n || np == n) {

        cout << "YES" << endl;

        return;

    }

    if(ns == 0 && np == 0) {

        cout << "YES" << endl;

        return;

    }

    s = ' ' + s;

    map<ll,ll> mp;

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

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

            mp[n-i+1]++;

        }

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

            mp[i]++;

        }

    }

    for(auto x : mp) {

        if(x.second > 1) {

            cout << " NO" << endl;

            return;

        }

    }

    cout << "YES" << endl;

    return;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}

Answer: 1