ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
def is_divi9 (num):
    s = sum(num)
    if s % 9 == 0:
        return "YES"
    for i in range(len(num)):
        if 1 < num[i] < 4 :
            if (s + num[i] ** 2 - num[i]) % 9 == 0:
                return "YES"
    for i in range(len(num)):
        if 1 < num[i] < 4:
            num[i] = num[i]**2
    if sum(num) % 9 == 0:
        return "YES"
    return "NO"
t = int(input())
lis = [0] * t
for i in range(t):
    lis[i] = [int(digit) for digit in input()]
for i in range(t):
    print(is_divi9(lis[i]))



Submission (verdict: Wrong answer on test 2):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # اگر مجموع اولیه بر 9 بخش‌پذیر باشد
        return "YES"
    
    # مرحله 1: بررسی جایگزینی هر رقم به‌صورت جداگانه
    for i in range(len(num)):
        if num[i] in (2, 3):  # فقط ارقام 2 و 3 بررسی شوند
            squared_digit = num[i] ** 2
            new_s = s - num[i] + squared_digit  # مجموع جدید
            if new_s % 9 == 0:  # بررسی بخش‌پذیری مجموع جدید
                return "YES"

    # مرحله 2: بررسی جایگزینی همه اعداد 2 و 3 به‌صورت همزمان
    new_num = [x**2 if x in (2, 3) else x for x in num]  # همه اعداد 2 و 3 جایگزین شوند
    if sum(new_num) % 9 == 0:  # بررسی بخش‌پذیری مجموع جدید
        return "YES"
    
    # اگر هیچ‌کدام از شرایط موفق نبود
    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
def is_divi9 (num):
    s = sum(num)
    if s % 9 == 0:
        return "YES"
    for i in range(len(num)):
        if num[i] < 4 :
            if (s + num[i] ** 2 - num[i]) % 9 == 0:
                return "YES"
    for i in range(len(num)):
        if num[i] < 4:
            num[i] = num[i]**2
    if sum(num) % 9 == 0:
        return "YES"
    return "NO"
t = int(input())
lis = [0] * t
for i in range(t):
    lis[i] = [int(digit) for digit in input()]
for i in range(t):
    print(is_divi9(lis[i]))
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # اگر مجموع اولیه بر 9 بخش‌پذیر باشد
        return "YES"
    
    # مرحله 1: بررسی جایگزینی هر رقم به‌صورت جداگانه
    for i in range(len(num)):
        if num[i] in (2, 3):  # فقط ارقام 2 و 3 بررسی شوند
            squared_digit = num[i] ** 2
            new_s = s - num[i] + squared_digit  # مجموع جدید
            if new_s % 9 == 0:  # بررسی بخش‌پذیری مجموع جدید
                return "YES"

    # مرحله 2: بررسی جایگزینی همه اعداد 2 و 3 به‌صورت همزمان
    new_num = [x**2 if x in (2, 3) else x for x in num]  # همه اعداد 2 و 3 جایگزین شوند
    if sum(new_num) % 9 == 0:  # بررسی بخش‌پذیری مجموع جدید
        return "YES"
    
    # اگر هیچ‌کدام از شرایط موفق نبود
    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


Submission (verdict: Time limit exceeded on test 3):
from itertools import product

def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # پیدا کردن ایندکس ارقام 2 و 3
    indices = [i for i in range(len(num)) if num[i] in (2, 3)]
    # تولید تمام ترکیب‌های ممکن از تغییر
    for changes in product((0, 1), repeat=len(indices)):  # 0: تغییر نکن، 1: تغییر کن
        new_s = s  # شروع از مجموع اولیه
        for idx, change in zip(indices, changes):
            if change == 1:  # اگر قرار است این رقم تغییر کند
                new_s += num[idx] ** 2 - num[idx]
        if new_s % 9 == 0:  # بررسی بخش‌پذیری مجموع جدید
            return "YES"
    
    return "NO"  # اگر هیچ حالتی موفق نبود

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
def is_divi9 (num):
    s = sum(num)
    if s % 9 == 0:
        return "YES"
    for i in range(len(num)):
        if num[i] < 4 :
            if (s + num[i] ** 2 - num[i]) % 9 == 0:
                return "YES"
    for i in range(len(num)):
        if num[i] < 4:
            num[i] = num[i]**2
    if sum(num) % 9 == 0:
        return "YES"
    return "NO"
t = int(input())
lis = [0] * t
for i in range(t):
    lis[i] = [int(digit) for digit in input()]
for i in range(t):
    print(is_divi9(lis[i]))



Submission (verdict: Wrong answer on test 2):
def is_divi9 (num):
    s = sum(num)
    if s % 9 == 0:
        return "YES"
    for i in range(len(num)):
        if 1 < num[i] < 4 :
            if (s + num[i] ** 2 - num[i]) % 9 == 0:
                return "YES"
    for i in range(len(num)):
        if 1 < num[i] < 4:
            num[i] = num[i]**2
    if sum(num) % 9 == 0:
        return "YES"
    return "NO"
t = int(input())
lis = [0] * t
for i in range(t):
    lis[i] = [int(digit) for digit in input()]
for i in range(t):
    print(is_divi9(lis[i]))
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long

#define pb push_back

#define F first

#define S second

#define coy cout<<"YES\n"

#define con cout<<"NO\n"

#define co1 cout<<"-1\n"

#define all(x) x.begin(),x.end()

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using namespace __gnu_pbds;

const int SI=3e5+7;

ll INF=8e18+7;

int MOD=998244353;





string a ,b ,c;

int sa,sb,sc;

int memo[1010][1010];







int dp(int i,int j) {

    if(i >= sa-1 && j >= sb-1)return 0;



    int &ret = memo[i][j];

    if (ret != -1) return ret;

    int top =1e9, bot=1e9;

    if (i < sa) top = dp(i+1,j) + (a[i+1] != c[i+1+j]);

    if (j < sb) bot = dp(i,j+1) + (b[j+1] != c[i+j+1]);



    return ret = min(top,bot);

}





void solve() {

    cin >> a >> b >> c;

    a = "0" + a;

    b = "0" + b;

    c = "0" + c;

    sa=a.size();

    sb=b.size();

    sc=c.size();

    memset(memo,-1,sizeof(memo));



    int ans = dp(0,0);



    cout << ans << endl;



}







int main() {

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

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

    fast

    int t= 1;

    cin >> t;

    while (t--) solve();



}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long

#define pb push_back

#define F first

#define S second

#define coy cout<<"YES\n"

#define con cout<<"NO\n"

#define co1 cout<<"-1\n"

#define all(x) x.begin(),x.end()

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using namespace __gnu_pbds;

const int SI=3e5+7;

ll INF=8e18+7;

int MOD=998244353;





string a ,b ,c;

int sa,sb,sc;

int memo[2010][2010];







int dp(int i,int j) {

    if(i >= sa-1 && j >= sb-1)return 0;



    int &ret = memo[i][j];

    if (ret != -1) return ret;



    int top =1e4, bot=1e4;

    if (i < sa) top = dp(i+1,j) + (a[i] != c[i+j]);

    if (j < sb) bot = dp(i,j+1) + (b[j] != c[i+j]);



    return ret = min(top,bot);

}





void solve() {

    cin >> a >> b >> c;

    sa=a.size();

    sb=b.size();

    sc=c.size();

    memset(memo,-1,sizeof(memo));



    int ans = dp(0,0);



    cout << ans << endl;



}







int main() {

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

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

    fast

    int t= 1;

    cin >> t;

    while (t--) solve();



}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long

#define pb push_back

#define F first

#define S second

#define coy cout<<"YES\n"

#define con cout<<"NO\n"

#define co1 cout<<"-1\n"

#define all(x) x.begin(),x.end()

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using namespace __gnu_pbds;

const int SI=3e5+7;

ll INF=8e18+7;

int MOD=998244353;





string a ,b ,c;

int sa,sb,sc;

int memo[1010][1010];







int dp(int i,int j) {

    if(i >= sa-1 && j >= sb-1)return 0;



    int &ret = memo[i][j];

    if (ret != -1) return ret;

    int top =1e9, bot=1e9;

    if (i < sa) top = dp(i+1,j) + (a[i+1] != c[i+1+j]);

    if (j < sb) bot = dp(i,j+1) + (b[j+1] != c[i+j+1]);



    return ret = min(top,bot);

}





void solve() {

    cin >> a >> b >> c;

    a = "0" + a;

    b = "0" + b;

    c = "0" + c;

    sa=a.size();

    sb=b.size();

    sc=c.size();

    memset(memo,-1,sizeof(memo));



    int ans = dp(0,0);



    cout << ans << endl;



}







int main() {

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

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

    fast

    int t= 1;

    cin >> t;

    while (t--) solve();



}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long

#define pb push_back

#define F first

#define S second

#define coy cout<<"YES\n"

#define con cout<<"NO\n"

#define co1 cout<<"-1\n"

#define all(x) x.begin(),x.end()

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using namespace __gnu_pbds;

const int SI=3e5+7;

ll INF=8e18+7;

int MOD=998244353;





string a ,b ,c;

int sa,sb,sc;

int memo[2010][2010];







int dp(int i,int j) {

    if(i >= sa-1 && j >= sb-1)return 0;



    int &ret = memo[i][j];

    if (ret != -1) return ret;



    int top =1e4, bot=1e4;

    if (i < sa) top = dp(i+1,j) + (a[i] != c[i+j]);

    if (j < sb) bot = dp(i,j+1) + (b[j] != c[i+j]);



    return ret = min(top,bot);

}





void solve() {

    cin >> a >> b >> c;

    sa=a.size();

    sb=b.size();

    sc=c.size();

    memset(memo,-1,sizeof(memo));



    int ans = dp(0,0);



    cout << ans << endl;



}







int main() {

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

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

    fast

    int t= 1;

    cin >> t;

    while (t--) solve();



}



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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long

#define pb push_back

#define F first

#define S second

#define coy cout<<"YES\n"

#define con cout<<"NO\n"

#define co1 cout<<"-1\n"

#define all(x) x.begin(),x.end()

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using namespace __gnu_pbds;

const int SI=3e5+7;

ll INF=8e18+7;

int MOD=998244353;





string a ,b ,c;

int sa,sb,sc;

int memo[2010][2010];







int dp(int i,int j) {

    if(i == sa && j == sb)return 0;



    int &ret = memo[i][j];

    if (ret != -1) return ret;



    int top =1e4, bot=1e4;

    if (i < sa) top = dp(i+1,j) + (a[i] != c[i+j]);

    if (j < sb) bot = dp(i,j+1) + (b[j] != c[i+j]);



    return ret = min(top,bot);

}





void solve() {

    cin >> a >> b >> c;

    sa=a.size();

    sb=b.size();

    sc=c.size();

    memset(memo,-1,sizeof(memo));



    int ans = dp(0,0);



    cout << ans << endl;



}







int main() {

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

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

    fast

    int t= 1;

    cin >> t;

    while (t--) solve();



}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int pos = 0;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            if ((abs(a[0] - a[n - 1]) < a[n - 1]) && (abs(a[0] - a[n - 1]) < a[n - 2]))
            {
                pos = 1;
            }
        }

        if (pos)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

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

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        int pos = 1, k = 0;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            while (k != 5)
            {
                for (ll i = 0; i < n - 1; i++)
                {
                    ll MIN = min(a[i], a[i + 1]);
                    a[i] -= MIN;
                    a[i + 1] -= MIN;
                }
                k++;
            }
            if (!is_sorted(a.begin(), a.end()))
            {
                pos = 0;
            }
        }

        if (pos)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int pos = 0, k = 1;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            if (abs(a[0] - a[n - 1] < a[n - 1]))
            {
                pos = 1;
            }
        }

        if (pos)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

Submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int pos = 0, k = 1;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            if ((abs(a[0] - a[n - 1]) < a[n - 1]) && (abs(a[0] - a[n - 1]) < a[n - 2]))
            {
                pos = 1;
            }
        }

        if (pos)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}v
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int pos = 0, k = 1;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            if ((abs(a[0] - a[n - 1]) < a[n - 1]) && (abs(a[0] - a[n - 1]) < a[n - 2]))
            {
                pos = 1;
            }
        }

        if (pos)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}v

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

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int pos = 0;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            if ((abs(a[0] - a[n - 1]) < a[n - 1]) && (abs(a[0] - a[n - 1]) < a[n - 2]))
            {
                pos = 1;
            }
        }

        if (pos)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

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

    ll t;

    cin >> t;

    while (t--)
    {

        ll n;
        cin >> n;

        vector<ll> a(n);

        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int pos = 0, k = 1;
        if (is_sorted(a.begin(), a.end()))
        {
            pos = 1;
        }
        else
        {
            if (abs(a[0] - a[n - 1] < a[n - 1]))
            {
                pos = 1;
            }
        }

        if (pos)
            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 <cstring>
#include <cmath>

using namespace std;

const int N = 1e4 + 10;
char a[N];

int main()
{
    int n;
    cin >> n;
    while (n --)
    {
        int tows = 0, threes = 0;
        scanf("%s",a);
        int len = strlen(a);
        int sum = 0;
        for (int i = 0; i < len; i ++)
        {
            if (a[i] == '2') tows ++;
            else if (a[i] == '3') threes ++;
            sum = sum + a[i] - '0';
        }
        
        bool flag = false;
        for (int i = 0; i < min(tows + 1, 9); i ++)
            for (int j = 0; j < min(threes + 1, 9); j ++)
            {
                if ((sum + i * 2 + j * 6) % 9 == 0)
                {
                    puts("yes");
                    flag = true;
                    break;
                }
            }
        if (!flag) puts("no");
    }
    return 0;
}

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

using namespace std;

const int N = 1e4 + 10;
char a[N];

int main()
{
    int n;
    cin >> n;
    while (n --)
    {
        int tows = 0, threes = 0;
        scanf("%s",a);
        int len = strlen(a);
        long long sum = 0;
        for (int i = 0; i < len; i ++)
        {
            if (a[i] == '2') tows ++;
            else if (a[i] == '3') threes ++;
            sum = sum + a[i] - '0';
        }
        
        bool flag = false;
        for (int i = 0; i < min(tows + 1, 9); i ++)
            for (int j = 0; j < min(threes + 1, 9); j ++)
            {
                if ((long long)(sum + i * 2 + j * 6) % 9 == 0)
                {
                    puts("yes");
                    flag = true;
                    break;
                }
            }
        if (!flag) puts("no");
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


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

using namespace std;

const int N = 1e4 + 10;
char a[N];

int main()
{
    int n;
    cin >> n;
    while (n --)
    {
        int tows = 0, threes = 0;
        scanf("%s",a);
        int len = strlen(a);
        int sum = 0;
        for (int i = 0; i < len; i ++)
        {
            if (a[i] == '2') tows ++;
            else if (a[i] == '3') threes ++;
            sum = sum + a[i] - '0';
        }
        
        bool flag = false;
        for (int i = 0; i < min(tows + 1, 9); i ++)
            for (int j = 0; j < min(threes + 1, 9); j ++)
            {
                if ((sum + i * 2 + j * 6) % 9 == 0)
                {
                    puts("yes");
                    flag = true;
                    break;
                }
            }
        if (!flag) puts("no");
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

const int N = 1e4 + 10;
char a[N];

int main()
{
    int n;
    cin >> n;
    while (n --)
    {
        int tows = 0, threes = 0;
        scanf("%s",a);
        int len = strlen(a);
        long long sum = 0;
        for (int i = 0; i < len; i ++)
        {
            if (a[i] == '2') tows ++;
            else if (a[i] == '3') threes ++;
            sum = sum + a[i] - '0';
        }
        
        bool flag = false;
        for (int i = 0; i < min(tows + 1, 9); i ++)
            for (int j = 0; j < min(threes + 1, 9); j ++)
            {
                if ((long long)(sum + i * 2 + j * 6) % 9 == 0)
                {
                    puts("yes");
                    flag = true;
                    break;
                }
            }
        if (!flag) puts("no");
    }
    return 0;
}

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

using namespace std;

const int N = 1e5 + 10;
char a[N];

int main()
{
    int n;
    cin >> n;
    while (n --)
    {
        int tows = 0, threes = 0;
        scanf("%s",a);
        int len = strlen(a);
        long long sum = 0;
        for (int i = 0; i < len; i ++)
        {
            if (a[i] == '2') tows ++;
            else if (a[i] == '3') threes ++;
            sum = sum + a[i] - '0';
        }
        
        bool flag = false;
        for (int i = 0; i < min(tows + 1, 9); i ++)
            for (int j = 0; j < min(threes + 1, 9); j ++)
            {
                if ((long long)(sum + i * 2 + j * 6) % 9 == 0)
                {
                    puts("yes");
                    flag = true;
                    break;
                }
            }
        if (!flag) puts("no");
    }
    return 0;
}