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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   ll ans = accumulate(a.begin(),a.end(),0ll);
   vector<ll>v;
   while(n>1)
   {
       for(int i = 0; i < n-1; i++)
        v.push_back(a[i+1]-a[i]);
       ans = max(ans,abs(accumulate(v.begin(),v.end(),0ll)));
       for(int i = 0; i < n-1; i++)
        a[i] = v[i];
       v.clear();
       n--;
   }
   cout << ans << '\n';
}



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

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rev(i, a, b) for (int i = a; i >= (b); i--)
#define fr first
#define sc second
#define pb push_back
#define endl "\n"

template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }
template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//void reset() {}

void solve_task() {
    int n;cin >> n;
    vector<ll> a(n);

    rep(i,0,n) cin >> a[i];

    vector<ll> b = a;

    ll ans = -1e18;

    while(sz(b) != 1) {
        chmax(ans,accumulate(all(b),0LL));

        if(b[0] > b[sz(b) - 1]) reverse(all(b));

        vector<ll> c;
        rep(i,0,sz(b) - 1) c.pb(b[i + 1] - b[i]);
        b = c;
    }

    chmax(ans,accumulate(all(b),0LL));

    cout << ans << endl;
}

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

    int tc = 1;cin >> tc;
    while(tc--) solve_task();

    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
void slove(){
    int n = 1; cin >> n;
    vector<int> v;
    for(int i = 0; i < n;i++){
        int t; cin >> t;
        v.push_back(t);
    }
    int ans = 1;
    for(int i = 0; i < n - 1; i++){
        int t = min(v[i],v[i+1]);
        v[i] -= t;
        v[i+1] -= t;
    }
    for(int i = 0; i < n - 1; i++){
        if(v[i] > v[i+1]){
            ans = 0;
            break;
        }
    }
    if(ans == 0){
        cout <<"NO" << endl; 
    }
    else{
        cout << "YES" << endl;
    }
}
signed main(){
    int n = 1; cin >> n;
    while(n--){
        slove();
    }
}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(0); 
	int t;
	cin >> t;
	for (; t > 0; --t) {
		int n, a, b;
		cin >> n;
		cin >> a;
		--n;
		for (; n > 0; --n) {
			cin >> b;
			if (a > b) {
				--n;
				while (n > 0) {
					cin >> b;
					--n;
				};
				goto NO;	
			};
			a = b - a;
		}
		
		cout << "YES" <<"\n";
		continue;
		NO:
			cout << "NO" << "\n";
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N=5e5+10;
ll a[N];

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
    
    int t;
    cin>>t;
    while(t--){
    	ll n,res=0,cnt;
    	cin>>n;
    	for(int i=0;i<n;i++) cin>>a[i],res+=a[i];
    	
    	for(int i=1;i<n;i++){
    		cnt=0;
    		int m=n-i;
    		for(int j=0;j<m;j++){
    			a[j]=a[j+1]-a[j];
    			cnt+=a[j];
			}
			
			res=max(res,max(cnt,-cnt));
		}
		
		cout<<res<<endl;
	}
	
	return 0;
}


Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define MOD 1000000007
#define INF 1e18
#define MAXN 400005
#define ZNF 1e9
#define PI 3.1415926535897932384626

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
 
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define si set<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define umii unordered_map<int, int>
#define usi unordered_set<int>
 
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
 
#define mod(x) ((x) % MOD)
#define inf(x) ((x) == INF ? "INF" : to_string(x))
#define deb(x) cerr << #x << " = " << x << "\n"
 
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define lp(i, a, b) for (int i = a; i < b; i++)
#define rlp(i, a, b) for (int i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)

void solve() {
    int n;
    cin >> n;
    vi a(n + 1);  
    int sum = 0;

    lp(i, 1, n + 1) {
        cin >> a[i];
        sum += a[i];
    }

    int mmx = sum;

    lp(i, 1, n) {
        sum = 0;
        lp(j, 1, n - i + 1) {
            a[j] = a[j + 1] - a[j];
            sum += a[j];
        }
        mmx = max(abs(sum), mmx);
    }

    cout << mmx << "\n";
}

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

    fast_io;
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
//  $$$$$$\  $$\   $$\     $$\  $$$$$$\  $$$$$$\  $$$$$$\  
// $$  __$$\ $$ |  \$$\   $$  |$$  __$$\ \_$$  _|$$  __$$\ 
// $$ /  $$ |$$ |   \$$\ $$  / $$ /  \__|  $$ |  $$ /  $$ |
// $$$$$$$$ |$$ |    \$$$$  /  \$$$$$$\    $$ |  $$$$$$$$ |
// $$  __$$ |$$ |     \$$  /    \____$$\   $$ |  $$  __$$ |
// $$ |  $$ |$$ |      $$ |    $$\   $$ |  $$ |  $$ |  $$ |
// $$ |  $$ |$$$$$$$$\ $$ |    \$$$$$$  |$$$$$$\ $$ |  $$ |
// \__|  \__|\________|\__|     \______/ \______|\__|  \__|
// 你是否赞同纯美女神爱莉希雅的美貌盖世无双？【愛門】!
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <climits>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::setprecision;
using std::setw;
using std::pair;
using std::string;
using std::to_string;
using std::vector;
using std::deque;
using std::queue;
using std::stack;
using std::priority_queue;
using std::set;
using std::map;
using std::sort;
using std::max_element;
using std::min_element;

void Solve(void);

int main(void)
{
	#ifdef Shimu_Guyue
		freopen("test.in" , "r", stdin );
		freopen("test.out", "w", stdout);
	#else
	#endif

    std::ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1;
	cin >> t;
	while (t--)
	{
		Solve();
		// cout << "-------------------------" << endl;
	}
	return 0;
}

void Solve(void)
{
	int n;
	cin >> n;
	int64_t ans = 0;
	vector<int64_t> as(n);
	for (int64_t &a : as)
	{
		cin >> a;
		ans += a;
	}

	if (n == 1)
	{
		cout << ans << endl;
		return;
	}

	while (n)
	{
		int64_t sum = 0;
		for (int i = 0; i < n - 1; ++i)
		{
			as[i] = as[i + 1] - as[i];
			sum += as[i];
		}
		as.pop_back();
		ans = std::max({ans, sum, -sum});
		--n;
	}
	cout << ans << endl;
}

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

int T;
ll a[55];

int main()
{
    scanf("%d", &T);
    while (T--)
    {
        int n;
        ll sum = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%lld", &a[i]);
        for (int i = 1; i <= n; i++)
            sum += a[i];
        for (int i = 1; i < n; i++)
            a[i] = a[i + 1] - a[i];
        for (int m = n - 1; m >= 1; m--)
        {
            ll sum2 = 0;
            for (int i = 1; i <= m; i++)
                sum2 += a[i];
            sum = max(sum, sum2);
            sum = max(sum, -sum2);
            for (int i = 1; i < m; i++)
                a[i] = a[i + 1] - a[i];
        }
        printf("%lld\n", sum);
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
#define f(i, R) for (int i = 0; i < R; i++)
#define fl(i, L, R) for (int i = L; i < R; i++)
#define all(v) v.begin(), v.end()
// using ll = long long
using namespace std;
#define MOD 1000000007
#define int long long

int modulo_exponent(int a, int b, int m)
{
    // recursive
    if (b == 0)
        return 1;
    if (b % 2 == 0)
    {
        int temp = modulo_exponent(a, b / 2, m);
        return (temp * temp) % m;
    }
    else
    {
        return (a % m * modulo_exponent(a, b - 1, m) % m) % m;
    }
}
void generateNumbers(int L, int R)
{
    int x = L, y = R;
    int bit = 29;

    for (int i = 29; i >= 0; i--)
    {
        if ((x & (1 << i)) ^ (y & (1 << i)))
        {
            bit = i;
            break;
        }
    }

    int a = 0, b = 0, c = 0;

    // cout<<bit<<endl;
     for (int i = 29; i >= 0; i--) {
        if (i > bit) {
            a |= (x & (1 << i));
            b |= (y & (1 << i));
        } else if (i == bit) {
            a |= (x & (1 << i)) ^ (1 << i); 
            b |= (y & (1 << i)) ^ (1 << i); 
        } else {
            if (!(a & (1 << bit))) a |= (1 << i);
            if (!(b & (1 << bit))) b |= (1 << i);
        }
    }


    if (a > b)
        swap(a, b);
    if (a + 1 == b)
        c = a == L ? b + 1 : a - 1;
    else
        c = a + 1;

    cout << a << " " << b << " " << c << endl;
}
void solve()
{
    int l, r;
    cin >> l >> r;
    generateNumbers(l, r);
}

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

    int tt = 1;
    cin >> tt;
    for (int i = 1; i <= tt; i++)
    {
        solve();
    }
}

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

int get_highest_diff_bin_bit(int l, int r){
    int diff = (l ^ r);
    int cnt = 0;
    while(diff){
        diff >>= 1;
        cnt++;
    }
    return cnt;
}

int get_bit_num(int n){
    int cnt = 0;
    while(n){
        n >>= 1;
        cnt++;
    }
    return cnt;
}

int rand_from_l_to_r(int l, int r, int first, int second){
    int res = rand() % (r - l + 1) + l;
    // cout << "l: "<<l << " r: "<<r << endl;
    while (res == first || res == second)
    {
        res = rand() % (r - l + 1) + l;
        
    }
    return res;
}


int main(){
    int k,l,r;
    cin >> k ;
    for (int i=0; i< k; i++){
        cin >> l >> r;
        //cout << two_sum << endl;
        int first =  l >> (get_highest_diff_bin_bit(l, r)-1);
        // cout << "prefix:" << first << endl;
        first <<= (get_highest_diff_bin_bit(l, r)-1);
        
        int mask = (1 << (get_highest_diff_bin_bit(l, r)-1)) - 1;

        first |= mask;
        
        int second = r >> (get_highest_diff_bin_bit(l, r)-1);
        // cout << "prefix:" << second << endl;
        second <<= (get_highest_diff_bin_bit(l, r)-1);
        
        int third = rand_from_l_to_r(l, r, first, second);
        cout << first << " " << second << " " << third << endl;
    }
    
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
#define ll long long
#define nl endl
const ll mod = 1e9+7;
using namespace std;
# define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define mkpr make_pair
#define fir first
#define sec second


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tt;
 cin>>tt;
 while(tt--)
 {
    ll n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    ll now=n;
    ll ans=-1e18;

    for (int i = 0; i < n; ++i)
    {
        ll sum=0;
        for (int i = 0; i < now; ++i)
        {
            sum+=a[i];
        }
        if(i==0)
            ans=max(ans,sum);
        else
            ans=max({ans,sum,-sum});

            for (int i = 0; i < now-1; ++i)
            {
                a[i]=a[i+1]-a[i];
            }
            now--;
        
    }
cout<<ans<<nl;
 }

   

}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
using namespace std;
#define ll long long
#define re(i,b) for(ll i=0;i<b;i++)
#define rre(i,b) for(ll i=b;i>=0;i--)
#define dd long double
#define all(x) x.begin(), x.end()
#define rall(a) (a).rbegin(), (a).rend()
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define lire(v) for (auto &u : v) cin >> u;
#define aff(v) for (auto u : v) cout << u << " "; cout << endl;
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define mpcl map<char, ll>
#define vdd vector<dd>
#define vbo vector<bool>
#define mpll map<ll, ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vss vector<string>
#define vcc vector<char>
#define scc set<char>
#define sss set<string>
// sort(a.begin(), a.end(), [](int x, int y) {
//       return x % 2 < y % 2;
//     });
//fixed<<setprecision(6)
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll t;
    cin >> t;
    re(w,t){
       ll n;cin>>n;
       vll a(n);
       ll s=LLONG_MIN;
       re(i,n){
           cin>>a[i];
       }
       re(i,n){
           ll s2=0;
           re(j,n-i){
               s2+=a[j];
           }
           if(i==0)s=max(s,s2);
           else s=max(s,max(s2,-(s2)));
           re(j,n-i-1)a[j]=a[j+1]-a[j];
       }
       cout<<s<<endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 250 ms):
#define mod 1000000007
#define ull unsigned long long
#define ll long long
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define hai cout<<-1<<endl
#define pb push_back
#define ff first
#define ss second
bool isprime(ll n){if (n <= 1)  return 0; if (n <= 3)  return 1; if (n%2 == 0 || n%3 == 0) return 0; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return 0; return 1;}
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    ll n,m;
    cin>>n>>m;
    priority_queue<ll> pq,pq1;
    for(ll i=0;i<n;i++){
        ll x;
        cin>>x;
        pq.push(x);
    }
    for(ll j=0;j<m;j++){
        ll x;
        cin>>x;
        pq1.push(x);
    }
    bool ans=true;
    while(!pq.empty()){
        if(!pq1.size() || pq1.size()>pq.size()){
            ans=false;
            break;
        }
        ll x=pq.top();
        ll y=pq1.top();
        pq1.pop();
        if(x>y){
            ans=false;
            break;
        }
        if(x==y){
            pq.pop();
        }
        else{
            pq1.push(y/2);
            pq1.push(y/2+y%2);
        }
    }
    if(!ans || pq.size() || pq1.size()){
        cn;
    }else{
        cy;
    }
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
  return 0;
}

Solution 2 (runtime: 218 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define endl "\n"
#define tt int t;cin>>t; while(t--)

string chk(multiset<ll>& st, ll m){
    if(m==0)return "NO";
    auto it1=st.find(m/2);
    string word;
    if(it1==st.end()){
        word= chk(st,m/2);
        if(word=="NO")return "NO";
    }
    else st.erase(it1);
    auto it2=st.find((m+1)/2);
    if(it2==st.end()){
        word= chk(st,(m+1)/2);
        if(word=="NO")return "NO";
    }
    else st.erase(it2);
    return "YES";
}

int main(){
    sync;
    tt{
        ll n,m;cin>>n>>m;
        vector<ll> a(n),b(m);
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<m;i++)cin>>b[i];
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        ll pt1=0,pt2=0;
        string ans="YES";
        multiset<ll> st;
        while(pt1<n && pt2<m){
            if(a[pt1]==b[pt2]){
                pt1++;pt2++;continue;
            }
            if(a[pt1]<b[pt2]){
                st.insert(a[pt1]);pt1++;
                continue;
            }
            if(a[pt1]>b[pt2]){
                ans=chk(st,b[pt2]);
                pt2++;
                if(ans=="NO")break;
            }
        }
        if(ans=="YES" && pt1<n)ans="NO";
        while(ans=="YES" && pt2<m){
            ans=chk(st,b[pt2]);
            pt2++;
        }
        if(!st.empty())ans="NO";
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

void sub(){
    int n;
    cin >> n;

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

    // Try to make the array non-decreasing using the subtraction operation
    for(int i = 0; i < n - 1; i++){
        int diff = min(arr[i], arr[i + 1]);
        arr[i] -= diff;
        arr[i + 1] -= diff;
    }

    // Check if the array is now sorted in non-decreasing order
    for(int i = 0; i < n - 1; i++){
        if(arr[i] > arr[i + 1]){
            cout << "No" << endl;
            return;
        }
    }
    
    cout << "Yes" << endl;
}

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

    while(t--){
        sub();
    }

    return 0;
}

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

using namespace std;



void solve() {

int n;

cin >> n;

vector<int> a(n + 1);

bool valid = true;



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

cin >> a[i];

if (i > 1) {

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

if (a[i] < 0) valid = false;

}

}



cout << (valid ? "YES" : "NO") << endl;

}



int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);



int t;

cin >> t;



while (t--) {

solve();

}



return 0;

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

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

#define ll long long

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

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

#define int long long

#define inf LONG_MAX

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

#define rep(i, a, n) for (int i = a; i < n; i++)

#define vec vector<int>

#define no cout << "NO" << '\n';

#define yes cout << "YES" << '\n';

#define nl cout << '\n';

#define MOD 1000000007

#define fs fflush(stdout);

#define pb push_back

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

#define ump unordered_map<int, int>

#define vs vector<string>

#define vv vector<vector<int>>

#define vb vector<bool>

using namespace std;



void solve();



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t = 1;

    cin >> t;

    while (t--)

        solve();

    return 0;

}





void solve() {

   int n,m,k;

   cin>>n>>m>>k;

   vec a(n,-1);

   a[m-1]=0;

   a[k-1]=1;

   m--,k--;

   for(int i=m+1;i<k-1;i++)

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



   if(a[k-1]==-1)

   a[k-1]=(a[k-2]==1?0:2);

   for(int i=k+1;;i++)

   {

       if(i%n==(m-1+n)%n)break;

       else if(a[i%n]==-1) a[i%n]=!a[(i-1+n)%n];

   }

   if(a[(m-1+n)%n]==-1)

   a[(m-1+n)%n] =(a[(m-2+n)%n]==0?1:2);

   loop(i,n) cout<<a[i]<<" ";nl

}



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

using namespace std;

using ll = long long;

void colveI(){

    int n,x,y;

    cin>>n>>x>>y;

    x--; y--;

    vector<ll> v(n);

    for(int i=0;i<n;i++) v[(x+i)%n] = i%2;

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

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

        if(i==n-1) cout<<v[i]<<'\n';

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

    }

}

int main(){

	ios_base::sync_with_stdio(false);

    cin.tie(0);

    int t; cin>>t;

    while(t--) colveI();

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

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

string func(int n, vector<int> &vec) {
   
    for(int i=0;i<n-1;i++){
            if(vec[i]>vec[i+1])return "NO";
            else{
                int mini=min(vec[i],vec[i+1]);
                vec[i]=0;
                vec[i+1]-=mini;
            }
    }
    return "YES";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for (int i = 0; i < n; i++) {
            cin >> vec[i];
        }
        string result = func(n, vec);
        cout << result<<endl;
       
    }
    return 0;
}

Solution 2 (runtime: 109 ms):
// #pragma GCC optimize(2)

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define pb push_back

#define st first

#define nd second

#define PII pair<ll, ll>

#define D(x, y) cout << x << "=" << y << endl;

#define fcout(x, n) cout << fixed << setprecision(x) << n << endl;

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

#define rep2(i, a, b) for (int i = a; i >= b; i--)

// #define int long long

// #define endl '\n'

typedef long long ll;

typedef unsigned long long ull;

const ll inf = 0x3f3f3f3f;

const int N = 1e6 + 10;

const int M = 1e9+7;

inline ll read()

{

    ll x = 0;

    bool f = 1;

    char c = getchar();

    for (; !isdigit(c); c = getchar())

        if (c == '-')

            f = 0;

    for (; isdigit(c); c = getchar())

        x = (x << 3) + (x << 1) + c - '0';

    return f ? x : 0 - x;

}

inline void out(ll x)

{

    if (x < 0)

        putchar('-'), x = -x;

    if (x > 9)

        out(x / 10);

    putchar(x % 10 + '0');

}

// __int128 rd()

// {

// 	char arr[30];

// 	__int128 res = 0;

// 	scanf("%s", arr);

// 	for (int i = 1; i <= strlen(arr); i++)

// 	{

// 		res *= 10;

// 		res += arr[i]-'0';

// 	}

// 	return res;

// }

// void pt(__int128 num)

// {

// 	if (num > 9) pt(num / 10);

// 	putchar(num % 10 + '0');

// }

ll n, m;

ll a[N];

void solve()

{

    cin>>n;

    rep(i,0,n) cin>>a[i];

    ll x=0;

    rep(i,1,n)

    {

        if(a[i-1]>a[i]) x=i;

    } 

    if(x==0) return cout<<"YES\n",void();

    rep(i,0,x)

    {

        ll mn=min(a[i],a[i+1]);

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

    }

    rep(i,1,n)

    {

        if(a[i-1]>a[i]) return cout<<"NO\n",void();

    }

    cout<<"YES\n";

}   

signed main()

{

    IOS

        // freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);

        ll T = 1;

    cin >> T;

    while (T--)

        solve();

}