ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: Python 3

Previous submission (verdict: Wrong answer on test 3):
'''
Observations:

- After a reversal, you must replace the sequence with its difference sequence as otherwise nothing has been done to the sum.
- The different sequence replacement reduces the length of the sequence by 1 so we can only do it a fixed number of times.

Therefore, if we brute-force:
Options are:
1. Nothing (current sum)
2. Reverse + difference
3. Difference
'''

from math import inf
from functools import lru_cache

def get_difference_sequence(path):
    return [path[i] - path[i - 1] for i in range(1, len(path))]

@lru_cache(None)
def backtrack(length, path):
    if length == 0:
        return -inf
    
    # Convert tuple back to list for processing
    path = list(path)
    
    # Reverse + Difference
    reverse_path = path[::-1]
    diff_path = get_difference_sequence(reverse_path)
    curr = sum(diff_path)
    ans = max(curr, backtrack(length - 1, tuple(diff_path)))
    
    # Difference only
    diff_path = get_difference_sequence(path)
    curr = sum(diff_path)
    
    return max(ans, backtrack(length - 1, tuple(diff_path)))

t = int(input())

while t > 0:
    n = int(input())
    a = tuple(map(int, input().split()))
    s = sum(a)
    
    if n == 1:
        print(s)
    else:
        print(max(s, backtrack(n, a)))
    
    t -= 1

Submission (verdict: Accepted):
'''
Observations:

- After a reversal, you must replace the sequence with its difference sequence as otherwise nothing has been done to the sum.
- The different sequence replacement reduces the length of the sequence by 1 so we can only do it a fixed number of times.

Therefore, if we brute-force:
Options are:
1. Nothing (current sum)
2. Reverse + difference
3. Difference
'''

from math import inf
from functools import lru_cache

def get_difference_sequence(path):
    return [path[i] - path[i - 1] for i in range(1, len(path))]

@lru_cache(None)
def backtrack(length, path):
    if length == 0:
        return -inf
    
    # Convert tuple back to list for processing
    path = list(path)
    
    # Reverse + Difference
    reverse_path = path[::-1]
    diff_path = get_difference_sequence(reverse_path)
    curr = sum(diff_path)
    ans = max(curr, backtrack(length - 1, tuple(diff_path)))
    
    # Difference only
    diff_path = get_difference_sequence(path)
    curr = sum(diff_path)
    
    return max(ans, curr, backtrack(length - 1, tuple(diff_path)))

t = int(input())

while t > 0:
    n = int(input())
    a = tuple(map(int, input().split()))
    s = sum(a)
    
    if n == 1:
        print(s)
    else:
        print(max(s, backtrack(n, a)))
    
    t -= 1
Problem: 2062C - Cirno and Operations
Language: Python 3


Submission (verdict: Time limit exceeded on test 2):
'''
Observations:

- After a reversal, you must replace the sequence with its difference sequence as otherwise nothing has been done to the sum.
- The different sequence replacement reduces the length of the sequence by 1 so we can only do it a fixed number of times.

Therefore, if we brute-force:
Options are:
1. Nothing (current sum)
2. Reverse + difference
3. Difference
'''

from math import inf

def backtrack(length, path):
    if length == 0:
        return -inf
        
    # reverse + Difference
    reverse_path = path[::-1]
    diff_path = []
    curr = 0
    
    for i in range(1, len(reverse_path)):
        diff_path.append(reverse_path[i] - reverse_path[i - 1])
        curr += diff_path[-1]
    
    ans = max(curr, backtrack(length - 1, diff_path))
    
    # difference
    diff_path = []
    curr = 0
    
    for i in range(1, len(path)):
        diff_path.append(path[i] - path[i - 1])
        curr += diff_path[-1]
    
    return max(ans, backtrack(length - 1, diff_path))

t = int(input())

while t > 0:
    n = int(input())
    a = list(map(int, input().split(' ')))
    s = sum(a)
    
    if n == 1:
        print(s)
    else:
        print(max(s, backtrack(n, a)))
    
    t -= 1
Problem: 2062C - Cirno and Operations
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 2):
'''
Observations:

- After a reversal, you must replace the sequence with its difference sequence as otherwise nothing has been done to the sum.
- The different sequence replacement reduces the length of the sequence by 1 so we can only do it a fixed number of times.

Therefore, if we brute-force:
Options are:
1. Nothing (current sum)
2. Reverse + difference
3. Difference
'''

from math import inf

def backtrack(length, path):
    if length == 0:
        return -inf
        
    # reverse + Difference
    reverse_path = path[::-1]
    diff_path = []
    curr = 0
    
    for i in range(1, len(reverse_path)):
        diff_path.append(reverse_path[i] - reverse_path[i - 1])
        curr += diff_path[-1]
    
    ans = max(curr, backtrack(length - 1, diff_path))
    
    # difference
    diff_path = []
    curr = 0
    
    for i in range(1, len(path)):
        diff_path.append(path[i] - path[i - 1])
        curr += diff_path[-1]
    
    return max(ans, backtrack(length - 1, diff_path))

t = int(input())

while t > 0:
    n = int(input())
    a = list(map(int, input().split(' ')))
    s = sum(a)
    
    if n == 1:
        print(s)
    else:
        print(max(s, backtrack(n, a)))
    
    t -= 1

Submission (verdict: Wrong answer on test 3):
'''
Observations:

- After a reversal, you must replace the sequence with its difference sequence as otherwise nothing has been done to the sum.
- The different sequence replacement reduces the length of the sequence by 1 so we can only do it a fixed number of times.

Therefore, if we brute-force:
Options are:
1. Nothing (current sum)
2. Reverse + difference
3. Difference
'''

from math import inf
from functools import lru_cache

def get_difference_sequence(path):
    return [path[i] - path[i - 1] for i in range(1, len(path))]

@lru_cache(None)
def backtrack(length, path):
    if length == 0:
        return -inf
    
    # Convert tuple back to list for processing
    path = list(path)
    
    # Reverse + Difference
    reverse_path = path[::-1]
    diff_path = get_difference_sequence(reverse_path)
    curr = sum(diff_path)
    ans = max(curr, backtrack(length - 1, tuple(diff_path)))
    
    # Difference only
    diff_path = get_difference_sequence(path)
    curr = sum(diff_path)
    
    return max(ans, backtrack(length - 1, tuple(diff_path)))

t = int(input())

while t > 0:
    n = int(input())
    a = tuple(map(int, input().split()))
    s = sum(a)
    
    if n == 1:
        print(s)
    else:
        print(max(s, backtrack(n, a)))
    
    t -= 1
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

using namespace std;

const int MAXN=2e5+10;

int T, n, num[MAXN], k, maxn, ans;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		ans=1;
		cin>>n;
		for(int i=1; i<=n; i++) e[i].clear();
		for(int i=1; i<=n; i++) num[i]=0;
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
			num[u]++;num[v]++;
		}
		k=0;maxn=0;
		for(int i=1; i<=n; i++) {
			if(num[i]>maxn) {
				k=i;maxn=num[i];
			}
		}
		ans+=maxn-1;
		for(auto x:e[k]) {
			num[x]--;
		}
		num[k]=0;
		sort(num+1, num+n+1, greater<int>());
		ans+=num[1]-1;
		cout<<ans<<'\n';
	}
	return 0;
}

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

using namespace std;

const int MAXN=2e5+10;

int T, n, num[MAXN], k, maxn, ans, md;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		ans=1;
		cin>>n;
		for(int i=1; i<=n; i++) e[i].clear();
		for(int i=1; i<=n; i++) num[i]=0;
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
			num[u]++;num[v]++;
		}
		k=0;maxn=0;md=0;
		for(int i=1; i<=n; i++) {
			if(num[i]>maxn) {
				k=i;maxn=num[i];
			}
			md=max(md, num[i]);
		}
		if(md==2 && n>=5) {
			cout<<3<<'\n';
			continue;
		}
		ans+=maxn-1;
		for(auto x:e[k]) {
			num[x]--;
		}
		num[k]=0;
		sort(num+1, num+n+1, greater<int>());
		ans+=num[1]-1;
		cout<<ans<<'\n';
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

using namespace std;

const int MAXN=2e5+10;

int T, n, num[MAXN], k, maxn, ans, md;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		ans=1;
		cin>>n;
		for(int i=1; i<=n; i++) e[i].clear();
		for(int i=1; i<=n; i++) num[i]=0;
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
			num[u]++;num[v]++;
		}
		k=0;maxn=0;md=0;
		for(int i=1; i<=n; i++) {
			if(num[i]>maxn) {
				k=i;maxn=num[i];
			}
			md=max(md, num[i]);
		}
		if(md==2 && n>=5) {
			cout<<3<<'\n';
			continue;
		}
		ans+=maxn-1;
		for(auto x:e[k]) {
			num[x]--;
		}
		num[k]=0;
		sort(num+1, num+n+1, greater<int>());
		ans+=num[1]-1;
		cout<<ans<<'\n';
	}
	return 0;
}

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

using namespace std;

const int MAXN=2e5+10;

multiset<int> s;
int deg[MAXN], T, n, ans, tmp;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		cin>>n;
		ans=1;
		s.clear();
		for(int i=1; i<=n; i++) deg[i]=0, e[i].clear();
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			deg[u]++;deg[v]++;
			e[u].push_back(v);
			e[v].push_back(u);
		}
		if(n==2) {
			cout<<0<<'\n';
			continue;
		}
		for(int i=1; i<=n; i++) s.insert(deg[i]);
		for(int i=1; i<=n; i++) {
			tmp=1;
			tmp+=deg[i]-1;
			s.erase(s.find(deg[i]));
			for(auto v : e[i]) {
				s.erase(s.find(deg[v]));
				s.insert(deg[v]-1);
			}
			tmp+=(*(--s.end()))-1;
			ans=max(ans, tmp);
			for(auto v : e[i]) {
				s.erase(s.find(deg[v]-1));
				s.insert(deg[v]);
			}
			s.insert(deg[i]);
		}
		cout<<ans<<'\n';
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

using namespace std;

const int MAXN=2e5+10;

int T, n, num[MAXN], k, maxn, ans;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		ans=1;
		cin>>n;
		for(int i=1; i<=n; i++) num[i]=0;
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
			num[u]++;num[v]++;
		}
		k=0;maxn=0;
		for(int i=1; i<=n; i++) {
			if(num[i]>maxn) {
				k=i;maxn=num[i];
			}
		}
		ans+=maxn-1;
		for(auto x:e[k]) {
			num[x]--;
		}
		num[k]=0;
		sort(num+1, num+n+1, greater<int>());
		ans+=num[1]-1;
		cout<<ans<<'\n';
	}
	return 0;
}

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

using namespace std;

const int MAXN=2e5+10;

int T, n, num[MAXN], k, maxn, ans;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		ans=1;
		cin>>n;
		for(int i=1; i<=n; i++) e[i].clear();
		for(int i=1; i<=n; i++) num[i]=0;
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
			num[u]++;num[v]++;
		}
		k=0;maxn=0;
		for(int i=1; i<=n; i++) {
			if(num[i]>maxn) {
				k=i;maxn=num[i];
			}
		}
		ans+=maxn-1;
		for(auto x:e[k]) {
			num[x]--;
		}
		num[k]=0;
		sort(num+1, num+n+1, greater<int>());
		ans+=num[1]-1;
		cout<<ans<<'\n';
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


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

using namespace std;

const int MAXN=2e5+10;

int T, n, num[MAXN], k, maxn, ans;
vector<int> e[MAXN];

int main() {
	cin>>T;
	while(T--) {
		ans=1;
		cin>>n;
		for(int i=1; i<=n; i++) num[i]=0;
		for(int i=1; i<n; i++) {
			int u, v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
			num[u]++;num[v]++;
		}
		k=0;maxn=0;
		for(int i=1; i<=n; i++) {
			if(num[i]>maxn) {
				k=i;maxn=num[i];
			}
		}
		ans+=maxn-1;
		for(auto x:e[k]) {
			num[x]--;
		}
		num[k]=0;
		sort(num+1, num+n+1, greater<int>());
		ans+=num[1]-1;
		cout<<ans<<'\n';
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;

void solve(){
    string s; 
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        int mx = s[i] - '0';
        int id = i;
        for(int j=i+1; j<n; j++){
            // cout<<mx<<" "<<s[j] - (j-i)<<" <<\n";
            if(s[j] - '0' - (j-i) > mx){
                mx = s[j] - '0' - (j-i);
                id = j;
            }
        } 
        // cout<<i<<" "<<s[i]<<" "<<mx - '0' <<endl;

        while(id>i){
            s[id] = s[id - 1];
            id--;
        }
        s[i] = mx+'0';
    }

    cout<<s<<endl;
}

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


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;

void solve(){
    string s; 
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        int mx = s[i] - '0';
        int id = i;
        for(int j=i+1; j< min(i+10, n); j++){
            // cout<<mx<<" "<<s[j] - (j-i)<<" <<\n";
            if(s[j] - '0' - (j-i) > mx){
                mx = s[j] - '0' - (j-i);
                id = j;
            }
        } 
        // cout<<i<<" "<<s[i]<<" "<<mx - '0' <<endl;

        while(id>i){
            s[id] = s[id - 1];
            id--;
        }
        s[i] = mx+'0';
    }

    cout<<s<<endl;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;

void solve(){
    string s; 
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        int mx = s[i];
        int id = i;
        for(int j=i+1; j<n; j++){
            // cout<<mx<<" "<<s[j] - (j-i)<<" <<\n";
            if(s[j] - (j-i) > mx){
                mx = s[j] - (j-i);
                id = j;
            }
        } 
        // cout<<i<<" "<<s[i]<<" "<<mx - '0' <<endl;

        while(id>i){
            s[id] = s[id - 1];
            id--;
        }
        s[i] = mx;
    }

    cout<<s<<endl;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;

void solve(){
    string s; 
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        int mx = s[i];
        int id = i;
        for(int j=i+1; j<n; j++){
            // cout<<mx<<" "<<s[j] - (j-i)<<" <<\n";
            if(s[j] - (j-i) > mx){
                mx = s[j] - (j-i);
                id = j;
            }
        } 
        // cout<<i<<" "<<s[i]<<" "<<mx - '0' <<endl;

        while(id>i){
            s[id] = s[id - 1];
            id--;
        }
        s[i] = mx;
    }

    cout<<s<<endl;
}

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


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;

void solve(){
    string s; 
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        int mx = s[i] - '0';
        int id = i;
        for(int j=i+1; j<n; j++){
            // cout<<mx<<" "<<s[j] - (j-i)<<" <<\n";
            if(s[j] - '0' - (j-i) > mx){
                mx = s[j] - '0' - (j-i);
                id = j;
            }
        } 
        // cout<<i<<" "<<s[i]<<" "<<mx - '0' <<endl;

        while(id>i){
            s[id] = s[id - 1];
            id--;
        }
        s[i] = mx+'0';
    }

    cout<<s<<endl;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(n) for(int i=0;i<n;i++)
#define pb push_back
const int mod = 1e9+7;
 
void solve(){
int n;
cin>>n;
int a[n];
loop(n) cin>>a[i];
// if(a[0]>a[1]) {
// cout<<"NO"<<endl;
// return;
// }
int ans=1;
loop(n-1){
if(a[i]<a[i+1]) continue;
else{
a[i]-=a[i-1];
if(a[i]>a[i+1]){
cout<<"NO"<<endl;
return;
}
}
}
cout<<"YES"<<endl;

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

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(n) for(int i=0;i<n;i++)
#define pb push_back
const int mod = 1e9+7;
 
void solve(){
int n;
cin>>n;
int a[n];
loop(n) cin>>a[i];
int ans=1;
if(a[0]>a[1]) ans=0;
else{
for(int i=0;i<n-1;i++){
int mini=min(a[i],a[i+1]);
a[i]-=mini;
a[i+1]-=mini;
}
}
loop(n-1){
if(a[i]>a[i+1]){ans=0;break;}
}
if(ans==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
 
int32_t main(){
int t;
cin>>t;
while(t--) solve();
return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(n) for(int i=0;i<n;i++)
#define pb push_back
const int mod = 1e9+7;
 
void solve(){
int n;
cin>>n;
int a[n];
loop(n) cin>>a[i];
if(a[0]>a[1]) {
cout<<"NO"<<endl;
return;
}
int ans=1;
loop(n-1){
if(a[i]<a[i+1]) continue;
else{
a[i]-=a[i-1];
if(a[i]>a[i+1]){
cout<<"NO"<<endl;
return;
}
}
}
cout<<"YES"<<endl;

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

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(n) for(int i=0;i<n;i++)
#define pb push_back
const int mod = 1e9+7;
 
void solve(){
int n;
cin>>n;
int a[n];
loop(n) cin>>a[i];
// if(a[0]>a[1]) {
// cout<<"NO"<<endl;
// return;
// }
int ans=1;
loop(n-1){
if(a[i]<a[i+1]) continue;
else{
a[i]-=a[i-1];
if(a[i]>a[i+1]){
cout<<"NO"<<endl;
return;
}
}
}
cout<<"YES"<<endl;

}
 
int32_t main(){
int t;
cin>>t;
while(t--) solve();
return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(n) for(int i=0;i<n;i++)
#define pb push_back
const int mod = 1e9+7;
 
void solve(){
int n;
cin>>n;
int a[n];
loop(n) cin>>a[i];
if(a[0]>a[1]) {
cout<<"NO"<<endl;
return;
}
int ans=1;
loop(n-1){
if(a[i]<a[i+1]) continue;
else{
a[i]-=a[i-1];
if(a[i]>a[i+1]){
cout<<"NO"<<endl;
return;
}
}
}
cout<<"YES"<<endl;

}
 
int32_t main(){
int t;
cin>>t;
while(t--) solve();
return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define f(n) for(int i=0;i<n;i++)
#define in(n) long long n; cin>>n;

void solve() {
    in(n);
    long long sum = 0;
    int c2 = 0, c3 = 0;
    // cout<<n<<" ";
    // Calculate the sum of digits and count of 2's and 3's
    while (n > 0) {
        int digit = n % 10;
        sum += digit;
        if (digit == 2) c2++;
        if (digit == 3) c3++;
        n /= 10;
    }
    
    // cout<<sum<<" ";
    for (int i = 0; i <=min(10,c2); i++) {
        for (int j =0; j <= min(10,c3); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                cout<< "YES\n";
                return;
            }
        }
    }
    
    cout << "NO\n";
}

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

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


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define f(n) for(int i=0;i<n;i++)
#define in(n) long long n; cin>>n;

void solve() {
    in(n);
    long long sum = 0;
    int c2 = 0, c3 = 0;
    // cout<<n<<" ";
    // Calculate the sum of digits and count of 2's and 3's
    while (n > 0) {
        int digit = n % 10;
        sum += digit;
        if (digit == 2) c2++;
        if (digit == 3) c3++;
        n /= 10;
    }
    
    // cout<<sum<<" ";
    for (int i = 0; i <=min(9,c2); i++) {
        for (int j =0; j <= min(2,c3); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                cout<< "YES\n";
                return;
            }
        }
    }
    
    cout << "NO\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define f(n) for(int i=0;i<n;i++)
#define in(n) long long n; cin>>n;

void solve() {
    in(n);
    long long sum = 0;
    int c2 = 0, c3 = 0;
    // cout<<n<<" ";
    // Calculate the sum of digits and count of 2's and 3's
    while (n > 0) {
        int digit = n % 10;
        sum += digit;
        if (digit == 2) c2++;
        if (digit == 3) c3++;
        n /= 10;
    }
    
    // cout<<sum<<" ";
    for (int i = 0; i <=min(8,c2); i++) {
        for (int j =0; j <= min(8,c3); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                cout<< "YES\n";
                return;
            }
        }
    }
    
    cout << "NO\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define f(n) for(int i=0;i<n;i++)
#define in(n) long long n; cin>>n;

void solve() {
    in(n);
    long long sum = 0;
    int c2 = 0, c3 = 0;
    // cout<<n<<" ";
    // Calculate the sum of digits and count of 2's and 3's
    while (n > 0) {
        int digit = n % 10;
        sum += digit;
        if (digit == 2) c2++;
        if (digit == 3) c3++;
        n /= 10;
    }
    
    // cout<<sum<<" ";
    for (int i = 0; i <=min(9,c2); i++) {
        for (int j =0; j <= min(2,c3); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                cout<< "YES\n";
                return;
            }
        }
    }
    
    cout << "NO\n";
}

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

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


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define f(n) for(int i=0;i<n;i++)
#define in(n) long long n; cin>>n;

void solve() {
    string s;cin>>s;
    int n=s.size();
    int sum=0,c2=0,c3=0;
    for(auto&i:s)
    {
        int x=i-'0';
        sum+=x;
        if(x==2)c2++;
        if(x==3)c3++;
    }
    
    // cout<<sum<<" ";
    for (int i = 0; i <=min(9,c2); i++) {
        for (int j =0; j <= min(2,c3); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                cout<< "YES\n";
                return;
            }
        }
    }
    
    cout << "NO\n";
}

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

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