ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


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

#include<cstdio>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#define no cout<<"NO\n";

#define yes cout<<"YES\n";

#define ll long long

using namespace std;

using namespace __gnu_pbds;

template<class T>

using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

//ll lcm(ll a,ll b){return (a/__gcd(a,b))*1LL*b;}

map<ll,ll>mp;

bool rec(ll a,ll b,ll cnt)

{

    if(!cnt)return 1;

    if(!a||!b)return 0;

    mp[a+b]+=cnt;

    int o=mp[a],z=mp[b];

    mp[a]-=cnt;

    mp[b]-=cnt;

    if(a==b)

    {

        if(mp[a]<2*cnt)

        {

            return rec(a/2,a/2+a%2,cnt-o/2);

        }

    }

    else

    {

        if(mp[a]<cnt)

        {

            return rec(a/2,a/2+a%2,cnt-o);

        }

        if(mp[b]<cnt)

        {

            return rec(b/2,b/2+b%2,cnt-z);

        }

    }

}

int main()

{

	ios_base::sync_with_stdio(NULL);

	cin.tie(0); cout.tie(0);

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

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

	int t;

	cin>>t;

	while(t--)

    {

        mp.clear();

        ll n,m,x;

        cin>>n>>m;

        set<ll>st;

        map<ll,ll>mp1,mp2;

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

            cin>>x,st.insert(x),mp1[x]++;

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

            cin>>x,st.insert(x),mp2[x]++;

        bool f=0;

        for(auto it:st)

        {

            if(mp1[it]==mp2[it])continue;

            if(mp1[it]<mp2[it])

            {

                x=mp2[it]-mp1[it];

                if(!rec(it/2,it/2+it%2,x)){f=1;break;}

                else {mp[it]-=x,mp1[it]=mp2[it];}

                continue;

            }

            x=mp1[it]-mp2[it];

            mp1[it]=mp2[it];

            mp[it]+=x;

        }

        for(auto [u,v] : mp)

        {

            if(v){f=1;break;}

        }

        if(f)no

        else yes

    }

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


Submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
#define take(x)       \
    for (auto &y : x) \
        cin >> y;
#define show(x)           \
    for (auto y : x)      \
        cout << y << " "; \
    cout << endl;
#define pb push_back
#define max3(a, b, c) max(max((a), (b)), (c))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min(min((a), (b)), (c))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define all(v) v.begin(), v.end()
ll M = 998244353;
ll mod = 1e9 + 7;

void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    map<ll,ll> mp;
    priority_queue<ll> pq;
    for(int i = 0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(all(a));
    for(int i = 0;i<m;i++)
    {
        cin>>b[i];
        pq.push(b[i]);
    }
    int used = 0;
    while(!pq.empty()||used < n)
    {
        if(pq.size() > n){
            cout<<"No"<<endl;
            return;
        }
        if(pq.top() < a[0])
        {
            cout<<"No"<<endl;
            return;
        }
        int tp = pq.top();
        pq.pop();
        if(mp[tp]>=1)
        {
            mp[tp]--;
            used++;
            continue;
        }
        if(tp&1)
        {
            ll x = (tp+1)/2;
            ll y = tp - x;
            if(mp[x]>=1 && mp[y]>=1)
            {
                used += 2;
                mp[x]--;
                mp[y]--;
                continue;
            }
            else if(mp[x]>=1)
            {
                used+=1;
                mp[x]--;
                pq.push(y);
                continue;
            }
            else if(mp[y]>=1)
            {
                used+=1;
                mp[y]--;
                pq.push(x);
                continue;
            }
            else
            {
                pq.push(x);
                pq.push(y);
                continue;
            }
        }
        else
        {
            ll x = (tp+1)/2;
            ll y = tp - x;
            if(mp[x]>=1 && mp[y]>=1)
            {
                used += 2;
                mp[x]--;
                mp[y]--;
                continue;
            }
            else if(mp[x]>=1)
            {
                used+=1;
                mp[x]--;
                pq.push(y);
                continue;
            }
            else if(mp[y]>=1)
            {
                used+=1;
                mp[y]--;
                pq.push(x);
                continue;
            }
            else
            {
                pq.push(x);
                pq.push(y);
                continue;
            }
        }

    }
    if(pq.empty()) 
    {
        cout<<"Yes"<<endl;
        return;
    }
    cout<<"No"<<endl;
    return;
}

int main()
{
    int tt;
    cin >> tt;
    while (tt--)
    {
        solve();
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

char s[N];
int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        for (int i = 1; i <= n; i ++) {
            int k = 0;
            for (int j = 1; j <= 9 && i + j <= n; j ++) {
                if (s[i + j] - j >= s[i + k]) k = j;
            }
            putchar(s[i + k] - k);
            for (int j = i + k; j > i; j --) s[j] = s[j - 1];
        }
        puts("");
    }
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

char s[N];
int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        for (int i = 1; i <= n; i ++) {
            int k = 0;
            for (int j = 1; j <= 9 && i + j <= n; j ++) {
                if (s[i + j] - j >= s[i + k]) k = j;
            }
            if (s[i + k] - k == s[i]) k = 0;
            putchar(s[i + k] - k);
            for (int j = i + k; j > i; j --) s[j] = s[j - 1];
        }
        puts("");
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

string s;
int main() {
    int T;
    cin >> T;
    while (T --) {
        cin >> s;
        for (int j = 0; j < 20; j ++) {
            for (int i = s.size() - 1; i; i --)
                if (s[i] - 1 > s[i - 1]) {
                    s[i] --;
                    swap(s[i], s[i - 1]);
                }
        }
        cout << s << '\n';
    }
    return 0;
}

Submission (verdict: Accepted):
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

string s;
int main() {
    int T;
    cin >> T;
    while (T --) {
        cin >> s;
        for (int i = 1; i < s.size(); i ++) {
            for (int j = i; j; j --)
                if (s[j] > s[j - 1] + 1) {
                    s[j] --;
                    swap(s[j], s[j - 1]);
                } else {
                    break;
                }
        }
        cout << s << '\n';
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

char s[N];
int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        for (int i = 1; i <= n; i ++) {
            int k = 0;
            for (int j = 1; j <= 9 && i + j <= n; j ++) {
                if (s[i + j] - j >= s[i + k]) k = j;
            }
            if (s[i + k] - k == s[i]) k = 0;
            putchar(s[i + k] - k);
            for (int j = i + k; j > i; j --) s[j] = s[j - 1];
        }
        puts("");
    }
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

string s;
int main() {
    int T;
    cin >> T;
    while (T --) {
        cin >> s;
        for (int j = 0; j < 10; j ++) {
            for (int i = s.size() - 1; i; i --)
                if (s[i] - 1 > s[i - 1]) {
                    s[i] --;
                    swap(s[i], s[i - 1]);
                }
        }
        cout << s << '\n';
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

char s[N];
int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        for (int i = 1; i <= n; i ++) {
            int k = 0;
            for (int j = 1; j <= 9 && i + j <= n; j ++) {
                if (s[i + j] - j >= s[i + k]) k = j;
            }
            putchar(s[i + k] - k);
            for (int j = i + k; j > i; j --) s[j] = s[j - 1];
        }
        puts("");
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

string s;
int main() {
    int T;
    cin >> T;
    while (T --) {
        cin >> s;
        for (int j = 0; j < 10; j ++) {
            for (int i = s.size() - 1; i; i --)
                if (s[i] - 1 > s[i - 1]) {
                    s[i] --;
                    swap(s[i], s[i - 1]);
                }
        }
        cout << s << '\n';
    }
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

string s;
int main() {
    int T;
    cin >> T;
    while (T --) {
        cin >> s;
        for (int j = 0; j < 20; j ++) {
            for (int i = s.size() - 1; i; i --)
                if (s[i] - 1 > s[i - 1]) {
                    s[i] --;
                    swap(s[i], s[i - 1]);
                }
        }
        cout << s << '\n';
    }
    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;
using ll = long long;
using pi = pair<ll,ll>;

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) a += i;
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << r << ' ' << a << ' ';
    if (a + 1 == r) cout << a-1 << '\n';
    else cout << a+1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}

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

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) {
                a += i;
                if (b - i >= l) b -= i;
            }
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << b << ' ' << a << ' ';
    if (a + 1 == b) cout << a-1 << '\n';
    else cout << a+1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}
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;
using ll = long long;
using pi = pair<ll,ll>;

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) {
                a += i;
                if (b - i >= l) b -= i;
            }
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << b << ' ' << a << ' ';
    if (a + 1 == b) cout << a-1 << '\n';
    else cout << a+1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll,ll>;

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) {
                a += i;
                if (b - i >= l) b -= i;
            }
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << b << ' ' << a << ' ';
    if (r != b && r != a) cout << r << '\n';
    else if (r-1 != b && r-1 != a) cout << r-1 << '\n';
    else cout << r-2 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}
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;
using ll = long long;
using pi = pair<ll,ll>;

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) a += i;
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << r << ' ' << a << ' ' << a << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll,ll>;

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) a += i;
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << r << ' ' << a << ' ';
    if (a + 1 == r) cout << a-1 << '\n';
    else cout << a+1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}
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;
using ll = long long;
using pi = pair<ll,ll>;

void solve() {
    ll l, r, i = (1LL << 30), a = 0, b;
    cin >> l >> r;
    b = r;
    while (i) {
        if (b & i) {
            if (a + i - 1 < l) a += i;
        } else {
            if (a+i<=r) a += i;
        }
        i /= 2;
    }
    cout << r << ' ' << a << ' ' << a << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        solve();
        t--;
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

vector <ll> v;
vector <vector<ll>> r;

void solve() {
    ll n, i, l1, l2, j = 0;
    cin >> n;
    r.clear();
    v.clear();
    r.resize(n);
    v.resize(n);
    for (i = 1; i < n; i++) {
        cin >> l1 >> l2;
        r[--l1].push_back(--l2);
        r[l2].push_back(l1);
    }
    for (i = 0; i < n; i++) {
        v[i] = r[i].size();
        if (v[j] < v[i]) j = i;
    }
    l1 = v[j];
    v[j] = 0;
    for (ll y : r[j]) v[y]--;
    cout << l1 + *max_element(v.begin(), v.end()) - 1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        t--;
        solve();
    }
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll,ll>;

vector <ll> v;
vector <vector<ll>> r;

ll F(ll u) {
    ll res = v[u], mx;
    for (ll y : r[u]) v[y]--;
    v[u] = 0;
    mx = *max_element(v.begin(), v.end());
    v[u] = res;
    for (ll y : r[u]) v[y]++;
    return mx+res-1;
}

void solve() {
    ll n, i, l1, l2, j = 0;
    cin >> n;
    r.clear();
    v.clear();
    r.resize(n);
    v.resize(n);
    vector <pi> vv;
    for (i = 1; i < n; i++) {
        cin >> l1 >> l2;
        r[--l1].push_back(--l2);
        r[l2].push_back(l1);
    }
    for (i = 0; i < n; i++) {
        v[i] = r[i].size();
        vv.push_back({v[i], i});
    }
    sort(vv.begin(), vv.end());
    cout << max(F(vv.back().second), F(vv[n-2].second)) << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        t--;
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll,ll>;

vector <vector<ll>> r;

bool F(ll v, ll u) {
    for (ll y : r[u]) {
        if (v == y) return 1;
    }
    return 0;
}

void solve() {
    ll n, i, v, u, a1, a2, a3;
    cin >> n;
    r.clear();
    r.resize(n);
    for (i = 1; i < n; i++) {
        cin >> v >> u;
        r[--v].push_back(--u);
        r[u].push_back(v);
    }
    vector <pi> vv(n);
    vector <ll> ff;
    for (i = 0; i < n; i++) vv[i] = {r[i].size(), i};
    sort(vv.begin(), vv.end());
    if (n == 2) {
            cout << "0\n";
    return;
    }
    a1 = vv.back().second;
    a2 = vv[n-2].second;
    a3 = vv[n-3].second;
    ff = {r[a1].size() + r[a2].size(), r[a2].size() + r[a3].size(), r[a1].size() + r[a3].size()};
    if (F(a1, a2)) ff[0]--;
    if (F(a2, a3)) ff[1]--;
    if (F(a1, a3)) ff[2]--;
    cout << max(max(ff[0], ff[1]), ff[2]) -1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        t--;
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

vector <vector<ll>> r;

bool F(ll v, ll u) {
    for (ll y : r[u]) {
        if (v == y) return 1;
    }
    return 0;
}

void solve() {
    ll n, i, v, u, a1, a2, a3;
    cin >> n;
    r.clear();
    r.resize(n);
    for (i = 1; i < n; i++) {
        cin >> v >> u;
        r[--v].push_back(--u);
        r[u].push_back(v);
    }
    vector <pi> vv(n);
    vector <ll> ff;
    for (i = 0; i < n; i++) vv[i] = {r[i].size(), i};
    sort(vv.begin(), vv.end());
    if (n == 2) {
            cout << "0\n";
    return;
    }
    a1 = vv.back().second;
    a2 = vv[n-2].second;
    a3 = vv[n-3].second;
    ff = {r[a1].size() + r[a2].size(), r[a2].size() + r[a3].size(), r[a1].size() + r[a3].size()};
    if (F(a1, a2)) ff[0]--;
    if (F(a2, a3)) ff[1]--;
    if (F(a1, a3)) ff[2]--;
    cout << max(max(ff[0], ff[1]), ff[2]) -1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        t--;
        solve();
    }
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll,ll>;

vector <ll> v;
vector <vector<ll>> r;

void solve() {
    ll n, i, l1, l2, j = 0;
    cin >> n;
    r.clear();
    v.clear();
    r.resize(n);
    v.resize(n);
    for (i = 1; i < n; i++) {
        cin >> l1 >> l2;
        r[--l1].push_back(--l2);
        r[l2].push_back(l1);
    }
    for (i = 0; i < n; i++) {
        v[i] = r[i].size();
        if (v[j] < v[i]) j = i;
    }
    l1 = v[j];
    v[j] = 0;
    for (ll y : r[j]) v[y]--;
    cout << l1 + *max_element(v.begin(), v.end()) - 1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t) {
        t--;
        solve();
    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? need%6 : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}

Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? (need%6 == 0 ? 6 :need%6) : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? need%6 : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}