ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 78 ms):
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define ll long long



void solve() {

int n;

cin >> n;

vector<int> a(n + 1, 0);

bool is_no = false;

for (int i = 1;i <= n;i++) cin >> a[i];

for (int i = 1;i <= n - 1;i++) {

if (a[i + 1] >= a[i]) {

a[i + 1] = a[i + 1] - a[i];

a[i] = 0;

continue;

}

else {

is_no = true;

break;

}

}

if (!is_no) cout << "YES" << endl;

else cout << "NO" << endl;

}



int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

return 0;

}

Solution 2 (runtime: 328 ms):
#include<bits/stdc++.h>

using namespace std;

void solve(){

int n;

cin>>n;

int arr[n];

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

cin>>arr[i];

}

int k=arr[0];

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

k=arr[i]-k;

if(k<0){ cout<<"no"<<endl;

return;

}

}

cout<<"yes"<<endl;

}

int main(){

int t;

cin>>t;

while(t--){

solve();

}

return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
/* Abhishek Jaiswal */
#include <bits/stdc++.h>
using namespace std;

const long long MOD=1e9+7;

#define ll long long int
#define vi vector<int>
#define vl vector<long long int>
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define umps unordered_map<int, unordered_set<int>>
#define pb push_back
#define pq priority_queue<int>
#define pqp priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>
#define fo(i,a, n) for (int i = a; i < n; i++)
#define fo_(i,a, n) for (int i = a; i > n; i--)


void solve(){
    int n; cin>>n; vi a(n); ll sum=0;
    fo(i,0,n) {
        cin>>a[i];
        sum+= a[i];
    }

    ll maxi = sum;
    reverse(a.begin(), a.end());
    vl b(n);
    fo(i,0,n) b[i] = a[i];
    int j=n-1;
    while(j!=0){
        sum=0;
        fo(i,0,j){
            b[i] = b[i+1]-b[i];
            sum+=b[i];
        }
        maxi = max(maxi, abs(sum));
        j--;
    }
    cout<<maxi<<endl;
}
 
// check if single Testcase is present && overflow && edgecases
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // ifstream cin("closing.in"); ofstream cout("closing.out"); // On Usaco
    int t = 1; cin >> t;
    for (int i = 1; i <= t; i++){
	// cout <<"Case #"<<i<<": ";
        solve();
   }
    return 0;
}


Solution 2 (runtime: 46 ms):
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long 
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double 
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

ll min(ll a, ll b){
	if (a<b)return a;
	return b;
}

ll max(ll a, ll b){
	if (a>b)return a;
	return b;
}

void solve(){
	ll n ; cin >> n;
	vl arr(n);
	ll sum =0;
	for (int i=0;i<n;i++){cin>>arr[i];sum+=arr[i];}
	if (n==1){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		ll s =0;
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
			s+=arr[j];
		}
		sum = max(abs(s),sum);
	}
	cout <<sum<<endl;
}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<iostream>
#include<cstdio>
#include<string> 
#include<algorithm> 
using namespace std;
string s;
const int N=2e5+10;
int b[N];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		bool flag=false;
		int a=0;
		int b=0;
		cin>>s;
		int sum=0;
		int len=s.size(); 
		for(int i=0;i<len;i++){
			sum+=s[i]-'0';
			if(s[i]=='2'){
				a++;
			}
			if(s[i]=='3'){
				b++;
			}
		}
		if(sum%9==0){
			flag=true;
		} 
			for(int i=0;i<=a;i++){
				for(int j=0;j<=b;j++){
					if((sum+i*2+j*6)%9==0){
						flag=true;
						break;
					}
				}
				if(flag==true){
					break;
				}
			}
		if(flag==true){
			printf("YES\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
} 

Solution 2 (runtime: 78 ms):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



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

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    tw=min(tw,10);

    si=min(si,10);



    f(i,0,tw+1){

        f(j,0,si+1){

            int v=(k+2*i+6*j);

            if(v%9==0){

                cout<<"Yes"<<"\n";

                

                return;

            }

        }

    }

    cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#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;
}

Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std; 

#define ll long long

void solve() {
    ll n;
    cin>>n;
    
    vector<ll> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    
    ll res = accumulate(arr.begin(),arr.end(),0LL);
    
    while(n > 1){
        vector<ll> temp(n-1);
        for(ll i=0;i<n-1;i++){
            temp[i] = (arr[i+1] - arr[i]);
        }
        
        res = max(res,abs(accumulate(temp.begin(),temp.end(),0LL)));
        
        for(ll i=0;i<n-1;i++){
            arr[i] = temp[i];
        }
        
        n--;
    }
    
    cout<<res<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin>>t;
    
    while(t--){
        solve();
    }
	
    return 0; 
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int f=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            
        }
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1])f=1;
        }
        
        if(f==1){
            
        int mini=0;
        for(int i=0;i<n-1;i++){
            
            mini=min(a[i],a[i+1]);
            a[i]-=mini;
            a[i+1]-=mini;
        }
         f=1;
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1])
            {
                f=0;
                break;
            }
            //cout<<a[i]<<" ";
            
        }
        (f==1)?cout<<"YES":cout<<"NO";
        
        }
        else cout<<"YES";
        cout<<endl;
        
    }

    return 0;
}

Solution 2 (runtime: 343 ms):
#include <bits/stdc++.h>
using namespace std;

string SubstractMin(int n, vector<long long> &a)
{
    int j = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] > a[i]) j = i;
    }
    if (j == 0) { 
        return "YES";
    }
    for (int i = 0; i < j; i++) {
        long long minN = min(a[i], a[i+1]);
        a[i] -= minN;
        a[i+1] -= minN;
    }
    return (is_sorted(a.begin(), a.end()) ? "YES" : "NO");
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cout << SubstractMin(n, a) << endl;
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
 
long long a[1010];
 
int main(){
	int t;
	cin >> t;
	while (t--){
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl; 
	}
	return 0;
}

Solution 2 (runtime: 46 ms):
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;	cin>>t;
	while(t--){
		long long n,a[100];
		cin>>n;
		long long ans=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];ans+=a[i];
		}
		if(n==1){
			cout<<ans<<endl;
			continue;
		}
		while(n){
			n--;
			long long sum=0;
			for(int i=1;i<=n;i++)a[i]=a[i+1]-a[i];
			for(int i=1;i<=n;i++)sum+=a[i];
			ans=max(ans,abs(sum));
		}
		cout<<ans<<endl;
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include<bits/stdc++.h>

using namespace std;

bool cmp(pair<int,int> &a, pair<int,int> &b) {
    return a.second > b.second;
}

void solution() {
    int n;
    cin >> n;
    vector<long long int>v;
    for(int i = 0; i < n; i++){int a; cin >> a; v.push_back(a);}
    long long int ans = accumulate(v.begin(), v.end(), 0) * 1LL;
    while(v.size() != 1) {
        vector<long long int>v2;
        
        for(int i = 1; i < v.size(); i++) {
            v2.push_back(v[i] - v[i - 1]);
        }
        
        for(int i = 0; i < v2.size(); i++)v[i] = v2[i];
        v.pop_back();
        long long x = 0;
        for(auto it : v2)x += it;
        
        ans = max(ans, max(x, -x));
    }
    long long y = 0;
    for(auto it : v)y += it;
    ans = max(y, ans);

    cout << ans << endl;



}


int main() {
    int t;
    cin >> t;
    while(t--) {
        solution();
    }
}

Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
int T,n;
long long tri[55][55],ans,fir,lst,a[55];
int main(){
    cin>>T;
    tri[1][1]=1;
    tri[2][1]=tri[2][2]=1;
    for(int i=3;i<=51;i++){
        tri[i][1]=tri[i][i]=1;
        for(int j=2;j<i;j++)
        tri[i][j]=tri[i-1][j]+tri[i-1][j-1];
    }
    for(int i=1;i<=T;i++){
        ans=0;
        cin>>n;
        for(int j=1;j<=n;j++){
            cin>>a[j];
            ans+=a[j];
        }
        if(n==1){
            cout<<ans<<endl;
            continue;
        }
        ans=max(ans,a[n]-a[1]);
        ans=max(ans,a[1]-a[n]);
        for(int j=2;j<=n-1;j++){
            fir=lst=0;
            for(int k=1;k<=j;k++){
                if(k%2)
                fir+=a[k]*tri[j][k]*-1;
                else
                fir+=a[k]*tri[j][k];
            }
            int cnt=0;
            for(int k=n-j+1;k<=n;k++){
                cnt++;
                if(cnt%2)
                lst+=a[k]*tri[j][cnt]*-1;
                else
                lst+=a[k]*tri[j][cnt];
            }
            ans=max(ans,fir-lst);
            ans=max(ans,lst-fir);
        }
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 186 ms):
#include <bits/stdc++.h>

using namespace std;

void solve(int tc) {

	int n, l, r;
	cin >> n >> l >> r;

	vector<int> a(n);
	for (auto& e : a) cin >> e;

	--l;
	--r;

	long long s = 0;
	for (int i = l; i <= r; ++i) {
		s += a[i];
	}

	sort(a.begin(), a.begin() + l);
	sort(a.begin() + r + 1, a.end());
	sort(a.begin() + l, a.begin() + r + 1);


	long long answer = s;
	long long s0 = s;

	int i = 0;
	int j = r;
	while (j >= l && i < l && a[j] > a[i]) {
		s0 -= a[j] - a[i];
		j--;
		i++;
	}
	answer = min(answer, s0);

	s0 = s;
	i = r+1;
	j = r;
	while (j >= l && i < n && a[j] > a[i]) {
		s0 -= a[j] - a[i];
		j--;
		i++;
	}
	answer = min(answer, s0);

	cout << answer << '\n';

}

int main() {
	int tt;
	cin >> tt;
	
	while (tt--) {
		solve(tt);
	}

	return 0;
}


Solution 2 (runtime: 92 ms):
#include<bits/stdc++.h>



using namespace std;



#define int long long

#define PB push_back

typedef vector<int> vi;

typedef vector<string> vs;



const int mod = 1e9 + 7;

const int inf = INT_MAX;



template<typename t>

vector<t> I(int n) {

    vector<t> vector;

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

        t input;

        cin >> input;

        vector.push_back(input);

    }



    return vector;

}



template<typename t>

void D(vector<t> vector) {

    for (auto i: vector) {

        cout << i << " ";

    }



    cout << "\n";

}





void solve() {

    int n, l , r;

    cin >> n >> l >> r;

    vi x = I<int>(n);

    vi first(x.begin(), x.begin() + r);

    vi second(x.begin() + l - 1, x.end());

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

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

    long long sum1 = accumulate(first.begin(), first.begin() + (r - l + 1), 0LL);

    long long sum2 = accumulate(second.begin(), second.begin() + (r - l + 1), 0LL);

    cout << min(sum1, sum2) << "\n";

}





int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#define int long long
#define eb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
#define m_p make_pair

using namespace std;

const int N=2e5+5;

int n,arr[N];

inline void init(){
 	string s;
  	cin >>s;n=s.size();
  	for(int i=0;i<n;++i)arr[i]=s[i]-'0';
}

inline void sol(){
	int sum=0,two=0,six=0;
	for(int i=0;i<n;++i){
		sum+=arr[i];
		if(arr[i]==2)++two;
		if(arr[i]==3)++six;
	}
//	cout<<sum<<" "<<two<<" "<<six<<'\n';
	sum%=9;int tmp=10;
	for(int i=0;i<=min(tmp,two);++i){
		for(int j=0;j<=min(tmp,six);++j){
			if((sum+i*2+j*6)%9==0){
				cout<<"YES\n";
				return;
			}
		}
	}

	cout<<"NO\n";
	return;
}

int32_t main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int t;cin >>t;
    while(t--)
    init(),sol();
    return 0;
}


Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>

using namespace std;

const int N=1e5+5;

int T,len,sum;

int cnt2,cnt3;

char a[N];

int main(){

    ios::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);

    cin>>T; while(T--){

        cnt2=cnt3=0;

        cin>>a+1;sum=0;

        len=strlen(a+1);

        for(int i=1;i<=len;++i){

            if(a[i]=='2')++cnt2;

            if(a[i]=='3')++cnt3;

            sum+=a[i]-'0';

        }bool flag=false;



        //cout<<cnt2<<' '<<cnt3<<' '<<sum<<"\n";



        cnt2=min(8,cnt2),

        cnt3=min(8,cnt3),

        sum%=9;

        sum=(9-sum)%9;//2k+6q+sum=0(mod 9)

        for(int k=0;k<=cnt2;++k)

        for(int q=0;q<=cnt3;++q){

            if((2*k+6*q)%9==sum){

                flag=true;

                break;

            }

        }

        if(flag)cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
void solve()
{
    LL l, r;
    cin >> l >> r;
    LL x = l, y = r;
    LL d = 0;
    while (__lg(l) == __lg(r))
    {
        d += LL(1 << __lg(r));
        l -= LL(1 << __lg(r)), r -= LL(1 << __lg(r));
    }
    LL t = LL(1 << __lg(r));
    cout << t + d << ' ' << t + d - 1 << ' ';
    if (t + d == y) cout << x << "\n";
    else cout << y << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T --)
    solve ();
    return 0;
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
#define ll long long
#define db double
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
using namespace std;
ll read(){
	ll sum=0,f=1;char st=getchar();
	while(st<'0'||st>'9'){
		if(st=='-')f=-1;
		st=getchar();
	}
	while('0'<=st&&st<='9'){
		sum=(sum<<3)+(sum<<1)+st-'0';
		st=getchar();
	}
	return sum*f;
}
const int maxn=100010,mod=998244353;
map<int,int> p;
int cnt[maxn];
int main(){
	int TT=read();
	while(TT--){
		int l=read(),r=read(),a=0,b=0,c=0;
		for(int i=30;i>=0;--i){
			int op1=(l>>i)&1,op2=(r>>i)&1;
			if(!op1&&op2){
				c=1<<i;
				for(int j=i-1;j>=0;--j)
					a|=(1<<j);
				break;
			}
		}
		if(c+1<=r)b=c+1;
		if(a-1>=l)b=a-1;
		printf("%d %d %d\n",a,b,c);
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
#define ll long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

void solve(string &str){
for(int i=1;i<str.length();i++){

 for(int j=i;j>0;j--){

if(str[j]-1>str[j-1]){
char temp=str[j];
str[j]=str[j-1];
str[j-1]=char(int(temp)-1);
}
else
  {
    break;
  }

 }


}

}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t;
cin>>t;
while(t--){
    string str;
    cin>>str;
 solve(str);
 cout<<str<<endl;

}}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>

#define pb       push_back

#define ff       first

#define ss       second

#define int      long long

#define out(v)   for(auto x : v) cout<<x<<" "

#define in(v)    for(auto &x:v) cin>>x;

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

#define oyes     cout<<"YES"<<endl

#define ono      cout<<"NO"<<endl

using namespace std;

const int M = 1e9+7;



signed main() {

    int t=1;

    cin>>t;

    while(t--) {

        string s;

        cin>>s;

        for(int i=0; i<s.size(); i++){

            int ind=i;

            for(int j=i; j<min(i+10, (int)s.size()); j++){

                int x=s[j]-(j-i);

                int y=s[ind]-(ind-i);

                if(x>y) ind=j;

            }

            char x=s[ind]-(ind-i);

            for(int j=ind; j>i; j--){

                swap(s[j], s[j-1]);

            }

            s[i]=x;

        }

        cout<<s<<endl;

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long t,sum,two,three; cin>>t;
    string num; bool pom;
    while(t--){
      cin>>num;
      sum=0; two=0; three=0;
      for(int i=0;i<num.length();i++){
        sum+=num[i]-48;
        if(num[i]=='2')two++;
        if(num[i]=='3')three++;
        sum%=9;
      }
      pom=0;
      for(int i=0;i<=two;i++){
        for(int j=0;j<=three;j++){
          if((sum+i*2+j*6)%9==0){
            pom=1;
            break;
          }
          if(pom)break;
        }
      }
        if(pom)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;



template<typename X, typename Y> bool ckmin(X& x , const Y& y ) { return (y < x) ? (x = y, 1) : 0; }

template<typename X, typename Y> bool ckmax(X& x , const Y& y ) { return (x < y) ? (x = y, 1) : 0; }



const int mx = 1e5+1;



void solve() {

    string n;

    cin >> n;



    ll sum = 0;

    ll two = 0, three = 0;

    for(char ele : n) {

        if(ele == '2') two++;

        else if(ele == '3') three++;

        sum += (ele-'0');

    }

    for(int i = 0; i <= min(9ll, two); i++) {

        for(int j = 0; j <= min(9ll, three); j++) {

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

                cout << "YES" << endl;

                return;

            }

        }

    }

    cout << "NO" << endl;



}

 

int main(){

    ios::sync_with_stdio(0);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    // solve();

    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 249 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define MOD 1000000007
#define MAX 1000005
#define pb push_back
#define mp make_pair

void solve()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    map<int,int>umap;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        umap[a[i]]+=1;
    }
    vector<pair<int,int>>mp;
    for (auto& it: umap) {
        pair<int,int>p;
        p.first = it.second;
        p.second = it.first;
        mp.push_back(p);
    }
    sort(mp.begin(), mp.end());
    int total = 0;
    int ans = 1;
    int idx = 0;
    for(int i=0;i<mp.size()-1;i++){
        if(mp[i].first > k){
            ans+=1;
            idx = i;
            break;
        }
        else{
            k = k - mp[i].first;
            idx=i;
        }
    }
    if(mp.size()>1){
        ans+=(mp.size()-idx-2);
    }
    cout<<ans<<endl;


}

int32_t main()
{
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Solution 2 (runtime: 234 ms):
/*********************************************
 * Author  : Gansukh Lkhagva
 * Created : 2025-02-17 20:19
 * Problem : 2057B - Gorilla and the Example
 * Source  : Codeforces Round #1000 (Div. 3)
 * Time    : 
 * Status  : 
 *********************************************/

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long

void solve() {
    int n, k, inp;
    cin >> n >> k;
    map<int, int> mp;
    vector<int> keyCount;
    for(int i = 0; i < n; i++) {
        cin >> inp;
        mp[inp]++;
    }
    for(auto it : mp) {
        keyCount.push_back(it.second);
    }
    sort(keyCount.begin(), keyCount.end());
    int prefixSum = 0, indexCnt=0;
    while(indexCnt < keyCount.size() && prefixSum + keyCount[indexCnt] <= k) {
        prefixSum += keyCount[indexCnt];
        indexCnt++;
    }
    cout << max((int)keyCount.size() - indexCnt, 1) << endl;
}

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