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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
typedef long long ll;
#define get(a, n) for (ll i = 0; i < n; i++) cin >> a[i]
using namespace std;
 
void pv(vector<int> a){
	for(ll i=0;i<a.size();i++){
		cout<<a[i]<<' ';
	}cout<<endl;
}
void haha(ll a,vector<int> &ap){
	for(int i=0;i<62;i++){
		ap[i]=a%2;
		a=a/2;
	}
}
ll fact(int a){
	ll ans=1;
	for(int i=2;i<a;i++){
		ans*=i;
	}return ans;
}
ll ncr(int a,int b){
	return fact(a)/(fact(b)*fact(a-b));
}
//long long cache[101][10][10][10][10];
//int n,x;


int main(){
	ios_base::sync_with_stdio(0);
  	cin.tie(0); cout.tie(0);
	ll t=1;
	cin>>t;
	//memset(cache,-1,sizeof(cache));
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int counts=0;
		int countp=0;
		for(int i=0;i<n;i++){
			if(s[i]=='s') counts++;
			if(s[i]=='p') countp++;
		}int tempcount=0;
		bool ans=true;
		for(int i=0;i<n;i++){
			if(s[i]=='p' && tempcount<counts){
				ans=false;
				break;
			}else if(s[i]=='s'){
				tempcount++;
			}
		}if(ans && countp!=0 && counts!=0){
			if(s[n-1]=='.' && s[0]=='.'){
				ans=false;
			}
		}if(ans) cout<<"YES";
		else cout<<"NO";
		cout<<endl;
	}
}

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

typedef long long ll;

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

using namespace std;

 

void pv(vector<int> a){

	for(ll i=0;i<a.size();i++){

		cout<<a[i]<<' ';

	}cout<<endl;

}

void haha(ll a,vector<int> &ap){

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

		ap[i]=a%2;

		a=a/2;

	}

}

ll fact(int a){

	ll ans=1;

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

		ans*=i;

	}return ans;

}

ll ncr(int a,int b){

	return fact(a)/(fact(b)*fact(a-b));

}

template <typename T>

class MapNode{

	public:

	string key;

	T value;

	MapNode<T>* next;



	public:

	MapNode(string key,T value){

		this->key=key;

		this->value=value;

		next=NULL;

	}

	~MapNode(){

		delete next;

	}

};

template <typename T>

class HashMap{

	MapNode<T>** buckets;

	int sizebucket;

	int count;

	int hashfunc(string key){

		int hashed=0;

		int coeff=1;

		for(int i=key.size()-1;i>=0;i--){

			hashed=(hashed+key[i]*coeff)%sizebucket;

			coeff=(coeff*37)%sizebucket;

		}return hashed;

	}

	void rehash(){

		MapNode<T> **temp=buckets;

		buckets=new MapNode<T>*[2*sizebucket];

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

			buckets[i]=NULL;

		}

		int tempbucketsize=sizebucket;

		sizebucket=2*sizebucket;

		count=0;

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

			MapNode<T>* head=temp[i];

			while(head!=NULL){

				insert(head->key,head->value);

				head=head->next;

			}

		}return;

	}

public:

	double getloadfactor(){

		return (1.0*count/sizebucket);

	}

	public:

	HashMap(){

		buckets=new MapNode<T>*[5];

		sizebucket=5;

		count=0;

	}

	int size(){

		return count;

	}

	T search(string key){

		int indexx=hashfunc(key);

		MapNode<T>* head=buckets[indexx];

		while(head!=NULL){

			if(head->key==key){

				return head->value;

			}head=head->next;

		}return 0;

	}

	void insert(string key,T value){

		int indexx=hashfunc(key);

		MapNode<T>* head=buckets[indexx];

		while(head!=NULL){

			if(head->key==key){

				head->value=value;

				return;

			}head=head->next;

		}head=buckets[indexx];

		MapNode<T>* temp=new MapNode<T>(key,value);

		temp->next=head;

		buckets[indexx]=temp;

		count++;

		if(getloadfactor()>0.7){

			rehash();

		}

		return;

	}

	T remove(string key){

		int indexx=hashfunc(key);

		MapNode<T>* head=buckets[indexx];

		MapNode<T>* prev=NULL;

		while(head!=NULL){

			if(head->key==key){

				if(prev==NULL){

					buckets[indexx]=head->next;

				}else{

					prev->next=head->next;

				}head->next=NULL;

				T value=head->value;

				delete head;

				count--;

				return value;

			}prev=head;

			head=head->next;

		}return 0;

	}

	~HashMap(){

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

			delete buckets[i];

		}delete [] buckets;

	}

};



class TrieNode{

public:

	char data;

	bool isTerminal;

	TrieNode** children;



	TrieNode(char data){

		this->data=data;

		isTerminal=false;

		children=new TrieNode*[26];

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

			children[i]=NULL;

		}

	}

	~TrieNode(){

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

			delete children[i];

		}

	}

};

class Trie{

	TrieNode* root;

public:



	void inserthelper(string word,TrieNode* root){

		if(word.size()==0){

			root->isTerminal=true;

			return;

		}

		int indexx=word[0]-'a';

		TrieNode* child;

		if(root->children[indexx]==NULL){

			child=new TrieNode(word[0]);

			root->children[indexx]=child;

		}else{

			child=root->children[indexx];

		}

		inserthelper(word.substr(1),child);

	}

	void removehelper(string word,TrieNode* root){

		if(word.size()==0){

			root->isTerminal=false;

			return;

		}int indexx=word[0]-'a';

		TrieNode* child;

		if(root->children[indexx]==NULL){

			return;

		}child=root->children[indexx];

		removehelper(word.substr(1),child);

		if(!child->isTerminal){

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

				if(child->children[i]!=NULL){

					return;

				}

			}delete child;

			root->children[indexx]=NULL;

			return;

		}

	}

public:

	Trie(){

		root=new TrieNode('\0');

	}

	void insert(string word){

		inserthelper(word,root);

	}void remove(string word){

		removehelper(word,root);

	}

};

bool triangle(int a,int b,int c){

	if((a+b)	<c || (b+c)<a || a+c<b){

		return false;

	}return true;

}



int main(){

	int t=1;

	cin>>t;

	while(t--){

		int n;

		cin>>n;

		string s;

		cin>>s;

		int countp=0,counts=0;

		bool ctp=false;

		bool ans=true;

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

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

				ctp=true;

				countp++;

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

				counts++;

			}

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

				ans=false;

			}

		}

		if(ans && countp!=0 && counts!=0){

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

				ans=false;

			}

		}if(ans) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

	}

}

//0 0 0 0 1 1 0