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

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

using namespace std;

int main()

{

    int n,i,t,th,sum,p,j,d,b,s;

    char str[100005];

    cin>>s;while(s--){

    cin>>str;

    t=0;th=0;sum=0;

    for(i=0;i<strlen(str);i++)

    {

       // cout<<str[i]-'a'+49<<"\n";

        if((str[i]-'a'+49)==2)

        {

                t=t+1;

        }

          if((str[i]-'a'+49)==3)

        {

            th=th+1;

        }

        sum=sum+str[i]-'a'+49;



    }



    p=0;

    if(sum%9==0)

    {

        p=p+1;

    }

    else

    {



        for(i=0;i<=t;i++)

        for(j=0;j<=th;j++)

        {

            d=2*i+6*j;

            b=sum+d;



            if(b%9==0)

            {

                p=p+1;

            }



        }

    }

    if(p>=1)

    {

        cout<<"YES";

    }else{cout<<"NO";}

    cout<<"\n";

    }

    return 0;

}

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

using namespace std;

int main()

{

    int n,i,t,th,sum,p,j,d,b,s;

    char str[100005];

    cin>>s;while(s--){

    cin>>str;

    t=0;th=0;sum=0;

    for(i=0;i<strlen(str);i++)

    {

       // cout<<str[i]-'a'+49<<"\n";

        if((str[i]-'a'+49)==2)

        {

                t=t+1;

        }

          if((str[i]-'a'+49)==3)

        {

            th=th+1;

        }

        sum=sum+str[i]-'a'+49;



    }



    p=0;

    if(sum%9==0)

    {

        p=p+1;

    }

    else

    {



        for(i=0;i<t+1;i++)

        for(j=0;j<th+1;j++)

        {

            d=2*i+6*j;

            b=sum+d;



            if(b%9==0)

            {

                p=p+1;

                i=t+1;

                j=th+1;

            }



        }

    }

    if(p>=1)

    {

        cout<<"YES";

    }else{cout<<"NO";}

    cout<<"\n";

    }

    return 0;

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


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

using namespace std;

int main()

{

    long long int n,a,b,t=0,th=0,p,i,j,sum,d,s;

    cin>>s;while(s--){

    cin>>n;

    a=n;

    b=0;

    t=0;th=0;

    while(a>0)

    {

      b=b+(a%10);

      if((a%10)==2){t=t+1;}

      if((a%10)==3){th=th+1;}

      a=a/10;

    }





    p=0;

    for(i=0;i<t+1;i++)

    for(j=0;j<th+1;j++)

    {

        sum=b;

        d=2*i+6*j;

        sum=sum+d;



        if(sum%9==0)

        {

            p=1;

            i=t+1;



        }

    }

    if(p==1){cout<<"YES";}else{cout<<"NO";}

        cout<<"\n";

    }



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,p,i,t;
    vector<int>v1;
    cin>>t;while(t--){
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        v1.push_back(m);
    }
    p=0;
    for(i=1;i<=n-2;i++)
    {
        if((v1[i]-min(v1[i],v1[i-1]))<=v1[i+1])
        {
            v1[i]=v1[i]-min(v1[i],v1[i-1]);
        }
        else{p=1;i>n;}
    }
    if(p>=1){cout<<"NO";}else{cout<<"YES";}cout<<"\n";
    v1.clear();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,p,i,t;
    vector<long long int>v1;
    cin>>t;while(t--){
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        v1.push_back(m);
    }

    if(v1.size()>=3){
    p=0;
    for(i=1;i<=n-2;i++)
    {
        if((v1[i]-min(v1[i],v1[i-1]))<=v1[i+1])
        {
            v1[i]=v1[i]-min(v1[i],v1[i-1]);
        }
        else{p=1;i>n;}
    }
    }

    if(v1.size()<=2)
    {
        p=0;
        if(v1[0]<=v1[1]){p=0;}else{p=1;}
    }
    if(p>=1){cout<<"NO";}else{cout<<"YES";}cout<<"\n";
    v1.clear();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,p,i,t;
    vector<int>v1;
    cin>>t;while(t--){
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        v1.push_back(m);
    }
    p=0;
    for(i=1;i<=n-2;i++)
    {
        if((v1[i]-min(v1[i],v1[i-1]))<=v1[i+1])
        {
            v1[i]=v1[i]-min(v1[i],v1[i-1]);
        }
        else{p=1;i>n;}
    }
    if(p>=1){cout<<"NO";}else{cout<<"YES";}cout<<"\n";
    v1.clear();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,p,i,t;
    vector<long long int>v1;
    cin>>t;while(t--){
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        v1.push_back(m);
    }

    if(v1.size()>=3){
    p=0;
    for(i=1;i<=n-2;i++)
    {
        if((v1[i]-min(v1[i],v1[i-1]))<=v1[i+1])
        {
            v1[i]=v1[i]-min(v1[i],v1[i-1]);
        }
        else{p=1;i>n;}
    }
    }

    if(v1.size()<=2)
    {
        p=0;
        if(v1[0]<=v1[1]){p=0;}else{p=1;}
    }
    if(p>=1){cout<<"NO";}else{cout<<"YES";}cout<<"\n";
    v1.clear();
    }
    return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,p,i,t;
    vector<int>v1;
    cin>>t;while(t--){
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        v1.push_back(m);
    }
    p=0;
    if(v1.size()<=2)
    {
        if(v1[0]<=v1[1]){p=0;}else{p=1;}
    }

    if(v1.size()>=3){

    for(i=0;i<=n-2;i++)
    {
      int d=min(v1[i],v1[i+1]);
      v1[i]=v1[i]-d;
      v1[i+1]=v1[i+1]-d;
    }

    for(int k=0;k<v1.size()-1;k++)
    {
      if(v1[k]>v1[k+1])
      {
          p=1;k=v1.size();
      }
    }

    }

    if(p>=1)
    {
        cout<<"NO";
    }
    else{cout<<"YES";}
    v1.clear();cout<<"\n";
}

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

void solve() {
    ll l, r;
    cin >> l >> r;
    ll x = l^r, msb = 0;
    while (x/(1<<msb) > 1) msb++;
    x = r/(1<<msb)*(1<<msb);
    cout << l << " " << x-1 << " " << x << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll 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;
const ll mod = 1e9 + 7;

void solve() {
    ll l, r;
    cin >> l >> r;
    if (l+2 == r) {
        cout << l << " " << l+1 << " " << r << endl;
        return;
    }
    ll x = l^r, msb = 0;
    while (x/(1<<msb) > 1) msb++;
    x = r/(1<<msb)*(1<<msb);
    cout << l << " " << x-1 << " " << x << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t; cin >> t;
    while (t--) 
        solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


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

typedef long long ll;
const ll mod = 1e9 + 7;

void solve() {
    ll l, r;
    cin >> l >> r;
    ll x = l^r, msb = 0;
    while (x/(1<<msb) > 1) msb++;
    x = r/(1<<msb)*(1<<msb);
    cout << l << " " << x-1 << " " << x << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t; cin >> t;
    while (t--) 
        solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

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

typedef long long ll;
const ll mod = 1e9 + 7;

void solve() {
    ll l, r;
    cin >> l >> r;
    if (l+2 == r) {
        cout << l << " " << l+1 << " " << r << endl;
        return;
    }
    ll x = l^r, msb = 0;
    while (x/(1<<msb) > 1) msb++;
    x = r/(1<<msb)*(1<<msb);
    cout << l << " " << x-1 << " " << x << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t; cin >> t;
    while (t--) 
        solve();

    return 0;
}

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

typedef long long ll;
const ll mod = 1e9 + 7;

void solve() {
    ll l, r;
    cin >> l >> r;
    ll x = l^r, msb = 0;
    while (x/(1<<msb) > 1) msb++;
    x = r/(1<<msb)*(1<<msb);
    if (x < r) cout << x-1 << " " << x << " " << r << endl;
    else cout << l << " " << x-1 << " " << x << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t; cin >> t;
    while (t--) 
        solve();

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = n-m;
    for (auto it = bmp.rbegin(); it != bmp.rend() && ops > 0; it++) {
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = min(ops, bfreq-afreq);
        ops -= sfreq;
        bmp[num] -= sfreq;
        if (bmp[num] == 0) bmp.erase(num);
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}

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

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = n-m;
    while (!bmp.empty() && ops > 0) {
        auto it = bmp.rbegin();
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = bfreq-afreq;
        if (ops < sfreq) {
            cout << "NO" << endl;
            return;
        }
        ops -= sfreq;
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
        amp.erase(num);
        bmp.erase(num);
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 12):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = 0;
    for (auto it = bmp.rbegin(); it != bmp.rend() && ops < n-m; it++) {
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = bfreq-afreq;
        bmp[num] -= sfreq;
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}

Submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = n-m;
    for (auto it = bmp.rbegin(); it != bmp.rend() && ops > 0; it++) {
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = min(ops, bfreq-afreq);
        ops -= sfreq;
        bmp[num] -= sfreq;
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 12):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = 0;
    for (auto it = bmp.rbegin(); it != bmp.rend() && ops < n-m; it++) {
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = bfreq-afreq;
        bmp[num] -= sfreq;
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = n-m;
    for (auto it = bmp.rbegin(); it != bmp.rend() && ops > 0; it++) {
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = min(ops, bfreq-afreq);
        ops -= sfreq;
        bmp[num] -= sfreq;
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}

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

#define int long long
const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &it: a) cin >> it;
    for (auto &it: b) cin >> it;
    int asum = accumulate(a.begin(), a.end(), 0);
    int bsum = accumulate(b.begin(), b.end(), 0);
    if (asum != bsum) {
        cout << "NO" << endl;
        return;
    }
    map<int, int> amp, bmp;
    for (auto it: a) amp[it]++;
    for (auto it: b) bmp[it]++;
    int ops = n-m;
    for (auto it = bmp.rbegin(); it != bmp.rend() && ops > 0; it++) {
        int num = it->first, bfreq = it->second;
        int afreq = amp[num];
        if (bfreq < afreq) {
            cout << "NO" << endl;
            return;
        }
        int sfreq = min(ops, bfreq-afreq);
        ops -= sfreq;
        bmp[num] -= sfreq;
        if (bmp[num] == 0) bmp.erase(num);
        bmp[num/2] += sfreq;
        bmp[num - num/2] += sfreq;
    }
    for (auto [num, afreq]: amp) {
        int bfreq = bmp[num];
        if (afreq != bfreq) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t; cin >> t;
    while (t--) 
        solve();

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

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <map>
using namespace std;

bool isDivisibleBy9(long long int n) {
    map<int, long long int> m;
    long long int sum = 0;
    while (n > 0) {
        sum += n % 10;
        if (n % 10 == 2) {
            m[2]++;
        } else if (n % 10 == 3) {
            m[3]++;
        }
        n = n / 10;
    }
    if (sum % 9 == 0) return true;

    for (int i = 0; i < min(10LL, m[2] + 1); i++) {
        for (int j = 0; j < min(10LL, m[3] + 1); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long int n;
        cin >> n;
        if (isDivisibleBy9(n)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <string>
using namespace std;

bool isDivisibleBy9(const string& n) {
    int sum = 0, count2 = 0, count3 = 0;

    // Calculate the sum of digits and count '2's and '3's
    for (char c : n) {
        int digit = c - '0';
        sum += digit;
        if (digit == 2) count2++;
        if (digit == 3) count3++;
    }

    if (sum % 9 == 0) return true;

    // Try replacing some '2's with '4's and '3's with '9's
    for (int i = 0; i <= count2; i++) {
        for (int j = 0; j <= count3; j++) {
            int adjustedSum = sum + i * (4 - 2) + j * (9 - 3);
            if (adjustedSum % 9 == 0) {
                return true;
            }
        }
    }

    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string n;
        cin >> n;
        if (isDivisibleBy9(n)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <map>
using namespace std;

bool isDivisibleBy9(long long int n) {
    map<int, long long int> m;
    long long int sum = 0;
    while (n > 0) {
        sum += n % 10;
        if (n % 10 == 2) {
            m[2]++;
        } else if (n % 10 == 3) {
            m[3]++;
        }
        n = n / 10;
    }
    if (sum % 9 == 0) return true;

   
    for (int i = 0; i <= m[2]; i++) {
        for (int j = 0; j <= m[3]; j++) {
            if ((sum - 2 * i - 3 * j + 4 * i + 9 * j) % 9 == 0) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long int n;
        cin >> n;
        if (isDivisibleBy9(n)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <map>
using namespace std;

bool isDivisibleBy9(long long int n) {
    map<int, long long int> m;
    long long int sum = 0;
    while (n > 0) {
        sum += n % 10;
        if (n % 10 == 2) {
            m[2]++;
        } else if (n % 10 == 3) {
            m[3]++;
        }
        n = n / 10;
    }
    if (sum % 9 == 0) return true;

    for (int i = 0; i < min(10LL, m[2] + 1); i++) {
        for (int j = 0; j < min(10LL, m[3] + 1); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long int n;
        cin >> n;
        if (isDivisibleBy9(n)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}