ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: c++17 

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

void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> arr(n);
    for (ll i=0; i<n; i++) cin >> arr[i];
    vector<ll> brr(m);
    for (ll i=0; i<m; i++) cin >> brr[i];

    multiset<ll> a;
    multiset<ll> b;

    sort(arr.begin(), arr.end());
    sort(brr.begin(), brr.end());
    ll i = 0;
    ll j = 0;
    while (i < n && j < m) {
        if (arr[i] == brr[j]) {
            i++;
            j++;
        }
        else if (arr[i] < brr[j]) {
            a.insert(arr[i]);
            i++;
        }
        else {
            b.insert(brr[j]);
            j++;
        }
    }

    while (i < n) a.insert(arr[i++]);
    while (j < m) b.insert(brr[j++]);

    while (!a.empty() && !b.empty()) {
        if (*a.rbegin() == *b.rbegin()) {
            a.erase(a.find(*a.rbegin()));
            b.erase(b.find(*b.rbegin()));
        }
        else if (a.size() < b.size() || *a.rbegin() > *b.rbegin()) {
            cout << "No" << endl;
            return;
        }
        else {
            ll t1 = *b.rbegin()/2;
            ll t2 = (*b.rbegin()+1)/2;
            b.erase(b.find(*b.rbegin()));
            b.insert(t1);
            b.insert(t2);
        }
    }

    if (!a.empty() || !b.empty()) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
}

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

#define IO cin.tie(0) -> sync_with_stdio(0)

#define endl "\n"

#define F first

#define S second

#define pLL pair<LL, LL>

#define mkp make_pair

#define pb emplace_back

#define LL loli

#define loli long long

using namespace std;

template<typename T> using Vec = vector<T>;

template<typename T> using Mat = Vec<Vec<T> >;

const LL mod = 1e9+7, inf = 9e18, maxN = 0;



LL TT = 1;

LL n, m, x;

multiset<LL> a, b;



void solve() {

  cin >> n >> m;

  a.clear(), b.clear();

  for(LL i=0; i<n; i++) {cin>>x, a.insert(x);}

  for(LL i=0; i<m; i++) {cin>>x, b.insert(x);}

  for(LL i=0; i<n-m; i++) {

    while(!b.empty() && a.find(*prev(b.end())) != a.end()) {

      a.erase(a.find(*prev(b.end())));

      b.erase(prev(b.end()));

    }

    if(b.empty()) break;

    LL k = *prev(b.end());

    b.erase(b.find(k)), b.insert(k/2), b.insert(k-k/2);

  }

  while(!b.empty() && a.find(*prev(b.end())) != a.end()) {

    a.erase(a.find(*prev(b.end())));

    b.erase(prev(b.end()));

  }

  cout << (a.empty()&&b.empty() ? "Yes" : "No") << endl;

}



int main() {

  IO;

  cin >> TT;

  for(int cs=0; cs<TT; cs++) {

    solve();

  }

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

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<ll> a(n);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        bool val = true;
        for(int i=1; i<n; i++){
            ll minL = min(a[i], a[i-1]);
            a[i]-= minL;
            a[i-1]-= minL;
            if (a[i-1]> a[i]){
                val = false;
                break;
            }
        }
        if(val) cout << "Yes";
        else cout << "No";
        cout << "\n";
    }
}


Solution 2 (runtime: 125 ms):
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define ull unsigned long long
#define ll long long
// #define int long long   
const int N = 3e5+9;
const int mod = 998244353;
void solve(){ 
     int n;
     cin>>n;
     vector<int>a(n+1);
     for(int i=1;i<=n;++i) cin>>a[i];
     for(int i=1;i<n;++i){
      if(a[i+1]>=a[i]) a[i+1]-=a[i],a[i]=0;
     }
     for(int i=1;i<n;++i){
       if(a[i]>a[i+1]){
         cout<<"no\n";
         return ;
       }
     }
     cout<<"yes\n";

}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int t; cin>>t;
    while(t--){
        int l,r; cin>>l>>r;
        int a=0,b=0,ans=0;
        for(int i=30;i>=0;i--){
            int x=0,y=0;
            if((1<<i)&l)
            x=1;
            if((1<<i)&r)
            y=1;
            if(x!=y){
                a=(ans+(1<<i));
                b=a-1;
                break;
            }
            else{
                ans+=((1<<i)*x);
            }
        }
        int c=0;
        for(int i=l;i<=r;i++){
            if((i!=a)&&(i!=b)){
                c=i;break;
            }
        }
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
}

Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define ull unsigned long long
using namespace std;
ll mll= LLONG_MAX;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll numx[105];
ll numy[105];
ll numz[105];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll t;
    cin>>t;
    while(t--)
    {
        ll x,y,xx,yy;
        cin>>x>>y;
        xx=x;
        yy=y;
        ll len=0;
        while(yy!=0)
        {
            len++;
            numy[len]=yy%2;
            yy/=2;
        }
        ll cur=0;
        while(xx!=0)
        {
            cur++;
            numx[cur]=xx%2;
            xx/=2;
        }
        cur=0;
        for(ll i=len;i>=1;i--)
        {
            if(numy[i]==1&&numx[i]==0)
            {
                cur=i;
                break;
            }
        }
        ll ans=-1;
        for(ll i=cur-1;i>=1;i--)
        {
            if(numx[i]==0)
            {
                ans=i;
                break;
            }
        }
        if(ans==-1)
        {
            for(ll i=len;i>=cur;i--)
            {
                numz[i]=numy[i];
            }
            for(ll i=cur-1;i>=1;i--)
            {
                numz[i]=0;
            }
        }
        else
        {
            for(ll i=len;i>=cur;i--)
            {
                numz[i]=numx[i];
            }
            for(ll i=cur-1;i>=1;i--)
            {
                numz[i]=1;
            }
        }
        ll z=0;
        ans=1;
        for(ll i=1;i<=len;i++)
        {
            z+=(numz[i])*ans;
            ans*=2;
        }
        cout<<x<<" "<<y<<" "<<z<<"\n";
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#ifdef debug
#include "debug.h"
#endif
 
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
const int mod = (int) 1e9 + 7;
const int _mod = 998244353;
const int inf = 1061109567;
const ll infll = 4557430888798830399;
const int N = 1e9 + 1;
const int MAX_N = 1001;


 // keep trying different approaches, dont repeat the same thoughts.
 
void solve() {
    int n,k;
    cin >> n;

    ll val[1001];

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

    ll ans = accumulate(val, val+n, 0LL);

    vector <ll> vi; 
    ll sum = 0;

    while ( n > 1){

        for(int i = 0 ; i < n-1 ; i ++){
            vi.push_back(val[i+1] - val[i]);
        }

        ans = max(ans, abs(accumulate(vi.begin(),vi.end(), 0LL) ));

        for(int i = 0 ; i < vi.size() ; i ++){
            val[i] = vi[i];
        }

        vi.clear();
        n--;
    }

    cout << ans << endl;
   

   



    
   
	
 }



    


   
  


int main() {
#ifndef debug
	 // freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
#endif
 
  ios::sync_with_stdio(0);
  cin.tie(0);
 
  int t = 1;
  cin >> t;
#ifdef debug
  int i = 1;
  t = 1e5;
#endif

  while(t --) {
#ifdef debug
    cout << "Case " << i ++ << ": ";
#endif
    solve();
    cout << flush;
  }
}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
#define MAGIC ios_base::sync_with_stdio(0);cin.tie(0);
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define F first
#define S second
#define PRES(c, x) ((c).find(x) != (c).end())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//////////////////////////////////////////////////////////

const int N = 2e5 + 4;
long long arr[N];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[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 + arr[i]) ;
        if (i == 1) ans = max(ans, sum);
        else ans = max(ans, max(sum, ( - sum) ));
        for (int i = 1; i < now; i++) arr[i] = (arr[i + 1] - arr[i]) ;
        now--;
    }
    cout << ans << endl; 
}

int main()
{
    //freopen("input.txt", "r", stdin);
    MAGIC
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(accumulate(brr.begin(),brr.end(),(long long)0)));
            swap(arr,brr);
        }
        
        cout<<sum<<endl;
    }
}

Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
void fillvector(vector<int>& nums, int n){
    for(int i=0;i<n;i++){
        int ele;
        cin>>ele;
        nums.push_back(ele);
    }
}
void print(vector<int>& nums){
    for(int i=0;i<nums.size();i++)
        cout<<nums[i]<<" ";
    cout<<endl;
}
void print(vector<int>& nums,string str){
    cout<<"Printing "<<str<<"... "<<endl;
    for(int i=0;i<nums.size();i++)
        cout<<nums[i]<<" ";
    cout<<endl;
}
void print(vector<vector<int>>& nums){
    if(nums.size()==0)
    return;
    for(int i=0;i<nums.size();i++){
        for(int j=0;j<nums[0].size();j++)
            cout<<nums[i][j]<<" ";
        cout<<endl;
    }  
}
void print(vector<vector<int>>& nums,string str){
    if(nums.size()==0)
    return;
    cout<<"Printing "<<str<<" ..."<<endl;
    for(int i=0;i<nums.size();i++){
        for(int j=0;j<nums[0].size();j++)
            cout<<nums[i][j]<<" ";
        cout<<endl;
    }  
}
int gcd(int a,int b){
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
//*****************************************************
//**************************************************** */

void rec(vector<int>& nums, int& n, int& ans){
    int sum=0;
    for(int i=0;i<nums.size();i++){
        sum+=nums[i];
    }
    ans=sum>ans?sum:ans;
    if(nums.size()<=1)
    return;
    if(nums[0]>nums.back()){
        int poss_ans=nums[0]-nums.back();
        ans=poss_ans>ans?poss_ans:ans;
        for(int i=0;i<nums.size()-1;i++){
            nums[i]-=nums[i+1];
        }
        nums.pop_back();
    }
    else{
        int poss_ans=nums.back()-nums[0];
        ans=poss_ans>ans?poss_ans:ans;
        for(int i=n-1;i>0;i--){
            nums[i]-=nums[i-1];
        }
        nums.erase(nums.begin(),nums.begin()+1);
    }
    rec(nums,n,ans);
}
void solve()
{
    int n,ans=INT32_MIN;
    cin>>n;
    vector<int> nums;
    fillvector(nums,n);
    rec(nums,n, ans);
    cout<<ans<<endl;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
ll l, r, a, b, c, x;

void solve(){
	cin >> l >> r;
	if(r - l == 2){
		cout << l << ' ' << l + 1 << ' ' << l + 2 << '\n';
		return;
	}
	for(int i = 30; i >= 0; i--){
		if(((l >> i) & 1)^(r >> i) & 1){
			x = i;
			break;
		}
	}
	a = ((1 << x) - 1) | l;
	b = a + 1;
	c = a == l ? r : l;
	cout << a << ' ' << b << ' ' << c << '\n';
}

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

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

typedef long long ll;
#define int ll
using namespace std;

bitset<10> p(int a) {
	return bitset<10>(a);
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int T; cin >> T;
	while(T--) {
		int l, r; cin >> l >> r;
		int k = 31 - __builtin_clz(l ^ r);
		int b = l | ((1 << k) - 1);
		int a = b + 1;
		int c;
		for(int i = l; i <= r; i++) {
			if(i != a && i != b) {
				c = i;
			}
		}
		cout << a << " " << b << " " << c << "\n";
	}
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

#define endl '\n'
using ll = long long;
using pii = pair<int, int>;
const double PI = acos(-1);
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
void solve() {
	ll l,r;cin>>l>>r;
	if(r-l==2) {
		cout<<r-2<<" "<<r-1<<" "<<r<<endl;
		return;
	}
	ll pre=0;
	int i=30;
	for(;i>=0;i--){
		if((l>>i)==(r>>i)){
			if((l>>i)&1){
				l-=(1<<i);
				r-=(1<<i);
				pre+=(1<<i);
			}
		}
		else break;
	}
	if((1<<i)==r){
		r=pre+r;
		cout<<r-2<<" "<<r-1<<" "<<r<<endl;
//		cout<<"异或值："<<(((r-2)^(r-1))+((r-2)^r)+((r-1)^r))<<endl;
	}
	else{
		r=pre+(1<<i);
		cout<<r-1<<" "<<r<<" "<<r+1<<endl;
//		cout<<"异或值："<<(((r-1)^r)+((r-1)^(r+1))+((r+1)^r))<<endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	
	int T = 1;
	cin>>T;
	while (T--) {
		solve();
	}
	
	return 0;
}
//异或值：6
//6 7 8
//异或值：30
//1 2 3
//异或值：6
//15 16 17
//异或值：62
//135 136 137
//异或值：30
//95 96 97
//异或值：126
//119 120 121
//异或值：30
//536870911 536870912 536870913
//异或值：2147483646




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

using namespace std;
#define ll long long
#define int ll
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        int l,r;
        cin>>l>>r;
        int a,b,c,ans=0;
        for (int i = 30; i >=0 ; i--) {
            int b1,b2;
            if(l & (1ll<<i)){
                b1=1;
            }
            else{
                b1=0;
            }
            if(r & (1ll<<i)){
                b2=1;
            }
            else{
                b2=0;
            }
            if(b1==b2){
                ans+=b1*(1ll<<i);
            }
            else{
                a=ans+(1ll<<i);
                b=a-1;
                break;
            }
        }
        for (int i = l; i <=r ; i++) {
            if(i!=a&& i!=b){
                c=i;
                break;
            }
        }
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

#define int long long 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
 
#define PB push_back
#define F first
#define S second
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937
 
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

void solve(){
    string s;
    cin >> s;
    int cnt2=0, cnt3=0;
    int sum=0;
    for(int i=0;i<s.size();i++){
        sum+=s[i]-'0';
        if(s[i]=='2') cnt2++;
        else if(s[i]=='3') cnt3++;
    }
    if(sum%9==0){
        cout << "YES" << endl;
        return;
    }
    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;
                return;
            }
        }
    }
    cout << "NO" << endl;
}

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

Solution 2 (runtime: 61 ms):
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n){
        string y;
        cin>>y;
        int sum=0;
        int count2=0;
        int count3=0;
        for(char e:y){
          sum+=(e-48)%9;
            if(e=='2') count2++;
            if(e=='3') count3++;
          
        }
        //cout<<sum;
        int rem=sum%9;
        rem=9-rem;
        rem=rem%9;
         //cout<<rem;
         bool flag=false;
        for(int i=0;i<=count2;i++){
            int sum=(2*i)%9;
            for(int j=0;j<=count3;j++){
              int we=(sum%9+(6*j)%9)%9;
              if(we==rem) {
                cout<<"YES";
                flag=true;
                break;
              }
             
            }
             if(flag==true) break;
        }
        if(!flag) cout<<"NO";
        cout<<endl;
        n--;
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

const int MOD=1e9+7;
const ll INF=1e18;

void run_case(){
      int n;
      cin>>n;
      vector<ll>a(n+1);
      for(int i=1;i<=n;i++){
        cin>>a[i];
      }
      ll ans=LLONG_MIN;
      int curr=n;
      for(int i=1;i<=n;i++){
          ll sum=0;
          for(int j=1;j<=curr;j++){
            sum+=a[j];
          }
          if(i==1){
            ans=max(ans,sum);
          }
          else{
            ans=max(ans, max(sum, -sum));
          }
          for(int j=1;j<curr;j++){
            a[j]=a[j+1]-a[j];
          }
          curr--;
      }
      cout<<ans<<endl;
      
      





}

int main(){
      cin.tie(0)->sync_with_stdio(0);
       int tt;
       cin>>tt;
       
       while(tt--){
           run_case();
       }
}

Solution 2 (runtime: 78 ms):
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int               long long
#define endl              "\n"
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define INF 1000000000000000000
#define mod 1000000007
#define esp 10e-7
const int mx=1e2+7;
int a[mx];
void solve()
{
  int n;
  cin>>n;
  vector<int>v(n);
  int ans=0;
  for(int i=0;i<n;i++)
    {cin>>a[i];v[i]=a[i];ans+=a[i];}
   
   if(n==1){
    cout<<a[0]<<endl;
    return;
   }

  for(int times=0;times<n-1;times++){
      for(int j=0;j<n-times-1;j++)
        v[j]=v[j+1]-v[j];
      int sum=0;

      for(int i=0;i<n-times-1;i++)
        sum+=v[i];
      ans=max(ans,max(sum,-sum));
  }
  

  
  cout<<ans<<endl;
}
signed main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt" , "w" , stderr);
    //#endif 
    IOS
    int t=1,n;
    cin>>t;
   
    while(t--)
    {
      solve();
    }
    
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define optimize()              \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define pi 3.14159265358979323846264338327950288419716939937510
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
#define pb push_back
#define vec(x) vector<x>
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define all(v) ((v).begin()), ((v).end())
#define rall(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define ff first
#define ss second
#define sfor(i, s, n, m) for (long long i = s; i < n; i += m)
#define refor(i, n, s, m) for (ll i = n - 1; i >= s; i -= m)
#define print(x) cout << x << " "
#define input(x) cin >> x
#define endl cout << "\n"
#define db double
#define ll long long
const int mod = 1e9 + 7;
void ShowInputandOutputInfile()
{
  system("cls");
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}

void solve()
{
  int n;

  cin >> n;

  vector <int> v(n);

  for(auto &u : v) cin >> u;

  for(int i = 0; i < n - 2; i++)
  {
    int temp = min(v[i], v[i + 1]);

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

  if(is_sorted(all(v))) YES;
  else NO;
}

int main()
{
  //ShowInputandOutputInfile();

  optimize();

  int test = 1;
  cin >> test;

  while (test--)
  {
    solve();
  }
}

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



using namespace std;



bool is(int * a, int n) {

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

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

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

a[i] = 0;

}



else {

return false;

}

}



return true;

}



int main() {

int t;

cin>>t;



while(t--) {

int n;

cin>>n;



int arr[n];



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

cin>>arr[i];

}



if(is(arr, n)) {

cout<<"yes";

}



else {

cout<<"no";

}

cout<<"\n";

}

return 0;

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

Solution 1 (runtime: 749 ms):
#include<bits/stdc++.h>
#define u32 unsigned int
#define i64 long long
#define u64 unsigned i64
const int N=2e5+5;
int n,m;
int a[N],b[N];
std::map<int,int> mp;
bool f(int x) {
    if(mp.count(x)&&mp[x]) {
        mp[x]--;
        n--;
        return true;
    } else if(x==1) {
        return false;
    }
    return (f(x/2)&&f((x+1)/2));
}
void solve() {
    mp.clear();
    std::cin >> n >> m;
    for(int i=1;i<=n;i++) {
        std::cin >> a[i];
        mp[a[i]]++;
    }
    for(int i=1;i<=m;i++) {
        std::cin >> b[i];
    }
    for(int i=1;i<=m;i++) {
        if(!f(b[i])) {
            std::cout<<"No\n";
            return;
        }
    }
    if(n) {
        std::cout<<"No\n";
    } else {
        std::cout<<"Yes\n";
    }
    return;
}

int main() {
    int t=1;
    std::cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

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

#include <vector>

#include <queue>

using namespace std;

typedef long long ll;

void solve () {

    ll n, m; cin >> n >> m;

    priority_queue<int> a, b;

    ll sum = 0;

    for (int i = 0, x; i < n; i++) cin >> x, sum += x, a.push(x);

    for (int i = 0, x; i < m; i++) cin >> x, sum -= x, b.push(x);

    if (sum) return cout << "No\n", void();

    int op = n - m;

    while (op--) {

        if (b.size() == 0 or a.size() == 0) break;

        int x = b.top(); b.pop();

        if (a.top() == x) {op++; a.pop(); continue;}

        int y = x / 2;

        x -= y;

        b.push(x), b.push(y);

    }

    while (b.size()) {

        if (a.size() == 0) return cout << "No\n", void();

        if (b.top() != a.top()) return cout << "No\n", void();

        b.pop(), a.pop();

    }

    if (a.size()) return cout << "No\n", void();

    cout << "Yes\n";

}



int main() {

    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);

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

    int t = 1; cin >> t;

    while (t--) solve();

}