Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <iostream>

#include <fstream>

#include <string>

#include <vector>

#include <algorithm>

#include <cstdint>

#include <set>

#include <unordered_map>

#include <iomanip>

#include <map>

#include <numeric> 

#include <bitset>

#include <climits>

typedef long long ll;

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define LOO(i,a,b) for (int i = a; i <= b; i++)

using namespace std;

ll MAX = 1e9 + 7;

void iO() {

    freopen("output.txt","w",stdout);

    freopen("input.txt","r",stdin);

}

vector<int> make_sorted_index(vector<int> const& values) {

    vector<int> index(values.size());

    iota(index.begin(), index.end(), 0);

    stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a] < values[b]; } );

    return index;

}



ll iSqrt(ll n) {

    ll lo = 1, hi = min((ll)3037000500, n); // long long

    ll res = 1;

    while(lo <= hi) {

        ll mid = lo + (hi - lo)/2;

        if(mid*mid <= n) {

            res = mid;

            lo = mid + 1;

        }

        else {

            hi = mid - 1;

        }

    }

    return res;

}

bool down(int num, int choice2, int choice3) {

    if (num == 0) {

        return true;

    }

    if (choice2 == 0 && choice3 == 0) {

        return false;

    }

    else if (choice2 == 0) {

        return down((num+6)%9, choice2, choice3 - 1);

    }

    else if (choice3 == 0) {

        return down((num+2)%9, choice2 - 1, choice3);

    }

    else {

        return down((num+2)%9, choice2 - 1, choice3) || down((num + 6)%9, choice2, choice3 - 1);

    }

}

int solve() {

    string n;

    cin >> n;

    int choices2=0;

    int choices3=0;

    int sum_of = 0;

    LOO(i, 0, n.size()-1) {

        if (n[i] == '2') {

            choices2++;

        }

        if (n[i] == '3') {

            choices3++;

        }

        sum_of = (sum_of + n[i] - '0')%9;

    }

    if (down(sum_of, choices2, choices3)) {

        cout << "YES" << endl;

    }

    else {

        cout << "NO" << endl;

    }

    return 0;

}





int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //iO();

    //pre_process();

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

}

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

#include <fstream>

#include <string>

#include <vector>

#include <algorithm>

#include <cstdint>

#include <set>

#include <unordered_map>

#include <iomanip>

#include <map>

#include <numeric> 

#include <bitset>

#include <climits>

typedef long long ll;

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define LOO(i,a,b) for (int i = a; i <= b; i++)

using namespace std;

ll MAX = 1e9 + 7;

void iO() {

    freopen("output.txt","w",stdout);

    freopen("input.txt","r",stdin);

}

vector<int> make_sorted_index(vector<int> const& values) {

    vector<int> index(values.size());

    iota(index.begin(), index.end(), 0);

    stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a] < values[b]; } );

    return index;

}



ll iSqrt(ll n) {

    ll lo = 1, hi = min((ll)3037000500, n); // long long

    ll res = 1;

    while(lo <= hi) {

        ll mid = lo + (hi - lo)/2;

        if(mid*mid <= n) {

            res = mid;

            lo = mid + 1;

        }

        else {

            hi = mid - 1;

        }

    }

    return res;

}



bool down(int num, int choice2, int choice3) {

    LOO(i, 0, min(2, choice2)) {

        LOO(j, 0, min(choice3, 2)) {

            if ((num + 6*j + 2*i)%9 == 0) {

                return true;

            }

        }

    }

    return false;

}

int solve() {

    string n;

    cin >> n;

    int choices2=0;

    int choices3=0;

    int sum_of = 0;

    LOO(i, 0, n.size()-1) {

        if (n[i] == '2') {

            choices2++;

        }

        if (n[i] == '3') {

            choices3++;

        }

        sum_of = (sum_of + n[i] - '0')%9;

    }

    if (down(sum_of, choices2, choices3)) {

        cout << "YES" << endl;

    }

    else {

        cout << "NO" << endl;

    }

    return 0;

}





int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //iO();

    //pre_process();

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

}