ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int tsum=0;
        for(int i=0;i<n;i++){
            tsum+=arr[i];
        }
        int ans=tsum;
        while(arr.size()>1){
            vector<int> nxt;
            for(int j=0;j<arr.size()-1;j++){
                nxt.push_back(arr[j+1]-arr[j]);
            }
            int s=0;
            for(int x:nxt){
                s+=x;
            }
            tsum=max(tsum,(int)abs(s));
            arr=nxt;
        }
        cout<<tsum<<endl;
    }
}




Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define nl "\n"
#define sp " "
#define pb push_back
#define fr(a,b,i) for(int i=a; i<b; i++)
#define v(type) vector<type>
#define vv(type) vector<vector<type>>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define rf(b,a,i) for(int i=b; i>=a; i--)
#define w(t) while(t--)
#define mset multiset
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ms multiset
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define si set<int>
#define sll set<ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define msi multiset<int>
#define msl multiset<ll>
using namespace std;

void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template<typename T>
void print(v(T) v) {
    fr(0, v.size(), i) { cout << v[i] << " "; }
    cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
 
 
ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}
 
 
void run() {
    ll n;
    cin>>n;
    if (n == 1) { 
        ll num;
        cin >> num;
        cout << num << nl;  
        return;
    }
    vll a_old(n);
    ll sum = 0;
    fr(0, n, i) {
        cin>>a_old[i];
        sum += a_old[i];
    }
    ll k = n;ll new_sum = 0;ll ans = 0;
    while(k>1){
    vll a_new(k - 1);
    new_sum = 0;
    fr(0,k-1,i){
        a_new[i] = a_old[i+1]-a_old[i];
        new_sum += a_new[i];
    }
    a_old = a_new;
    ans = max(ans,abs(new_sum));
    k--;
    }
    cout<<max(sum,ans)<<nl;
    
;}

int main() {
    fastIO();
 
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
 
 
    int t;
    cin >> t;
    w(t) {
        run();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

using namespace std;

using ll = long long;

using vll = vector <ll>;

using ii = pair <ll, ll>;

using vii = vector <ii>;



int main(){

    ios::sync_with_stdio(false); cin.tie(0);

    int t; cin >> t;

    while(t--){

        string s; cin >> s;

        int n=0, m=0;

        int ans=0;

        bool flag=0;

        for(char c:s){

            if(c=='2') n+=1;

            if(c == '3') m+=1;

            ans = (ans + (c-'0') % 9) % 9;

        }

        n = (n>=8)? 8:n;

        m = (m>=8)? 8:m;

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

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

                if((ans + (x*2+y*6)%9)%9 == 0){

                    flag = 1;

                }

            }

        }

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

        else cout << "No\n";

        

    }

}

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

#define ll long long

#define vi vector<int>

#define pll pair<long long,long long>

#define t(ok) ok?cout<<"YES"<<endl:cout<<"NO"<<endl;

#define vll vector<long long>

#define vpll vector <pair<ll,ll>>

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

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

#define py cout << "YES" << endl

#define pn cout << "NO" << endl

#define print(vec) for(int zwzq = 0; zwzq < vec.size() ; zwzq++){cout << vec[zwzq] << ' ';}cout << endl;

#define print_pair(vec) for(int zwzq = 0; zwzq < vec.size() ; zwzq++){cout << '[' <<vec[zwzq].first << ',' << vec[zwzq].second << ']' << ' ';}cout << endl;

#define pl "\n"

using namespace std;

long long powermod(long long x, long long y, long long p){

    long long res = 1;

    x = x % p;

    if (x == 0){return 0;}

    while (y > 0){

        if (y & 1)

            res = (res * x) % p;

        y = y >> 1;

        x = (x * x) % p;

    }

   return res;

}





void solve(){

   string s;

   cin>>s;

   ll sum = 0LL;

   map<int,int>mp;

   f(i,0,s.size()){

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

        if (s[i]-'0'==2 ||s[i]-'0'==3){

        mp[s[i]-'0']++;}

   }    

//    cerr<<sum<<" "<<s<<endl;

//    int val = sum%9;

//    bool ok = false;

   f(i,0,min(10,mp[2]+1)){

    f(j,0,min(10,mp[3]+1)){

        if ((sum + i*2+j*6)%9==0) {cout<<"YES"<<pl;return;}

    }

   }

   cout<<"NO"<<pl;

//    if (val == 0) {ok = true;}

//    else if (val ==1 && (mp[3]&&mp[2])||(mp[2]>3)) {ok = true;}

//    else if (val ==2 && (mp[3]>1&&mp[2]>1)||(mp[3]&&mp[2]>4)||mp[2]>7) {ok = true;}

//    else if (val ==3 && (mp[3]) || (mp[2]>2)) {ok = true;}

//    else if (val ==4 && (mp[3]>1&&mp[2]) || (mp[3] && mp[2]>3) || mp[2]>6){ ok = true;}

//    else if (val ==5 && mp[2]>1) {ok = true;}

//    else if (val ==6 && (mp[3]>1) || (mp[2]>5) || (mp[3] && mp[2]>2)){ ok = true;}

//    else if (val ==7 && mp[2]) {ok = true;}

//    else if (val ==8 && (mp[3]&&mp[2]>1) || (mp[2]>4)) {ok = true;}

//    t(ok)

                }

// FIND BRUTE FORCE FIRST 

int main(){



    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



    ll t;

    cin >> t;

    while (t--){

      solve();

        }

    return 0;

}
Problem: 2049B - pspspsps
Language: c++17 

Solution 1 (runtime: 46 ms):
#if 1

#ifdef ONLINE_JUDGE

#define vangtruong ios_base::sync_with_stdio(false); cin.tie(nullptr)//Expert --> delete

#define hihihaha //*** debug ***//

#define debug(x) //*** debug ***//

#define debugv(x) //*** debug ***//

#include<bits/stdc++.h>

#else

#include "D:/05.Learning/01.Algorithm/01.Algorithms/debug.h"

#endif

using namespace std;

//*** define ***//

#define int long long

#define INF LONG_LONG_MAX

#define MP make_pair

#define FOR(_i,_a,_b) for(int _i = (_a); _i < (_b); _i++)

#define FORI(_i,_a,_b) for(int _i = (_a); _i <= (_b); _i++)

#define FORE(it,x) for(auto it = x.begin(); it != x.end(); ++it)

using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>;

using vc = vector<char>; using vvc = vector<vc>; using pi = pair<int,int>; int itemp = 0; string stemp = "";

#endif

//**************************** CODING SPACE ****************************//



void solve() {

    int n; cin >> n;

    string v; cin >> v; vi P(n), S(n);

    FOR(i,0,n){

        if(v[i] == 'p') P[i] = i+1;

        if(v[i] == 's') S[i] = n-i;

    }

    // debug(P); debug(S);

    // check P

    FOR(i,0,n-1) {

        if(P[i] == 0) continue;

        for(int k = n-1; k >= 1; k--) {

            if(S[k] == 0) continue;

            cout << "NO\n"; return;

        }

    }

    cout << "YES\n";

}



int32_t main() {

    vangtruong; int tcs = 1; cin >> tcs;

    while (tcs--) {solve();} hihihaha; return 0; }

Solution 2 (runtime: 46 ms):
// Author : Hardik Ahuja



#include <bits/stdc++.h>

using namespace std;



#define int long long

#define loop(i,m,n) for(int i = (m);i < (n);i++)

#define rloop(i,m,n) for(int i = (m);i >= (n);i--)

#define ivec(vec) for(int i = 0;i < vec.size();i++)cin>>vec[i]

#define ovec(vec) for(int i = 0;i < vec.size();i++)cout<<vec[i]<<' '

#define endl '\n'

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

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





void solve(){

    int n;cin>>n;

    string s;cin>>s;



    int p = 0;

    int c = 0;

    int dot = 0;

    for(auto i: s){

        if(i == 's')c++;

        else if(i == 'p')p++;

        else dot++;

    }



    if(p + dot == n){

        YES;

    }

    else if(c + dot == n){

        YES;

    }

    else if(c == 1 && s[0] == 's' && p + dot == n - 1)YES;

    else if(p == 1 && s[n - 1] == 'p' && c + dot == n - 1)YES;

    else NO;





}



int32_t main(){



    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: c++17 

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

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

    x--,y--;

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

        v[(x + i) % n] = i % 2;

    }

    if (n % 2 || (x - y) % 2 == 0)

        v[x] = 2;

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

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

    

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}

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

using namespace std;

 

void solve(){

   int n,x,y;

cin>>n>>x>>y;

 --x;--y;

int a[n];

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

    a[(x+i)%n]=i%2;

    if(n%2!=0 || (x-y)%2==0){

        a[x]=2;

    }

}

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

        cout<<a[i]<<" ";

    }

    cout<<endl;

    }

    

 

 

 

    

int main(){

    long long t;

	cin>>t;

	while(t--)

    {

       solve();

}

}
Problem: 2050B - Transfusion
Language: c++17 

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

 

using namespace std;



int a[300000];

 

void phong(){

    int n;

    long long sum = 0;

    cin  >> n;

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

        cin >> a[i];

        sum += a[i];

    }

    

    if (sum%n != 0){

        cout << "no" << endl;

        return;

    }

    

    sum = sum/n;

    

    long long cc = 0;

    

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

        cc += (a[i] - sum);

    }

    

    if (cc != 0){

        cout << "no" << endl;

        return;

    }

    

    cc = 0;

    

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

        cc += (a[i] - sum);

    }

    

    if (cc != 0){

        cout << "no" << endl;

        return;

    }

    

    cout << "yes" << endl;

}

 

int main(){

    int x;

    cin >> x;

    for (int i=1; i<=x; i++) phong();

    return 0;

}

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vector<int>arr(n);

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

    {

        cin>>arr[i];

    }

    long long sumEven=0;

    long long sumOdd=0;

    long long indEven=(n + 1) / 2;

    long long indOdd=n / 2;

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

    {

        if(i%2==0){

            sumEven+=arr[i];

        }

        else{

            sumOdd+=arr[i];

        }

    }

    if(sumEven%indEven !=0 || sumOdd%indOdd != 0){

        cout<<"NO"<<endl;

        return;

    }

    if(sumEven/indEven == sumOdd/indOdd ){

        cout<<"YES"<<endl;

        return;

    }

    cout<<"NO"<<endl;

    return;

}



int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 625 ms):
// Online C++ compiler to run C++ program online
#include <iostream>
#include<queue>
#include<vector>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int m,n;
        cin>>m>>n;
        priority_queue<int> a;
        priority_queue<int> b;
        for(int i=0;i<m;i++){
            int x;
            cin>>x;
            a.push(x);
        }
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            b.push(x);
        }
        bool ans=true;
        while(!a.empty() && !b.empty()){
            int first=a.top();
            int second=b.top();
            if(first>second || a.size()<b.size()){
                ans=false;
                break;
            }
            else if(first==second){
                a.pop();
                b.pop();
            }
            else{
                b.pop();
                int x=second/2;
                b.push(x);
                b.push(second-x);
            }
        }
        if(!a.empty() || !b.empty())
            ans=false;
        cout<<(ans?"YES":"NO")<<endl;
        
    }
    return 0;
}

Solution 2 (runtime: 718 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define nl "\n"
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pair<ll,ll>>vpll;
#define pb                push_back 
#define fori(n)           for (ll i=0; i<n; i++) 
#define forj(n)           for (ll j=0; j<n; j++) 
#define isort(v)          sort(v.begin(),v.end())
#define dsort(v)          sort(v.rbegin(),v.rend())
#define all(x)            (x).begin(), (x).end()

const ll M = 1e9+7;

void solve(){
	ll n,m;
	cin>>n>>m;
	vll v(n);
	fori(n){
		cin>>v[i];
	}
	isort(v);
	priority_queue<ll>pq;
    fori(m){
		ll a;cin>>a;
        pq.push(a);
	}
	ll p = n-1;
	while(p>=0){
		if(pq.size()>p+1 || pq.empty()){
			cout<<"No"<<nl;
			return;
		}
		if(pq.top()>v[p]){
			ll element = pq.top();
			pq.pop();
			pq.push(element/2);
			pq.push(element/2+element%2);
		}else if(pq.top()<v[p]){
			cout<<"No"<<nl;
			return;
		}else{
			pq.pop();
			p--;
		}
	}
	cout<<"Yes"<<nl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt;cin >> tt;for (int i=1; i<=tt; i++){solve();}
    // solve();
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 108 ms):
#include<iostream>

#include<algorithm>

#define int long long

using namespace std;



const int N=1e5+5;



int t;

int a[N],b[N];



inline bool cmp(int a,int b){

	return a<b;

}



inline void work(){

	int n,l,r;

	int a_=0,b_=0;

	cin>>n>>l>>r;

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

	sort(a+1,a+r+1,cmp);

	sort(b+l,b+n+1,cmp);

	for(int i=1;i<=r-l+1;++i)a_+=a[i];

	for(int i=l;i<=r;++i)b_+=b[i];

	cout<<min(a_,b_)<<"\n";

	return ;

}



signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--)work();

	return 0;

}

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

#include <vector>

#include <algorithm>

using namespace std;



void solve() {

    int n, l, r;

    cin >> n >> l >> r;

    l--;

    r--;



    vector<int> arr(n);

    for (int i = 0; i < n; i++) cin >> arr[i];

    vector<int> brr = arr;

    sort(brr.begin() + l, brr.end());

    long long ans1 = 0;

    for (int i = l; i <= r; i++) ans1 += brr[i];

    vector<int> crr = arr;

    sort(crr.begin(), crr.begin() + r + 1, greater<int>());

    long long ans2 = 0;

    for (int i = l; i <= r; i++) ans2 += crr[i];

    cout << min(ans1, ans2) << "\n";

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 108 ms):

#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;
#define ww '\n'
#define ll long long int
#define fi(a, b) for (ll i = a; i < b; i++)
#define fj(a, b) for (ll j = a; j < b; j++)
#define fk(a, b) for (ll k = a; k < b; k++)
#define fri(a, b) for (ll i = a; i >= b; i--)
#define frj(a, b) for (ll j = a; j >= b; j--)
#define in(x) \
    ll x;     \
    cin >> x;
#define inarr(x, n) \
    ll x[n];        \
    fi(0, n) cin >> x[i];
#define printarr(x, n)            \
    fi(0, n) cout << x[i] << " "; \
    cout << endl;
#define strin(x) \
    string x;    \
    cin >> x;
#define print(x) cout << x << endl;
#define vi vector<int>
#define vll vector<ll>
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
const ll MOD = 1e9 + 7;
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end() 
ll FIND_LCM(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

vector<vector<int>>dp; 

int helper(string &a,string &b,string &c,int i,int j)
{
    if(i==a.size() && j==b.size()) 
        return 0;
    if(dp[i][j]!=-1) 
        return dp[i][j];

    int res = 1e9; 
    int pos = i+j;
    
    if(i<a.size()){
        int cost = helper(a,b,c,i+1,j) + (a[i]!=c[pos]);
        res = min(res,cost);
    }
    
    if(j<b.size()){
        int cost = helper(a,b,c,i,j+1) + (b[j]!=c[pos]);
        res = min(res,cost);
    }
    
    return dp[i][j] = res;
}

void  solve()
{
    string a,b,c; cin >> a >> b >> c;
    int n = a.size(); 
    int m = b.size();  
    dp.assign(n+1,vector<int>(m+1,-1));
    cout << helper(a,b,c,0,0) << ww;
}

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

   
    return 0;
}


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

using namespace std;

#define ll long long

ll dp[2000][2000];

void fun()

{

	string a, b, c;

	cin >> a >> b >> c;

	ll la = a.size();

	ll lb = b.size();

	for (ll i = 0; i <= la; i++)

		for (ll j = 0; j <= lb; j++)

			dp[i][j] = 200000;

	dp[0][0] = 0;

	for (ll i = 0; i <= la; i++)

		for (ll j = 0; j <= lb; j++)

		{

			if (i < la)

			{

				ll pos = i + j;

				if (pos < c.size())

				{

					ll tem = dp[i][j] + (a[i] != c[pos] ? 1 : 0);

					dp[i + 1][j] = min(dp[i+1][j], tem);

				}

			}

			if (j < lb)

			{

				ll pos = i + j;

				if (pos < c.size())

				{

					ll tem = dp[i][j] + (b[j] != c[pos] ? 1 : 0);

					dp[i][j + 1] = min(dp[i][j+1], tem);

				}

			}

		}



	cout << dp[la][lb] << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

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

Solution 1 (runtime: 264 ms):
#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
	int t;
	cin>>t;
	while(t--){
		long long n,m;
		cin>>n>>m;
		mp.clear();
		for(int i=1;i<=n;i++){
			int a;
			cin>>a;
			mp[a]++;
		}
		multiset<int>st;
		for(auto b:mp)
			st.insert(b.second);
		int ans=st.size();
		for(int a:st){
			if(m>=a)ans--,m-=a;
		}cout<<max(1,ans)<<'\n';
	}
}

Solution 2 (runtime: 280 ms):

#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
	int T;
	cin>>T;
	while(T--){
		long long n,m;
		cin>>n>>m;
		mp.clear();
		for(int i=1;i<=n;i++){
			int a;
			cin>>a;
			mp[a]++;
		}
		multiset<int>st;
		for(auto b:mp){
			st.insert(b.second);
		}
		int ans=st.size();
		for(int a:st){
			if(m>=a)ans--,m-=a;
		}cout<<max(1,ans)<<'\n';
	}
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define all(a) a.begin(), a.end()
#define pii pair<ll, ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

void solve(string num)
{
    ll num2 = 0, num3 = 0;
    ll sum = 0;
    for (auto i : num)
    {
        sum += i - '0';
        if (i == '2')
        {
            num2++;
        }
        else if (i == '3')
        {
            num3++;
        }
        sum = sum % 9;
    }
    if (sum % 9 == 0)
    {
        yes;
        return;
    }
    for (int i = 0; i <= num2; i++)
    {
        for (int j = 0; j <= num3; j++)
        {
            ll xx = sum + (6 * j) + (2 * i);
            if (xx % 9 == 0)
            {
                yes;
                return;
            }
        }
    }
    no;
}
int main()
{

    ll t;
    cin >> t;
    while (t--)
    {
        string num ; 
        cin >> num ; 
        solve(num);
    }

    return 0;
}

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

using namespace std;

using ll = long long;

using pll = pair<long, long>;

using pii = pair<int, int>;



int two, three;

ll sum;



void solve() {

  string temp;

  cin >> temp;



	sum = 0;

  two = 0;

  three = 0;



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

    int x = temp[i] - '0';

    if (x == 2) {

      two++;

    } else if (x == 3) {

      three++;

    } else {

      sum += x;

    }

  }



  for (int w = 0; w <= min(two, 8); w++) {

    for (int h = 0; h <= min(three, 8); h++) {

      if ((sum + w * 4 + (two - w) * 2 + h * 9 + (three - h) * 3) % 9 == 0) {

        cout << "YES" << endl;

        return;

      }

    }

  }

  cout << "NO" << endl;

}



signed main() {

  int t;

  cin >> t;

  while (t > 0) {

    solve();

    t--;

  }

}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 859 ms):
// GO GET GOLD ALLAHUAKBAR
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
const int MAXN = 2e5;

int n, m;
int a[MAXN+5];
int b[MAXN+5];
unordered_map<int, int> frek;

void reset(){
    for(int i = 0; i <= n+1; i++){
        a[i] = 0;
        b[i] = 0;
    }
    frek.clear();
}

bool merge(int x, int y){
    // cerr << "xy : " << x << ' ' << y << endl;
    bool ret = 1;
    if(frek[x] == 0){
        if(x/2 == 0) return 0;
        ret = merge(x/2, (x+1)/2);
    }else{
        frek[x]--;
    }

    if(!ret) return ret;

    if(frek[y] == 0){
        if(y/2 == 0) return 0;
        ret = merge(y/2, (y+1)/2);
    }else{
        frek[y]--;
    }
    
    return ret;
}

void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        frek[a[i]]++;
    }
    for(int i = 1; i <= m; i++){
        cin >> b[i];
    }
    sort(b, b+m+1);

    bool yes = 1;
    for(int i = 1; i <= m; i++){
        if(frek[b[i]]){
            frek[b[i]]--;
            continue;
        }

        yes = merge(b[i]/2, (b[i]+1)/2);
        if(!yes) break;
    }

    for(auto i : frek){
        if(i.second){
            yes = 0;
            break;
        }
    }

    if(yes) cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

    int tc = 1; 
    cin >> tc;
    while(tc--){
        reset();
        solve();
    }


    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;
    while (tt--) {
        int n, m; cin >> n >> m;
        priority_queue<int> a, b;
        for (int i = 0; i < n; ++i) {
            int x; cin >> x;
            a.push(x);
        }
        for (int i = 0; i < m; ++i) {
            int x; cin >> x;
            b.push(x);
        }
        int times = n - m;
        bool can = true;
        while (times && !a.empty() && !b.empty()) {
            if (a.top() == b.top()) {
                a.pop();
                b.pop();
                continue;
            }
            else if (a.top() < b.top()) {
                int aux = b.top();
                b.pop();
                b.push((aux + 1) / 2);
                b.push(aux / 2);
                times--;
            }
            else {
                can = false;
                break;
            }
        }
        if (!can) {
            cout << "NO\n";
            continue;
        }
        if (a.size() == b.size()) {
            while (!a.empty()) {
                if (a.top() == b.top()) a.pop(), b.pop();
                else {
                    can = false;
                    break;
                }
            }
            cout << (can ? "YES" : "NO") << "\n";
        }
        else {
            cout << "NO\n";
        }
    }
    return 0;
}