ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1<<x)

int n,oo=1000000007,c=1,k,mn=1e9+9,m;

signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
{
  int l,r;cin>>l>>r;m=-1;
  int x=0,y=0;
  for(int i=0;i<=30;i++)
  {
    if(isON(l,i))x=i;
    if(isON(r,i))y=i;
  }
  
    int a=0,b=0,c=0,z=0;
for(int i=30;i>=0;i--)
{
 if(isON(r,i)&&!isON(l,i)&&z!=1){a+=twopowx(i);z=1;x=twopowx(i);}
 else if(isON(l,i)&&isON(r,i)&&!z){b+=twopowx(i);c+=twopowx(i);a+=twopowx(i);}
 else if(z)
 {
  if(!isON(l,i))
  {
    c+=twopowx(i);
    b+=(twopowx(i)-1);
    break;
  }
  else 
  {
    c+=twopowx(i);
    b+=twopowx(i);
  }
 }
}

if(b==c)c+=x;


cout<<a<<" "<<b<<" "<<c<<"\n";
 // cout<<(a^b)+(b^c)+(a^c)<<"\n";
 // cout<<(u^o)+(o^p)+(u^p)<<"\n";

}

}

Submission (verdict: Accepted):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1<<x)

int n,oo=1000000007,c=1,k,mn=1e9+9,m;

signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
{
  int l,r;cin>>l>>r;m=-1;
  int x=0,y=0;
  for(int i=0;i<=30;i++)
  {
    if(isON(l,i))x=i;
    if(isON(r,i))y=i;
  }
  
    int a=0,b=0,c=0,z=0;
for(int i=30;i>=0;i--)
{
 if(isON(r,i)&&!isON(l,i)&&z!=1){a+=twopowx(i);z=1;x=twopowx(i);}
 else if(isON(l,i)&&isON(r,i)&&!z){b+=twopowx(i);c+=twopowx(i);a+=twopowx(i);}
 else if(z)
 {
  if(!isON(l,i))
  {
    c+=twopowx(i);
    b+=(twopowx(i)-1);
    break;
  }
  else 
  {
    c+=twopowx(i);
    b+=twopowx(i);
  }
 }
}

if(b==c)c=r;


cout<<a<<" "<<b<<" "<<c<<"\n";
 // cout<<(a^b)+(b^c)+(a^c)<<"\n";
 // cout<<(u^o)+(o^p)+(u^p)<<"\n";

}

}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1<<x)

int n,oo=1000000007,c=1,k,mn=1e9+9,m;

signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
{
  int l,r;cin>>l>>r;m=-1;
  int x=0,y=0;
  for(int i=0;i<=30;i++)
  {
    if(isON(l,i))x=i;
    if(isON(r,i))y=i;
  }
  
    int a=0,b=0,c=0,z=0;
for(int i=y;i>=0;i--)
{
 if(z==0){ if(isON(r,i)&&isON(l,i))
  {
    a+=twopowx(i);
    b+=twopowx(i);
    c+=twopowx(i);
  }
  else if(!isON(r,i)&&!isON(l,i))continue;
  else 
  {
    a+=twopowx(i);
    if(i>0)
    {
      m=twopowx(y)-1+c;
    }
    x=twopowx(i);
    z=1;
  }}
  else if(z==1)
  {
    if(!isON(l,i)){c+=twopowx(i);}
    
  }

}
b=l;

int mx=0,o=0;
if(c<=l)
{
  c=twopowx(y+1)-1;
 //cout<<c<<"\n";
  for(int i=0;i<=y;i++)
  {
    int x=twopowx(i);
    if(c^x>l&&c^x<r&&c^x!=a)
    {
      if((a^b)+(b^(c^x))+(a^(c^x))>=mx)o=x;
    }
  }
  c=c^o;
  if(a!=r)c=r;
}
if(m!=-1&&m!=a&&m>l&&m<=r)
{
  if((a^b)+(b^c)+(a^c)<(a^b)+(b^m)+(a^m))c=m;
}
if(r-l==2)
{
  a=l;b=r;c=l+1;
}
cout<<a<<" "<<b<<" "<<c<<"\n";
 // cout<<(a^b)+(b^c)+(a^c)<<"\n";
 // cout<<(u^o)+(o^p)+(u^p)<<"\n";

}

}

Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1<<x)

int n,oo=1000000007,c=1,k,mn=1e9+9,m;

signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
{
  int l,r;cin>>l>>r;m=-1;
  int x=0,y=0;
  for(int i=0;i<=30;i++)
  {
    if(isON(l,i))x=i;
    if(isON(r,i))y=i;
  }
  
    int a=0,b=0,c=0,z=0;
for(int i=30;i>=0;i--)
{
 if(isON(r,i)&&!isON(l,i)&&z!=1){a+=twopowx(i);z=1;x=twopowx(i);}
 else if(isON(l,i)&&isON(r,i)&&!z){b+=twopowx(i);c+=twopowx(i);a+=twopowx(i);}
 else if(z)
 {
  if(!isON(l,i))
  {
    c+=twopowx(i);
    b+=(twopowx(i)-1);
    break;
  }
  else 
  {
    c+=twopowx(i);
    b+=twopowx(i);
  }
 }
}

if(b==c)c+=x;


cout<<a<<" "<<b<<" "<<c<<"\n";
 // cout<<(a^b)+(b^c)+(a^c)<<"\n";
 // cout<<(u^o)+(o^p)+(u^p)<<"\n";

}

}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1<<x)

int n,oo=1000000007,c=1,k,mn=1e9+9,m;

signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
{
  int l,r;cin>>l>>r;m=-1;
  int x=0,y=0;
  for(int i=0;i<=30;i++)
  {
    if(isON(l,i))x=i;
    if(isON(r,i))y=i;
  }
  
    int a=0,b=0,c=0,z=0;
for(int i=y;i>=0;i--)
{
 if(z==0){ if(isON(r,i)&&isON(l,i))
  {
    a+=twopowx(i);
    b+=twopowx(i);
    c+=twopowx(i);
  }
  else if(!isON(r,i)&&!isON(l,i))continue;
  else 
  {
    a+=twopowx(i);
    if(i>0)
    {
      m=twopowx(y)-1+c;
    }
    x=twopowx(i);
    z=1;
  }}
  else if(z==1)
  {
    if(!isON(l,i)){c+=twopowx(i);}
    
  }

}
b=l;

int mx=0,o=0;
if(c<=l)
{
  c=twopowx(y+1)-1;
 //cout<<c<<"\n";
  for(int i=0;i<=y;i++)
  {
    int x=twopowx(i);
    if(c^x>l&&c^x<r&&c^x!=a)
    {
      if((a^b)+(b^(c^x))+(a^(c^x))>=mx)o=x;
    }
  }
  c=c^o;
  if(a!=r)c=r;
}
if(m!=-1&&m!=a&&m>l&&m<=r)
{
  if((a^b)+(b^c)+(a^c)<(a^b)+(b^m)+(a^m))c=m;
}
if(r-l==2)
{
  a=l;b=r;c=l+1;
}
cout<<a<<" "<<b<<" "<<c<<"\n";
 // cout<<(a^b)+(b^c)+(a^c)<<"\n";
 // cout<<(u^o)+(o^p)+(u^p)<<"\n";

}

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

Previous submission (verdict: Time limit exceeded on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1ll<<x)
int solve(vector<int>v)
{
  if(v.size()==1)return v[0];
  vector<int>temp;
  int sum=v[0];
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);sum+=v[i];
  }
  int op1=solve(temp);
  
  temp.clear();
  for(int i=0;i<v.size()-1;i++)
  {
    temp.push_back(v[i]-v[i+1]);
  }
  int op2=solve(temp);
  return max({op1,op2,sum});
}
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
  {int n;cin>>n;
  vector<int>vec;
  vec.resize(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  cout<<solve(vec)<<"\n";
}
}

Submission (verdict: Accepted):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1ll<<x)
map<vector<int>,int>mp;
int solve(vector<int>v)
{
  if(v.size()==1)return v[0];
  if(mp.count(v))return mp[v];
  vector<int>temp;
  int sum=v[0];
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);sum+=v[i];
  }
  int op1=solve(temp);
  
  temp.clear();
  for(int i=0;i<v.size()-1;i++)
  {
    temp.push_back(v[i]-v[i+1]);
  }
  int op2=solve(temp);
  return mp[v]=max({op1,op2,sum});
}
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
  {int n;cin>>n;
  vector<int>vec;
  vec.resize(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  cout<<solve(vec)<<"\n";
}
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1ll<<x)
int solve(vector<int>v)
{
  if(v.size()==1)return v[0];
  vector<int>temp;
  int sum=v[0];
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);sum+=v[i];
  }
  int op1=solve(temp);
  reverse(v.begin(),v.end());
  temp.clear();
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);
  }
  int op2=solve(temp);
  return max({op1,op2,sum});
}
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
  {int n;cin>>n;
  vector<int>vec;
  vec.resize(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  cout<<solve(vec)<<"\n";
}
}

Submission (verdict: Time limit exceeded on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1ll<<x)
int solve(vector<int>v)
{
  if(v.size()==1)return v[0];
  vector<int>temp;
  int sum=v[0];
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);sum+=v[i];
  }
  int op1=solve(temp);
  
  temp.clear();
  for(int i=0;i<v.size()-1;i++)
  {
    temp.push_back(v[i]-v[i+1]);
  }
  int op2=solve(temp);
  return max({op1,op2,sum});
}
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
  {int n;cin>>n;
  vector<int>vec;
  vec.resize(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  cout<<solve(vec)<<"\n";
}
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 2):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1ll<<x)
int solve(vector<int>v)
{
  if(v.size()==1)return v[0];
  vector<int>temp;
  int sum=v[0];
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);sum+=v[i];
  }
  int op1=solve(temp);
  reverse(v.begin(),v.end());
  temp.clear();
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);
  }
  int op2=solve(temp);
  return max({op1,op2,sum});
}
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
  {int n;cin>>n;
  vector<int>vec;
  vec.resize(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  cout<<solve(vec)<<"\n";
}
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;

int main()

{

    int t;

    cin >> t;

    while(t--) {

        ll n;

        cin >> n;

        

        unordered_map<int, int> m; 

        vector<int> v;

        ll sum = 0;

        while(n != 0) {

            int x = n % 10;

            v.push_back(x);

            sum += x;

            m[x]++;

            n /= 10; 

        }

        

        ll p = sum % 9;

        

        int a = m[2];

        int b = m[3];

        bool possible = 0;

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

            for(int j = 0; j <= b; j++) {

                if((p + 2 * i + 6 * j) % 9 == 0) {

                    possible = true;

                    break;

                }

            }

            if(possible) break; 

        }

        if(possible) 

            cout << "YES" << endl;

        else 

            cout << "NO" << endl;

    } 



    return 0;

}



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

using namespace std;

typedef long long ll;

 

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        ll sum = 0;

        int freq[10] = {0};

        for (char c : s) {

            int d = c - '0';

            sum += d;

            freq[d]++;

        }

        

       ll p = sum % 9;

        

        int count2 = freq[2], count3 = freq[3];

        bool possible = false;

        for (int i = 0; i <= count2 && !possible; i++){

            for (int j = 0; j <= count3; j++){

                if ((p + 2 * i + 6 * j) % 9 == 0) {

                    possible = true;

                    break;

                }

            }

        }

        

        cout << (possible ? "YES" : "NO") << "\n";

    }

    

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

typedef long long ll;

int main()

{

    int t;

    cin >> t;

    while(t--) {

        ll n;

        cin >> n;

        

        unordered_map<int, int> m; 

        vector<int> v;

        ll sum = 0;

        while(n != 0) {

            int x = n % 10;

            v.push_back(x);

            sum += x;

            m[x]++;

            n /= 10; 

        }

        

        ll p = sum % 9;

        

        if(p == 1) {

            if((m[2] >= 1 && m[3] >= 1) || (m[2] >= 4)) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 2) {

            if((m[3] >= 2 && m[2] >= 2) || (m[3] >= 1 && m[2] >= 5) || m[2] >= 8) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 4) {

            if((m[3] >= 2 && m[2] >= 1) || (m[3] >= 1 && m[2] >= 4) || m[2] >= 7) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 6) {

            if(m[3] >= 2 || (m[3] >= 1 && m[2] >= 3) || m[2] >= 6) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 8) {

            if((m[3] >= 1 && m[2] >= 2) || m[2] >= 5) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 3) {

            if(m[3] >= 1 || m[2] >= 3) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 5) {

            if(m[2] >= 2) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else if(p == 7) {

            if(m[2] >= 1) {

                cout << "YES" << endl;

            } else {

                cout << "NO" << endl;

            }

        } else {

            cout << "YES" << endl;

        }

    }



    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64


Submission (verdict: Time limit exceeded on test 17):
from collections import Counter
for i in range(int(input())):
       n,k=map(int,input().split())
       arr=list(map(int,input().split()))
       idx=0
       cnt=0
       dict1=Counter(arr)
       sorted_dict=sorted(dict1,key=lambda x:dict1[x])
       total=len(sorted_dict)
       for i in sorted_dict:              
              while k>0 and dict1[i]>0:
                     k-=1
                     dict1[i]-=1
              if dict1[i]==0:
                     total-=1
       print(max(total,1))
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 17):
from collections import Counter
for i in range(int(input())):
       n,k=map(int,input().split())
       arr=list(map(int,input().split()))
       idx=0
       cnt=0
       dict1=Counter(arr)
       sorted_dict=sorted(dict1,key=lambda x:dict1[x])
       total=len(sorted_dict)
       for i in sorted_dict:              
              while k>0 and dict1[i]>0:
                     k-=1
                     dict1[i]-=1
              if dict1[i]==0:
                     total-=1
       print(max(total,1))

Submission (verdict: Wrong answer on test 1):
import sys
input = sys.stdin.readline #input
from collections import defaultdict
 
def solve():
    n,k = map(int,input().split())
    arr = input().split()
    freq = defaultdict(lambda: 0)
    total=len(freq)
    for num in arr:
        freq[num]+=1
 
    for key in sorted(freq, key = lambda x: freq[x]):
        if freq[key]<=k:
            k-=freq[key]
            total-=1
        else:
            break
    print(max(total,1))
 
 
for _ in range(int(input())):
    solve()
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
import sys
input = sys.stdin.readline #input
from collections import defaultdict
 
def solve():
    n,k = map(int,input().split())
    arr = input().split()
    freq = defaultdict(lambda: 0)
    total=len(freq)
    for num in arr:
        freq[num]+=1
 
    for key in sorted(freq, key = lambda x: freq[x]):
        if freq[key]<=k:
            k-=freq[key]
            total-=1
        else:
            break
    print(max(total,1))
 
 
for _ in range(int(input())):
    solve()

Submission (verdict: Accepted):
import sys
input = sys.stdin.readline #input
from collections import defaultdict
 
def solve():
    n,k = map(int,input().split())
    arr = input().split()
    freq = defaultdict(lambda: 0)
    for num in arr:
        freq[num]+=1
    total=len(freq)
 
    for key in sorted(freq, key = lambda x: freq[x]):
        if freq[key]<=k:
            k-=freq[key]
            total-=1
        else:
            break
    print(max(total,1))
 
 
for _ in range(int(input())):
    solve()
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 3):
#include <iostream>
#include <math.h>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;

bool recursive(string num, ll iter, ll sum){
    if(sum%9 == 0){
        return true;
    }
    while(num[num.length()-iter] != '2' && num[num.length()-iter] != '3'){
        if(iter > num.length()){
            return false;
        }
        iter++;
    }
    string numTwo = num;
    ll sumTwo = sum;
    if(num[num.length()-iter] == '2'){
        numTwo[num.length()-iter] += 2;
        sumTwo += 2;
    }else if(num[num.length()-iter] == '3'){
        numTwo[num.length()-iter] += 6;
        sumTwo += 6;
    }
    iter++;
    return recursive(num, iter, sum) || recursive(numTwo, iter, sumTwo);
}

void answer(){
    string a;
    cin >> a;
    ll sum = 0;
    for(ll i = 0; i<a.length();i++){
        sum += a[i] - '0'; 
    }
    if(recursive(a, 1, sum)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i<n;i++){
        answer();
    }
    return EXIT_SUCCESS;
}

Submission (verdict: Accepted):
#include <iostream>
#include <math.h>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;

bool recursion(ll sum, ll two, ll three){
    if(sum%9 == 0){
        return true;
    }else if(two == 0 && three == 0){
        return false;
    }
    if(two > 0 && three > 0){
        return recursion(sum+2, two-1, three) || recursion(sum+6, two, three-1);
    }else if(two > 0){
        return recursion(sum+2, two-1, three);
    }else{
        return recursion(sum+6, two, three-1);
    }
}

void answer(){
    string a;
    cin >> a;
    ll sum = 0;
    ll two = 0;
    ll three = 0;
    for(ll i = 0; i<a.length();i++){
        sum += a[i] - '0'; 
        if(a[i] == '2' && two < 9){
            two++;
        }else if(a[i] == '3' && three < 9){
            three++;
        }
    }
    if(recursion(sum, two, three)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i<n;i++){
        answer();
    }
    return EXIT_SUCCESS;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 3):
#include <iostream>
#include <math.h>
#include <limits>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef long double ld;

bool recursive(ll num, ll iter){
    while((num/iter)%10 != 2 && (num/iter)%10 != 3){
        if(iter >= num){
            if(num%9 == 0){
                return true;
            }else{
                return false;
            }
        }
        iter *= 10;
    }
    ll numTwo = num;
    if((num/iter)%10 == 2){
        numTwo += iter*2;
    }else if((num/iter)%10 == 3){
        numTwo += iter*6;
    }
    iter *= 10;
    return recursive(num, iter) || recursive(numTwo, iter);
}

void answer(){
    ll a;
    cin >> a;
    if(recursive(a, 1)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i<n;i++){
        answer();
    }
    return EXIT_SUCCESS;
}

Submission (verdict: Runtime error on test 3):
#include <iostream>
#include <math.h>
#include <limits>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef long double ld;

bool recursive(ll num, ll iter){
    while((num/iter)%10 != 2 && (num/iter)%10 != 3){
        if(num%9 == 0){
            return true;
        }
        if(iter >= num){
            return false;
        }
        iter *= 10;
    }
    ll numTwo = num;
    if((num/iter)%10 == 2){
        numTwo += iter*2;
    }else if((num/iter)%10 == 3){
        numTwo += iter*6;
    }
    iter *= 10;
    return recursive(num, iter) || recursive(numTwo, iter);
}

void answer(){
    ll a;
    cin >> a;
    if(recursive(a, 1)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i<n;i++){
        answer();
    }
    return EXIT_SUCCESS;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 3):
#include <iostream>
#include <math.h>
#include <limits>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef long double ld;

bool recursive(ll num, ll iter){
    while((num/iter)%10 != 2 && (num/iter)%10 != 3){
        if(iter >= num){
            if(num%9 == 0){
                return true;
            }else{
                return false;
            }
        }
        iter *= 10;
    }
    ll numTwo = num;
    if((num/iter)%10 == 2){
        numTwo += iter*2;
    }else if((num/iter)%10 == 3){
        numTwo += iter*6;
    }
    iter *= 10;
    return recursive(num, iter) || recursive(numTwo, iter);
}

void answer(){
    ll a;
    cin >> a;
    if(recursive(a, 1)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i<n;i++){
        answer();
    }
    return EXIT_SUCCESS;
}