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


Submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    a=list(map(int,list(input())))
    t2,t3=0,0
    for i in a:
        if i==2:
            t2+=1
        elif i==3:
            t3+=1
    k=sum(a)%9
    if (not k) or len(a)==t3:
        print('YES')
    elif k==7 and t2:
        print('YES')
    elif k==5 and t2>1:
        print('YES')
    elif k==3 and (t3 or t2>2):
        print('YES')
    elif k==1 and ((t3 and t2) or t2>3):
        print('YES')
    else:
        print('NO')
Problem: 2050C - Uninteresting Number
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    a=list(map(int,list(input())))
    t2,t3=0,0
    for i in a:
        if i==2:
            t2+=1
        elif i==3:
            t3+=1
    k=sum(a)%9
    if (not k) or len(a)==t3:
        print('YES')
    elif k==7 and t2:
        print('YES')
    elif k==5 and t2>1:
        print('YES')
    elif k==3 and (t3 or t2>2):
        print('YES')
    elif k==1 and ((t3 and t2) or t2>3):
        print('YES')
    else:
        print('NO')

Submission (verdict: Runtime error on test 1):
for _ in range(int(input())):
    a=map(int,list(input()))
    s=sum(a)
    t1,t2=a.count(2),a.count(3)
    for i in range(t1+1):
        for j in range(t2+1):
            if (s+t1*i+t2*j)%9==0:
                print('YES')
                break
        else:continue
        break
    else:
        print('NO')
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#warning Check FastIO
#ifdef ONLINE_JUDGE
    #pragma GCC optimize("Ofast")
    #pragma GCC target("avx,avx2,fma")
#endif
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <random>
#include <chrono>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
#define vll vector<ll>
#define sll set<ll>
#define vstr vector<string>
#define ll long long
#define ld long double
#define supra main
#define pb push_back
#define add insert
#define rall(x) rbegin(x),rend(x)
#define all(x) (x).begin(),(x).end()
#define I ios_base::sync_with_stdio(false);
#define Hear cin.tie(NULL);
#define Shots cout.tie(NULL);
#define Ratatatata
#define bits_on(a) (__builtin_popcountll(a))
#define mx_pw2(a) (__builtin_ctzll(a))
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());  
#define SHUFFLE(v) shuffle(all(v), RNG); 
const ll inf=LLONG_MAX;
void input(vll& a)
{
    for(auto& i:a)
        cin>>i;
}
void pyn(bool a)
{
    cout<<(a?"YES":"NO")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
  if(b==0){
    return 1;
  }
  ll temp=powmod(a,b/2,modulo);
  if(b%2==0){
    return (temp*temp)%modulo;
  }
  else{
    return (a*((temp*temp)%modulo))%modulo;
  }
}

bool Prime(ll n){
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;
    return (n>1);
}
void solve()
{
    ll l,r;
    cin>>l>>r;
    ll aa=l,bb=l+1,cc=l+2;
    ll mx=(aa^bb)+(bb^cc)+(aa^cc);
    for(ll pw=1;pw<=r;pw*=2)
    {
        if(pw<=r and l<=pw)
        {
            // fudge
            ll a=pw,b=pw-1,c=l^(pw-1);
            // pw^(pw-1) == pw*2 - 1
            ll cur=(a^b)+(a^c)+(b^c);
            if(cur>mx)
            {
                mx=cur;
                aa=a,bb=b,cc=c;
            }
        }
    }
    cout<<aa<<' '<<bb<<' '<<cc<<endl;
}
int supra(){
    I Hear Shots Ratatatata
    ll tqwertyuiop=1;
    cin>>tqwertyuiop;
    for(int tp=1;tp<=tqwertyuiop;tp++)
    {
        // cout<<"Case #"<<tp<<": ";
        solve();
    }
    return 0;
}
/*
Bro use only in a emergency 
this is kind of hacking
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
*/
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n,x,y;

        cin >> n>>x>>y;

        vector<int> v(n);



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

            cin >> v[i];

        }



        int c = y-x+1;

      //  cout<<c;

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

        int sum=0;

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

                sum+=v[i];

        }



        cout<<sum<<endl;

    }



    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n,x,y;

        cin >> n>>x>>y;

        vector<int> v(n);



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

            cin >> v[i];

        }



        int c = y-x+1;

      //  cout<<c;

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

        int sum=0;

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

                sum+=v[i];

        }



        cout<<sum<<endl;

    }



    return 0;

}



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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n,x,y;

        cin >> n>>x>>y;

        vector<int> v(n);



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

            cin >> v[i];

        }



        vector<int>v2,v3;

        int c=y-x+1;

      //  cout<<c;

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

        int sum=0,sum1=0;

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

                v2.push_back(v[i]);

        }



               for(int i=n-1;i>=x-1;i--){

                v3.push_back(v[i]);

        }

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

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

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

            sum=sum+v2[i];

            sum1+=v3[i];

         }



        cout<<min(sum,sum1)<<endl;

    }



    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n,x,y;

        cin >> n>>x>>y;

        vector<int> v(n);



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

            cin >> v[i];

        }



        vector<int>v2,v3;

        int c=y-x+1;

      //  cout<<c;

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

        int sum=0,sum1=0;

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

                v2.push_back(v[i]);

        }



               for(int i=n-1;i>=x-1;i--){

                v3.push_back(v[i]);

        }

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

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

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

            sum=sum+v2[i];

            sum1+=v3[i];

         }



        cout<<min(sum,sum1)<<endl;

    }



    return 0;

}



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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n,x,y;

        cin >> n>>x>>y;

        vector<int> v(n);



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

            cin >> v[i];

        }



        vector<int>v2,v3;

        int c=y-x+1;

      //  cout<<c;

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

        long long sum=0,sum1=0;

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

                v2.push_back(v[i]);

        }



               for(int i=n-1;i>=x-1;i--){

                v3.push_back(v[i]);

        }

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

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

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

            sum=sum+v2[i];

            sum1+=v3[i];

         }



        cout<<min(sum,sum1)<<endl;

    }



    return 0;

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define NITRO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define endl "\n"
typedef long long ll;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

vector<ll> GetDifferenceVec(vector<ll> &v)
{
    ll i;
    vector<ll> nxvec;
    for(i=1;i<v.size();i++)
    {
        ll dif = v[i]-v[i-1];
        nxvec.push_back(dif);
        //cout<<dif<<"  dddd"<<endl;
    }
    return nxvec;
}

int main()
{
    NITRO;
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    int t=1,h=1;
    cin>>t;
    while(t--)
    {
        ll i,n;
        cin>>n;
        vector<ll>a(n);
        ll sm=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = sm;
        while(a.size()>=1)
        {
            vector<ll>ab = GetDifferenceVec(a);
            //cout<<a.size()<<"  aaaa"<<endl;
            sm=0;
            for(i=0;i<a.size();i++)
            {
                sm+= a[i];
            }
            ans = max(ans, abs(sm));
            if(ab.size()<1) break;
            a = ab;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define NITRO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define endl "\n"
typedef long long ll;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

vector<ll> GetDifferenceVec(vector<ll> &v)
{
    ll i;
    vector<ll> nxvec;
    for(i=1;i<v.size();i++)
    {
        ll dif = v[i]-v[i-1];
        nxvec.push_back(dif);
        //cout<<dif<<"  dddd"<<endl;
    }
    return nxvec;
}

int main()
{
    NITRO;
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    int t=1,h=1;
    cin>>t;
    while(t--)
    {
        ll i,n;
        cin>>n;
        vector<ll>a(n);
        ll sm=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = sm;
        vector<ll> ab = GetDifferenceVec(a);
        a=ab;
        while(a.size()>=1)
        {
            vector<ll>ab = GetDifferenceVec(a);
            //cout<<a.size()<<"  aaaa"<<endl;
            sm=0;
            for(i=0;i<a.size();i++)
            {
                sm+= a[i];
            }
            ans = max(ans, abs(sm));
            if(ab.size()<1) break;
            a = ab;
        }
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define NITRO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define endl "\n"
typedef long long ll;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

vector<int> GetDifferenceVec(vector<int> &v)
{
    int i;
    vector<int> nxvec;
    for(i=1;i<v.size();i++)
    {
        int dif = v[i]-v[i-1];
        nxvec.push_back(dif);
        //cout<<dif<<"  dddd"<<endl;
    }
    return nxvec;
}

int main()
{
    NITRO;
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    int t=1,h=1;
    cin>>t;
    while(t--)
    {
        int i,n;
        cin>>n;
        vector<int>a(n);
        ll sm=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = sm;
        while(a.size()>=1)
        {
            vector<int>ab = GetDifferenceVec(a);
            //cout<<a.size()<<"  aaaa"<<endl;
            sm=0;
            for(i=0;i<a.size();i++)
            {
                sm+= a[i];
            }
            ans = max(ans, abs(sm));
            if(ab.size()<1) break;
            a = ab;
        }
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define NITRO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define endl "\n"
typedef long long ll;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

vector<int> GetDifferenceVec(vector<int> &v)
{
    int i;
    vector<int> nxvec;
    for(i=1;i<v.size();i++)
    {
        int dif = v[i]-v[i-1];
        nxvec.push_back(dif);
        //cout<<dif<<"  dddd"<<endl;
    }
    return nxvec;
}

int main()
{
    NITRO;
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    int t=1,h=1;
    cin>>t;
    while(t--)
    {
        int i,n;
        cin>>n;
        vector<int>a(n);
        ll sm=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = sm;
        while(a.size()>=1)
        {
            vector<int>ab = GetDifferenceVec(a);
            //cout<<a.size()<<"  aaaa"<<endl;
            sm=0;
            for(i=0;i<a.size();i++)
            {
                sm+= a[i];
            }
            ans = max(ans, abs(sm));
            if(ab.size()<1) break;
            a = ab;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define NITRO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define endl "\n"
typedef long long ll;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

vector<ll> GetDifferenceVec(vector<ll> &v)
{
    ll i;
    vector<ll> nxvec;
    for(i=1;i<v.size();i++)
    {
        ll dif = v[i]-v[i-1];
        nxvec.push_back(dif);
        //cout<<dif<<"  dddd"<<endl;
    }
    return nxvec;
}

int main()
{
    NITRO;
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    int t=1,h=1;
    cin>>t;
    while(t--)
    {
        ll i,n;
        cin>>n;
        vector<ll>a(n);
        ll sm=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = sm;
        while(a.size()>=1)
        {
            vector<ll>ab = GetDifferenceVec(a);
            //cout<<a.size()<<"  aaaa"<<endl;
            sm=0;
            for(i=0;i<a.size();i++)
            {
                sm+= a[i];
            }
            ans = max(ans, abs(sm));
            if(ab.size()<1) break;
            a = ab;
        }
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 8):
#include <iostream>

#include <string>



using namespace std;



void solve(string &s);



int main()

{

int t;

string s;

cin >> t;

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

{

cin >> s;

solve(s);

cout << s << endl;

}

return 0;

}



void operation(string &s, unsigned int i, unsigned int j)

{

char first = s[i] - 1;

char second = s[j];

s[i] = second;

s[j] = first;

}



void solve(string &s)

{

if (s.length() == 1) return;

bool has_switch;

unsigned int index;

unsigned int end = 1;

while (end < s.size())

{

index = s.size() - 1;

has_switch = false;

while (index > 0)

{

if (s[index] != '0' && s[index] - 1 > s[index - 1])

{

operation(s, index, index - 1);

has_switch = true;

}

index--;

}

if (!has_switch) return;

end++;

}

}

Submission (verdict: Time limit exceeded on test 8):
#include <iostream>

#include <string>



using namespace std;



void solve(string &s);



int main()

{

int t;

string s;

cin >> t;

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

{

cin >> s;

solve(s);

cout << s << endl;

}

return 0;

}



void operation(string &s, unsigned int i, unsigned int j)

{

char first = s[i] - 1;

char second = s[j];

s[i] = second;

s[j] = first;

}



void solve(string &s)

{

if (s.length() == 1) return;

bool has_switch;

unsigned int index;

unsigned int end = 1;

while (end < s.size())

{

index = s.size() - 1;

has_switch = false;

while (index > 0 && index >= end)

{

if (s[index] != '0' && s[index] - 1 > s[index - 1])

{

operation(s, index, index - 1);

has_switch = true;

}

index--;

}

if (!has_switch) return;

end++;

}

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 8):
#include <iostream>

#include <string>



using namespace std;



void solve(string &s);



int main()

{

int t;

string s;

cin >> t;

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

{

cin >> s;

solve(s);

cout << s << endl;

}

return 0;

}



void operation(string &s, unsigned int i, unsigned int j)

{

char first = s[i] - 1;

char second = s[j];

s[i] = second;

s[j] = first;

}



void solve(string &s)

{

if (s.length() == 1) return;

bool has_switch;

unsigned int index;

unsigned int end = 1;

while (end < s.size())

{

index = s.size() - 1;

has_switch = false;

while (index > 0)

{

if (s[index] != '0' && s[index] - 1 > s[index - 1])

{

operation(s, index, index - 1);

has_switch = true;

}

index--;

}

if (!has_switch) return;

end++;

}

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 8):
#include <iostream>

#include <string>



using namespace std;



void solve(string &s);



int main()

{

int t;

string s;

cin >> t;

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

{

cin >> s;

solve(s);

cout << s << endl;

}

return 0;

}



void operation(string &s, unsigned int i, unsigned int j)

{

char first = s[i] - 1;

char second = s[j];

s[i] = second;

s[j] = first;

}



void solve(string &s)

{

if (s.length() == 1) return;

bool has_switch;

unsigned int index;

unsigned int end = 1;

while (end < s.size())

{

index = s.size() - 1;

has_switch = false;

while (index > 0 && index >= end)

{

if (s[index] != '0' && s[index] - 1 > s[index - 1])

{

operation(s, index, index - 1);

has_switch = true;

}

index--;

}

if (!has_switch) return;

end++;

}

}

Submission (verdict: Accepted):
#include <iostream>

#include <string>



using namespace std;



void solve(string &s);



int main()

{

int t;

string s;

cin >> t;

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

{

cin >> s;

solve(s);

cout << s << endl;

}

return 0;

}



void operation(string &s, unsigned int i, unsigned int j)

{

char first = s[i] - 1;

char second = s[j];

s[i] = second;

s[j] = first;

}



void solve(string &s)

{

if (s.length() == 1) return;

bool has_switch;

unsigned int index;

unsigned int start = 1;

while (start < s.size())

{

index = start;

while (index > 0 && s[index] != '0' && s[index] - 1 > s[index - 1])

{

operation(s, index, index - 1);

has_switch = true;

index--;

}

start++;

}

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int md= 998244353;
const int N=200005;
const int M=1<<13;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
string dir="RLDU";
vector<int>v;
signed main()
{
    //freopen("distinct.in","r",stdin);
   //freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
    int t=1;cin>>t;
    while(t--)
    {
        string s;cin>>s;
        int sum=0,f=0;
        int num2=0,num3=0;
        for(auto&it:s)sum+=it-'0',num2+=(it=='2'),num2+=3*(it=='3');
        sum%=9;
       
        for(int i=9;i<=9*s.size();i+=9){
            if((i-sum)%2==0&&((i-sum)/2)<=num2)
        {
            f=1;break;
        }
        }
        if(f)cout<<"YES\n";
        else cout<<"NO\n";
    }
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int md= 998244353;
const int N=200005;
const int M=1<<13;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
string dir="RLDU";
vector<int>v;
signed main()
{
    //freopen("distinct.in","r",stdin);
   //freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
    int t=1;cin>>t;
    while(t--)
    {
        string s;cin>>s;
        int sum=0,f=0;
        int num2=0,num3=0;
        for(auto&it:s)sum+=it-'0',num2+=(it=='2'),num2+=3*(it=='3');
        sum%=9;
       
        for(int i=9;i<=9*s.size();i+=9){
            if((i-sum)%2==0&&((i-sum)/2)<=num2)
        {
            f=1;break;
        }
        }
        if(f)cout<<"YES\n";
        else cout<<"NO\n";
    }
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int md= 998244353;
const int N=200005;
const int M=1<<13;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
string dir="RLDU";
vector<int>v;
signed main()
{
    //freopen("distinct.in","r",stdin);
   //freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
    int t=1;cin>>t;
    while(t--)
    {
        string s;cin>>s;
        int sum=0;
        int num2=0,num3=0;
        for(auto&it:s)sum+=it-'0',num2+=(it=='2'),num3+=(it=='3');
        sum%=9;
        if(!sum)cout<<"YES\n";
        else
        {
            if((sum==1&&(num2>=4||(num2&&num3)))||(sum==3&&(num2>=3||num3))||(sum==5&&(num2>=2))||(sum==7&&num2)||(sum==2&&((num2>=8)||(num3&&num2>=5)||(num3>=2&&num2>=2)))||(sum==4&&((num2>=7)||(num3&&num2>=4)||(num3>=2&&num2>=1)))||(sum==6&&((num2>=6)||(num3&&num2>=3)||(num3>=2))))cout<<"YES\n";
             else cout<<"NO\n";
        }
    }
}