ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: c++23 

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

using namespace std;

#define int long long

#define endl '\n'

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

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



const int N = 1e6 + 5;



signed main() // Road to red

{

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

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

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

        string s; cin >> s;

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

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

        {

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

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

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

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

using namespace std;

#define int long long

#define endl '\n'

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

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



const int N = 1e6 + 5;



signed main() // Road to red

{

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

    int tes = 1;

    cin >> tes;

    while (tes--)

    {

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

        string s; cin >> s;

        bool p = 0;

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

        {

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

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

        }

        bool ss = 0;

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

        {

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

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

        }

        if(res){YES}

        else{NO}

    }

    return 0;

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#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";



    }

}

Code 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 = 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
Problem: 2049B - pspspsps
Language: python

Code 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")

    

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

      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
Problem: 2049B - pspspsps
Language: c++17 

Code 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();

    }

}



Code 2:
#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
Problem: 2049B - pspspsps
Language: c++23 

Code 1:
#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;

}

Code 2:
#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
Problem: 2049B - pspspsps
Language: c++17 

Code 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();

}

Code 2:
#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
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#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;

}

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

    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
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#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();

		}

	}



Code 2:
#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
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;



int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        int n;

        cin>>n;

        string s;

        cin>>s;



        if(s[0]=='s' || s[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;

}

Code 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[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
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#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;

}

Code 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>1&&j!=n){

	                f=1;

	                break;

	            }

	        }

	        if(f) break;

	    }

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

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

    }

    return 0;

}

Answer: 2
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
// **************** 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;

}

Code 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>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
Problem: 2049B - pspspsps
Language: c++17 

Code 1:
#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;

}

Code 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[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
Problem: 2049B - pspspsps
Language: c++20 

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



*/

Code 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'))||(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