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

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

using namespace std;

void solve() {
    string number;
    cin >> number;

    int digitSum = 0;
    for (const auto c : number) {
        digitSum += c - '0';
    }

    if (digitSum % 9 == 0) {
        cout << "YES" << endl;
        return;
    }
    // 0 => 0
    // 1 => 1
    // 2 => 4 +2
    // 3 => 9 +6
    int twos = 0, threes = 0;
    for (const auto c : number) {
        if (c == '2') {
            twos++;
        } else if (c == '3') {
            threes++;
        }
    }

    int originalDigitSum = digitSum;

    for (int i = 0; i < threes; i++) {
        digitSum += 6;
        if (digitSum % 9 == 0) {
            cout << "YES" << endl;
            return;
        }
    }
    if (twos == 0) {
        cout << "NO" << endl;
        return;
    }

    digitSum = originalDigitSum;

    digitSum += 2;
    for (int i = 0; i < threes; i++) {
        digitSum += 6;
        if (digitSum % 9 == 0) {
            cout << "YES" << endl;
            return;
        }
    }

    if (twos == 1) {
        cout << "NO" << endl;
        return;
    }

    digitSum = originalDigitSum;

    digitSum += 4;
    for (int i = 0; i < threes; i++) {
        digitSum += 6;
        if (digitSum % 9 == 0) {
            cout << "YES" << endl;
            return;
        }
    }

    if (twos == 2) {
        cout << "NO" << endl;
        return;
    }

    digitSum = originalDigitSum;
    twos += (3*threes);

    for (int i = 0; i < twos; i++) {
        digitSum += 2;
        if (digitSum % 9 == 0) {
            cout << "YES" << endl;
            return;
        }
    }

    cout << "NO" << endl;
}

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }

    return 0;
}

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

using namespace std;

bool canConvert(int digitSum, int occurance, int value) {
    if (digitSum % 9 == 0) {
        return true;
    }
    for (int i = 0; i < occurance; i++) {
        digitSum += value;
        if (digitSum % 9 == 0) {
            return true;
        }
    }
    return false;
}

void solve() {
    string number;
    cin >> number;

    int digitSum = 0;
    for (const auto c : number) {
        digitSum += c - '0';
    }

    if (digitSum % 9 == 0) {
        cout << "YES" << endl;
        return;
    }
    // 0 => 0
    // 1 => 1
    // 2 => 4 +2
    // 3 => 9 +6
    int twos = 0, threes = 0;
    for (const auto c : number) {
        if (c == '2') {
            twos++;
        } else if (c == '3') {
            threes++;
        }
    }

    if (canConvert(digitSum, threes, 6)) {
        cout << "YES" << endl;
        return;
    }

    if (twos >= 1) {
        if (canConvert(digitSum+2, threes, 6)) {
            cout << "YES" << endl;
            return;
        }
    }

    if (twos >= 2) {
        if (canConvert(digitSum+4, threes, 6)) {
            cout << "YES" << endl;
            return;
        }

        twos += (3*threes);
        if (canConvert(digitSum, twos, 2)) {
            cout << "YES" << endl;
            return;
        }
    }

    cout << "NO" << endl;
}

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }

    return 0;
}