ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

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

void solve() {
    string s;
    cin >> s;
    long long sm = 0;
    int n = s.length();
    int a2 = 0, a3 = 0;
    
    for (int i = 0; i < n; i++) {
        if (s[i] == '2') a2++;
        if (s[i] == '3') a3++;
        sm += s[i] - '0';
    }
    
    if (sm % 9 == 0) {
        cout << "YES" << endl;
        return;
    }
    
    long long req = 9 - (sm % 9);
    
    for (int i = 0; i <= a2; i++) {
        for (int j = 0; j <= a3; j++) {
            if ((2 * i + 6 * j) % 9 == req) {
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
}

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


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


int main(){
          int T;
          cin>>T;
          while(T--){
             string num;
             cin>>num;
             long long sum=0;
             long long two=0;
             long long three=0;
             for(auto i:num){
                       if(i=='2') two++;
                       else if(i=='3') three++;
                       sum+=(i-'0');
             }
             bool flag=true;
             long long diff=(9-sum%9)%9;
             for(long long i=0; i<=three; i++){
                       long long new_diff=(diff-6LL*i)%9;
                       if(new_diff<0) new_diff+=9;
                       long long a=(new_diff*5)%9;
                       if(a<=two){
                                 cout<<"YES"<<endl;
                                 flag=false;
                                 break;
                       }
             }
             if(flag) cout<<"NO"<<endl;
          }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

using namespace std;

class Solution {
public:
	void solve(int n, vector<int> final_order) {
      vector<vector<int> > overtakes;
      vector<int>jumpCompleted(n+1, 0);
		for(int i=n-1; i>0; i--){
         int candidate = final_order[i];
         jumpCompleted[candidate] = 1;
         for(int j=candidate-1; j>=1; j--){
            if(jumpCompleted[j])continue;
            overtakes.push_back({candidate,j});
         }
         for(int j=1; j<=n; j++){
            if(jumpCompleted[j])continue;
            overtakes.push_back({j,candidate});
         }
      }
		cout<< overtakes.size()<<endl;
		for(auto overtake:overtakes){
			cout<<overtake[0]<<" "<<overtake[1]<<endl;
		}
	}
};

int main(){
   int n;
   cin>>n;
   vector<int> final_order(n);
   for(int i=0;i<n;i++){
      cin>>final_order[i];
   }
   Solution s;
   s.solve(n, final_order);
   return 0;
}

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

int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> c(n);
    set<int> s;

    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        s.insert(c[i]);
    }

    vector<pair<int, int>> ans; 

    for (int i = 0; i < n; ++i) 
    {
        auto it = s.upper_bound(c[i]);
        

        while (it != s.end()) {
            ans.push_back({*it, c[i]});
            ++it;
        }
        it--;
        while((*it)!=c[i])
        {
            ans.push_back({c[i],*it});
            --it;
        }
        for (auto it2 = it; it2 != s.begin(); --it2) {
            if(*it2!=c[i]) ans.push_back({c[i], *it2});
        }
        if(*s.begin()!=c[i]) ans.push_back({c[i],*s.begin()});
        s.erase(c[i]);
    }

    cout << ans.size() << "\n";
    for (auto val : ans) {
        cout << val.first << " " << val.second << "\n";
    }

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

Solution 1 (runtime: 77 ms):
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        int sizeA = a.size();
        int sizeB = b.size();
        int dp[sizeA+1][sizeB+1];
        // vector<vector<int>>dp(sizeA+1,vector<int>(sizeB+1,0));
        std::fill(&dp[0][0], &dp[0][0] + (sizeA + 1) * (sizeB + 1), 0x3f3f3f3f);
        dp[0][0] = 0;
        for(int i=0;i<sizeA;i++)
        {
            {
                dp[i+1][0] = dp[i][0] + (c[i] != a[i]); 
            }
        }
        for(int i=0;i<sizeB;i++)
        {
            {
                dp[0][i+1] = dp[0][i] + (c[i] != b[i]);
            }
        }
        for(int i=1;i<=sizeA;i++)
        {
            for(int j=1;j<=sizeB;j++)
            {
                dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[j+i-1]),
                        dp[i][j-1] + (b[j-1] != c[j+i-1])
                    );
            }
        }
        cout<<dp[sizeA][sizeB]<<endl;
    }
}

Solution 2 (runtime: 77 ms):
//jai bajrang bali

#include <bits/stdc++.h>

using namespace std;



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

#define int long long

const int MOD = 1e9 + 7;

const int N = 1e5 + 1;

const int INF = 1e18;



int dx[4] = {-1, 0, 1, 0};

int dy[4] = {0, 1, 0, -1};







void solve() {

    string a, b ,c;

    cin >> a >> b >> c;



    int n = a.size();

    int m = b.size();



    vector<vector<int>>dp(n+1, vector<int>(m+1, INF));

    dp[0][0] = 0;



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

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

            if(i > 0){

                dp[i][j] = min(dp[i][j], dp[i-1][j] + (a[i-1] != c[i+j-1]));

            }

            if(j > 0){

                dp[i][j] = min(dp[i][j], dp[i][j-1] + (b[j-1] != c[i+j-1]));

            }

        }

    }



    cout << dp[n][m] << endl;

 

}



signed main() {

    Sachin_3059

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

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

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <algorithm>
using namespace std;

void solve() {
    string s;
    cin >> s;

    // Convert string digits to integers and calculate sum
    int sm = 0;
    int twos = 0;
    int threes = 0;

    for (char c : s) {
        int digit = c - '0';
        sm += digit;
        if (digit == 2) {
            twos++;
        } else if (digit == 3) {
            threes++;
        }
    }

    for (int i = 0; i <= min(9, twos); i++) {
        for (int j = 0; j <= min(9, threes); j++) {
            if ((sm + i * 2 + j * 6) % 9 == 0) {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve(); // Solve for each test case
    }
}


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

typedef unsigned long long ull ;
typedef long long ll ;
typedef long double ld ;

const ll mod = 1e9+7;
const ld eps = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf = 1e15;
const ll minf = -inf;

#define int long long
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()


void solve(){
    string s ; cin >> s ;
    int n = s.size() ;

    int sum = 0 ;
    int two = 0 , three = 0 ;

    for(int i=0;i<n;i++){
        if(s[i] == '2')two++ ;
        if(s[i] == '3')three++ ;
        sum += s[i]-'0' ;
    }

    for(int i=0;i<min(10ll , two+1);i++){
        for(int j=0;j<min(10ll , three+1);j++){
            if((sum + i*2 + j*6) %9 == 0){
                cout << "YES" << endl ;
                return ;
            }
        }
    }
    cout << "NO" << endl ;
    return ;
}

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

   int t = 1; cin >> t;
    for(int i=1; i<=t; i++){
        //cout<<"Case #"<<i<<": \n";
        solve();
    }
}
Problem: 2049C - MEX Cycle
Language: c++17 

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

#define ll long long int

using namespace std;

int main(){

    ll t;

    cin>>t;

    while(t--){

        ll n,x,y;

        cin>>n>>x>>y;

        vector<ll>v(n,0);

        --x;

        --y;

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

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

        }   

        if(n%2 || (y-x) % 2==0) v[x]=2;

        for(int i=0;i<=n-1;i++) cout<<v[i]<<" ";

        cout<<endl;

    }

    return 0;

}

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

#include <vector>

#include <string>

#include <sstream>

#include <fstream>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <map>

#include <bitset>

#include <numeric>

#include <set>

#include <queue>

#include <unordered_map>

#include <cassert>

#include <array>

#include <deque>

#include <functional>





using namespace std;

#define NDEBUG

#define endl "\n"

#define ff first

#define ss second

#define vi vector<int>

#define pii pair<int, int>

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

//#define int long long

constexpr int MAX_N = 100'005;

constexpr int INF = 1E9;  





int32_t main() {

    // ifstream cin("MEXcycle.txt");

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t; cin>>t; 



    while(t--) {

        int n, x, y; 

        cin>>n>>x>>y; 

        --x, --y; 



        vector<int> ans(n); 

        

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

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

        }

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

            ans[x] = 2;

        }

    

        for (auto& i : ans) cout<<i<<" ";

        cout<<endl; 

    }

}
Problem: 2050D - Digital string maximization
Language: c++17 

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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

        string b;

        cin >> b;



        vector<int> a;

        for(ll i = 0;i<b.size();i++){

            a.push_back((int)b[i]-48);

        }

        if(a.size() == 1) {

            cout << a[0] << endl;

            continue;

        }

        for(ll i = 1;i<b.size();i++){

            ll k = i;



            while(a[k]-1 > a[k-1] && k > 0){



                swap(a[k],a[k-1]);

                a[k-1] -= 1;

                k--;



            }

        }

        for(ll i = 0;i<a.size();i++){

            cout << a[i];

        }

        cout << endl;

    }

}



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

#define ll long long

using namespace std;



void solve(){

    string x;

    cin >> x;

    int l=x.size();

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

        int maxi = i;

        for(int j=i+1;j<l&&j<i+9;j++){

            if(x[j]-(j-i) > x[maxi]-(maxi-i)) maxi=j;

        }

        if(maxi!=i){//update anwser

            char seti=x[maxi]-(maxi-i);

            for(int k=maxi;k>i;k--){

                x[k] = x[k-1];//?????? 

            }

            x[i]=seti;

        }

    }

    cout << x << endl;

}



int main(){

    ios::sync_with_stdio(0);

    cin.tie(nullptr),cout.tie(nullptr);

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    return 0;

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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAX=2000+10;
int dp[MAX][MAX];
char a[MAX],b[MAX],c[MAX];
int main()
{
	int T,lena,lenb,i,j;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",a+1);
		scanf("%s",b+1);
		scanf("%s",c+1);
		lena=strlen(a+1);
		lenb=strlen(b+1);
		for(i=0;i<=lena;i++)
		{
			for(j=0;j<=lenb;j++)
			{
				dp[i][j]=INF;
			}
		}
		dp[0][0]=0;
		for(i=0;i<=lena;i++)
		{
			for(j=0;j<=lenb;j++)
			{
				if(i==0 && j==0) continue;
				if(i==0) dp[i][j]=dp[i][j-1]+(b[j]!=c[i+j]);
				else if(j==0) dp[i][j]=dp[i-1][j]+(a[i]!=c[i+j]);
				else dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]),
								  dp[i][j-1]+(b[j]!=c[i+j]));
			}
		}
		printf("%d\n",dp[lena][lenb]);
	}
	return 0;
}


Solution 2 (runtime: 62 ms):
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <climits>

using namespace std;

// Function to calculate the minimum number of changes
vector<int> minChanges(int t, vector<tuple<string, string, string>> &testCases) {
    vector<int> results;

    for (int test = 0; test < t; ++test) {
        string a = get<0>(testCases[test]);
        string b = get<1>(testCases[test]);
        string c = get<2>(testCases[test]);

        int n = a.size(), m = b.size();
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT_MAX));
        
        dp[0][0] = 0; // Base case: no characters taken, no mismatch
        
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= m; ++j) {
                int k = i + j; // Current position in c
                if (k == 0) continue;
                
                if (i > 0) { // Consider taking from a
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[k - 1] != a[i - 1]));
                }
                if (j > 0) { // Consider taking from b
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + (c[k - 1] != b[j - 1]));
                }
            }
        }
        
        results.push_back(dp[n][m]);
    }

    return results;
}

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

    vector<tuple<string, string, string>> testCases(t);
    for (int i = 0; i < t; ++i) {
        string a, b, c;
        cin >> a >> b >> c;
        testCases[i] = make_tuple(a, b, c);
    }

    vector<int> results = minChanges(t, testCases);

    for (int result : results) {
        cout << result << endl;
    }

    return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin>>n;
        int a[n],i;
        long long se=0,so=0;
        vector<int> ev,od;
        for(i=0;i<n;i++){
            cin>>a[i];
            if(i%2==0){
                ev.push_back(a[i]);
                se+=a[i];
            }
            else{
                od.push_back(a[i]);
                so+=a[i];
            }
        }
        if((se%ev.size()==0) && (so%od.size()==0) && (se/ev.size()==so/od.size())){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


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

using namespace std;

void solve(){

    int n;cin>>n;

    vector <int> vec(n+1);

    vec[0]=0;

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

        cin>>vec[i];

    }



    long long int odd=0,even=0;

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

        if(i&1) odd+=vec[i];

        else even+=vec[i];

    }

    if(n%2==0){

        if(even==odd && even%(n/2)==0){

            cout<<"YES"<<endl;

        }

        else {

            cout<<"NO"<<endl;

        }

    }

    else{

        if(odd%((n+1)/2)==0 && even%(n/2)==0 && odd/((n+1)/2)==even/(n/2)){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }



}

int main(){

int t;cin>>t;

    while(t--){

        solve();

    };

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

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

using namespace std;



#define int long long

using pii = pair<int,int>;



signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int T = 1;

    cin >> T;

    while(T--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        string ans = "YES";



        int countp = 0, counts = 0;

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

            if(s[i] == 'p')

                countp++;

            if(s[i] == 's')

                counts++;

            if(countp>0 and (s[i]=='s'))

                ans = "NO";

            if(counts>1 && countp>1)

                ans = "NO";

        }

        if((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')

            ans = "NO";

        if((counts>1 && countp>0) && s[n-1]=='.')

            ans = "NO";

        if((countp>1 && counts>0) && s[0]=='.')

            ans="NO";

        cout<<ans<<endl;

    }

}

/*

..sp

4321

sp..

1234



.spp

3124

spp.

3214



ssp.

4213

.ssp

4321



*/

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

using namespace std;

typedef long long ll;

typedef long double ld;

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

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

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;







int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

  



    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        

        string s;



        int t=0;



        cin >> s;



        if(s[0]=='s')

        {

            s[0] = '.';

        }

        if(s[n-1]=='p')

        {

            s[n-1] = '.';

        }



        int g=0,h=0;



        f(i,n)

        {



            if(s[i]=='p')

            {

                g =1;

            }

            if(s[i]=='s')

            {

                h =1;

            }



        }



        if(g==1 && h==1)

        {

            cout << "NO" << endl;

        }

        else

        {

            cout << "YES" << endl;

        }





    }



    return 0;

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

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> ve;
typedef vector<long long> vl;
#define ll long long
#define pq priority_queue
#define inf INT_MIN
#define pi pair<int, int>
#define fi first
#define se second
#define pb push_back
#define con continue
#define rep(i, a, b) for (int i = a; i < b; i++)
#define res(j, a, b) for (int j = a; j >= b; j--)
#define all(x) begin(x), end(x)
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;

void setIO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

int mod = 998244353  ;

void solve() {
 int n , k ;
 cin>>n>>k;
 map<int,int>mp;
 rep(i,0,n){
    int x ;
    cin>>x;
    mp[x]++;
 }
 ve v;
 for(auto & x : mp)
    v.pb(x.se);
 sort(all(v));
 int ct = 1 ;
 rep(i,0,v.size()-1)if(k>=v[i])k-=v[i] ; else ct ++;
 cout<<ct<<endl;
}

signed main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    setIO();

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

    return 0;
}


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

int main() {
	int t;
	cin>>t;
	while(t--){
	    int n,k;
	    cin>>n>>k;
	    map<int,int> mp;
	    for(int i=0;i<n;i++){
	        int a;
	        cin>>a;
	        mp[a]++;
	    }
	    vector<int> v;
	    for(auto x:mp){
	        v.push_back(x.second);
	    }
	    sort(v.begin(),v.end());
	    int ans = v.size();
	    for(int i=0;i<v.size();i++){
	        k-=v[i];
	        if(k<0){
	            break;
	        }
	        ans--;
	    }
	    cout<<max(ans,1)<<endl;
	}

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

Solution 1 (runtime: 92 ms):
#include <bits/stdc++.h>
using namespace std;
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define test  \
    ll t;    \
    cin >> t; \
    while (t--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define new cout << endl;
#define cin(a)                  \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
typedef long double ld;
typedef long long ll;

 
void solve()
{
  ll n,l,r;cin>>n>>l>>r;
  vector<ll>a,b,c;
  for(ll i=0;i<n;i++)
  {
    ll x;cin>>x;
    a.pb(x);
  }
  for(ll i=0;i<r;i++)
  {
    b.pb(a[i]);
  }
  for(ll i=l-1;i<n;i++)
  {
    c.pb(a[i]);
  }
  sort(all(b));
  sort(all(c));
  ll sum1=0,sum2=0;
for(ll i=0;i<((r-l)+1);i++)
{
    sum1+=b[i];
    sum2+=c[i];
}
 
  cout<<min(sum1,sum2)<<endl;
}


int_fast32_t main()
{
    fast
        test
        solve();
    return 0;
}

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

long long int func(int r1,int r2,vector<int>v,vector<int>dummy,long long int sum)
{
    vector<int>temp;
    for(int i=r1-1;i<r2;i++)
    {
        temp.push_back(v[i]);
    }
    sort(temp.begin(),temp.end());
    sort(dummy.begin(),dummy.end());
   // for(int i=0;i<temp.size();i++) cout<<temp[i]<<" ";cout<<endl;
   // for(int i=0;i<dummy.size();i++) cout<<dummy[i]<<" ";cout<<endl;
    int left=temp.size()-1,right=0;
    while (left>=0 && right<dummy.size())
    {
        if(dummy[right]<temp[left])
        {
            sum+=dummy[right];
            sum-=temp[left];
        }
        right++;
        left--;
    }
   // cout<<"d_sum=="<<sum<<endl;
    return sum;


}
int main()
{
    int tc;cin>>tc;
     for(int ii=1;ii<=tc;ii++)
    {
        int n,r1,r2;cin>>n>>r1>>r2;
        vector<int>v;
        long long int sum=0,sum1=0;
        for(int i=0;i<n;i++)
        {
            int x;cin>>x;
            v.push_back(x);
            if(i>=r1-1 && i<r2)
            {
                sum+=v[i];
            }
        }
        sum1=sum;
        vector<int>dummy;
         for(int i=0;i<r1-1;i++)
         {
            dummy.push_back(v[i]);
         }

        long long res=func(r1,r2,v,dummy,sum);
         sum=min(sum,res);
         dummy.clear();
        for(int i=r2;i<n;i++)
        {
            dummy.push_back(v[i]);
        }

        res=func(r1,r2,v,dummy,sum1);
        sum1=min(sum1,res);
        cout<<min(sum,sum1)<<endl;

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

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

long long max(long long a, long long b){
    return (a>b)?a:b;
}

long long min(long long a, long long b){
    return (a<b)?a:b;
}

int max(int a, int b){
    return (a>b)?a:b;
}

int min(int a, int b){
    return (a<b)?a:b;
}



void soln(){
    int n, p, q, r, s;
    long long a, b, c, d;
    bool flag = true;
    cin>>n;
    vector<long long> v(n), temp;
    for(int i = 0; i<n; i++) cin>>v[i];
    for(int i = 0; i<n-1; i++){
        if(v[i]>v[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            v[i+1] = v[i+1]-v[i];
            v[i] = 0;
        }
    }
    cout<<"YES"<<endl;








    
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
        soln();
}




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

using namespace std;
/*
4
1 4 3 2
0 3
4
1 3 4 2
0 2 2 2
2
4
1 4 3 2
4
1 3 4 2
*/
int T, a[200001], n;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while(T--)
    {
        int i;
        cin >> n;
        for(i = 1; i <= n; i++)
            cin >> a[i];
        if(a[1] > a[2])
            cout << "NO\n";
        else
        {
            a[2] -= a[1];
            a[1] = 0;
            for(i = 3; i <= n; i++)
            {
                int x = a[i - 1];
                if(a[i - 1] != 0)
                {
                    while(a[i - 1] != 0 and a[i - 1] >= a[i - 2])
                    {
                        a[i] -= a[i - 1];
                        a[i - 1] -= a[i - 1];
                    }
                }
            }
            bool ok = true;
            for(i = 1; i < n and ok == true; i++)
                if(a[i] > a[i + 1])
                    ok = false;
            if(ok == false)
                cout << "NO\n";
            else cout << "Yes\n";
        }
    }
    return 0;
}