ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        int x2=0;
        int x3=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            if(num==2){
                x2++;
            }
            if(num==3){
                x3++;
            }
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        else if(x3==n.size()){
            cout<<"YES"<<endl;
        }
        
        else{
            for(int i=1;i<=x2;i++){
                for(int j=0;j<=x3;j++){
                    int x=sum+2*i+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
            if(flag==true){
                cout<<"NO"<<endl;
            }
        }

    }
}

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


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        int x2=0;
        int x3=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            if(num==2){
                x2++;
            }
            if(num==3){
                x3++;
            }
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        
        
        else{
            if(x2==0){
                for(int j=0;j<=x3;j++){
                    int x=sum+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                
            }
            else if(x3==0){
                for(int i=1;i<=x2;i++){
                
                    int x=sum+2*i;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                
            }
            else{
                for(int i=1;i<=x2;i++){
                for(int j=0;j<=x3;j++){
                    int x=sum+2*i+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
            }
            
            if(flag==true){
                cout<<"NO"<<endl;
            }
        }

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

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


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        else{
            for(int i=0;i<n.size();i++){
                int num = n[i] - '0';
                if(num<=3){
                    sum-=num;
                    sum+=num*num;
                    if(sum%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                    else{
                        sum-=num*num;
                        sum+=num;
                    }
                }
                
            }
            if(flag==true){
                for(int i=0;i<n.size();i++){
                int num = n[i] - '0';
                if(num<=3){
                    sum-=num;
                    sum+=num*num;
                    }
            }
            if(sum%9==0){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        }

    }
}

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


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        int x2=0;
        int x3=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            if(num==2){
                x2++;
            }
            if(num==3){
                x3++;
            }
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        else if(x3==n.size()){
            cout<<"YES"<<endl;
        }
        
        else{
            for(int i=1;i<=x2;i++){
                for(int j=0;j<=x3;j++){
                    int x=sum+2*i+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
            if(flag==true){
                cout<<"NO"<<endl;
            }
        }

    }
}
Problem: 2062C - Cirno and Operations
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
t=int(input())
for _ in range(t):
    n=int(input())
    if n==1:
        print(int(input()))
    else:
        lis=list(map(int,input().split()))
        for i in range(1,n):
            for j in range(n-1,i-1,-1):
                lis[j]-=lis[j-1]
        print(abs(lis[-1]))

Submission (verdict: Runtime error on test 1):
t=int(input())
for _ in range(t):
    n=int(input())
    if n==1:
        print(int(input()))
    else:
        ans=sum(lis)
        lis=list(map(int,input().split()))
        for i in range(1,n):
            for j in range(n-1,i-1,-1):
                lis[j]-=lis[j-1]
            ans=max(ans,abs(sum(lis[i:])))
        print(max(abs(lis[-1]),ans))
Problem: 2062C - Cirno and Operations
Language: Python 3

Previous submission (verdict: Runtime error on test 1):
t=int(input())
for _ in range(t):
    n=int(input())
    if n==1:
        print(int(input()))
    else:
        ans=sum(lis)
        lis=list(map(int,input().split()))
        for i in range(1,n):
            for j in range(n-1,i-1,-1):
                lis[j]-=lis[j-1]
            ans=max(ans,abs(sum(lis[i:])))
        print(max(abs(lis[-1]),ans))

Submission (verdict: Accepted):
t=int(input())
for _ in range(t):
    n=int(input())
    if n==1:
        print(int(input()))
    else:
      
        lis=list(map(int,input().split()))
        ans=sum(lis)
        for i in range(1,n):
            for j in range(n-1,i-1,-1):
                lis[j]-=lis[j-1]
            ans=max(ans,abs(sum(lis[i:])))
        print(max(abs(lis[-1]),ans))
Problem: 2062C - Cirno and Operations
Language: Python 3


Submission (verdict: Wrong answer on test 1):
t=int(input())
for _ in range(t):
    n=int(input())
    if n==1:
        print(int(input()))
    else:
        lis=list(map(int,input().split()))
        for i in range(1,n):
            for j in range(n-1,i-1,-1):
                lis[j]-=lis[j-1]
        print(abs(lis[-1]))
Problem: 2063B - Subsequence Update
Language: Python 3


Submission (verdict: Runtime error on test 2):
t=int(input())
for _ in range(t):
    n,l,r=map(int,input().split())
    if n==1:
        s=input()
        print(int(s))
        continue
    lis=[int(i) for i in input().split()]
    x=lis[:l-1]
    y=lis[r:]
    x.sort()
    y.sort()
    o=lis[l-1:r]
    o.sort()
    low=0
    high=len(o)-1
    repsum=0
    while low<l-1 and high>=0:
        if x[low]<o[high]:
            repsum+=o[high]-x[low]
            low+=1
            high-=1
        else:
            break
    low=0
    high=len(y)-1
    rep2=0
    while high>=0 and low<len(o):
        if y[low]<o[high]:
            rep2+=o[high]-y[low]
            low+=1
            high-=1
        else:
            break
    u=max(rep2,repsum)
    print(sum(o)-u)
Problem: 2063B - Subsequence Update
Language: Python 3

Previous submission (verdict: Runtime error on test 2):
t=int(input())
for _ in range(t):
    n,l,r=map(int,input().split())
    if n==1:
        s=input()
        print(int(s))
        continue
    lis=[int(i) for i in input().split()]
    x=lis[:l-1]
    y=lis[r:]
    x.sort()
    y.sort()
    o=lis[l-1:r]
    o.sort()
    low=0
    high=len(o)-1
    repsum=0
    while low<l-1 and high>=0:
        if x[low]<o[high]:
            repsum+=o[high]-x[low]
            low+=1
            high-=1
        else:
            break
    low=0
    high=len(y)-1
    rep2=0
    while high>=0 and low<len(o):
        if y[low]<o[high]:
            rep2+=o[high]-y[low]
            low+=1
            high-=1
        else:
            break
    u=max(rep2,repsum)
    print(sum(o)-u)

Submission (verdict: Runtime error on test 2):
t=int(input())

for _ in range(t):

    n,l,r=map(int,input().split())

    if n==1:

        s=input()

        print(int(s))

        continue

    lis=[int(i) for i in input().split()]

    x=lis[:l-1]

    y=lis[r:]

    if len(x)>0:

        x.sort()

    if len(y)>0:

        y.sort()

    o=lis[l-1:r]

    o.sort()

    low=0

    high=len(o)-1

    repsum=0

    while low<l-1 and high>=0:

        if x[low]<o[high]:

            repsum+=o[high]-x[low]

            low+=1

            high-=1

        else:

            break

    low=0

    high=len(y)-1

    rep2=0

    while high>=0 and low<len(o):

        if y[low]<o[high]:

            rep2+=o[high]-y[low]

            low+=1

            high-=1

        else:

            break

    u=max(rep2,repsum)

    print(sum(o)-u)
Problem: 2063B - Subsequence Update
Language: Python 3

Previous submission (verdict: Runtime error on test 2):
t=int(input())

for _ in range(t):

    n,l,r=map(int,input().split())

    if n==1:

        s=input()

        print(int(s))

        continue

    lis=[int(i) for i in input().split()]

    x=lis[:l-1]

    y=lis[r:]

    if len(x)>0:

        x.sort()

    if len(y)>0:

        y.sort()

    o=lis[l-1:r]

    o.sort()

    low=0

    high=len(o)-1

    repsum=0

    while low<l-1 and high>=0:

        if x[low]<o[high]:

            repsum+=o[high]-x[low]

            low+=1

            high-=1

        else:

            break

    low=0

    high=len(y)-1

    rep2=0

    while high>=0 and low<len(o):

        if y[low]<o[high]:

            rep2+=o[high]-y[low]

            low+=1

            high-=1

        else:

            break

    u=max(rep2,repsum)

    print(sum(o)-u)

Submission (verdict: Runtime error on test 2):
t=int(input())
for _ in range(t):
    n,l,r=map(int,input().split())
    if n==1:
        s=input()
        print(int(s))
        continue
    lis=[int(i) for i in input().split()]
    x=lis[:l-1]
    y=lis[r:]
    if len(x)>0:
        x.sort()
    if len(y)>0:
        y.sort()
    o=lis[l-1:r]
    o.sort()
    low=0
    high=len(o)-1
    repsum=0
    while low<l-1 and high>=0:
        if x[low]<o[high]:
            repsum+=o[high]-x[low]
            low+=1
            high-=1
        else:
            break
    low=0
    high=len(y)-1
    rep2=0
    while high>=0 and low<len(y):
        if y[low]<o[high]:
            rep2+=o[high]-y[low]
            low+=1
            high-=1
        else:
            break
    u=max(rep2,repsum)
    print(sum(o)-u)
Problem: 2063B - Subsequence Update
Language: Python 3

Previous submission (verdict: Runtime error on test 2):
t=int(input())
for _ in range(t):
    n,l,r=map(int,input().split())
    if n==1:
        s=input()
        print(int(s))
        continue
    lis=[int(i) for i in input().split()]
    x=lis[:l-1]
    y=lis[r:]
    if len(x)>0:
        x.sort()
    if len(y)>0:
        y.sort()
    o=lis[l-1:r]
    o.sort()
    low=0
    high=len(o)-1
    repsum=0
    while low<l-1 and high>=0:
        if x[low]<o[high]:
            repsum+=o[high]-x[low]
            low+=1
            high-=1
        else:
            break
    low=0
    high=len(y)-1
    rep2=0
    while high>=0 and low<len(y):
        if y[low]<o[high]:
            rep2+=o[high]-y[low]
            low+=1
            high-=1
        else:
            break
    u=max(rep2,repsum)
    print(sum(o)-u)

Submission (verdict: Accepted):
t=int(input())
for _ in range(t):
    n,l,r=map(int,input().split())
    if n==1:
        s=input()
        print(int(s))
        continue
    lis=[int(i) for i in input().split()]
    x=lis[:l-1]
    y=lis[r:]
    if len(x)>0:
        x.sort()
    if len(y)>0:
        y.sort()
    o=lis[l-1:r]
    o.sort()
    low=0
    high=len(o)-1
    repsum=0
    while low<l-1 and high>=0:
        if x[low]<o[high]:
            repsum+=o[high]-x[low]
            low+=1
            high-=1
        else:
            break
    low=0
    high=len(o)-1
    rep2=0
    while high>=0 and low<len(y):
        if y[low]<o[high]:
            rep2+=o[high]-y[low]
            low+=1
            high-=1
        else:
            break
    u=max(rep2,repsum)
    print(sum(o)-u)
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

void solve() {
    int n;
    cin>>n;
    vector<int> deg(n);
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        deg[x]++,deg[y]++;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    auto cmp=[&](int x,int y){
        return deg[x]<deg[y];
    };
    priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
    for(int i=0;i<n;i++){
        pq.push(i);
    }
    int x=pq.top();
    pq.pop();
    for(int y:adj[x]){
        deg[y]--;
    }
    int y=pq.top();
    int ans=deg[x]+deg[y]-1;
    for(int v:adj[x]){
        ans=max(ans,deg[v]==0?deg[x]-1:deg[x]+deg[v]);
    }
    cout<<ans<<"\n";
}

int main(){  
    ios::sync_with_stdio(0);cin.tie(0);
    int t=1;
    cin>>t; 
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

void solve() {
    int n;
    cin>>n;
    vector<int> deg(n);
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        deg[x]++,deg[y]++;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    auto cmp=[&](int x,int y){
        return deg[x]<deg[y];
    };
    priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
    for(int i=0;i<n;i++){
        pq.push(i);
    }
    int x=pq.top();
    pq.pop();
    for(int y:adj[x]){
        deg[y]--;
    }
    int y=pq.top();
    int ans=deg[x]+deg[y]-1;
    // for(int v:adj[x]){
    //     ans=max(ans,deg[v]==0?deg[x]-1:deg[v]==1?deg[x]:deg[x]+deg[v]);
    // }
    cout<<ans<<"\n";
}

int main(){  
    ios::sync_with_stdio(0);cin.tie(0);
    int t=1;
    cin>>t; 
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

void solve() {
    int n;
    cin>>n;
    vector<int> deg(n);
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        deg[x]++,deg[y]++;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    auto cmp=[&](int x,int y){
        return deg[x]<deg[y];
    };
    priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
    for(int i=0;i<n;i++){
        pq.push(i);
    }
    // int x=pq.top();
    // pq.pop();
    if(n==2){
        cout<<0<<'\n';
        return;
    }
    int a=pq.top();
    pq.pop();
    int b=pq.top();
    pq.pop();
    int c=pq.top();
    pq.pop();
    if(deg[a]==deg[b] && deg[b]==deg[c]){
        cout<<deg[a]*2-1<<'\n';
        return;
    }
    pq.push(b);
    pq.push(c);
    for(int y:adj[a]){
        deg[y]--;
    }
    int y=pq.top();
    int ans=deg[a]+deg[y]-1;
    // for(int v:adj[x]){
    //     ans=max(ans,deg[v]==0?deg[x]-1:deg[v]==1?deg[x]:deg[x]+deg[v]);
    // }
    cout<<ans<<"\n";
}

int main(){  
    ios::sync_with_stdio(0);cin.tie(0);
    int t=1;
    cin>>t; 
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

void solve() {
    int n;
    cin>>n;
    vector<int> deg(n);
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        deg[x]++,deg[y]++;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    auto cmp=[&](int x,int y){
        return deg[x]<deg[y];
    };
    priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
    for(int i=0;i<n;i++){
        pq.push(i);
    }
    int x=pq.top();
    pq.pop();
    for(int y:adj[x]){
        deg[y]--;
    }
    int y=pq.top();
    int ans=deg[x]+deg[y]-1;
    for(int v:adj[x]){
        ans=max(ans,deg[v]==0?deg[x]-1:deg[x]+deg[v]);
    }
    cout<<ans<<"\n";
}

int main(){  
    ios::sync_with_stdio(0);cin.tie(0);
    int t=1;
    cin>>t; 
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

void solve() {
    int n;
    cin>>n;
    vector<int> deg(n);
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        deg[x]++,deg[y]++;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    auto cmp=[&](int x,int y){
        return deg[x]<deg[y];
    };
    priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
    for(int i=0;i<n;i++){
        pq.push(i);
    }
    int x=pq.top();
    pq.pop();
    for(int y:adj[x]){
        deg[y]--;
    }
    int y=pq.top();
    int ans=deg[x]+deg[y]-1;
    // for(int v:adj[x]){
    //     ans=max(ans,deg[v]==0?deg[x]-1:deg[v]==1?deg[x]:deg[x]+deg[v]);
    // }
    cout<<ans<<"\n";
}

int main(){  
    ios::sync_with_stdio(0);cin.tie(0);
    int t=1;
    cin>>t; 
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


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

void solve()
{
	string str;
	cin>>str;
	
	int n=str.length();
	vector<vector<int>> arr(n,vector<int>(10,0));
	
	arr[0][str[0]-'0']++;
	if(str[0]<='3') arr[0][(str[0]-'0')*(str[0]-'0')]++;

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(arr[i-1][j]>0)
			{
				int temp=str[i]-'0';
				arr[i][(j+temp)%9]++;
				if(temp<=3) arr[i][(j+temp*temp)%9]++;
			}
		}
	}
	
	// for(int i=0;i<10;i++) cout<<arr[n-1][i]<<" ";
	// cout<<"\n";
	if(arr[n-1][0]>0) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

void solve()
{
	string str;
	cin>>str;
	
	int n=str.length();
	vector<vector<int>> arr(n,vector<int>(10,0));
	
	arr[0][str[0]-'0']++;
	if(str[0]<='3') arr[0][((str[0]-'0')*(str[0]-'0'))%9]++;

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(arr[i-1][j]>0)
			{
				int temp=str[i]-'0';
				arr[i][(j+temp)%9]++;
				if(temp<=3) arr[i][(j+temp*temp)%9]++;
			}
		}
	}
	
	// for(int i=0;i<10;i++) cout<<arr[n-1][i]<<" ";
	// cout<<"\n";
	if(arr[n-1][0]>0) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	ios_base::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;

void solve()
{
	string str;
	cin>>str;
	
	int n=str.length();
	vector<vector<int>> arr(n,vector<int>(10,0));
	
	arr[0][(str[0]-'0')%9]++;
	if(str[0]<='3') arr[0][((str[0]-'0')*(str[0]-'0'))%9]++;

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(arr[i-1][j]>0)
			{
				int temp=str[i]-'0';
				arr[i][(j+temp)%9]++;
				if(temp<=3) arr[i][(j+temp*temp)%9]++;
			}
		}
	}
	
	// for(int i=0;i<10;i++) cout<<arr[n-1][i]<<" ";
	// cout<<"\n";
	if(arr[n-1][0]>0) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

void solve()
{
	string str;
	cin>>str;
	
	int n=str.length();
	vector<vector<int>> arr(n,vector<int>(10,0));
	
	arr[0][str[0]-'0']++;
	if(str[0]<='3') arr[0][(str[0]-'0')*(str[0]-'0')]++;

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(arr[i-1][j]>0)
			{
				int temp=str[i]-'0';
				arr[i][(j+temp)%9]++;
				if(temp<=3) arr[i][(j+temp*temp)%9]++;
			}
		}
	}
	
	// for(int i=0;i<10;i++) cout<<arr[n-1][i]<<" ";
	// cout<<"\n";
	if(arr[n-1][0]>0) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}

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

void solve()
{
	string str;
	cin>>str;
	
	int n=str.length();
	vector<vector<int>> arr(n,vector<int>(10,0));
	
	arr[0][str[0]-'0']++;
	if(str[0]<='3') arr[0][((str[0]-'0')*(str[0]-'0'))%9]++;

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(arr[i-1][j]>0)
			{
				int temp=str[i]-'0';
				arr[i][(j+temp)%9]++;
				if(temp<=3) arr[i][(j+temp*temp)%9]++;
			}
		}
	}
	
	// for(int i=0;i<10;i++) cout<<arr[n-1][i]<<" ";
	// cout<<"\n";
	if(arr[n-1][0]>0) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}