ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 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 = -1;
      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['.'] == n || m['p'] == n ){
        YES;
        return;
       }
       if(slast == 0 || pfirst == n-1){
        YES;
        return;
       }
       NO;
      

      }

    



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

Submission (verdict: Accepted):
#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;
}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 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;

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

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

}

int main(){
   fast_io;
    int t ;
    cin>>t ;
    while(t--){
      akibify();
        
    }
 
 
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
int solve(int i,int j,int k,int x,int y,int z,string a,string b,string c,vector<vector<int>>&dp)   //int val,int&mn,
{
    if(dp[i][j]!=-1)return dp[i][j];
    if(k==z)
    {
        return dp[i][j]=0;
    }
    int va=INT_MAX;
    int vb=INT_MAX;
    if(i<x)
    {
        if(a[i]==c[k])va=solve(i+1,j,k+1,x,y,z,a,b,c,dp);
        else va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+1;
    }
    if(j<y)
    {
        if(b[j]==c[k])vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp);
        else vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp)+1;
    }
    return dp[i][j]=min(vb,va);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        // int mn=INT_MAX;
        vector<vector<int>>dp(a.size()+1,vector<int>(b.size()+1,-1));
        cout<<solve(0,0,0,a.size(),b.size(),c.size(),a,b,c,dp)<<"\n";
        // cout<<mn<<"\n";
        
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
int solve(int i,int j,int k,int x,int y,int z,string a,string b,string c,vector<vector<int>>&dp)   //int val,int&mn,
{
    if(dp[i][j]!=-1)return dp[i][j];
    if(k==z)
    {
        return dp[i][j]=0;
    }
    int va=INT_MAX;
    int vb=INT_MAX;
    if(i<x)
    {
        if(a[i]==c[k])va=solve(i+1,j,k+1,x,y,z,a,b,c,dp);
        else va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+1;
    }
    if(j<y)
    {
        if(b[j]==c[k])vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp);
        else vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp)+1;
    }
    return dp[i][j]=min(vb,va);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        // int mn=INT_MAX;
        vector<vector<int>>dp(a.size()+1,vector<int>(b.size()+1,-1));
        cout<<solve(0,0,0,a.size(),b.size(),c.size(),a,b,c,dp)<<"\n";
        // cout<<mn<<"\n";
        
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
int solve(int i,int j,int k,int x,int y,int z,string a,string b,string c,vector<vector<int>>&dp)   //int val,int&mn,
{
    if(dp[i][j]!=-1) return dp[i][j];
    if(k==z)
    {
        return dp[i][j]=0;
    }
    int va=INT_MAX;
    int vb=INT_MAX;
    if(i<x)
    {
        if(a[i]==c[k])va=solve(i+1,j,k+1,x,y,z,a,b,c,dp);
        else va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+1;
    }
    if(j<y)
    {
        if(b[j]==c[k])vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp);
        else vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp)+1;
    }
    return dp[i][j]=min(vb,va);
}
int main()
{
    vector<vector<int>>dp(2001,vector<int>(2001,-1));
    int t;
    cin>>t;
    // cin.ignore();
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        
        // getline(cin,a);
        // getline(cin,b);
        // getline(cin,c);
        // int mn=INT_MAX;
        
        cout<<solve(0,0,0,a.size(),b.size(),c.size(),a,b,c,dp)<<"\n";
        // cout<<mn<<"\n";
        for(int i=0;i<2001;i++)
        for(int j=0;j<2001;j++)
        dp[i][j]=-1;
        
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
int solve(int i,int j,int k,int x,int y,int z,string a,string b,string c,vector<vector<int>>&dp)   //int val,int&mn,
{
    if(dp[i][j]!=-1) return dp[i][j];
    if(k==z)
    {
        return dp[i][j]=0;
    }
    int va=INT_MAX;
    int vb=INT_MAX;
    if(i<x)
    {
        if(a[i]==c[k])va=solve(i+1,j,k+1,x,y,z,a,b,c,dp);
        else va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+1;
    }
    if(j<y)
    {
        if(b[j]==c[k])vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp);
        else vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp)+1;
    }
    return dp[i][j]=min(vb,va);
}
int main()
{
    vector<vector<int>>dp(2001,vector<int>(2001,-1));
    int t;
    cin>>t;
    // cin.ignore();
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        
        // getline(cin,a);
        // getline(cin,b);
        // getline(cin,c);
        // int mn=INT_MAX;
        
        cout<<solve(0,0,0,a.size(),b.size(),c.size(),a,b,c,dp)<<"\n";
        // cout<<mn<<"\n";
        for(int i=0;i<2001;i++)
        for(int j=0;j<2001;j++)
        dp[i][j]=-1;
        
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int solve(int i,int j,int k,int &x,int &y,int &z,string &a,string &b,string &c,vector<vector<int>>&dp)   //int val,int&mn,
{
    if(dp[i][j]!=-1) return dp[i][j];
    if(k==z)
    {
        return dp[i][j]=0;
    }
    int va=INT_MAX;
    int vb=INT_MAX;
    if(i<x)
    {
        // if(a[i]==c[k])va=solve(i+1,j,k+1,x,y,z,a,b,c,dp);
        // else va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+1;



        va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+(((a[i]!=c[k])));
        // ***************************************************************
    
    
    
    }
    if(j<y)
    {
       
        vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp)+(b[j]!=c[k]);
    }
    return dp[i][j]=min(vb,va);
}
int main()
{
    
    int t;
    cin>>t;
    // cin.ignore();
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        int x=a.size(),y=b.size(),z=c.size();
        vector<vector<int>>dp;
        dp.assign(x+1,vector<int>(y+1,-1));
        // getline(cin,a);
        // getline(cin,b);
        // getline(cin,c);
        // int mn=INT_MAX;
        
        cout<<solve(0,0,0,x,y,z,a,b,c,dp)<<"\n";
        // cout<<mn<<"\n";
        // for(int i=0;i<2001;i++)
        // for(int j=0;j<2001;j++)
        // dp[i][j]=-1;
        
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;



void solve() {

    int n, x, y;

    cin >> n >> x >> y;

    x -= 1, y -= 1;

    if (abs(x - y) <= 1) {

        if (n % 2) {

            for (int i = 0; i < n - 1; i++) cout << i % 2 << " ";

            cout << "2\n";

        } else {

            for (int i = 0; i < n; i++) cout << i % 2 << " ";

            cout << "\n";

        }

        return;

    }

    vector<int> ans(n);

    if (n % 2) {

        for (int i = 0; i < n - 1; i++) ans[i] = i % 2;

        ans[n - 1] = 2;

        if (ans[x] == ans[y]) {

            if (ans[(x - 1) % n] == 2 || ans[(x + 1) % n] == 2) ans[y] = 2;

            else ans[x] = 2;

        }

    } else {

        for (int i = 0; i < n; i++) ans[i] = i % 2;

        if (ans[x] == ans[y]) ans[x] = 2;

    }

    for (auto& ansi : ans) cout << ansi << " ";

    cout << "\n";

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;



void solve() {

    int n, x, y;

    cin >> n >> x >> y;

    x -= 1, y -= 1;

    if (x > y) swap(x, y);

    if (y - x == 1 || (x == 0 && y == n - 1)) {

        if (n % 2) {

            for (int i = 0; i < n - 1; i++) cout << i % 2 << " ";

            cout << "2\n";

        } else {

            for (int i = 0; i < n; i++) cout << i % 2 << " ";

            cout << "\n";

        }

        return;

    }

    vector<int> ans(n);

    if (n % 2) {

        for (int i = 0; i < n - 1; i++) ans[i] = i % 2;

        ans[n - 1] = 2;

        if (ans[x] == ans[y]) {

            if (ans[(x + n - 1) % n] == 2 || ans[(x + n + 1) % n] == 2) ans[y] = 2;

            else ans[x] = 2;

        }

    } else {

        for (int i = 0; i < n; i++) ans[i] = i % 2;

        if (ans[x] == ans[y]) ans[x] = 2;

    }

    for (auto& ansi : ans) cout << ansi << " ";

    cout << "\n";

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}

Submission (verdict: Accepted):
#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;



void solve() {

    int n, x, y;

    cin >> n >> x >> y;

    x -= 1, y -= 1;

    if (x > y) swap(x, y);

    if (y - x == 1 || (x == 0 && y == n - 1)) {

        if (n % 2) {

            for (int i = 0; i < n - 1; i++) cout << i % 2 << " ";

            cout << "2\n";

        } else {

            for (int i = 0; i < n; i++) cout << i % 2 << " ";

            cout << "\n";

        }

        return;

    }

    vector<int> ans(n);

    if (n % 2) {

        for (int i = 0; i < n - 1; i++) ans[i] = i % 2;

        ans[n - 1] = 2;

        if (ans[x] == ans[y]) {

            ans[x] = 2;

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

                ans[(x + 1 + i) % n] = i % 2;

            }

        }

    } else {

        for (int i = 0; i < n; i++) ans[i] = i % 2;

        if (ans[x] == ans[y]) ans[x] = 2;

    }

    for (auto& ansi : ans) cout << ansi << " ";

    cout << "\n";

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;



void solve() {

    int n, x, y;

    cin >> n >> x >> y;

    x -= 1, y -= 1;

    if (abs(x - y) <= 1) {

        if (n % 2) {

            for (int i = 0; i < n - 1; i++) cout << i % 2 << " ";

            cout << "2\n";

        } else {

            for (int i = 0; i < n; i++) cout << i % 2 << " ";

            cout << "\n";

        }

        return;

    }

    vector<int> ans(n);

    if (n % 2) {

        for (int i = 0; i < n - 1; i++) ans[i] = i % 2;

        ans[n - 1] = 2;

        if (ans[x] == ans[y]) {

            if (ans[(x - 1) % n] == 2 || ans[(x + 1) % n] == 2) ans[y] = 2;

            else ans[x] = 2;

        }

    } else {

        for (int i = 0; i < n; i++) ans[i] = i % 2;

        if (ans[x] == ans[y]) ans[x] = 2;

    }

    for (auto& ansi : ans) cout << ansi << " ";

    cout << "\n";

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}

Submission (verdict: Wrong answer on test 1):
#pragma GCC optimize("O3")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;



void solve() {

    int n, x, y;

    cin >> n >> x >> y;

    x -= 1, y -= 1;

    if (x > y) swap(x, y);

    if (y - x == 1 || (x == 0 && y == n - 1)) {

        if (n % 2) {

            for (int i = 0; i < n - 1; i++) cout << i % 2 << " ";

            cout << "2\n";

        } else {

            for (int i = 0; i < n; i++) cout << i % 2 << " ";

            cout << "\n";

        }

        return;

    }

    vector<int> ans(n);

    if (n % 2) {

        for (int i = 0; i < n - 1; i++) ans[i] = i % 2;

        ans[n - 1] = 2;

        if (ans[x] == ans[y]) {

            if (ans[(x + n - 1) % n] == 2 || ans[(x + n + 1) % n] == 2) ans[y] = 2;

            else ans[x] = 2;

        }

    } else {

        for (int i = 0; i < n; i++) ans[i] = i % 2;

        if (ans[x] == ans[y]) ans[x] = 2;

    }

    for (auto& ansi : ans) cout << ansi << " ";

    cout << "\n";

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

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

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



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

        seen_s = true;

    }

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

        seen_p = true;

    }



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

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

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

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

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }

    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;

}

Submission (verdict: Accepted):
#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;

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


Submission (verdict: Wrong answer on test 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] == 's'){

        seen_s = true;

    }

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

        seen_p = true;

    }



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

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

            if(seen_p){

                cout << "no/n";

                return;

            }

            seen_s = true;

        }

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

            if(seen_s){

                cout << "no/n";

                return;

            }

            seen_p = true;

        }       

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

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

Previous submission (verdict: Wrong answer on test 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] == 's'){

        seen_s = true;

    }

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

        seen_p = true;

    }



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

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

            if(seen_p){

                cout << "no/n";

                return;

            }

            seen_s = true;

        }

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

            if(seen_s){

                cout << "no/n";

                return;

            }

            seen_p = true;

        }       

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

}

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



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

        seen_s = true;

    }

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

        seen_p = true;

    }



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

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

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

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

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

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

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



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

        seen_s = true;

    }

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

        seen_p = true;

    }



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

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

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

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

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

}

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



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

        seen_s = true;

    }

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

        seen_p = true;

    }



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

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

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

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

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }

    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;

}