ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

string solve() {
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    if (accumulate(a,a+n,0LL) != accumulate(b,b+m,0LL)) return "No";
    priority_queue<ll> pq;
    for (int x : b) pq.push(x);
    map<ll,ll> freq;
    for (int x : a) freq[x]++;
    while (!pq.empty()) {
        ll x = pq.top(); pq.pop();
        if (freq[x] > 0) {
            freq[x]--;
            continue;
        }
        if (x == 1)
            return "No";
        pq.push(x/2);
        pq.push((x+1)/2);
    }
    return "Yes";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

Submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    
    vector<int> a(n), b(m);
    unordered_map<int, int> freqA;
    priority_queue<int> pq;
    
    int sumA = 0, sumB = 0;
    // Read sequence a and count frequencies.
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sumA += a[i];
        freqA[a[i]]++;
    }
    // Read sequence b and push into the max heap.
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        sumB += b[i];
        pq.push(b[i]);
    }
    
    // If the total sums differ, it's impossible.
    if (sumA != sumB) {
        cout << "No\n";
        return;
    }
    
    // Greedy splitting process:
    // While there are numbers in the heap, try to match numbers in a.
    while (!pq.empty()) {
        int x = pq.top();
        pq.pop();
        
        // If x is required (exists in a), "match" it.
        if (freqA[x] > 0) {
            freqA[x]--;
        } 
        // Otherwise, if x is greater than 1, split it.
        else if (x > 1) {
            int left = x / 2;
            int right = (x + 1) / 2;
            pq.push(left);
            pq.push(right);
        } 
        // If x is 1 and is not required, we cannot split further.
        else {
            cout << "No\n";
            return;
        }
    }
    
    cout << "Yes\n";
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

string solve() {
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    if (accumulate(a,a+n,0LL) != accumulate(b,b+m,0LL)) return "No";
    priority_queue<ll> pq;
    for (int x : b) pq.push(x);
    map<ll,ll> freq;
    for (int x : a) freq[x]++;
    while (!pq.empty()) {
        ll x = pq.top(); pq.pop();
        if (freq[x] > 0) {
            freq[x]--;
            continue;
        }
        if (x == 1)
            return "No";
        pq.push(x/2);
        pq.push((x+1)/2);
    }
    return "Yes";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        cout << solve() << endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    
    vector<int> a(n), b(m);
    unordered_map<int, int> freqA;
    priority_queue<int> pq;
    
    int sumA = 0, sumB = 0;
    // Read sequence a and count frequencies.
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sumA += a[i];
        freqA[a[i]]++;
    }
    // Read sequence b and push into the max heap.
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        sumB += b[i];
        pq.push(b[i]);
    }
    
    // If the total sums differ, it's impossible.
    if (sumA != sumB) {
        cout << "No\n";
        return;
    }
    
    // Greedy splitting process:
    // While there are numbers in the heap, try to match numbers in a.
    while (!pq.empty()) {
        int x = pq.top();
        pq.pop();
        
        // If x is required (exists in a), "match" it.
        if (freqA[x] > 0) {
            freqA[x]--;
        } 
        // Otherwise, if x is greater than 1, split it.
        else if (x > 1) {
            int left = x / 2;
            int right = (x + 1) / 2;
            pq.push(left);
            pq.push(right);
        } 
        // If x is 1 and is not required, we cannot split further.
        else {
            cout << "No\n";
            return;
        }
    }
    
    cout << "Yes\n";
}

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


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

void solve() {
    int n, m, x;
    cin >> n >> m;
    map<int, int> fq;
    priority_queue<int, vector<int>, greater<int>> pq;
    bool ch = true;
    for (int i = 0; i < n; i++) {
        cin >> x;
        pq.push(x);
    }
    for (int i = 0; i < m; i++) {
        cin >> x;
        fq[x]++;
    }
    while (pq.size() > 0) {
        if (fq[pq.top()] > 0) {
            fq[pq.top()]--;
            pq.pop();
        } else {
            if (pq.size() == 1) break;
            int l = pq.top();
            pq.pop();
            if (abs(pq.top()-l)<=1) {
                l+= pq.top();
            } else {
                break;
            }
            pq.pop();
            if (fq[l] > 0) {
                fq[l]--;
            } else {
                if (l < 1e9+7) {
                    pq.push(l);
                }
            }
        }
    }
    for (auto q : fq) {
        if (q.s > 0) ch = false;
    }
    if (ch && pq.size() == 0) { 
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

void solve() {
    int n, m, x;
    cin >> n >> m;
    map<int, int> fq;
    priority_queue<int, vector<int>, greater<int>> pq;
    bool ch = true;
    for (int i = 0; i < n; i++) {
        cin >> x;
        pq.push(x);
    }
    for (int i = 0; i < m; i++) {
        cin >> x;
        fq[x]++;
    }
    while (pq.size() > 0) {
        if (fq[pq.top()] > 0) {
            fq[pq.top()]--;
            pq.pop();
        } else {
            if (pq.size() == 1) break;
            int l = pq.top();
            pq.pop();
            if (abs(pq.top()-l)<=1) {
                l+= pq.top();
            } else {
                break;
            }
            pq.pop();
            if (fq[l] > 0) {
                fq[l]--;
            } else {
                if (l < 1e9+7) {
                    pq.push(l);
                }
            }
        }
    }
    for (auto q : fq) {
        if (q.s > 0) ch = false;
    }
    if (ch && pq.size() == 0) { 
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

void solve() {
    int n, m, x, s1=0, s2=0;
    cin >> n >> m;
    map<int, int> fq;
    queue<int> q;
    for (int i = 0; i < n; i++) {
        cin >> x;
        fq[x]++;
        s1+=x;
    }
    for (int i = 0; i < m; i++) {
        cin >> x;
        q.push(x);
        s2+=x;
    }
    bool ch = true;
    while (q.size() > 0) {
        if (q.size() > n) {
            ch = false;
            break;
        }
        if (fq[q.front()] > 0) {
            fq[q.front()]--;
            q.pop();
        } else {
            int fr = q.front();
            q.pop();
            q.push(fr/2);
            q.push(fr/2+(fr%2));
        }
    }
    for (auto q : fq) {
        if (q.s > 0) ch = false;
    }
    if (ch) {
        cout << "Yes" << endl;
    } else { 
        cout << "No" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    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 int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;
void change(vector<int>&a1,vector<int>&a){
    int n=a.size();
    for(int i=0;i<n-1;i++){
        a1.push_back(a[i+1]-a[i]);
    }
}


void solve() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
if(n==1){
    cout<<a[0]<<endl;
}else{
    vector<int>a1=a;
    int z=accumulate(a.begin(),a.end(),0ll);
for(int i=0;i<n-1;i++){
   vector<int>a2;
   int x=accumulate(a1.begin(),a1.end(),0ll);
   if(x<0)reverse(a1.begin(),a1.end());
   z=max(z,x);
   change(a2,a1);
   a1=a2;
}
int y=accumulate(a1.begin(),a1.end(),0ll);
cout<<max(abs(y),abs(z))<<endl;}
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;
   

    while (t--) {
        solve();
    }

    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 int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;
void change(vector<int>&a1,vector<int>&a){
    int n=a.size();
    for(int i=0;i<n-1;i++){
        a1.push_back(a[i+1]-a[i]);
    }
}


void solve() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
if(n==1){
    cout<<a[0]<<endl;
}else{
    vector<int>a1=a;
    int z=accumulate(a.begin(),a.end(),0ll);
for(int i=0;i<n-1;i++){
   vector<int>a2;
   int x=accumulate(a1.begin(),a1.end(),0ll);
   if(x<0)reverse(a1.begin(),a1.end());
   z=max(z,x);
   change(a2,a1);
   a1=a2;
}
int y=accumulate(a1.begin(),a1.end(),0ll);
cout<<max(abs(y),abs(z))<<endl;}
}

int32_t 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;

#define int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;
void change(vector<int>&a1,vector<int>&a){
    int n=a.size();
    for(int i=0;i<n-1;i++){
        a1.push_back(a[i+1]-a[i]);
    }
}


void solve() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
if(n==1){
    cout<<a[0]<<endl;
}else{
    vector<int>a1=a;
    int z=accumulate(a.begin(),a.end(),0ll);
for(int i=0;i<n-1;i++){
   vector<int>a2;
   int x=accumulate(a1.begin(),a1.end(),0ll);
   if(x<0)reverse(a1.begin(),a1.end());
   z=max(z,x);
   change(a2,a1);
   a1=a2;
}
int y=accumulate(a1.begin(),a1.end(),0ll);
cout<<max(abs(y),(z))<<endl;}
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;
   

    while (t--) {
        solve();
    }

    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 int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;
void change(vector<int>&a1,vector<int>&a){
    int n=a.size();
    for(int i=0;i<n-1;i++){
        a1.push_back(a[i+1]-a[i]);
    }
}


void solve() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
if(n==1){
    cout<<a[0]<<endl;
}else{
    vector<int>a1=a;
    int z=accumulate(a.begin(),a.end(),0ll);
for(int i=0;i<n-1;i++){
   vector<int>a2;
   int x=accumulate(a1.begin(),a1.end(),0ll);
   if(x<0)reverse(a1.begin(),a1.end());
   z=max(z,x);
   change(a2,a1);
   a1=a2;
}
int y=accumulate(a1.begin(),a1.end(),0ll);
cout<<max(abs(y),(z))<<endl;}
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;
   

    while (t--) {
        solve();
    }

    return 0;
}

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

#define int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;
void change(vector<int>&a1,vector<int>&a){
    int n=a.size();
    for(int i=0;i<n-1;i++){
        a1.push_back(a[i+1]-a[i]);
    }
}


void solve() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
if(n==1){
    cout<<a[0]<<endl;
}else{
    int sum2=accumulate(a.begin(),a.end(),0ll);
    vector<int>a1=a;
    int z=accumulate(a.begin(),a.end(),0ll);
while(a1.size()>=1){
   vector<int>a2=a1;
   reverse(a2.begin(), a2.end());
            a1.clear();
            int temp = 0;
            for (int i = 1; i < a2.size(); i++)
            {
                a1.push_back(a2[i] - a2[i - 1]);
                temp = temp + a1.back();
            }
            sum2 = max(sum2, abs(temp));
        }
        cout << sum2 << endl;
}
}


int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;
   

    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


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

void solve()
{
    int n, k; cin >> n >> k;
    std::vector<int> a(n);
    map<int, int>mp;

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }

    vector<pair<int,int>>dmp;
    for(auto x : mp){
        dmp.push_back(make_pair(x.second, x.first));
    }

    for(auto x=dmp.begin(); x!=dmp.end(); x++){
        if(k==0) break;
        else if(x->first<=k){
            //cout << x.first << " ";
            //cout << k << " ";
            k-=x->first; int y=x->second;
            //cout << y << " ";
            mp.erase(y);
            //cout << k << " ";
        }
    }
    //cout << '\n';

    if(mp.size()==0) cout << 1 << '\n';
    else cout << mp.size() << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while(t--) solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
    int n, k; cin >> n >> k;
    std::vector<int> a(n);
    map<int, int>mp;

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }

    vector<pair<int,int>>dmp;
    for(auto x : mp){
        dmp.push_back(make_pair(x.second, x.first));
    }

    for(auto x=dmp.begin(); x!=dmp.end(); x++){
        if(k==0) break;
        else if(x->first<=k){
            //cout << x.first << " ";
            //cout << k << " ";
            k-=x->first; int y=x->second;
            //cout << y << " ";
            mp.erase(y);
            //cout << k << " ";
        }
    }
    //cout << '\n';

    if(mp.size()==0) cout << 1 << '\n';
    else cout << mp.size() << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while(t--) solve();
}

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

void solve()
{
    int n, k; cin >> n >> k;
    std::vector<int> a(n);
    map<int, int>mp;

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }

    vector<pair<int,int>>dmp;
    for(auto x : mp){
        dmp.push_back(make_pair(x.second, x.first));
    }

    for(auto x=dmp.begin(); x!=dmp.end(); x++){
        if(k==0 || mp.size()==1) break;
        else if(x->first<=k){
            //cout << x.first << " ";
            //cout << k << " ";
            k-=x->first; int y=x->second;
            //cout << y << " ";
            mp.erase(y);
            //cout << k << " ";
        }
    }
    //cout << '\n';

    cout << mp.size() << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while(t--) solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
    int n, k; cin >> n >> k;
    std::vector<int> a(n);
    map<int, int>mp;

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }

    vector<pair<int,int>>dmp;
    for(auto x : mp){
        dmp.push_back(make_pair(x.second, x.first));
    }

    for(auto x=dmp.begin(); x!=dmp.end(); x++){
        if(k==0 || mp.size()==1) break;
        else if(x->first<=k){
            //cout << x.first << " ";
            //cout << k << " ";
            k-=x->first; int y=x->second;
            //cout << y << " ";
            mp.erase(y);
            //cout << k << " ";
        }
    }
    //cout << '\n';

    cout << mp.size() << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while(t--) solve();
}

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

void solve()
{
    int n, k; cin >> n >> k;
    std::vector<int> a(n);
    map<int, int>mp;

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }

    vector<int>v;
    for(auto x: mp){
        v.push_back(x.second);
    }

    int ans=v.size();
    sort(v.begin(), v.end());
    for(int i=0; i<v.size()-1; i++){
        if(v[i]<=k){
            ans--; k-=v[i];
        }
    }

    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while(t--) solve();
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ll long long
const int inf = 1e18,mod=1e9+7;

int solve(string a, string b, string c, int i, int j, vector<vi> &dp) {
    if (i + j == c.size()) return 0;

    if (dp[i][j] != -1) return dp[i][j];

    if (i == a.size()) {
        int res = 0;
        for (; j < b.size(); j++) {
            if (b[j] == c[i + j]) res++;
        }
        return dp[i][j] = res;
    }

    if (j == b.size()) {
        int res = 0;
        for (; i < a.size(); i++) {
            if (a[i] == c[i + j]) res++;
        }
        return dp[i][j] = res;
    }

    if (a[i] == c[i + j]) {
        return dp[i][j] = max(1 + solve(a, b, c, i + 1, j,dp), solve(a, b, c, i, j + 1,dp));
    }

    if (b[j] == c[i + j]) {
        return dp[i][j] = max(solve(a, b, c, i + 1, j,dp), 1 + solve(a, b, c, i, j + 1,dp));
    }

    return dp[i][j] = max(solve(a, b, c, i + 1, j, dp), solve(a, b, c, i, j + 1, dp));
}


signed main(){ 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        auto begin = chrono::high_resolution_clock::now();
        string a,b,c;
        cin>>a>>b>>c;
        int res=0;
        vector<vi> dp(a.size()+1,vi(b.size()+1,-1));
        cout<<c.size()-solve(a,b,c,0,0,dp)<<endl;

        auto end = chrono::high_resolution_clock::now();
        auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - begin);
        cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds."<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
    ll t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0;
        int count_2=0;
        int count_3=0;
        int count_9=0;
        for(int i=0;i<n.size();i++){
            sum+=int(n[i])-'0';
            if(int(n[i])-'0'==2){
                count_2+=1;
            }
            if(int(n[i])-'0'==3){
                count_3+=1;
            }
        }
        int flag=0;
        for(int i=0;i<=count_2;i++){
            for(int j=0;j<=count_3;j++){
                ans=sum;
                ans=ans+2*i+3*j;
                if(ans%9==0){
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}
    
        

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
    ll t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0;
        int count_2=0;
        int count_3=0;
        int count_9=0;
        for(int i=0;i<n.size();i++){
            sum+=int(n[i])-'0';
            if(int(n[i])-'0'==2){
                count_2+=1;
            }
            if(int(n[i])-'0'==3){
                count_3+=1;
            }
        }
        int flag=0;
        for(int i=0;i<=count_2;i++){
            for(int j=0;j<=count_3;j++){
                int ans=sum;
                ans=ans+2*i+3*j;
                if(ans%9==0){
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}