ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
int MOD = (int) 1e9 + 7; // 998244353;
int di[] = {0, 0, 1, -1}, dj[] = {1, -1, 0, 0};

void solve() {
    string s;
    cin >> s;
    int sum = 0, n = s.size(), twos = 0, threes = 0;
    for (int i = 0; i < n; ++i) {
        int digit = s[i] - '0';
        sum += digit;
        if (digit == 2) ++twos;
        if (digit == 3) ++threes;
    }
    
    if (sum % 9 == 0 || twos >= 9) {
        cout << "YES\n";
        return;
    }
    int diff = 9 - (sum % 9);
    set<int> possible;
    for (int i = 0; i <= twos; ++i) {
        for (int j = 0; j <= min(2, threes); ++j) {
            possible.insert((2*i + 6*j) % 9);
        }
    }
    cout << ((possible.find(diff) != possible.end()) ? "YES" : "NO") << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

#define RANGE(i, a, b)                                                         \
    for (auto i = a - (a > b); (i < b) ^ (a > b); i += 1 - 2 * (a > b))
#define ll long long
/*
 1 -> 1 No change
 2 -> 4: +2 // only this can be applied twice, in that case: +5
 3 -> 9: +6
 So we can change x 2s to 4, and y 3s to 6s. The new remainder of the number
 becomes 2*x + 6*y == 0 [9]. We must find a solution for (x, y), with the upper
 bound being the actual number of occurence of 2s and 3s.
 Les restes possible d'un multiplication par 2 mod 9:
 1*2 = 2 [9]
 2*2 = 4 [9]
 3*2 = 6 [9]
 4*2 = 8 [9]
 5*2 = 0 [9]
 Les restes possible d'une multiplication par 6 mod 9:
 1*6 = 6 [9]
 2*6 = 3 [9]
 3*6 = 0 [9]
 Tableau des additions possibles:
 ---- 0 2 4 6 8
    0 0 2 4 6 7
    3 3 5 7 0 2
    6 6 8 1 3 5

*/

void solve() {
    string n;
    cin >> n;
    ll count2 = 0, count3 = 0;
    ll rem = 0;
    for (auto d : n) {
        int c = d - '0';
        rem += c % 10;
        rem %= 9;
        if (c % 10 == 2)
            count2++;
        else if (c % 10 == 3)
            count3++;
    }
    for (int n2 = 0; n2 <= min(count2, 10ll); n2++)
        for (int n3 = 0; n3 <= min(count3, 10ll); n3++)
            if (((n2 * 2) % 9 + (n3 * 6) % 9 + rem) % 9 == 0) {
                cout << "Yes" << endl;
                return;
            }
    cout << "No" << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;



const int N = 10010;



void solve()

{

    long long n, sum = 0;

    long long a[N];

    long long sum1 = 0, sum2 = 0;

    long long cnt1 = 0, cnt2 = 0;

    cin >> n;

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

    {

        cin >> a[i];

        if (i % 2)

            sum2 += a[i];

        else

            sum1 += a[i];

    }

    if (n % 2)

    {

    	cnt1 = (n + 1) / 2;

        cnt2 = (n - 1) / 2;

        

    }

    else

    {

        cnt1 = n / 2;

        cnt2 = n / 2;

    }



    if ((sum1 % cnt1)!= 0 || (sum2 % cnt2)!= 0 || (sum1 / cnt1 != sum2 / cnt2))

        cout << "NO" << endl;

    else 

    	cout<<"YES"<<endl;

    return;

}



int main()

{

    int t = 1;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}

Solution 2 (runtime: 358 ms):
#include <bits/stdc++.h>

using namespace std;

int main()

{

  long long t, n, a, b;

  cin >> t;

  while (t--)

  {

    cin >> n;

    long long sum = 0, sum1 = 0, sum2 = 0;

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

    {

      cin >> a;

      sum += a;

      if (i % 2 == 0)

        sum1 += a;

      else

        sum2 += a;

    }

    if (n % 2 == 0)

    {

      a = n / 2;

      b = n / 2;

    }

    else

    {

      a = n / 2 + 1;

      b = n / 2;

    }

    if (sum % n == 0 && sum1 == a * sum / n && sum2 == b * sum / n)

      cout << "YES\n";

    else

      cout << "NO\n";

  }

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    while(t--){
      int n,l,r;
      cin>>n>>l>>r;
      int ar[n];
      for(int i=0; i<n; i++){
        cin>>ar[i];
      }
      if(l!=1) sort(ar,ar+l-1);
      sort(ar+l-1,ar+r);
      sort(ar+r,ar+n);
      long long sum=0;
      int count=0;
      int i=0,j=l-1;
      while(count<r-l+1){
        if(ar[i]<ar[j] && i<l-1){
          sum+=(long long)ar[i];
          i++;
        }
        else{
          sum+=(long long)ar[j];
          j++;
        }
        count++;
      }
      count=0;
      long long ans1=0;
      i=l-1,j=r;
      while(count<r-l+1){
        if(ar[i]<ar[j] || j>=n){
          ans1+=(long long)ar[i];
          i++;
        }
        else{
          ans1+=(long long)ar[j];
          j++;
        }
        count++;
      }
      cout<<min(sum,ans1)<<"\n";
    }
    return 0;
}

Solution 2 (runtime: 186 ms):
//25 feb : 1000 div 2 

#include<bits/stdc++.h>

using namespace std ; 

using ll = long long int ; 

int main () {

    int t ; 

    cin>>t;

    while(t--){ 

       ll n , l , r ; 

       cin>>n>>l>>r;

       vector<ll>a(n+1); 

       ll osum = 0 ; 

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

        cin>>a[i]; 



        if(i >= l && i <= r){

            osum += a[i]; 

        }

       }





       sort(a.begin()+1 , a.begin() + l) ; 

       sort(a.begin() + l  , a.begin() + r+1) ; 

       sort(a.begin()+r +1 , a.begin() + n + 1) ; 



    //    for(auto i : a){

    //     cout<<i<<" "; 

    //    }





    ll i = 1 ; 

    ll j = r ; 

    ll diff = 0 ; 

    while(j  >= l  && i < l   ){

        if(a[i] < a[j]){

            // cout<<i<<" l "<<a[i]<<endl; 

           diff += a[j] - a[i] ; 

        }

        i++;

        j--; 

    }

    // cout<<endl; 



    i = r+1 ; 

    j = r ; 

    ll diff2 = 0 ; 



    while(j >= l  && i <= n ){

        if(a[i] < a[j]){

            // cout<<i<<" "<<a[i]<<endl; 

           diff2 += a[j] - a[i] ; 

        }

        i++;

        j--; 

    }





    cout<<min({osum , osum-diff , osum-diff2})<<endl; 













    }}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
 
using namespace std;
 
void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s;
}
 
int main() {
    int TESTS = 1; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 2000006
#define mod 1000000007
#define endl "\n"
#define bug(x) cout << #x << " : "<< x << "\n"

void Cry(int& tc) {
    string s; cin >> s;
    vector <int> v(s.size());

    for (int i = 0; i < s.size(); i++) {
        v[i] = s[i] - '0';
    }


    for (int i = 1; i < v.size(); i++) {

        int temp = i;

        if (v[temp] - 1 > v[temp - 1]) {

            int j = temp - 1;

            while (j >= 0 && v[temp] - 1 > v[j]) {
                v[temp]--;
                swap(v[j], v[temp]);
                temp--;
                j--;
            }
        }
    }

    for (int i = 0; i < v.size(); i++) cout << v[i];
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int testCase = 1;
    cin >> testCase;

    for (int i = 1; i <= testCase; i++) {
        Cry(testCase);
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>



using namespace std;



#define endl "\n"

#define int long long



void s1() {

    int n; cin >> n;

    vector<int> a(n);



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

        cin >> a[i];

    }



    if (a[0] > a[1]) {

        cout << "NO" << endl;

        return;

    }



    bool flag = true;

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

        if (a[i] > a[i + 1]) {

            flag = false;

            break;

        }

    }



    if (flag) {

        cout << "YES" << endl;

        return;

    }



    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }



    if (sdd > 0 && sdd % 2 == 1) sdd--;

    

    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }



    // cerr << sdd << endl;



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

        if (a[i] > a[i + 1]) {

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }



        int temp = min(a[i], a[i + 1]);

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }



    cout << "YES" << endl;

    return;

}



signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t; cin >> t;

    while (t--) {

        s1();

    }



    // s1();



    return 0;

}

Solution 2 (runtime: 93 ms):
#include <iostream>

#include <algorithm>

#include <cmath>

#include <vector>

#include <map>

#include <set>

#include <stack>

#include <string>

#include <queue>

#include <numeric>

#include <bitset>

#include <stdio.h>

#include <time.h>

#include <assert.h>

#include <unordered_map>



using namespace std;



long long a[300001];



int main (){

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

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

            cin >> a[i];

        }

        int k = 0;

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

            if (a[i] >= a[i-1]) {

                a[i] -= a[i-1];

            }

            else {

                if (a[i-1] > a[i]) {

                    cout << "No" <<"\n";

                    k = 1;

                    break;

                }

            }

        }

        if (k == 0) {

            cout << "yes" <<"\n";

        }

    }



}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>

using namespace std;

int main(){
    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        int sum = 0, twos = 0, threes = 0;
        for(auto i: s){
            twos += i == '2';
            threes += i == '3';
            sum += i - '0';
        }
        int remSum = sum - 2*twos - 3*threes, targetMod = (9 - (remSum)%9)%9;
        bool answer = false; 
        for(int i = 0; i <= twos; i++){
            for(int j = 0; j <= threes; j++){
                if((2*twos + 3*threes + i*2 + j*6)%9 == targetMod){
                    answer = true;
                    break;
                }
            }
            if(answer) break;
        }
        cout << (answer == true ? "YES" : "NO")  << endl;
    }
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    long long  sum = 0, two = 0, three = 0;

    string n;

    cin >> n;

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

        if(n[i]=='2') two++;

        if(n[i]=='3') three++;

        sum+=n[i]-48;

    }



    if (sum % 9 == 0) {

        cout << "YES" << endl;

        return;

    }



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

        for (int j = 0; j <= three; j++) {

            long long new_sum = sum + i * 2 + j * 6;

            if (new_sum % 9 == 0) {

                cout << "YES" << endl;

                return;

            }

        }

    }



    cout << "NO" << endl;

}



int main() {

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>
using namespace std;
void solve(vector<long long> finder, long long n){
    long long sum_even = 0; 
    long long count_even = 0; 
    long long sum_odd = 0; 
    long long count_odd = 0; 
    for(long long i = 0; i<n; i++){
        if(i%2 == 0){
            sum_even+=finder[i];
            count_even++;
        }
        else{
            sum_odd+=finder[i];
            count_odd++; 
        }
    }
    if(sum_odd%count_odd!=0 || sum_even%count_even!=0){
        cout<<"NO"<<endl; 
        return; 
    }
    else if(sum_odd/count_odd!=sum_even/count_even){
        cout<<"NO"<<endl; 
        return; 
    }
    else {
        cout<<"YES"<<endl; 
        return ; 
    }
}
int main() {
    long long t; 
    cin>>t; 
    while(t--){
        long long n; 
        cin>>n; 
        vector<long long> finder(n);
        for(long long i = 0; i<n; i++){
            cin>>finder[i];
        }
        solve(finder,n);
    }
}


Solution 2 (runtime: 327 ms):
#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        int arr[n];

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

            cin>>arr[i];

        }

        long long oddsm=0,evensm=0,oddcnt=0,evencnt=0;

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

            if(i%2==0){

                evensm+=arr[i];

                evencnt++;

            }

            else{

                oddsm+=arr[i];

                oddcnt++;

            }

        }

        if (oddsm%oddcnt == 0 && evensm%evencnt == 0 && oddsm * evencnt == evensm * oddcnt)

            cout << "YES" << endl;

        else

            cout << "NO" << endl;

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <iostream>
#include <vector>
using namespace std;

bool isNonDecreasing(const vector<int>& a) {
    for (int i = 0; i < a.size() - 1; ++i) {
        if (a[i] > a[i + 1]) {
            return false;
        }
    }
    return true;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    vector<int> temp = a;
    for (int i = 0; i < n - 1; ++i) {
        int m = min(temp[i], temp[i + 1]);
        temp[i] -= m;
        temp[i + 1] -= m;
    }
    
    if (isNonDecreasing(temp)) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 93 ms):
/*
╔░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╗
║                                                                                           ║
║ ███╗   ██╗  █████╗  ██╗   ██╗ ██████╗          ███████╗ ██╗      ██████╗   ██╗ ███╗   ██╗ ║
║ ██╔██╗ ██║ ██╔══██╗ ██║   ██║ ██╔══██╗         ██╔════╝ ██║      ██╔══██╗  ╚═╝ ██╔██╗ ██║ ║
║ ██║╚██╗██║ ██║  ██║ ██║   ██║ ██████╔╝         █████╗   ██║      ██║  ██║  ██╗ ██║╚██╗██║ ║
║ ██║ ╚████║ ██║  ██║ ██║   ██║ ██╔══██╗         ██╔══╝   ██║      ██║  ██║  ██║ ██║ ╚████║ ║
║ ██║  ╚███║ ╚█████╔╝ ╚██████╔╝ ██║  ██║         ███████╗ ███████╗ ██████╔╝  ██║ ██║  ╚███║ ║
║ ╚═╝   ╚══╝  ╚════╝   ╚═════╝  ╚═╝  ╚═╝ ███████╗╚══════╝ ╚══════╝ ╚═════╝   ╚═╝ ╚═╝   ╚══╝ ║
║                                        ╚══════╝                                           ║
╚░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╝
*/

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Max(v) *max_element(all(v))
#define Min(v) *min_element(all(v))
#define Lio ios_base::sync_with_stdio(0); cin.tie(0) , cout.tie(0);
using namespace std;

const int mod = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const ll OO = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;


// 4 5 4 5 4 5 4 5
// 0 0 0 0 0 0 0 3

// 4 5 2 3
// 0 0 0 2

// 2 5 1 2
// 0 0 0

void TestCase () {
    ll n; cin >> n;
    vector<ll>v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    if (v.size() == 2)
        return void (cout << (v[1] >= v[0] ? "YES" : "NO") <<endl);
    for (int i = 2; i < n; ++i) {
        v[i-1]-=v[i-2];
        if (v[i] < v[i-1] || v[i-1] < 0)
            return void (cout << "NO" <<endl);
    }
    cout << "YES" <<endl;
}

int main()
{
    Lio
#ifndef ONLINE_JUDGE
    freopen("Input.txt","r",stdin);
    freopen("Output.txt", "w", stdout);
#endif
    int TC = 1;
    cin >> TC;
    for (int i = 0; i < TC; ++i) {
        TestCase();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 202 ms):
#include<bits/stdc++.h>
using namespace std;
#define MAX_SIZE 100
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> vll;
typedef pair<int,int> PII;
typedef priority_queue<int> dheap;
typedef priority_queue<int,vector<int>,greater<int> > xheap;
#define all(a) a.begin(),a.end()
const int N=2e5+10,M=2e5;
const int Size=2e5+10+1;



void solve(){
    int m;
    cin>>m;
    vi p(m);
    vii st(m+1,vi(m+1,1));
    int ans=0;
    for(int i=0;i<m;i++)cin>>p[i];
    for(int i=0;i<m-1;i++){
        for(int j=i+1;j<m;j++){
            if(p[i]>p[j]){
                st[p[j]][p[i]]--;ans++;
            }else ans+=2;
        }
    }cout<<ans<<"\n";
    vi pp(m);
    for(int i=0;i<m;i++)pp[i]=i+1;
    while(ans){
        for(int i=m-1;i;i--){
            if(st[pp[i]][pp[i-1]]){
                cout<<pp[i]<<' '<<pp[i-1]<<'\n';
                st[pp[i]][pp[i-1]]--;ans--;swap(pp[i],pp[i-1]);
            }
        }
    }
}

int main() {
    #ifdef Online_Judge
    freopen("INPUT.in","r",stdin); 
    freopen("OUTPUT.out","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    for(int i=0;i<t;i++)
    {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 1531 ms):

#include <bits/stdc++.h>
#define int long long
using namespace std;
 
const int MOD = 1e9 + 7;
const int mod=998244353;
 
int32_t main() {
    
    //int t; cin>>t;
    //for (int i=1;i<=t;i++) {
        int n;cin>>n;
        int c[n];
        for(int i=0;i<n;i++){cin>>c[i];}
        vector<int>temp(n,0);
        for(int i=0;i<n;i++){
            temp[i]=i+1;
        }
        int ans=0;
        vector<pair<int,int>>v;
        for(int i=0;i<n;i++){
            int no=c[i];
            int ind=-1;
            for(int j=0;j<n;j++){
                if(temp[j]==no)ind=j;
            }
            int re=n-1-ind;
            ans+=2*re;
            ans+=(ind-i);
            //cout<<ans<<" ";
            for(int j=ind+1;j<n;j++){
                v.push_back({temp[j],no});
            }

            for(int j=n-1;j>=ind+1;j--){
                v.push_back({no,temp[j]});
            }

            for(int j=ind-1;j>=i;j--){
                v.push_back({no,temp[j]});
            }

            for(int j=ind;j>=i+1;j--){
                temp[j]=temp[j-1];
            }
            temp[i]=no;
            // if(i==0){
            //     for(auto it:temp)cout<<it<<" ";
            //     cout<<endl;
            // }
        }
        cout<<ans<<endl;
        for(auto it:v){
            cout<<it.first<<" "<<it.second<<endl;
        }
    //}
    return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

Solution 1 (runtime: 46 ms):
#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;

}

Solution 2 (runtime: 62 ms):
#include<iostream>

#include<map>

#include<algorithm>



using namespace std;



typedef long long LL;



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



int T;

LL n, m;

int a[N], b[N];



int main() {

    cin >> T;



    while (T--) {

        cin >> n;



        string s;

        cin >> s;



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

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



        int f1 = 0, f2 = 0;

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

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

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

        } 



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

        else puts("YES");



    }



    return 0;

}