ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#define ll long long

#define endl "\n"

#define IOS \

    ios::sync_with_stdio(0);\

    cin.tie(0);\

    cout.tie(0);

using namespace std;

int main()

{

    IOS;

    int t ;

    cin>>t;

    while(t--)

    {



       ll n , l , r;

       cin>>n>>l>>r;

       vector<ll>v(n);

       ll j = r - l + 1;

       ll ans = 0 ;

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

            cin>>v[i];

       }



       sort(v.begin() , v.end());



       for(int i = 0 ; i < j ; i++ )ans += v[i];



       cout<<ans<<endl;





    }

}













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

#define ll long long

#define endl "\n"

#define IOS \

    ios::sync_with_stdio(0);\

    cin.tie(0);\

    cout.tie(0);

using namespace std;

int main()

{

    IOS;

    int t ;

    cin>>t;

    while(t--)

    {



        ll n, l, r;

        cin>>n>>l>>r;

        vector<ll>v(n);

        vector<ll>v1;

        ll j = r - l + 1;

        ll ans = 0 ;

        ll mi = 1e18+7 ;

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

        {

            cin>>v[i];

            mi = min(mi,v[i]);

        }

        if(j == 1)cout<<mi<<endl;

        else

        {



            ll ans = 0 ;

            j -- ;

            ll l = 0 ;

            ll r = j-1 ;

            for(int i = 0 ; i < j ; i++ )

            {

                ans += v[i];

            }



            ll num1 = ans ;

            ll x = 0 ;

            ll num = 0 ;

            for(int i = j ; i < n; i++)

            {

                num = num1 - v[x];

                num += v[i];

                x++;

                if(num < ans)

                {



                    l = x ;

                    r = i ;

                    ans = num ;

                }

                num1 = num ;



            }



          //  cout<<l<<" "<<r<<endl;

            mi = 1e9+7;

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

            {

                if(i >= l && i <= r)continue;

                mi = min(mi,v[i]);

            }



            cout<<ans+mi<<endl;









        }

    }

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

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

#define ll long long

#define endl "\n"

#define IOS \

    ios::sync_with_stdio(0);\

    cin.tie(0);\

    cout.tie(0);

using namespace std;

int main()

{

    IOS;

    int t ;

    cin>>t;

    while(t--)

    {



        ll n, l, r;

        cin>>n>>l>>r;

        vector<ll>v(n);

        vector<ll>v1;

        ll j = r - l + 1;

        ll ans = 0 ;

        ll mi = 1e18+7 ;

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

        {

            cin>>v[i];

            mi = min(mi,v[i]);

        }

        if(j == 1)cout<<mi<<endl;

        else

        {



            ll ans = 0 ;

            j -- ;

            ll l = 0 ;

            ll r = j-1 ;

            for(int i = 0 ; i < j ; i++ )

            {

                ans += v[i];

            }



            ll num1 = ans ;

            ll x = 0 ;

            ll num = 0 ;

            for(int i = j ; i < n; i++)

            {

                num = num1 - v[x];

                num += v[i];

                x++;

                if(num < ans)

                {



                    l = x ;

                    r = i ;

                    ans = num ;

                }

                num1 = num ;



            }



          //  cout<<l<<" "<<r<<endl;

            mi = 1e9+7;

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

            {

                if(i >= l && i <= r)continue;

                mi = min(mi,v[i]);

            }



            cout<<ans+mi<<endl;









        }

    }

}













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

#define ll long long

#define endl "\n"

#define IOS \

    ios::sync_with_stdio(0);\

    cin.tie(0);\

    cout.tie(0);

using namespace std;

int main()

{

    IOS;

    int t ;

    cin>>t;

    while(t--)

    {



        ll n, l, r;

        cin>>n>>l>>r;

        vector<ll>v(n);

        vector<ll>v1;

        vector<ll>v2;

        

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

        {

            cin>>v[i];

        }

        

        ll ans = 0 ;

        ll ans1 = 0 ;

        ll j = r-l+1;



        for(int i = 0 ; i < r ;i++ )v1.push_back(v[i]);

        for(int i = l-1 ; i< n ;i++)v2.push_back(v[i]);

        

        sort(v1.begin() , v1.end());

        sort(v2.begin() , v2.end());

        

        for(int i = 0 ; i< j ;i++)ans += v1[i];

        for(int i = 0 ; i< j ;i++)ans1 += v2[i];



        cout<<min(ans,ans1)<<endl;



    }

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


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

#define ll long long

#define endl "\n"

#define IOS \

    ios::sync_with_stdio(0);\

    cin.tie(0);\

    cout.tie(0);

using namespace std;

int main()

{

    IOS;

    int t ;

    cin>>t;

    while(t--)

    {



       ll n , l , r;

       cin>>n>>l>>r;

       vector<ll>v(n);

       ll j = r - l + 1;

       ll ans = 0 ;

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

            cin>>v[i];

       }



       sort(v.begin() , v.end());



       for(int i = 0 ; i < j ; i++ )ans += v[i];



       cout<<ans<<endl;





    }

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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



#define ll long long int

#define for1(x1) for(ll i = 0; i < x1; i++)

#define for2(x2) for(ll j = 0; j < x2; j++)

#define for3(vc_1) for(auto &it : vc_1) cin >> it;

#define so(x3) sort((x3).begin(), (x3).end())

#define rev(x3) reverse((x3).begin(), (x3).end())

#define nl endl

#define nb "\n"

#define fast_IO ios_base::sync_with_stdio(false); cin.tie(NULL);

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

using namespace std;



istream& operator>> (istream &input, vector <ll> &vc_1)

{

    for3(vc_1);

    return input;

}



const ll mod = 1e9 + 7;

const int N = 2e5 + 5;  



vector<int> adj[N];     

bool vis[N];      





ll gcd(ll a, ll b)

{

    if(b == 0) return a;

    return gcd(b, a%b);

}



ll mult(ll a, ll b)

{

    return (a%mod * b%mod)%mod;

}



ll add(ll a, ll b)

{

    return (a%mod + b%mod)%mod;

}



ll subtract(ll a, ll b)

{

    return (a%mod - b%mod + 2*mod)%mod;

}







char di[] = {'D', 'L', 'U', 'R'};

int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};

int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};





void Ahmed_log()

{

    ll siz; cin >> siz; vector <ll> vc_1 (siz); cin >> vc_1;

    if (*max_element(all(vc_1)) == vc_1.front())

    {

        cout << "NO" << nl;

    }

    else cout << "YES" << nl;

}



// Example: nums.erase(remove(nums.begin(), nums.end(), Player1), nums.end());



int main()

{

    fast_IO;

    ll test_case = 1;

    cin >> test_case;

    while(test_case--)

    {

        Ahmed_log();

    }

    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r;
    cin >> l >> r;
    while (true) {
        if (msb(l) != msb(r)) {
            cout << msb(r) << ' ' << msb(r) - 1 << ' ' << (r == msb(r) ? r - 2 : r);
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        if (t)
            cout << '\n';
    }
}

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

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r, r1;
    cin >> l >> r, r1 = r;
    while (true) {
        if (msb(l) != msb(r)) {
            int a, b, c;
            for (int i = 0; i < 35; ++i) {
                if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) {
                    a = (r1 - (1ll << i) + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1);
                    break;
                }
            }
            cout << a << ' ' << b << ' ' << c;
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        if (t)
            cout << '\n';
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r, r1;
    cin >> l >> r, r1 = r;
    while (true) {
        if (msb(l) != msb(r)) {
            int a, b, c;
            for (int i = 0; i < 35; ++i) {
                if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) {
                    a = (r1 - (1ll << i) + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1);
                    break;
                }
            }
            cout << a << ' ' << b << ' ' << c;
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        if (t)
            cout << '\n';
    }
}

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

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r, r1;
    cin >> l >> r, r1 = r;
    while (true) {
        if (msb(l) != msb(r)) {
            int a, b, c;
            for (int i = 0; i < 35; ++i) {
                if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) {
                    int x = r1 & ((1ll << (i + 1)) - 1);
                    a = (r1 - x + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1);
                    break;
                }
            }
            cout << a << ' ' << b << ' ' << c;
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        if (t)
            cout << '\n';
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

using namespace std;

#define int long long

int msb(int n) {

    // calculate the  number
    // of leading zeroes
    int k = __builtin_clz(n);

    // To return the value
    // of the number with set
    // bit at (31 - k)-th position
    // assuming 32 bits are used
    return 1 << (31 - k);
}

void solve() {
    int l, r;
    cin >> l >> r;
    while (true) {
        if (msb(l) != msb(r)) {
            cout << msb(r) << ' ' << msb(r) - 1 << ' ' << (r == msb(r) ? r - 2 : r);
            return;
        }
        r ^= msb(r);
        l ^= msb(l);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        if (t)
            cout << '\n';
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


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> 

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")

using ll = long long;
using ld = long double;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

constexpr ll inf=2e18;
constexpr ld eps=1e-9;
constexpr ll mod=1e9+7;

#define F first
#define S second
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()

template<typename T>
istream& operator>>(istream &istream, vector<T> &v)
{
	for(auto &it : v)
		cin>>it;
	return istream;
}

template<typename T>
ostream& operator<<(ostream &ostream, const vector<T> &c)
{
	for(auto &it : c)
		cout<<it<<" ";
	return ostream;
}

vector<int> fact_dp(2e5+2,-1);

int binpow(int a, int b, int m=mod)
{
	if(b==0)
		return 1;

	int x = binpow(a,b/2);
	if(b&1)
		return ((x*x)%m*a)%m;
	return (x*x)%m;
}

int modinv(int x, int m=mod)
{
	return binpow(x,m-2,m);
}

int fact(int x){
	if(x<=1) return 1;
	if(fact_dp[x] != -1) return fact_dp[x];

	return fact_dp[x] = (x%mod * fact(x-1)%mod)%mod;
}

int nCr(int n, int r){
	int x = (modinv(fact(r)) * modinv(fact(n-r)))%mod;
	int y = fact(n);
	return (x*y)%mod;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	cin >> a >> b;
	sort(all(a));
	sort(all(b));

	priority_queue<int, vector<int>, greater<int>> q;
	for(auto it : a){
		q.push(it);
	}

	int j = 0;
	while(!q.empty() && j<m){
		int cur = q.top();
		q.pop();

		if(cur==b[j]) j++;
		else{
			if(q.empty()){
				cout << "NO\n";
				return;
			}else{
				int cur2=q.top();

				if(abs(cur2-cur)<=1){
					q.pop();
					q.push(cur+cur2);
				}else{
					cout << "NO\n";
					return;
				}
			}
		}
	}

	if(q.empty() && j==m){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << setprecision(12) << fixed;

	int t=1;
	cin>>t;
	while(t--){
		solve();
	}

	return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


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

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define yes cout << "YES" << endl 
#define no cout << "NO" << endl 
#define pb push_back
#define l_b lower_bound
#define u_b upper_bound
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;
typedef unordered_map<int, int> umap_ii;
typedef unordered_map<string, int> umap_si;

bool isPossible(multiset<ll>& st, ll target) {
    if (st.find(target) != st.end()) {
        st.erase(st.find(target)); 
        return true;
    }

    if (target==1 || st.empty()) return false; 
    ll part1 = target/2;
    ll part2 = target-part1;

    if (st.count(part1)>0) {
        
        st.erase(st.find(part1));
        if (isPossible(st, part2)) {
            return true;
        }
        st.insert(part1);
    }

    if (st.count(part2)>0) {
       
        st.erase(st.find(part2));
        if (isPossible(st, part1)) {
            return true;
        }
        st.insert(part2);
    }

    return false;
}

void solve() {
    ll n, m;
    cin >> n >> m;
    vl a(n), b(m);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<m; i++) cin >> b[i];

    sort(all(a));
    sort(all(b));
    if(a[n-1]>b[m-1]) {
        no; 
        return;
    }
    if (n==m) {
        for (int i=0; i<m; i++) {
            if (a[i]!=b[i]) {
                no;
                return;
            }
        }
        yes;
        return;
    }

    multiset<ll> st;
    for (auto x : a) {
        st.insert(x);
    }

    for (int i = 0; i < m; i++) {
        ll x = b[i];
        if (st.find(x)!=st.end()) {
            st.erase(st.find(x)); 
        } 
        else if (!isPossible(st, x)) {
            no;
            return;
        }
    }
    if(!st.empty()) {
        no;
        return;
    }
    yes;
}

int main() {
    _fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
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 fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define nline '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pr_vec(vec) for(auto &num: vec){cout<<num<<" ";}cout<<endl;
#define pr_vecPair(vec) for(auto &num: vec){cout<<num.first<<" "<<num.second<<'\n';}cout<<endl;
#define inp_vec1(vec) for(auto &ele: vec){cin>>ele;} 
#define inp_vec2(vec,n)for(long long int i=1;i<=n;++i){cin>>vec[i];}
bool odd(ll num) { return ((num & 1)  ); }
bool even(ll num) { return (!(num & 1)); }
void solve(ll tc)
{
    ll n;
    cin>>n;
    ll sum = 0;
    ll x = n, two =0,three=0;
    while(x>0)
    {
        sum+=x%10;
        if(x%10 == 2)two++;
        if(x%10 == 3)three++;
        x/=10;
    }
    if(sum%9==0)
    {
        yes;return;
    }
    ll found = false;
    // cout<<two<<" "<<three<<nline;
    for(ll i=0;i<=min(two, 8LL);++i)
    {//cout<<i<<nline;
        for(ll j=0;j<=min(three,8LL);++j)
        {
            ll new_sum = sum + (i*2) + (j* 6);
            // cout<<j<<" "<<sum<<nline;
            if(new_sum%9==0) 
            {
               yes;
               return;
            }
        }
    }
    no;
    // cout<<n<<nline;
    // cout<<sum<<nline;

}

int main()
{
    fast
    ll t;
    cin>>t;
    ll i=1;

    while(i<=t)
    {
        solve(i);
        i++;
    }
    return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define nline '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pr_vec(vec) for(auto &num: vec){cout<<num<<" ";}cout<<endl;
#define pr_vecPair(vec) for(auto &num: vec){cout<<num.first<<" "<<num.second<<'\n';}cout<<endl;
#define inp_vec1(vec) for(auto &ele: vec){cin>>ele;} 
#define inp_vec2(vec,n)for(long long int i=1;i<=n;++i){cin>>vec[i];}
bool odd(ll num) { return ((num & 1)  ); }
bool even(ll num) { return (!(num & 1)); }
void solve(ll tc)
{
    string s;
    cin>>s;
    ll sum = 0;
    ll  two =0,three=0;
   for(ll i=0;i<s.length();++i)
   {
       sum+=s[i]-'0';
       if(s[i]=='2')two++;
       if(s[i]=='3')three++; 
   }
    if(sum%9==0)
    {
        yes;return;
    }
    ll found = false;
    // cout<<two<<" "<<three<<nline;
    for(ll i=0;i<=two;++i)
    {//cout<<i<<nline;
        for(ll j=0;j<=three;++j)
        {
            ll new_sum = sum + (i*2) + (j* 6);
            // cout<<j<<" "<<sum<<nline;
            if(new_sum%9==0) 
            {
               yes;
               return;
            }
        }
    }
    no;
    // cout<<n<<nline;
    // cout<<sum<<nline;

}

int main()
{
    fast
    ll t;
    cin>>t;
    ll i=1;

    while(i<=t)
    {
        solve(i);
        i++;
    }
    return 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 fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define nline '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pr_vec(vec) for(auto &num: vec){cout<<num<<" ";}cout<<endl;
#define pr_vecPair(vec) for(auto &num: vec){cout<<num.first<<" "<<num.second<<'\n';}cout<<endl;
#define inp_vec1(vec) for(auto &ele: vec){cin>>ele;} 
#define inp_vec2(vec,n)for(long long int i=1;i<=n;++i){cin>>vec[i];}
bool odd(ll num) { return ((num & 1)  ); }
bool even(ll num) { return (!(num & 1)); }
void solve(ll tc)
{
    ll n;
    cin>>n;
    ll sum = 0;
    ll x = n, two =0,three=0;
    while(x>0)
    {
        sum+=x%10;
        if(x%10 == 2)two++;
        if(x%10 == 3)three++;
        x/=10;
    }
    if(sum%9==0)
    {
        yes;return;
    }
    ll found = false;
    // cout<<two<<" "<<three<<nline;
    for(ll i=0;i<=two;++i)
    {//cout<<i<<nline;
        for(ll j=0;j<=three;++j)
        {
            ll new_sum = sum + i*2 + j* 6;
            // cout<<j<<" "<<sum<<nline;
            if(new_sum%9==0) 
            {
                found = true;
                break;
            }
        }
    }
    if(found) yes;
    else no;
    // cout<<n<<nline;
    // cout<<sum<<nline;

}

int main()
{
    fast
    ll t;
    cin>>t;
    ll i=1;

    while(i<=t)
    {
        solve(i);
        i++;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define nline '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pr_vec(vec) for(auto &num: vec){cout<<num<<" ";}cout<<endl;
#define pr_vecPair(vec) for(auto &num: vec){cout<<num.first<<" "<<num.second<<'\n';}cout<<endl;
#define inp_vec1(vec) for(auto &ele: vec){cin>>ele;} 
#define inp_vec2(vec,n)for(long long int i=1;i<=n;++i){cin>>vec[i];}
bool odd(ll num) { return ((num & 1)  ); }
bool even(ll num) { return (!(num & 1)); }
void solve(ll tc)
{
    ll n;
    cin>>n;
    ll sum = 0;
    ll x = n, two =0,three=0;
    while(x>0)
    {
        sum+=x%10;
        if(x%10 == 2)two++;
        if(x%10 == 3)three++;
        x/=10;
    }
    if(sum%9==0)
    {
        yes;return;
    }
    ll found = false;
    // cout<<two<<" "<<three<<nline;
    for(ll i=0;i<=two;++i)
    {//cout<<i<<nline;
        for(ll j=0;j<=three;++j)
        {
            ll new_sum = sum + (i*2) + (j* 6);
            // cout<<j<<" "<<sum<<nline;
            if(new_sum%9==0) 
            {
               yes;
               return;
            }
        }
    }
    no;
    // cout<<n<<nline;
    // cout<<sum<<nline;

}

int main()
{
    fast
    ll t;
    cin>>t;
    ll i=1;

    while(i<=t)
    {
        solve(i);
        i++;
    }
    return 0;
}