ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq):

if i == len(seq) - 1:

i += 1

continue

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val

if i == 0 :

i+= 1

continue

if seq[i] < seq[i-1] or seq[i] > seq[i+1]:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)

Submission (verdict: Accepted):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq):

if i == len(seq) - 1:

if seq[i] < seq[i-1]:

answer = 'NO'

break

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val

if (seq[i] < seq[i-1] or seq[i] > seq[i+1]) and i > 0:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq) - 1:

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val



if seq[i] > seq[i-1]:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq) - 1:

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val



if seq[i] > seq[i-1]:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)

Submission (verdict: Wrong answer on test 2):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq) - 1:

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val

if i == 0:

i+= 1

continue

if seq[i] < seq[i-1] or seq[i] > seq[i+1]:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq) - 1:

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val

if i == 0:

i+= 1

continue

if seq[i] < seq[i-1] or seq[i] > seq[i+1]:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)

Submission (verdict: Wrong answer on test 2):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq):

if i == len(seq) - 1:

i += 1

continue

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val

if i == 0 :

i+= 1

continue

if seq[i] < seq[i-1] or seq[i] > seq[i+1]:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,l,r;
	    cin>>n>>l>>r;
	    vector<int> v(n);
	    for(int i=0;i<n;i++){
	        cin>>v[i];
	    }
	    sort(v.begin(),v.end());
	    int ans=0;
	    for(int i=0;i<r-l+1;i++){
	        ans+=v[i];
	    }
	    cout<<ans<<endl;
	        
	    
	}

}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,l,r;
	    cin>>n>>l>>r;
	    vector<int> v(n);
	    for(int i=0;i<n;i++){
	        cin>>v[i];
	    }
	    sort(v.begin()+l-1,v.begin()+r);
	    sort(v.begin(),v.begin()+l-1);
	    sort(v.begin()+r,v.end());
	    int ans=0;
	    for(int i=l-1;i<r;i++){
	        ans+=v[i];
	    }
	    int ans1=0,ans2=0;
	    for(int i=r-1;i>=l-1;i--){
	        if(r-1-i<l-1&&v[i]>v[r-1-i]){
	            ans1+=v[i]-v[r-1-i];
	        }
	        else{
	            break;
	        }
	    }
	    for(int i=r-1;i>=l-1;i--){
	        if(2*r-i-1<n&&v[i]>v[2*r-i-1]){
	            ans2+=v[i]-v[2*r-i-1];
	        }
	        else{
	            break;
	        }
	    }
	    ans-=max(ans1,ans2);
	    cout<<ans<<endl;
	    
	}

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,l,r;
	    cin>>n>>l>>r;
	    vector<int> v(n);
	    for(int i=0;i<n;i++){
	        cin>>v[i];
	    }
	    sort(v.begin()+l-1,v.begin()+r);
	    sort(v.begin(),v.begin()+l-1);
	    sort(v.begin()+r,v.end());
	    int ans=0;
	    for(int i=l-1;i<r;i++){
	        ans+=v[i];
	    }
	    int ans1=0,ans2=0;
	    for(int i=r-1;i>=l-1;i--){
	        if(r-1-i<l-1&&v[i]>v[r-1-i]){
	            ans1+=v[i]-v[r-1-i];
	        }
	        else{
	            break;
	        }
	    }
	    for(int i=r-1;i>=l-1;i--){
	        if(2*r-i-1<n&&v[i]>v[2*r-i-1]){
	            ans2+=v[i]-v[2*r-i-1];
	        }
	        else{
	            break;
	        }
	    }
	    ans-=max(ans1,ans2);
	    cout<<ans<<endl;
	    
	}

}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    long long n,l,r;
	    cin>>n>>l>>r;
	    vector<long long> v(n);
	    for(long long i=0;i<n;i++){
	        cin>>v[i];
	    }
	    sort(v.begin()+l-1,v.begin()+r);
	    sort(v.begin(),v.begin()+l-1);
	    sort(v.begin()+r,v.end());
	    long long ans=0;
	    for(long long i=l-1;i<r;i++){
	        ans+=v[i];
	    }
	    long long ans1=0,ans2=0;
	    for(long long i=r-1;i>=l-1;i--){
	        if(r-1-i<l-1&&v[i]>v[r-1-i]){
	            ans1+=v[i]-v[r-1-i];
	        }
	        else{
	            break;
	        }
	    }
	    for(long long i=r-1;i>=l-1;i--){
	        if(2*r-i-1<n&&v[i]>v[2*r-i-1]){
	            ans2+=v[i]-v[2*r-i-1];
	        }
	        else{
	            break;
	        }
	    }
	    ans-=max(ans1,ans2);
	    cout<<ans<<endl;
	    
	}

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,l,r;
	    cin>>n>>l>>r;
	    vector<int> v(n);
	    for(int i=0;i<n;i++){
	        cin>>v[i];
	    }
	    sort(v.begin(),v.end());
	    int ans=0;
	    for(int i=0;i<r-l+1;i++){
	        ans+=v[i];
	    }
	    cout<<ans<<endl;
	        
	    
	}

}
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
def solve():
    n = int(input())

    memo = {}
    def dp(k):
        if k == 0:
            return False
        if k % 9 == 0:
            return True
        if k in memo:
            return memo[k]
        cur = False
        left, right, p = k, 0, 1
        while left:
            p *= 10
            d = left % 10
            left //= 10
            if d in [2, 3]:
                cur = cur or dp(left * p + ((d ** 2) * (p // 10) + right))
            right = d * (p // 10) + right
        memo[k] = cur
        return cur

    if dp(n):
        return 'YES'
    else:
        return 'NO'

NUM_TESTS = int(input())

for _ in range(NUM_TESTS):
    print(solve())

Submission (verdict: Time limit exceeded on test 3):
def solve():
    n = int(input())

    memo = {}
    def dp(k):
        if k % 9 == 0:
            return True
        if k in memo:
            return memo[k]
        cur = False
        left, right, p = k, 0, 1
        while left:
            p *= 10
            d = left % 10
            left //= 10
            if d in [2, 3]:
                cur = cur or dp(left * p + ((d ** 2) * (p // 10) + right))
            right = d * (p // 10) + right
        memo[k] = cur
        return cur

    if dp(n):
        return 'YES'
    else:
        return 'NO'

NUM_TESTS = int(input())

for _ in range(NUM_TESTS):
    print(solve())
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
def solve():
    n = int(input())

    memo = {}
    def dp(k):
        if k == 0:
            return False
        if k % 9 == 0:
            return True
        if k in memo:
            return memo[k]
        cur = False
        left, right, p = k, 0, 1
        while left:
            p *= 10
            d = left % 10
            left //= 10
            if d in [2, 3]:
                cur = cur or dp(left * p + ((d ** 2) * (p // 10) + right))
            right = d * (p // 10) + right
        memo[k] = cur
        return cur

    if dp(n):
        return 'YES'
    else:
        return 'NO'

NUM_TESTS = int(input())

for _ in range(NUM_TESTS):
    print(solve())
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 3):
def solve():
    n = int(input())

    memo = {}
    def dp(k):
        if k % 9 == 0:
            return True
        if k in memo:
            return memo[k]
        cur = False
        left, right, p = k, 0, 1
        while left:
            p *= 10
            d = left % 10
            left //= 10
            if d in [2, 3]:
                cur = cur or dp(left * p + ((d ** 2) * (p // 10) + right))
            right = d * (p // 10) + right
        memo[k] = cur
        return cur

    if dp(n):
        return 'YES'
    else:
        return 'NO'

NUM_TESTS = int(input())

for _ in range(NUM_TESTS):
    print(solve())

Submission (verdict: Accepted):
def solve():
    s = [int(x) for x in list(input())]
    ss = sum(s)
    two = s.count(2)
    three = s.count(3)

    for i in range(two + 1):
        for j in range(three + 1):
            if (ss + (i * 2) + (j * 6)) % 9 == 0:
                return 'YES'
    return 'NO'

NUM_TESTS = int(input())

for _ in range(NUM_TESTS):
    print(solve())
Problem: 2061D - Kevin and Numbers
Language: Java 8


Submission (verdict: Time limit exceeded on test 5):
import java.io.*;
import java.util.*;

public class Main {
    static void solveCase(FastReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        long sumA = 0;
        Map<Long, Integer> freq = new HashMap<>();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
            sumA += a[i];
            freq.put(a[i], freq.getOrDefault(a[i], 0) + 1);
        }
        long sumB = 0;
        long[] b = new long[m];
        for (int i = 0; i < m; i++) {
            b[i] = in.nextLong();
            sumB += b[i];
        }
        if (sumA != sumB) {
            out.println("No");
            return;
        }
        
        PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
        for (long x : b) {
            pq.add(x);
        }
        
        while (!pq.isEmpty() && !freq.isEmpty()) {
            long cur = pq.poll();
            if (freq.containsKey(cur)) {
                int cnt = freq.get(cur);
                if (cnt == 1) freq.remove(cur);
                else freq.put(cur, cnt - 1);
                continue;
            }
            if (cur == 1) {
                out.println("No");
                return;
            }
            long left = cur / 2;
            long right = cur - left;
            pq.add(left);
            pq.add(right);
        }
        out.println(freq.isEmpty() ? "Yes" : "No");
    }
    
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = in.nextInt();
        while (t-- > 0) {
            solveCase(in, out);
        }
        out.close();
    }
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):

// author: arnavwinner

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

const int INF = 1E9;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    string a, b, c;
    cin >> a >> b >> c;
    a = "$" + a;
    b = "$" + b;
    c = "$" + c;
    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n + 1, vector<int> (m + 1, -1));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
      dp[i][0] = dp[i - 1][0] + a[i] != c[i];
    }
    for (int i = 1; i <= m; i++) {
      dp[0][i] = dp[0][i - 1] + b[i] != c[i];
    }
    function<int(int, int)> rec = [&] (int N, int M) -> int {
      // if (N < 0) return INF;
      // if (M < 0) return INF; // THIS DOESN'T WORK... You Initialized dp[N][M] with -1
      // now that you are checking only dp[N][M] != -1 below... that is v important to see
      if (dp[N][M] != -1) {
        return dp[N][M];
      }
      if (a[N] == c[N + M] && b[M] != c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M));
      }
      if (a[N] != c[N + M] && b[M] == c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M) + 1);
      }
      if (a[N] == c[N + M] && b[M] == c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M));
      }
      if (a[N] != c[N + M] && b[M] != c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M) + 1);
      }
    };
    rec(n, m);
    cout << dp[n][m] << '\n';
  }
  return 0;
}

Submission (verdict: Wrong answer on test 1):

// author: arnavwinner

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

const int INF = 1E9;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    string a, b, c;
    cin >> a >> b >> c;
    a = "$" + a;
    b = "$" + b;
    c = "$" + c;
    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n + 1, vector<int> (m + 1, -1));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
      dp[i][0] = dp[i - 1][0] + a[i] != c[i];
    }
    for (int i = 1; i <= m; i++) {
      dp[0][i] = dp[0][i - 1] + b[i] != c[i];
    }
    function<int(int, int)> rec = [&] (int N, int M) -> int {
      // if (N < 0) return INF;
      // if (M < 0) return INF; // THIS DOESN'T WORK... You Initialized dp[N][M] with -1
      // now that you are checking only dp[N][M] != -1 below... that is v important to see
      if (dp[N][M] != -1) {
        return dp[N][M];
      }
      if (a[N] == c[N + M] && b[M] != c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M));
      }
      if (a[N] != c[N + M] && b[M] == c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M) + 1);
      }
      if (a[N] == c[N + M] && b[M] == c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M));
      }
      if (a[N] != c[N + M] && b[M] != c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M) + 1);
      }
    };
    cout << rec(n, m) << '\n';
    // cout << dp[n][m] << '\n';
  }
  return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):

// author: arnavwinner

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

const int INF = 1E9;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    string a, b, c;
    cin >> a >> b >> c;
    a = "$" + a;
    b = "$" + b;
    c = "$" + c;
    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n + 1, vector<int> (m + 1, -1));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
      dp[i][0] = dp[i - 1][0] + a[i] != c[i];
    }
    for (int i = 1; i <= m; i++) {
      dp[0][i] = dp[0][i - 1] + b[i] != c[i];
    }
    function<int(int, int)> rec = [&] (int N, int M) -> int {
      // if (N < 0) return INF;
      // if (M < 0) return INF; // THIS DOESN'T WORK... You Initialized dp[N][M] with -1
      // now that you are checking only dp[N][M] != -1 below... that is v important to see
      if (dp[N][M] != -1) {
        return dp[N][M];
      }
      if (a[N] == c[N + M] && b[M] != c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M));
      }
      if (a[N] != c[N + M] && b[M] == c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M) + 1);
      }
      if (a[N] == c[N + M] && b[M] == c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M));
      }
      if (a[N] != c[N + M] && b[M] != c[N + M]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M) + 1);
      }
    };
    rec(n, m);
    cout << dp[n][m] << '\n';
  }
  return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
std::set<ll> generateSums(int count2, int count3) {
    std::set<ll> sums;

    // Iterate through all possible numbers of 2s (0 to count2)
    for (int i = 0; i <= count2; ++i) {
        // Iterate through all possible numbers of 3s (0 to count3)
        for (int j = 0; j <= count3; ++j) {
            // Calculate the sum for the current combination
            ll sum =(ll)i * 2 + (ll)j * 6;
            sums.insert(sum);
        }
    }

    return sums;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    // Log output to console
    int t;
         cin >> t;

 while(t--){
    string s;
    cin >> s;
    if(t==(3600-401)) cout << s << endl;
    int c2=0;
    int c3=0;
    rep(i,0,s.size()){
       if(s[i]=='2') c2++;
       if(s[i]=='3') c3++;
    }
    auto x = generateSums(min(9,c2),min(2,c3));
    ll os=0;
    rep(i,0,s.size()){
        int y=s[i]-'0';
        os+=y;
    }
    // cout << os << endl;
    bool f=false;  
    if(os%9==0){
     cout << "YES" << endl;
     f=true;
    }
    for(auto sum: x){
        if((sum+os)%9==0 && sum!=0){
            // cout << os <<" " << sum;
            cout << "YES" << endl;
            f=true;
            break;
        }
    }
    if(not f){
        cout << "NO" << endl;
    }
     

 }
    return (ll)0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
std::set<ll> generateSums(int count2, int count3) {
    std::set<ll> sums;

    // Iterate through all possible numbers of 2s (0 to count2)
    for (int i = 0; i <= count2; ++i) {
        // Iterate through all possible numbers of 3s (0 to count3)
        for (int j = 0; j <= count3; ++j) {
            // Calculate the sum for the current combination
            ll sum =(ll)i * 2 + (ll)j * 6;
            sums.insert(sum);
        }
    }

    return sums;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    // Log output to console
    int t;
         cin >> t;

 while(t--){
    string s;
    cin >> s;
   
    int c2=0;
    int c3=0;
    rep(i,0,s.size()){
       if(s[i]=='2') c2++;
       if(s[i]=='3') c3++;
    }
    auto x = generateSums(min(8,c2),min(8,c3));
    ll os=0;
    rep(i,0,s.size()){
        int y=s[i]-'0';
        os+=y;
    }
    // cout << os << endl;
    bool f=false;  
    // if(os%9==0){
    //  cout << "YES" << endl;
    //  f=true;
    // }
    for(auto sum: x){
        if((sum+os)%9==0){
            // cout << os <<" " << sum;
            cout << "YES" << endl;
            f=true;
            break;
        }
    }
    if(not f){
        cout << "NO" << endl;
    }
     

 }
    return (ll)0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
std::set<int> generateSums(int count2, int count3) {
    std::set<int> sums;

    // Iterate through all possible numbers of 2s (0 to count2)
    for (int i = 0; i <= count2; ++i) {
        // Iterate through all possible numbers of 3s (0 to count3)
        for (int j = 0; j <= count3; ++j) {
            // Calculate the sum for the current combination
            int sum = i * 2 + j * 6;
            sums.insert(sum);
        }
    }

    return sums;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    // Log output to console
    int t;
         cin >> t;

 while(t--){
    string s;
    cin >> s;
    int c2=0;
    int c3=0;
    rep(i,0,s.size()){
       if(s[i]=='2') c2++;
       if(s[i]=='3') c3++;
    }
    auto x = generateSums(min(9,c2),min(2,c3));
    ll os=0;
    rep(i,0,s.size()){
        int y=s[i]-'0';
        os+=y;
    }
    // cout << os << endl;
    bool f=false;  
    if(os%9==0){
     cout << "YES" << endl;
     f=true;
    }
    for(int sum: x){
        if((sum+os)%9==0 && sum!=0){
            // cout << os <<" " << sum;
            cout << "YES" << endl;
            f=true;
            break;
        }
    }
    if(not f){
        cout << "NO" << endl;
    }
     

 }
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
std::set<ll> generateSums(int count2, int count3) {
    std::set<ll> sums;

    // Iterate through all possible numbers of 2s (0 to count2)
    for (int i = 0; i <= count2; ++i) {
        // Iterate through all possible numbers of 3s (0 to count3)
        for (int j = 0; j <= count3; ++j) {
            // Calculate the sum for the current combination
            ll sum =(ll)i * 2 + (ll)j * 6;
            sums.insert(sum);
        }
    }

    return sums;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    // Log output to console
    int t;
         cin >> t;

 while(t--){
    string s;
    cin >> s;
    int c2=0;
    int c3=0;
    rep(i,0,s.size()){
       if(s[i]=='2') c2++;
       if(s[i]=='3') c3++;
    }
    auto x = generateSums(min(9,c2),min(2,c3));
    ll os=0;
    rep(i,0,s.size()){
        int y=s[i]-'0';
        os+=y;
    }
    // cout << os << endl;
    bool f=false;  
    if(os%9==0){
     cout << "YES" << endl;
     f=true;
    }
    for(auto sum: x){
        if((sum+os)%9==0 && sum!=0){
            // cout << os <<" " << sum;
            cout << "YES" << endl;
            f=true;
            break;
        }
    }
    if(not f){
        cout << "NO" << endl;
    }
     

 }
    return (ll)0;
}