ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Memory limit exceeded on test 1):
#include<bits/stdc++.h>

using namespace std;

const int N = 10010;
int f[N][N];
int t;
string s;

bool dfs(int i,int j) {
    if(f[i][j] != -1) return f[i][j];
    bool ok;
    if(i == s.size()) ok = j % 9 == 0;
    else if(s[i] >= '4') ok = dfs(i+1,j + s[i] - '0');
    else {
        int path = s[i] - '0';
        ok = dfs(i+1,j + s[i] - '0') || dfs(i+1,j + path * path);
    }
    f[i][j] = ok;
    return f[i][j];
}

int main() {
    cin >> t;
    while(t--) {
        memset(f,-1,sizeof f);
        cin >> s;
        if(dfs(0,0)) {
            cout << "YES" << endl;
        }
        else cout <<"NO" << endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

const int N = 10010;
int f[10];
int t;
string s;

// bool dfs(int i,int j) {
//     if(f[i][j] != -1) return f[i][j];
//     bool ok;
//     if(i == s.size()) ok = j == 0;
//     else if(s[i] >= '4') ok = dfs(i+1,j + s[i] - '0');
//     else {
//         int path = s[i] - '0';
//         ok = dfs(i+1,(j + s[i] - '0') % 9) || dfs(i+1,(j + path * path) % 9);
//     }
//     f[i][j] = ok;
//     return f[i][j];
// }

int main() {
    cin >> t;
    while(t--) {
        cin >> s;
        int t2 = 0,t3 = 0;
        int sum = 0;
        bool ok = false;
        for(auto c : s) {
            sum += c - '0';
            if(c == '2') t2++;
            if(c == '3') t3 ++;
        }
        for(int i = 0; i<=t2 && i <= 8 && !ok; i++) {
            for(int j = 0; j<=t3 && j <= 8 && !ok; j++) {
                int t = sum + i * 2 + j * 6;
                if(t % 9 == 0) {
                    cout << "YES" << endl;
                    ok = true;
                }
            }
        }
        if(!ok) cout << "NO" << endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

const int N = 10010;
int f[N];
int t;
string s;

bool dfs(int i,int j) {
    if(i == s.size()) return j % 9 == 0;
    if(s[i] >= '4') return dfs(i+1,j + s[i] - '0');
    else {
        int path = s[i] - '0';
        return dfs(i+1,j + s[i] - '0') || dfs(i+1,j + path * path);
    }
}

int main() {
    cin >> t;
    while(t--) {
        cin >> s;
        if(dfs(0,0)) {
            cout << "YES" << endl;
        }
        else cout <<"NO" << endl;
    }
    return 0;
}

Submission (verdict: Memory limit exceeded on test 1):
#include<bits/stdc++.h>

using namespace std;

const int N = 10010;
int f[N][N];
int t;
string s;

bool dfs(int i,int j) {
    if(f[i][j] != -1) return f[i][j];
    bool ok;
    if(i == s.size()) ok = j % 9 == 0;
    else if(s[i] >= '4') ok = dfs(i+1,j + s[i] - '0');
    else {
        int path = s[i] - '0';
        ok = dfs(i+1,j + s[i] - '0') || dfs(i+1,j + path * path);
    }
    f[i][j] = ok;
    return f[i][j];
}

int main() {
    cin >> t;
    while(t--) {
        memset(f,-1,sizeof f);
        cin >> s;
        if(dfs(0,0)) {
            cout << "YES" << endl;
        }
        else cout <<"NO" << endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

const int N = 10010;
int f[N];
int t;
string s;

bool dfs(int i,int j) {
    if(i == s.size()) return j % 9 == 0;
    if(s[i] >= '4') return dfs(i+1,j + s[i] - '0');
    else {
        int path = s[i] - '0';
        return dfs(i+1,j + s[i] - '0') || dfs(i+1,j + path * path);
    }
}

int main() {
    cin >> t;
    while(t--) {
        cin >> s;
        if(dfs(0,0)) {
            cout << "YES" << endl;
        }
        else cout <<"NO" << endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <vector>

#include <map>

using namespace std;

typedef long long ll;

void solve () {

    ll n, m; cin >> n >> m;

    ll sum = 0;

    map<ll,ll> a, b;

    for (ll i = 0, x; i < n; i++) cin >> x, sum += x, a[x]++;

    for (ll i = 0, x; i < m; i++) cin >> x, sum -= x, b[x]++;

    if (sum != 0) return cout << "No\n", void();

    ll op = n - m;

    auto tmp = a;

    while (op--) {

        ll flag = 0;

        for (auto [x, y] : tmp) {

            if (tmp[x] >= 2) {

                tmp[x] -= 2, tmp[2 * x]++;

                flag = 1; break;

            }

            if (tmp[x] >= 1 and tmp[x + 1] >= 1) {

                tmp[x]--, tmp[x + 1]--;

                tmp[2 * x + 1]++;

                flag = 1;

                break;

            }

        }

        if (!flag) return cout << "No\n", void();

    }

    for (auto [x, y] : b) {

        if (tmp[x] < y) return cout << "No\n", void();

    }

    for (auto [x, y] : tmp) {

        if (y > 0 and b[x] == 0) return cout << "No\n", void();

    }

    cout << "Yes\n";

}



int main() {

    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1; cin >> t;

    while (t--) solve();

}





Submission (verdict: Accepted):
#include <iostream>

#include <vector>

#include <queue>

using namespace std;

typedef long long ll;

void solve () {

    ll n, m; cin >> n >> m;

    priority_queue<int> a, b;

    ll sum = 0;

    for (int i = 0, x; i < n; i++) cin >> x, sum += x, a.push(x);

    for (int i = 0, x; i < m; i++) cin >> x, sum -= x, b.push(x);

    if (sum) return cout << "No\n", void();

    int op = n - m;

    while (op--) {

        if (b.size() == 0 or a.size() == 0) break;

        int x = b.top(); b.pop();

        if (a.top() == x) {op++; a.pop(); continue;}

        int y = x / 2;

        x -= y;

        b.push(x), b.push(y);

    }

    while (b.size()) {

        if (a.size() == 0) return cout << "No\n", void();

        if (b.top() != a.top()) return cout << "No\n", void();

        b.pop(), a.pop();

    }

    if (a.size()) return cout << "No\n", void();

    cout << "Yes\n";

}



int main() {

    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1; cin >> t;

    while (t--) solve();

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <vector>

#include <map>

using namespace std;

typedef long long ll;

void solve () {

    int n, m; cin >> n >> m;

    int sum = 0;

    map<int,int> a, b;

    for (int i = 0, x; i < n; i++) cin >> x, sum += x, a[x]++;

    for (int i = 0, x; i < m; i++) cin >> x, sum -= x, b[x]++;

    if (sum != 0) return cout << "No\n", void();

    int op = n - m;

    auto tmp = a;

    while (op--) {

        int flag = 0;

        for (auto [x, y] : tmp) {

            if (tmp[x] >= 2) {

                tmp[x] -= 2, tmp[2 * x]++;

                flag = 1; break;

            }

            if (tmp[x] >= 1 and tmp[x + 1] >= 1) {

                tmp[x]--, tmp[x + 1]--;

                tmp[2 * x + 1]++;

                flag = 1;

                break;

            }

        }

        if (!flag) return cout << "No\n", void();

    }

    for (auto [x, y] : b) {

        if (tmp[x] < y) return cout << "No\n", void();

    }

    for (auto [x, y] : tmp) {

        if (y > 0 and b[x] == 0) return cout << "No\n", void();

    }

    cout << "Yes\n";

}



int main() {

    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1; cin >> t;

    while (t--) solve();

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <vector>

#include <map>

using namespace std;

typedef long long ll;

void solve () {

    int n, m; cin >> n >> m;

    int sum = 0;

    map<int,int> a, b;

    for (int i = 0, x; i < n; i++) cin >> x, sum += x, a[x]++;

    for (int i = 0, x; i < m; i++) cin >> x, sum -= x, b[x]++;

    if (sum != 0) return cout << "No\n", void();

    int op = n - m;

    auto tmp = a;

    while (op--) {

        int flag = 0;

        for (auto [x, y] : tmp) {

            if (tmp[x] >= 2) {

                tmp[x] -= 2, tmp[2 * x]++;

                flag = 1; break;

            }

            if (tmp[x] >= 1 and tmp[x + 1] >= 1) {

                tmp[x]--, tmp[x + 1]--;

                tmp[2 * x + 1]++;

                flag = 1;

                break;

            }

        }

        if (!flag) return cout << "No\n", void();

    }

    for (auto [x, y] : b) {

        if (tmp[x] < y) return cout << "No\n", void();

    }

    for (auto [x, y] : tmp) {

        if (y > 0 and b[x] == 0) return cout << "No\n", void();

    }

    cout << "Yes\n";

}



int main() {

    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1; cin >> t;

    while (t--) solve();

}





Submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <vector>

#include <map>

using namespace std;

typedef long long ll;

void solve () {

    ll n, m; cin >> n >> m;

    ll sum = 0;

    map<ll,ll> a, b;

    for (ll i = 0, x; i < n; i++) cin >> x, sum += x, a[x]++;

    for (ll i = 0, x; i < m; i++) cin >> x, sum -= x, b[x]++;

    if (sum != 0) return cout << "No\n", void();

    ll op = n - m;

    auto tmp = a;

    while (op--) {

        ll flag = 0;

        for (auto [x, y] : tmp) {

            if (tmp[x] >= 2) {

                tmp[x] -= 2, tmp[2 * x]++;

                flag = 1; break;

            }

            if (tmp[x] >= 1 and tmp[x + 1] >= 1) {

                tmp[x]--, tmp[x + 1]--;

                tmp[2 * x + 1]++;

                flag = 1;

                break;

            }

        }

        if (!flag) return cout << "No\n", void();

    }

    for (auto [x, y] : b) {

        if (tmp[x] < y) return cout << "No\n", void();

    }

    for (auto [x, y] : tmp) {

        if (y > 0 and b[x] == 0) return cout << "No\n", void();

    }

    cout << "Yes\n";

}



int main() {

    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1; cin >> t;

    while (t--) solve();

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define si set<int>
#define sll set<long long>
#define sc set<char>
#define ss set<string>
#define usi unordered_set<int>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define pii pair<int, int>
#define pllll pair<long long, long long>
#define f(i,s,e) for(int i = s; i < e; i++)
#define cf(i,s,e) for(int i = s; i <= e; i++)
#define rf(i,e,s) for(int i = e-1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb embrace_back
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)(x).size()
#define fastioa ios::sync_with_stdio(0); cin.tie(0); freopen("a.in", "r", stdin); freopen("a.out", "w", stdout);
#define fastio ios::sync_with_stdio(0); cin.tie(0);
#define MOD 1000000007
#define inf 1e9  // Use for int (e.g., distance)
#define inf_ll 1e18  // Use for long long
#define eps 1e-9  // Precision for floating-point comparisons

void solve()
{
    string number;
    cin >> number;
    vector<int> num;
    int sum = 0;
    int a = 0, b = 0;
    for (char digit : number)
    {
        sum += (digit - '0');
        if (digit - '0' == 2) a++;
        if (digit - '0' == 3) b++;
    }
    f (i, 0, min(8, a + 1))
    {
        f (j, 0, min(8, b + 1))
        {
            if ((sum + i * 2 + j * 6) % 9 == 0)
            {
                cout << "YES" << "\n"; return;
            }
        }
    }
    cout << "No" << "\n";


}
int main()
{
    fastio
    int t; cin >> t;
    while (t --)
    {
        solve();
    }
}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


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

using namespace std;

#define ll long long

#define od(n) (n & 1)

#define loop(k) for (ll i = 0; i < k; i++)

#define out(k) cout << k << endl

ll ceil(ll a, ll b) { return (a + b - 1) / b; }

ll expo(ll a, ll b, ll mod)

{

    ll res = 1;

    while (b > 0)

    {

        if (b & 1)

            res = (res * a) % mod;

        a = (a * a) % mod;

        b = b >> 1;

    }

    return res;

}

ll pow(ll a, ll b)

{

    ll res = 1;

    while (b > 0)

    {

        if (b & 1)

            res = (res * a);

        a = (a * a);

        b = b >> 1;

    }

    return res;

}

ll mo(ll a, ll b) { return (a >= 0) ? a % b : ((a % b) + b) % b; }

void printv(vector<ll> v)

{

    loop(v.size()) cout << v[i] << " ";

    cout << endl;

}

void primeFactor(ll x, map<ll, ll> &mp)

{

    for (ll j = 2; j * j <= x; j++)

    {

        while (x % j == 0)

        {

            mp[j]++;

            x /= j;

        }

    }

    if (x > 1)

        mp[x]++;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    ll t = 1;

    cin >> t;

    ll mod = 1e9;

    while (t--)

    {

        ll n, x, y;

        cin >> n >> x >> y;

        vector<int> v(n, 0);

        if (n & 1)

        {

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

                v[i] = !v[i - 1];

            v[n - 2] = 2;

            v[n - 1] = 1;

            if (v[x - 1] == v[y - 1])

                reverse(v.begin(), v.end());

        }

        else

        {

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

                v[i] = !v[i - 1];

            v[x - 1] = 2;

        }

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

            cout << v[i] << " ";

        cout << endl;

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)

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

#define ll long long

using namespace std;

void solve()

{

    ll n;

    cin >> n;

    string s;

    cin >> s;

    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;

}

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

}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)

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

#define ll long long

using namespace std;

void solve()

{

    ll n;

    cin >> n;

    string s;

    cin >> s;

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

}

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

#define ll long long

using namespace std;

void solve()

{

    ll n;

    cin >> n;

    string s;

    cin >> s;

    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;

}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)


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

#define ll long long

using namespace std;

void solve()

{

    ll n;

    cin >> n;

    string s;

    cin >> s;

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

}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)

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

}

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

        {

            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;

}