ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

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

using namespace std;

int main()

{

	int t;

	cin >> t;

	while (t--)

	{

		string man;

		cin >> man;

		int n = man.size();

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

		{

			int op = i;

			char pp = man[op];

			int flag = 0;

			char kobe;

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

			{

				if (man[j] - (j - i) > pp)

				{

					op = j;

					pp = man[j] - (j - i);

					flag = 1;

				}

				if (j - i >= 8)

				{

					break;

				}

			}

			





			if (flag == 1)

			{

				man.erase(op, 1);

				man.insert(i, 1, pp);

			}

		}

		cout << man << endl;

	}



}

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

using namespace std;

typedef long long int ll;

typedef vector<int> vi;

typedef vector<vector<int>> vvi;

typedef vector<ll> vll;

typedef pair<int,int>pii;

 

//for vectors

#define sz(x) int(size(x))

#define bg(x) begin(x)

#define all(x) bg(x), end(x)

#define rall(x) rbegin(x), rend(x)

#define sor(x) sort(all(x))

#define rsor(x) sort(rall(x))

#define rsz resize

#define ins insert

#define pb push_back

#define eb emplace_back

#define ft front()

#define bk back()

#define endl '\n'

 



 

void solve(){

    string s;

    cin >> s;

    ll n = s.size();

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

        ll diff = 0;

        ll index = -1;

        for(ll j=i+1; j<min(n, i+8); j++){

            ll tdiff = s[j]-s[i]-(j-i);

            if(tdiff > diff){

                diff = tdiff;

                index = j;

            }

        }

        if(index == -1){

            continue;

        }

        ll temp = s[index];

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

            s[j] = s[j-1];

        }

        s[i] = temp-(index-i);

    }

    cout << s << endl;

    

    

 

}

int main(){ 

    ios_base::sync_with_stdio(false); 

    cin.tie(NULL); 

    int tc;

    cin>>tc;

    while(tc--){

        solve();

    }

    return 0;

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

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        int ans=0;
        for(int i=0;i<n;i++){
            cin >> a[i];
            ans+=a[i];
        }
        while(a.size()>1){
            vector<int> dif;
            for(int i=1;i<a.size();i++){
                dif.push_back(a[i]-a[i-1]);
            }
            a=dif;
            int sum=0;
            for(int i=0;i<a.size();i++){
                sum+=a[i];
            }
            ans=max(ans,abs(sum));
        }
        cout << ans << endl;
    }
}


Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf (1LL<<60)
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
int main() {
   init_code();
   int t;
   cin >> t;
   while(t--){
         int n;
         cin>>n;

         ll arr[n];
         for(int i=0;i<n;i++){
            cin>>arr[i];
         }
         
         ll j=n;
         ll max_sum=0;
         for(int i=0;i<n;i++){
            max_sum+=arr[i];
         }
         if(n>1){
               while(j>0){
               
               
               ll k=0;
               for(ll i=1;i<j;i++){
                  arr[k++]=arr[i]-arr[i-1];
               }
               j--;

               ll sum=0;
               for(int i=0;i<j;i++){
                  sum+=arr[i];
               }
               max_sum=max(max_sum,abs(sum));

            }
         }
         
         cout<<max_sum<<endl;


   }
   return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i, a, b) for(int i = a; i < b; i++)
#define rfo(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) ((a).begin(), (a).end())
#define rall(a) ((a).begin(), (a).end(), greater<int>())
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int, int>>
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define al cout << "Alice\n"
#define bo cout << "Bob\n"
#define deb cout << "#"
#define nl cout << "\n"
#define def(vr) for(auto it : vr) cout << it << " "
#define defp(vr) for(auto it : vr) cout << it.ff << " " << it.ss << "\n"
const int MOD = 1e9 + 7;
const int N = 1e7 + 9;
const int mod = 998244353;
const int mx = 11 * 2 * 1e5 + 1;



void solve()
{   
    int n;    cin>>n;
    vi vr(n);   fo(i,0,n) cin>>vr[i];
    fo(i,1,n)
    {
        if(vr[i]<vr[i-1])
        {
            if(i==1)
            {
                no;
                return;
            }
            else
            {
                if(vr[i]<abs(vr[i-1]-vr[i-2]))
                {
                    no;
                    return;
                }
                int mn=min(vr[i-1],vr[i-2]);
                vr[i-1]-=mn;
                vr[i-2]-=mn;
            }
        }
        else
        {
            int mn=min(vr[i-1],vr[i]);
            vr[i-1]-=mn;
            vr[i]-=mn;

        }

    }
    yes;
    
}



signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;

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



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

using namespace std;



int main() {

	// your code goes here

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        vector<int> v(n,0);

        int max = 0;

        int flag = 0;

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

            cin>>v[i];

            if(v[i]>max)

            max=v[i];

            

        }

        {

            

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

                if(v[i]<v[i-1]){

                    flag=1;

                    break;

                }

                v[i]-=v[i-1];

            }

            if(flag)

            cout<<"No"<<endl;

            else

            cout<<"Yes"<<endl;

        } 

    }

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

Solution 1 (runtime: 327 ms):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
 
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        ll od = 0, ev = 0;
        for (int i=0; i<n; i++) {
            int x;
            cin >> x;
            if (i%2 == 0) ev += x;
            else od += x;
        }
        ll eve = n / 2, ode = n / 2;
        if (n%2 != 0) eve ++;
        if (ev % eve == 0 && od % ode == 0 && ev / eve == od / ode) cout << "yes\n";
        else cout << "no\n";
    }
}

Solution 2 (runtime: 77 ms):

#include <bits/stdc++.h>
using namespace std;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> a(n);
    array<int64_t, 2> sum = {0, 0};
    array<int64_t, 2> cnt = {0, 0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum[i % 2] += a[i];
      cnt[i % 2] += 1;
    }
    if (sum[0] % cnt[0] == 0 && sum[1] % cnt[1] == 0 && sum[0] / cnt[0] == sum[1] / cnt[1]) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
  return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int t;
  cin >> t;
  while(t--){
    string s;
    cin >> s;
    int cnt2 = 0 ;
    int cnt3 = 0 ;
    int sum = 0 ;
    for(int i = 0 ; i < s.size() ; i++){
      if(s[i] == '2'){
        cnt2++;
      }
      else if(s[i] == '3'){
        cnt3++;
      }
      sum += s[i] - '0';
      sum %= 9;
    }
    if(sum % 9 == 0){
      cout << "yes" << endl;
      continue;
    }
    bool flag = true;
    for(int i = 0 ; i <= cnt2 && flag ; i++){
      for(int j = 0 ; j <= cnt3 && flag ; j++){
        if((sum + (i * 2 + j * 6)) % 9 == 0){
          flag = false;
          break;
        }
      }
    }
    if(!flag){
      cout << "yes" << endl;
      continue;
    }
    cout << "no" << endl;
  }
}

Solution 2 (runtime: 46 ms):
#include <iostream>
#include <cstring>
#define endl '\n'
using namespace std;
const int N = 100010;
bool solve()
{
	int a = 0, b = 0, sum = 0;
	char c[N];
	cin >> c;
	for (int i = 0; i < strlen(c); i ++ )
	{
//		cout << c << endl;
		int t = c[i] - '0';
		sum += t;
		if (t == 2) a ++ ;
		if (t == 3) b ++ ;
	}
	int t = sum % 9;
	if (t == 0) return true;
//	if (t != 6 && t % 2 == 0) return false;
	if (t == 8)
	{
		if (a >= 5 || (a >= 2 && b >= 1)) return true;
		else return false;
	}
	if (t == 7)
	{
		if (a >= 1) return true;
		else return false;
	}
	if (t == 6)
	{
		if (b >= 2 || a >= 6 || (b >= 1 && a >= 3)) return true;
		else return false;
	}
	if (t == 5)
	{
		if (a >= 2) return true;
		else return false;
	}
	if (t == 4)
	{
		if (a >= 7 || (b >= 1 && a >= 4) || (b >= 2 && a >= 1)) return true;
		else return false;
	}
	if (t == 3)
	{
		if (a >= 3 || b >= 1) return true;
		else return false;
	}
	if (t == 2)
	{
		if (a >= 8 || (b >= 1 && a >= 5) || (b >= 2 && a >= 2)) return true;
		else return 0;
	}
	if (t == 1)
	{
		if (a >= 4 || (a >= 1 && b >= 1)) return true;
		else return false;
	}
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t -- )
	{
		if (solve()) cout << "YES" <<endl;
		else cout << "NO" << endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

#include <algorithm>

#include <cstring>

#include <vector>

#include <queue>

#include <deque>

#include <cmath>

#include <map>

#include <set>

#define endl '\n'

#define db(a) cout << #a << "=" << (a) << endl;

#define x first

#define y second

using namespace std;



const int N = 2e5 + 10, M = 2e5 + 10, INF = 0x3f3f3f3f;



typedef long long ll;



typedef pair<int, int> PII;



int T;

ll a[N], b[N], c[N];



int main() {

	cin >> T;

	while(T --){

		int n, l, r;

		cin >> n >> l >> r;

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

			cin >> a[i];

			b[i] = a[i];

			c[i] = a[i];

		} 

		sort(b + 1, b + r + 1);

		sort(c + l, c + n + 1);

		int len = r - l + 1;

		ll s1 = 0, s2 = 0;

		for(int i = 1; i <= len; i ++) s1 += b[i];

		for(int i = l; i < l + len; i ++) s2 += c[i];

		ll ans = min(s1, s2);

		cout << ans << endl;

	}

    return 0;

}







Solution 2 (runtime: 171 ms):
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

void sortInParts(vector<int>& arr, int l, int r){
    if(l>1){
        sort(arr.begin(),arr.begin()+l-1);
    }
    sort(arr.begin()+l-1,arr.begin()+r);
    if(r<arr.size()){
        sort(arr.begin()+r,arr.end());
    }
    return;
}

long long int maxDiff(vector<int>& arr, int l, int r, int start, int end){
    long long int dif = 0;
    while(start<=end && r>=l){
        if(arr[start]>=arr[r]) break;
        dif += arr[r]-arr[start];
        start++;r--;
    }
    return dif;
}

int main(){
    int t;
    cin>>t;

    while(t--){
        int n,l,r;
        cin>>n>>l>>r;

        vector<int> arr(n);

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

        sortInParts(arr,l,r);

        long long int dif1 = 0;
        if(l>1) dif1 = maxDiff(arr,l-1,r-1,0,l-2);

        long long int dif2 = 0;
        if(r<n) dif2 = maxDiff(arr,l-1,r-1,r,n-1);

        long long int maxdif = max(dif1,dif2);
        
        long long int ans = 0;
        for(int i=l-1;i<r;i++){
            ans += arr[i];
        }

        ans -= maxdif;

        cout<<ans<<endl;

    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

#include <vector>

#include <queue>

#include <stack>

#include <algorithm>

#include <climits>

#include <set>

#include <map>

#include <cstring>

#include <string>

#include <cmath>

#include <cstring>

using namespace std;

typedef long long ll;



ll n, m, k, l, r;



int main() {

	ios_base::sync_with_stdio(0);

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

	int T; cin >> T;

	while (T--) {

		vector<ll> v, rv, lv, mv;

		cin >> n >> l >> r; l--; r--;

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

			ll input; cin >> input;

			v.push_back(input);

		}



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

			lv.push_back(v[i]);

		}

		for (int i = l; i <= r; i++) {

			mv.push_back(v[i]);

		}

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

			rv.push_back(v[i]);

		}



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

		sort(mv.rbegin(), mv.rend());

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



		ll res = 0, a = 0;

		for (auto ele : mv) a += ele;



		res = a;



		ll tmp = a;

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

			if (i > mv.size() - 1 || lv[i] > mv[i]) break;



			tmp = tmp - mv[i] + lv[i];

		}

		res = min(res, tmp);



		tmp = a;

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

			if (i > mv.size() - 1 || rv[i] > mv[i]) break;



			tmp = tmp - mv[i] + rv[i];

		}

		res = min(res, tmp);



		cout << res << '\n';

	}

}

Solution 2 (runtime: 77 ms):
//infront or in back we want to find the smaller values than the current in symmetry but if we take both it will result in no difference



#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n,l,r;

    cin >> n >> l >> r;

    vector<int> a(n);

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

        cin >> a[i];

    }

    vector<int> b = a;

    sort(b.begin()+l-1, b.end());

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

    long long s1 = 0;

    long long s2 = 0;

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

        s1 += a[i];

        s2 += b[i];

    }

    cout << min(s1,s2) << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

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

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

int main()
{
    int test_cases;
    cin>>test_cases;
    for(int i=0;i<test_cases;i++)
    {
        int len;
        cin>>len;
        vector<long long> arr(len);
        for(int j=0;j<len;j++)
        {
            cin>>arr[j];
        }
        long long maxsum=INT_MIN;
        long long sum1=0;
        long long sum2;
        for(int j=0;j<len;j++)
        {
            sum1+=arr[j];
        }
        maxsum=max(maxsum,sum1);
        while(len>1)
        {   
            sum1=0;
            sum2=0;
            for(int j=0;j<len-1;j++)
            {
                arr[j]=arr[j+1]-arr[j];
                sum1+=arr[j];
                sum2+=arr[j]*(-1);
            }
            maxsum=max(sum1,maxsum);
            maxsum=max(sum2,maxsum);
            len--;
        }
        cout<<maxsum<<endl;
    }
    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define isEven(a) ((a & 1) == 0)
#define isOdd(a) ((a & 1) == 1)
#define isPowerof2(a) (((a) & ((a) - 1)) == 0)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define fi(a, b) for (int i = (a); (i) < (b); (i)++)
#define fj(a, b) for (int j = (a); (j) < (b); (j)++)
#define fx(m) for (auto &x : m)
#define fy(m) for (auto &y : m)
#define fz(m) for (auto &z : m)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define po pop_back
#define M (int)(1e9+7)
#define N (int)(2e5+20)
#define sc second
#define fs first
#define make_unique(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin());
#define print_vec(v) fx(v) cout << x << " "; cout << "\n"

void solve(){
	ll n;
	cin>>n;
	vll a;
	fi(0,n){
		ll x;
		cin>>x;
		a.pb(x);
	}
	ll sum=0;
	ll ans=INT_MIN;
	fi(0,n){
		sum+=a[i];
	}
	ans=max(sum,ans);
    ll num=n-1;
    while(num--){
    	ll j=1;
    	ll sum=0;
    	ll n=a.size();
    	vector<ll> temp;
    	while(j<n){
    		temp.pb(a[j]-a[j-1]);
    		sum+=a[j]-a[j-1];
    		j++;
    	} 
    	a=temp;
    	ans=max(ans,abs(sum));
    }
    cout << ans << endl;

}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 155 ms):
// Name-Anshu Raj Jaiswal
// Scholar id-2212172
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define mpq priority_queue<ll,vector<ll>,greater<ll>>
#define mpqp priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> 
#define Mpq priority_queue<ll>
#define Mpqp priority_queue<pair<ll,ll>>
#define all(x) (x).begin(), (x).end()
const ll MOD=998244353;
const ll N=200000;
ll ceil(ll a,ll b){return (a+b-1)/b;}
void solve()
{         
 ll n;
 cin>>n;
 vector<ll>temp(n+1,0);
 vector<ll>temp2(n+1,0);
 vector<pair<ll,ll>>arr(n-1);
 map<ll,ll>my;
 for(ll i=0;i<n-1;i++)
 {
  ll u,v;
  cin>>u>>v;
  temp[u]++;temp[v]++;
  arr[i]={u,v};
 } 
 ll ans=0;
 ll in=-1;
 for(ll i=1;i<=n;i++)
 {
   if(temp[i]>ans)
   {
    ans=temp[i];
    in=i;
   }
   my[temp[i]]++;
 }     
 if(my[ans]>2)
 {
  cout<<2*ans-1<<endl;
  return;
 }  
 ans--;
 for(ll i=0;i<n-1;i++) 
 {      
  ll u=arr[i].ff,v=arr[i].ss;       
  if(u==in || v==in)              
  continue;
  temp2[u]++;temp2[v]++;
 }
 ll pi=0;
 for(ll i=1;i<=n;i++)
 pi=max(pi,temp2[i]); 
 ans+=pi;
 cout<<ans<<endl;
} 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  ll t;
  cin>>t;
  while(t--)
  {        
	  solve();
  }
  return 0;
} 

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

void solve(int n) {
    vector<vector<int>> adj(n+1);
    vector<int> deg(n+1, 0);
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++; deg[b]++;
    }

    int c1 = 0, c2 = 0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] >= deg[c2]) {
            c2 = i;
            if (deg[c2] >= deg[c1]) swap(c1, c2);
        }
    }

    int ans1 = 0, ans2 = 0;
    for (int u : adj[c1]) deg[u]--;
    for (int i = 1; i <= n; i++) if (i != c1) ans1 = max(ans1, deg[i]);
    for (int u : adj[c1]) deg[u]++;
    ans1 += (deg[c1]-1);
    for (int u : adj[c2]) deg[u]--;
    for (int i = 1; i <= n; i++) if (i != c2) ans2 = max(ans2, deg[i]);
    ans2 += (deg[c2]-1);
    cout << max(ans1, ans2) << '\n';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        solve(n);
    }

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int t;
int c;
int x,y;
int sum;
bool f=0;
int main(){
	cin>>t;
	while(t--){
		string s;
		cin>>s;
		c=s.size();
		sum=0;
		f=0;
		x=0,y=0;
		for(int i=0;i<c;i++){
			sum+=int(s[i]-'0');
			if(int(s[i]-'0')==2){
				x++;
			}
			if(int(s[i]-'0')==3){
				y++;
			}
		}
		sum%=9;
		if(sum==0){
			cout<<"Yes"<<endl;
			continue;
		}
		for(int i=0;i<=x;i++){
			for(int j=0;j<=y;j++){
				if((sum+2*i+6*j)%9==0){
					f=1;
					break;
				}
			}
			if(f==1)break;
		}
		if(f==0){
			cout<<"No"<<endl;
		}else{
			cout<<"Yes"<<endl;
		}
	}
	return 0;
}

Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int sum = 0;
        int cnt2 = 0;
        int cnt3 = 0;
        for(int i=0; s[i]!='\0'; i++){
            if(s[i] == '2'){
                cnt2++;
            }
            else if(s[i] == '3'){
                cnt3++;
            }
            int b = s[i] - '0';
            sum+=b;
        }
        if(sum%9 == 0){
            cout << "YES" << endl;
        }
        else{
            int isPossible = 0;
            for(int i=0; i<=cnt2; i++){
                for(int j=0; j<=cnt3; j++){
                    if((sum + i*2 + j*6) % 9 == 0){
                        cout << "YES" << endl;
                        isPossible = 1;
                        break;
                    }
                }
                if(isPossible){
                    break;
                }
            }
            if(!(isPossible)){
                cout << "NO" << endl;
            }
        }
    }
    
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 327 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;

void solve(){
    int n;
    cin>>n;
    vector<int> nums(n,0);
    
    for(int i=0;i<n;i++){
        cin>>nums[i];
    }

    for(int i=1;i<n;i++){
        if(nums[i-1]<=nums[i]){
            int temp=nums[i-1];
            nums[i-1]-=temp;
            nums[i]-=temp;
        }else{
            cn;
            return;
        }
    }

    cy;
    
    
    return;
}


int32_t main() {
    
    int t;
    cin >> t;

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

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

using namespace std;

#define endl '\n'

#define int long long

#define sqrt sqrtl

#define ref(i,r) for(int i=0;i<r;i++)

#define arv vector<int>v(n)

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

#define pm cout << "-1" << endl

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

const int MOD = 1e9+7;

const int INF = LLONG_MAX >> 1;





signed main()

{

    int t; cin >>t;

    while(t--){

       int n; cin>>n;

       arv;

       ref(i,n){

        cin>>v[i];

       }

       if(v.size()>1 && v[0] > v[1]) pn;

       else{

        bool flag = true;

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

            if(v[i]!=0 && v[i] <= v[i+1]){

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

                v[i] = 0;

            }

       }

       ref(i,n-1){

            if(v[i] > v[i+1]){

                flag = false;

                break;

            }

       }

       if(flag) py;

       else pn;

    }

    }

 return 0;

}