ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: c++17 

Code 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n;
const int maxn=2e5+5;
int a[maxn];
signed main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int ans=0,sum=0;
        for(int i=1;i<=n;i+=2)
            ans+=a[i];
        for(int i=2;i<=n;i+=2)
            sum+=a[i];
        if(n%2==0){
            if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans==sum) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }else{
            if(ans%(n/2+1)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans/(n/2+1)==sum/(n/2)) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }
    } 
    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		int a[n + 2]={};
		int sum[n + 2]={};
		int sum1[n  + 2]={};
		int sum2[n  + 2]={};
		for (int j = 0; j < n; j++) {
			cin >> a[j];
		}
		sum[0] = a[0];
		sum1[0] = a[0];
		sum2[1] = a[1];
		for (int j = 1; j < n; j++) {
			sum[j] += sum[j - 1] + a[j];
			cout<<sum[j]<<"  "<<1<<"\n";
		}
		for (int j = 1; j < n; j += 2) {
			sum1[j + 1] += sum1[j - 1] + a[j + 1];
			cout<<sum1[j+1]<<"  "<<2<<"\n";
		}
		for (int j = 1; j < n; j += 2) {
			sum2[j + 2] += sum2[j] + a[j + 2];
			cout<<sum2[j+2]<<"  "<<3<<"\n";
		}
		if (n % 2 == 0) {
if (sum[n-1]%n==0&&sum1[n-2]%(n/2)==0&&sum2[n-1]%(n/2)==0&&sum[n-1]/n==sum1[n-2]/(n/2)&&sum[n-1]/n==sum2[n-1]/(n/2)){
				cout<<"Yes"<<"\n";
			}
			else cout<<"No"<<"\n";
			} 
	
		else {
if (sum[n-1]%n==0&&sum1[n-1]%(n/2+1)==0&&sum2[n-2]%(n/2)==0&&sum[n-1]/n==sum1[n-1]/(n/2+1)&&sum[n-1]/n==sum2[n-2]/(n/2)){
				cout<<"Yes"<<"\n";
			}
			else cout<<"No"<<"\n";
			}
	}

}

Answer: 1
Problem: 2050B - Transfusion
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        float sum_even = 0, sum_odd = 0, count_even = 0, count_odd = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i % 2 == 0)
            {
                sum_even += a[i];
                count_even++;
            }
            else
            {
                sum_odd += a[i];
                count_odd++;
            }
        }
        
        float avg_even = sum_even / count_even;
        float avg_odd = sum_odd / count_odd;
        
        if (fmod(avg_even, 2) != 0 || fmod(avg_odd, 2) != 0)
        {
            cout << "NO" << endl;
        }
        else if (count_even == 0 || count_odd == 0 || avg_even != avg_odd)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
        }
    }

    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

void solve(int t) {
    while (t--) {
        int n;
        cin >> n;
        vector<int> v(n);
        long long oddSum = 0, evenSum = 0, oddCount = 0, evenCount = 0;

        for (int i = 0; i < n; i++) {
            cin >> v[i];
            if (i % 2 == 0) {
                oddSum += v[i];
                oddCount++;
            } else {
                evenSum += v[i];
                evenCount++;
            }
        }

        bool isValid = false;

        if (oddSum % oddCount == 0 && evenSum % evenCount == 0) {
            if (oddSum / oddCount == evenSum / evenCount) {
                isValid = true;
            }
        }

        cout << (isValid ? "YES" : "NO") << endl;
    }
}

int main() {
    int t;
    cin >> t;
    solve(t);
    return 0;
}


Answer: 2
Problem: 2050B - Transfusion
Language: c++23 

Code 1:
#include <bits/stdc++.h>



using namespace std;



typedef vector<int> vi;

typedef vector<long long> vll;

typedef vector<pair<long long, long long>> vpair;

typedef long long ll;

typedef long double lld;

typedef pair<long long, long long> pll;

typedef vector<vector<int>> vvi;

typedef vector<vector<long long>> vvl;





#define f(i, n) for(int i=0; i<n; i++)

#define pb push_back

#define min3(a,b,c) min(a,min(b,c))

#define max3(a,b,c) max(a,max(b,c))

#define nl "\n"

#define ss second

#define ff first

#define mod 1000000007

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





void solve() {

    int n;

    cin >> n;

    

    vll a(n);

    f(i, n) cin >> a[i];

    

    for(int i=1; i<n-1; i++) {

        int diff=a[i+1]-a[i-1];

        

        if(diff>0) {

            a[i-1]+=diff/2;

            a[i+1]-=diff/2;

        }

        else {

            a[i-1]-=(abs(diff)+1)/2;

            a[i+1]+=(abs(diff)+1)/2;

        }

    }

    

    for(int i=0; i<n-1; i++) {

        if(a[i]!=a[i+1]) {

            cout << "No\n";

            return;

        }

    }

    cout << "Yes\n";

}





int main() {

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    

    ll t=1;

    cin>>t;

    while(t--) {

        solve();

    }



    return 0;

}

Code 2:
#include <bits/stdc++.h>



using namespace std;



typedef vector<int> vi;

typedef vector<long long> vll;

typedef vector<pair<long long, long long>> vpair;

typedef long long ll;

typedef long double lld;

typedef pair<long long, long long> pll;

typedef vector<vector<int>> vvi;

typedef vector<vector<long long>> vvl;





#define f(i, n) for(int i=0; i<n; i++)

#define pb push_back

#define min3(a,b,c) min(a,min(b,c))

#define max3(a,b,c) max(a,max(b,c))

#define nl "\n"

#define ss second

#define ff first

#define mod 1000000007

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





void solve() {

    int n;

    cin >> n;

    

    ll odds=0, evens=0, oddSum=0, evenSum=0;

    f(i, n) {

        ll x;

        cin >> x;

        if(i&1) {

            odds++;

            oddSum+=x;

        }

        else {

            evens++;

            evenSum+=x;

        }

    }

    

    if(oddSum%odds==0 && evenSum%evens==0 && oddSum/odds==evenSum/evens) {

        cout << "Yes\n";

    }

    else {

        cout << "No\n";

    }

}





int main() {

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    

    ll t=1;

    cin>>t;

    while(t--) {

        solve();

    }



    return 0;

}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

long long get_sum(long long sum){
    while(sum > 9){
        long long n = sum;
        sum = 0;
        while(n > 0){
            sum += n%10;
            n /= 10;
        }
    }
    return sum;
}

void solve(string s){
    long long arr[s.size()];
    long long sum = 0,two = 0,three = 0;
    for(int i = 0;i < s.size();i++){
        arr[i] = s[i] - '0';
        sum += arr[i];
        if(arr[i] == 2)two++;
        else if(arr[i] == 3)three++;
    }
    sum = get_sum(sum);
    for(int i = 0;i < min(10,two + 1);i++){
        for(int j = 0;j < min(10,three + 1);j++){
            if((sum + i*2 + j*3)%9 == 0){
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
    return;
}


int main(){
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        solve(s);
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>

using namespace std;

long long get_sum(long long sum){
    while(sum > 9){
        long long n = sum;
        sum = 0;
        while(n > 0){
            sum += n%10;
            n /= 10;
        }
    }
    return sum;
}

void solve(string s){
    long long arr[s.size()];
    long long sum = 0;
    int two = 0,three = 0;
    for(int i = 0;i < s.size();i++){
        arr[i] = s[i] - '0';
        sum += arr[i];
        if(arr[i] == 2)two++;
        else if(arr[i] == 3)three++;
    }
    sum = get_sum(sum);
    for(int i = 0;i < min(10,two + 1);i++){
        for(int j = 0;j < min(10,three + 1);j++){
            if((sum + i*2 + j*6)%9 == 0){
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
    return;
}


int main(){
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        solve(s);
    }
    return 0;
}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: python

Code 1:
testCases = int(input())
for i in range(testCases):
    two = 0
    three = 0
    total = 0
    number = input()
    for j in number:
        
        if j == "2":
            two += 1
        elif j == "3":
            three += 1
        total += int(j)
    total = total % 9
    if total == 0:
        print("YES")
    elif total == 3 and three >= 1 or total == 6 and three >= 2:
        print("YES")
    elif (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
        print("YES")
    elif three >= 2:
        total += 3
        total = total % 9
        if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
            print("YES")
        else:
            print("NO")
    elif three >= 1:
        total += 6
        total = total % 9
        if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
    


Code 2:
testCases = int(input())
for i in range(testCases):
    two = 0
    three = 0
    total = 0
    number = input()
    for j in number:
        
        if j == "2":
            two += 1
        elif j == "3":
            three += 1
        total += int(j)
    total = total % 9
    if total == 0:
        print("YES")
    elif total == 3 and three >= 1 or total == 6 and three >= 2:
        print("YES")
    elif (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
        print("YES")
    elif three >= 2:
        total += 3
        total = total % 9
        if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
            print("YES")
        else:
            total += 3
            total = total % 9
            if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
                    print("YES")
            else:
                print("NO")
    elif three >= 1:
        total += 6
        total = total % 9
        if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
    


Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++20 

Code 1:
#include <bits/stdc++.h>



using namespace std;



int main(){

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.length(), r = 0, c2 = 0, c3 = 0;

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

            c2 += s[i] == '2';

            c3 += s[i] == '3';

            r = (r + s[i] - '0') % 9;

        }

        cout << r << " " << c2 << " " << c3 << endl;

        bool flag = false;

        for(int i = 0; i <= min(c2, 8); i++){

            for(int j = 0; j <= min(2, c3); j++)    if((r + i + i + j + j + j) % 9 == 0){

                flag = true;

                break;

            }

            if(flag)    break;

        }

        cout << (flag? "YES": "NO") << endl;

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>



using namespace std;



int main(){

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.length(), r = 0, c2 = 0, c3 = 0;

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

            c2 += s[i] == '2';

            c3 += s[i] == '3';

            r = (r + s[i] - '0') % 9;

        }

        bool flag = false;

        for(int i = 0; i <= min(c2, 8); i++){

            for(int j = 0; j <= min(2, c3); j++)    if((r + i + i + j * 6) % 9 == 0){

                flag = true;

                break;

            }

            if(flag)    break;

        }

        cout << (flag? "YES": "NO") << endl;

    }

    return 0;

}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
#define M "MUHA"
#define all(x) x.begin(),x.end()
#define ssd ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn = 1e5+5,N=20,mod = 1e9+7;
void solve(){
    int n;
    cin >>n;
    int cal2=0,cal3=0;
    int cal=0;
    string s = to_string(n);
    for(int i=0;i<s.size();i++){
        cal+=s[i]-'0';
        if(s[i]=='2')cal2++;
        if(s[i]=='3')cal3++;
    }
    if(cal%9==0){
        cout<<"YES"<<'\n';
        return;
    }
    int c2=10,c3=10;
    c2 = min(c2,cal2);c3 = min(c3, cal3);
    for(int i=0;i<=c3;i++){
        for(int j=0;j<=c2;j++){
            if((i*6+j*2+cal)%9==0){
                cout<<"YES"<<'\n';
                return;
            }
        }
    }
    cout<<"NO"<<'\n';
}
signed main(){
    //freopen("lepus.in", "r", stdin);
    //freopen("lepus.out",   "w", stdout);
    ssd
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++){
        //cout<<"Case "<<i<<":"<<'\n';
        solve();
    }
}


Code 2:
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
#define M "MUHA"
#define all(x) x.begin(),x.end()
#define ssd ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn = 1e5+5,N=20,mod = 1e9+7;
void solve(){
    string s;
    cin >>s;
    int cal2=0,cal3=0;
    int cal=0;
    for(int i=0;i<s.size();i++){
        cal+=s[i]-'0';
        if(s[i]=='2')cal2++;
        if(s[i]=='3')cal3++;
    }
    
    if(cal%9==0){
        cout<<"YES"<<'\n';
        return;
    }
    int c2=10,c3=10;
    c2 = min(c2, cal2);
    c3 = min(c3, cal3);
    for(int i=0;i<=c3;i++){
        for(int j=0;j<=c2;j++){
            if((i*6+j*2+cal)%9==0){
                cout<<"YES"<<'\n';
                return;
            }
        }
    }
    cout<<"NO"<<'\n';
}
signed main(){
    //freopen("lepus.in", "r", stdin);
    //freopen("lepus.out",   "w", stdout);
    ssd
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++){
        //cout<<"Case "<<i<<":"<<'\n';
        solve();
    }
}


Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include<bits/stdc++.h>



using namespace std;



#define ll long long



void solve(){

    string s;

    cin>>s;

    int c2 = 0, c3 = 0, sum = 0;

    for(int i=0; i<s.size(); i++){

        if(s[i] == '2')c2++;

        else if(s[i] == '3')c3++;

        sum += int(s[i]-'0');

    }

    function<bool()> check = [&]() -> bool {

        int r = (9-sum%9)%9;

        c3 %= 3;

        c2 %= 9;

        if(c2 >= (r*5)%9)return true;

        if(c3 > 0 && c2 >= ((r+3)*5)%9)return true;

        if(c3 > 1 && c2 >= ((r+6)*5)%9)return true;

        return false;

    };

    cout<<(check() ? "YES" : "NO")<<"\n";

}



int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

Code 2:
#include<bits/stdc++.h>



using namespace std;



#define ll long long



void solve(){

    string s;

    cin>>s;

    int c2 = 0, c3 = 0, sum = 0;

    for(int i=0; i<s.size(); i++){

        if(s[i] == '2')c2++;

        else if(s[i] == '3')c3++;

        sum += int(s[i]-'0');

    }

    function<bool()> check = [&]() -> bool {

        for(int i=0; i<=min(c2, 9); i++){

            for(int j=0; j<=min(c3, 9); j++){

                if((sum+2*i+6*j) % 9 == 0)return true;

            }

        }

        return false;

    };

    cout<<(check() ? "YES" : "NO")<<"\n";

}



int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define int long long

bool fn(int num_2, int num_6, int sum){

    vector<bool> dp(9,false);
    dp[sum] = true;

    for(int i=0;i<=num_2;i++){
        for(int j=0;j<=num_6;j++){
            if(i==0 && j==0){
                continue;
            }
            int num = sum + 2*i + 6*j;
            num%=9;
            dp[num] = true;
        }
    }

    return dp[0];   
}


main(){

    cin.tie(0);
    ios::sync_with_stdio(0);

    int t;
    
    cin>>t;

    while(t--){
        string s;

        cin>>s;

        int n = s.size();
        int num_2 = 0;
        int num_6 = 0;

        int sum = 0;

        for(int i=0;i<n;i++){
            int num = s[i] - '0';
            sum += num;

            if(num==2){
                num_2++;
            }

            if(num==3){
                num_6++;
            }
        }
        sum%=9;
        
        if(fn(num_2,num_6,sum)){
            cout<<"YES"<<endl;
        }

        else{
            cout<<"NO"<<endl;
        }

    }

    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define int long long

bool fn(int num_2, int num_6, int sum){

    vector<bool> dp(9,false);
    dp[sum] = true;

    for(int i=0;i<=min((int)18,num_2);i++){
        for(int j=0;j<=min(num_6,(int)3);j++){
            if(i==0 && j==0){
                continue;
            }
            int num = sum + 2*i + 6*j;
            num%=9;
            dp[num] = true;
        }
    }

    return dp[0];   
}


main(){

    cin.tie(0);
    ios::sync_with_stdio(0);

    int t;
    
    cin>>t;

    while(t--){
        string s;

        cin>>s;

        int n = s.size();
        int num_2 = 0;
        int num_6 = 0;

        int sum = 0;

        for(int i=0;i<n;i++){
            int num = s[i] - '0';
            sum += num;

            if(num==2){
                num_2++;
            }

            if(num==3){
                num_6++;
            }
        }
        sum%=9;
        
        if(fn(num_2,num_6,sum)){
            cout<<"YES"<<endl;
        }

        else{
            cout<<"NO"<<endl;
        }

    }

    return 0;
}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string n;
        cin >> n;
        vector<int> digits;
        int sum = 0;
        for (char c : n) {
            int digit = c - '0';  
            digits.push_back(digit);
            sum += digit;  
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        int count2 = 0, count3 = 0;
        for (int digit : digits) {
            if (digit == 2) count2++;
            if (digit == 3) count3++;
        }
        bool possible = false;
        for (int i = 0; i <= count2 && !possible; i++) { 
            for (int j = 0; j <= count3 && !possible; j++) { 
                int newSum = sum + i * 2 + j * 6;
                if (newSum % 9 == 0) {
                    possible = true;
                    break;
                }
            }
        }
        if (possible) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        ll n;
        cin >> n;

        vector<int> digits;
        ll sum = 0;

        while (n > 0) {
            ll temp = n % 10;
            digits.push_back(temp);
            sum += temp;
            n /= 10;
        }

        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }

        ll count2 = 0, count3 = 0;
        for (int digit : digits) {
            if (digit == 2) count2++;
            if (digit == 3) count3++;
        }
        bool possible = false;
        for (ll i = 0; i <= count2 && !possible; i++) { 
            for (ll j = 0; j <= count3 && !possible; j++) { 
                ll newSum = sum + i * 2 + j * 6;
                if (newSum % 9 == 0) {
                    possible = true;
                    break;
                }
            }
            if(possible){break;}
        }

        if (possible) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Answer: 1
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    /* ll n;
    cin >> n;
    string s = to_string(n); */
    string s;
    cin >> s;
    ll sum = 0LL;
    ll _2 = 0, _3 = 0;
    for (auto it : s)
    {
        sum += it - '0';
        if (it == '2')
            _2++;
        else if (it == '3')
            _3++;
    }
    if (sum % 9 == 0)
    {
        cout << "YES" << endl;
        return;
    }
    else
    {
        for (ll i = 0; i <= _2; i++)
        {
            for (ll j = 0; j <= _3; j++)
            {
                if ((sum + (2 * i) + (6 * j)) % 9 == 0)
                {
                    cout << "YES" << endl;
                    return;
                }
            }
        }
        cout << "NO" << endl;
        return;
    }
}
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    ll n;
    cin >> n;
    string s = to_string(n);
    ll sum = 0LL;
    ll _2 = 0, _3 = 0;
    for (auto it : s)
    {
        sum += it - '0';
        if (it == '2')
            _2++;
        else if (it == '3')
            _3++;
    }
    if (sum % 9 == 0)
    {
        cout << "YES" << endl;
        return;
    }
    else
    {
        for (ll i = 0; i <= _2; i++)
        {
            for (ll j = 0; j <= _3; j++)
            {
                if ((sum + 2 * i + 6 * j) % 9 == 0)
                {
                    cout << "YES" << endl;
                    return;
                }
            }
        }
        cout << "NO" << endl;
        return;
    }
}
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}


Answer: 1
Problem: 2050C - Uninteresting Number
Language: other

Code 1:
import Control.Monad (forM_)

main :: IO ()
main = do
  t <- readLn :: IO Int
  forM_ [1 .. t] $ \_ -> do
    n <- getLine
    putStrLn (solveStr n)

solveStr inp = if solve inp then "YES" else "NO"

solve :: String -> Bool
solve num =
  let (num2, num3) = (numDigits '2' num, numDigits '3' num)
   in checkPossible num2 num3 (sumDigits num)

checkPossible :: Int -> Int -> Int -> Bool
checkPossible num2 num3 total
  | min num2 num3 < 0 = False
  | total `mod` 9 == 0 = True
  | otherwise = checkPossible (num2 - 1) num3 (total + 2) || checkPossible num2 (num3 - 1) (total + 6)

numDigits :: Char -> [Char] -> Int
numDigits target = length . filter (== target)

sumDigits :: [Char] -> Int
sumDigits str = sum (map convertToInt str)
  where
    convertToInt c = read [c] :: Int


Code 2:
import Control.Monad (forM_)

main :: IO ()
main = do
  t <- readLn :: IO Int
  forM_ [1 .. t] $ \_ -> do
    n <- getLine
    putStrLn (solveStr n)

solveStr inp = if solve inp then "YES" else "NO"

solve :: String -> Bool
solve num =
  let (num2, num3) = (numDigits '2' num, numDigits '3' num)
   in checkPossible num2 num3 num2 num3 (sumDigits num)

checkPossible num2 num3 num2In num3In total
  | num2In - num2 > 9 = False
  | num3In - num3 > 9 = False
  | min num2 num3 < 0 = False
  | total `mod` 9 == 0 = True
  | otherwise = checkPossible (num2 - 1) num3 num2In num3In (total + 2) || checkPossible num2 (num3 - 1) num2In num3In (total + 6)

numDigits :: Char -> [Char] -> Int
numDigits target = length . filter (== target)

sumDigits :: [Char] -> Int
sumDigits str = sum (map convertToInt str)
  where
    convertToInt c = read [c] :: Int


Answer: 2