ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 7):
#include<iostream>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int>PII;
queue<PII>q;
map<int,int>m;
int main(){
	int n,sum=0;
	cin>>n;
	int a[10001];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n;i>=1;i--){
		m[a[i]]=1;
		if(i==1)break;
		if(i>=2){
			int t1=1;
			for(int j=a[i]+1;j<=n;j++){
				if(m[j]==0){
					q.push({j,a[i]});
					sum++;
					t1=0;
				}
			}
			if(t1==1){
				
				for(int j=a[i]-1;j>=1;j--){
					if(m[j]==0){
						q.push({a[i],j});
						sum++;
					}
				}
				for(int j=1;j<=a[i]-1;j++){
					if(m[j]==0){
						q.push({j,a[i]});
						sum++;
					}
				}
			}
		}
	}
	cout<<sum<<endl;
	while(!q.empty()){
		PII t=q.front();
		q.pop();
		cout<<t.first<<' '<<t.second<<endl;
	}
	return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int>PII;
queue<PII>q;
map<int,int>m;
int main(){
	int n,sum=0;
	cin>>n;
	int a[10001];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n;i>=1;i--){
		m[a[i]]=1;
		if(i==1)break;
		if(i>=2){
			for(int j=a[i]-1;j>=1;j--){
				if(m[j]==0){
					q.push({a[i],j});
					sum++;
				}
			}
			for(int j=1;j<=a[i]-1;j++){
				if(m[j]==0){
					q.push({j,a[i]});
					sum++;
				}
			}
			for(int j=a[i]+1;j<=n;j++){
				if(m[j]==0){
					q.push({j,a[i]});
					sum++;
				}
			}
		}
	}
	cout<<sum<<endl;
	while(!q.empty()){
		PII t=q.front();
		q.pop();
		cout<<t.first<<' '<<t.second<<endl;
	}
	return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;

const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;

ll a[N] , b[N];
void solve(){
	ll n , m;
	cin >> n >> m;
	multiset<ll> st;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		st.insert(a[i]);
	}
	for(ll j = 1; j <= m; j++){
		int b;
		cin >> b;
		multiset<int> stb;
		stb.insert(b);
		while(stb.size() > 0){
			int a = *stb.begin();
			stb.erase(stb.find(a));
			if(st.find(a) != st.end()) {
				st.erase(st.find(a));
				continue;
			}
			if(a == 0) continue;
			if(a == 1){
				cout << "No\n";
				return;
			}
			stb.insert(a/2);
			stb.insert(a-a/2);
		}
	}
	if(st.size()){
		cout << "No\n";
		return;
	} 
	cout << "Yes\n";
}
/*

*/
signed main(){
	ios;
	ll t;
	cin >> t;
	while(t--) solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;

const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;

ll a[N] , b[N];
void solve(){
	ll n , m;
	cin >> n >> m;
	multiset<ll> st;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		st.insert(a[i]);
	}
	for(ll j = 1; j <= m; j++){
		int b;
		cin >> b;
		multiset<int> stb;
		stb.insert(b);
		while(stb.size() > 0){
			int a = *stb.begin();
			stb.erase(stb.find(a));
			if(st.find(a) != st.end()) {
				st.erase(st.find(a));
				continue;
			}
			if(a == 1){
				cout << "No\n";
				return;
			}
			stb.insert(a/2);
			stb.insert(a-a/2);
		}
	}
	if(st.size()){
		cout << "No\n";
		return;
	} 
	cout << "Yes\n";
}
/*

*/
signed main(){
	ios;
	ll t;
	cin >> t;
	while(t--) solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
#define int ll

using namespace std;
using ll = long long;

const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;

ll a[N] , b[N];
void solve(){
	ll n , m;
	cin >> n >> m;
	multiset<ll> sta, stb;
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
        sta.insert(a[i]);
    }
    for(ll i = 1; i <= m; i++) {
        cin >> b[i];
        stb.insert(b[i]);
    }
    while(!stb.empty()) {
        if(*stb.begin() < *sta.begin()) {
            cout << "No\n";
            return;
        }
        ll x = *stb.begin();
        if(sta.find(x) != sta.end()) {
            sta.erase(sta.find(x));
            stb.erase(stb.begin());
        }
        else {
            if(x == 1) {
                cout << "No\n";
                return;
            }
            ll u = -1, v = -1;
            u = x/2, v = x-x/2;
            stb.erase(stb.begin());
            stb.insert(u);
            stb.insert(v);
        }
    }
    if(sta.size()) cout << "No\n";
    else cout << "Yes\n";
    return;
}
/*

*/
signed main(){
	ios;
	ll t;
	cin >> t;
	while(t--) solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;

const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;

ll a[N] , b[N];
void solve(){
	ll n , m;
	cin >> n >> m;
	multiset<ll> st;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		st.insert(a[i]);
	}
	for(ll j = 1; j <= m; j++){
		int b;
		cin >> b;
		multiset<int> stb;
		stb.insert(b);
		while(stb.size() > 0){
			int a = *stb.begin();
			stb.erase(stb.find(a));
			if(st.find(a) != st.end()) {
				st.erase(st.find(a));
				continue;
			}
			if(a == 0) continue;
			if(a == 1){
				cout << "No\n";
				return;
			}
			stb.insert(a/2);
			stb.insert(a-a/2);
		}
	}
	if(st.size()){
		cout << "No\n";
		return;
	} 
	cout << "Yes\n";
}
/*

*/
signed main(){
	ios;
	ll t;
	cin >> t;
	while(t--) solve();
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;

const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;

ll a[N] , b[N];
void solve(){
	ll n , m;
	cin >> n >> m;
	multiset<ll> st;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		st.insert(a[i]);
	}
	for(ll j = 1; j <= m; j++){
		int b;
		cin >> b;
		multiset<int> stb;
		stb.insert(b);
		while(stb.size() > 0){
			int a = *stb.begin();
			stb.erase(stb.find(a));
			if(st.find(a) != st.end()) {
				st.erase(st.find(a));
				continue;
			}
			if(a == 1){
				cout << "No\n";
				return;
			}
			stb.insert(a/2);
			stb.insert(a-a/2);
		}
	}
	if(st.size()){
		cout << "No\n";
		return;
	} 
	cout << "Yes\n";
}
/*

*/
signed main(){
	ios;
	ll t;
	cin >> t;
	while(t--) solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5, MOD=1e9+7;
void precompute() {
}
string s;

void turn_to_binary(long long x, vector <long long> &v){
    while (x>0){
        v.push_back(x%2);
        x/=2;
    }
    while (v.size()<30){
        v.push_back(0);
    }
    reverse(v.begin(), v.end());
}

void turn_to_decimal(vector <long long> &v, long long &x){
    x=0;
    for (int i=0;i<v.size();i++){
        x=x*2+v[i];
    }
}

long long l, r;
void solve() {
    cin>>l>>r;
    vector <long long> lb, rb, midb;
    turn_to_binary(l, lb);
    turn_to_binary(r, rb);
    int i=0;
    while (lb[i]==rb[i]){
        midb.push_back(lb[i]);
        i++;
    } 
    if (lb[i+1]==0 and rb[i+1]==1){
        midb.push_back(0);
        midb.push_back(1);
        i+=2;
    } else if (lb[i+1]==rb[i+1]) {
        if (lb[i+1]==0){
            midb.push_back(0);
            midb.push_back(1);
            i+=2;
        }
        else {
            midb.push_back(1);
            midb.push_back(0);
            i+=2;
        }
    } else {
        int j = i+1;
        while (j<30 && lb[j]==0 && rb[j]==0){
            j++;
        } 
        if (rb[j]==0) {
            midb.push_back(0);
            i++;
            while (i<j){
                midb.push_back(1);
                i++;
            }
        } else {
            midb.push_back(1);
            i++;
            while (i<j){
                midb.push_back(0);
                i++;
            }
        }
    }
    while (i<30){
        midb.push_back(1-lb[i]);
        i++;
    }
    long long a, b, c;
    turn_to_decimal(lb, a);
    turn_to_decimal(rb, b);
    turn_to_decimal(midb, c);
    cout<<a<<" "<<b<<" "<<c<<endl;
}

int main() {
    int t;
    precompute();
    cin>>t;
    while (t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define int long long

struct node {
    int id, du;
};
int solve(int _) {
    int n, a, b;
    cin >> n;

    vector<node>v(n);
    set<int>se;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        --a, --b;
        se.emplace(a * 1000000 + b);
        se.emplace(b * 1000000 + a);
        v[i].id = i;
        v[a].du++;
        v[b].du++;
    }

    sort(v.begin(), v.end(), [](node a, node b) {
        return a.du > b.du;
    });

    int ans = v[0].du + v[1].du - 1;
    if (se.count(v[0].id * 1000000 + v[1].id) || se.count(v[1].id * 1000000 + v[0].id))
        ans--;
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        cout << solve(_) << endl;
    }
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define int long long

struct node {
    int id, du;
};
int solve(int _) {
    int n, a, b;
    cin >> n;

    map<int, int>ma;
    map<int, int>ma1;
    vector<pair<int, int>>input;
    vector<node>v(n);
    for (int i = 0; i < n; ++i) v[i].id = i, v[i].du = 0;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        --a, --b;
        input.emplace_back(a, b);
        v[a].du++;
        v[b].du++;
    }
    for (int i = 0; i < n; ++i) {
        ma1[v[i].du]++;
    }
    for (auto &[a, b] : input) ma[v[a].du + v[b].du]++;

    sort(v.begin(), v.end(), [](node a, node b) {
        return a.du > b.du;
    });

    int ans = v[0].du + v[1].du;
    debug(ans)
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        cnt += ma1[ans - v[i].du];
        if (v[i].du == ans - v[i].du)cnt--;
        debug(cnt)
    }
    cnt /= 2;

    if (cnt == ma[ans]) {
        ans--;
    }
    ans--;
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        cout << solve(_) << endl;
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define int long long

struct node {
    int id, du;
};
int solve(int _) {
    int n, a, b;
    cin >> n;

    vector<node>v(n);
    set<int>se;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        --a, --b;
        se.emplace(a * 100000 + b);
        se.emplace(b * 100000 + a);
        v[i].id = i;
        v[a].du++;
        v[b].du++;
    }

    sort(v.begin(), v.end(), [](node a, node b) {
        return a.du > b.du;
    });

    int ans = v[0].du + v[1].du - 1;
    if (se.count(v[0].id * 100000 + v[1].id) || se.count(v[1].id * 100000 + v[0].id))
        ans--;
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        cout << solve(_) << endl;
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define int long long

struct node {
    int id, du;
};
int solve(int _) {
    int n, a, b;
    cin >> n;

    vector<node>v(n);
    set<int>se;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        --a, --b;
        se.emplace(a * 100000 + b);
        se.emplace(b * 100000 + a);
        v[i].id = i;
        v[a].du++;
        v[b].du++;
    }

    sort(v.begin(), v.end(), [](node a, node b) {
        return a.du > b.du;
    });

    int ans = v[0].du + v[1].du - 1;
    if (se.count(v[0].id * 100000 + v[1].id) || se.count(v[1].id * 100000 + v[0].id))
        ans--;
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        cout << solve(_) << endl;
    }
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define int long long

struct node {
    int id, du;
};
int solve(int _) {
    int n, a, b;
    cin >> n;

    vector<node>v(n);
    set<int>se;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        --a, --b;
        se.emplace(a * 1000000 + b);
        se.emplace(b * 1000000 + a);
        v[i].id = i;
        v[a].du++;
        v[b].du++;
    }

    sort(v.begin(), v.end(), [](node a, node b) {
        return a.du > b.du;
    });

    int ans = v[0].du + v[1].du - 1;
    if (se.count(v[0].id * 1000000 + v[1].id) || se.count(v[1].id * 1000000 + v[0].id))
        ans--;
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        cout << solve(_) << endl;
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <numeric>
#include <ostream>
#include <pthread.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll; 
typedef unsigned long long ull; 

#define pi (2 * acos(0)) 
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)

void one_piece() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

// int freq['z'-'a'+5];
// int freq[105];

ll n, m, k, x, y, z, q;

const ll limit_size = 1e6 + 10; 
const ll MOD = 1e9 + 7;
// ll a[limit_size];
// ll b[limit_size];
// ll c[limit_size];
// ll freq[limit_size];


void solve() {
    cin >> n;

    vector<ll> nums(n);
    for (auto &i : nums) {
        cin >> i;
    }

    ll mx = *max_element(nums.begin(), nums.end());

    if (nums[0] == mx) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

int main() {
    one_piece();

    // freopen("input.txt", "r", stdin);

    int t = 1;
    std::cin >> t;
    while (t--) {
    // for (ll test = 1; test <= t; test++) {
        // cout << "Case #" << test << ": ";
        solve();
    }
 
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <numeric>
#include <ostream>
#include <pthread.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll; 
typedef unsigned long long ull; 

#define pi (2 * acos(0)) 
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)

void one_piece() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

// int freq['z'-'a'+5];
// int freq[105];

ll n, m, k, x, y, z, q;

const ll limit_size = 1e6 + 10; 
const ll MOD = 1e9 + 7;
// ll a[limit_size];
// ll b[limit_size];
// ll c[limit_size];
// ll freq[limit_size];


void solve() {
    cin >> n;

    vector<ll> nums(n);
    for (auto &i : nums) {
        cin >> i;
    }

    ll mx = *max_element(nums.begin(), nums.end());

    if (nums[0] == mx) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

int main() {
    one_piece();

    // freopen("input.txt", "r", stdin);

    int t = 1;
    std::cin >> t;
    while (t--) {
    // for (ll test = 1; test <= t; test++) {
        // cout << "Case #" << test << ": ";
        solve();
    }
 
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <numeric>
#include <ostream>
#include <pthread.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll; 
typedef unsigned long long ull; 

#define pi (2 * acos(0)) 
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)

void one_piece() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

// int freq['z'-'a'+5];
// int freq[105];

ll n, m, k, x, y, z, q;

const ll limit_size = 1e6 + 10; 
const ll MOD = 1e9 + 7;
// ll a[limit_size];
// ll b[limit_size];
// ll c[limit_size];
// ll freq[limit_size];


void solve() {
    cin >> n;

    vector<ll> nums(n);
    for (auto &i : nums) {
        cin >> i;
    }

    ll prev = nums[0];
    for (ll i = 1; i < n-1; i++) {
        if (nums[i] - prev < 0) {
            cout << "NO" << endl;
            return;
        }

        prev = nums[i] - prev;
    }

    cout << "YES" << endl;
}

int main() {
    one_piece();

    // freopen("input.txt", "r", stdin);

    int t = 1;
    std::cin >> t;
    while (t--) {
    // for (ll test = 1; test <= t; test++) {
        // cout << "Case #" << test << ": ";
        solve();
    }
 
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <numeric>
#include <ostream>
#include <pthread.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll; 
typedef unsigned long long ull; 

#define pi (2 * acos(0)) 
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)

void one_piece() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

// int freq['z'-'a'+5];
// int freq[105];

ll n, m, k, x, y, z, q;

const ll limit_size = 1e6 + 10; 
const ll MOD = 1e9 + 7;
// ll a[limit_size];
// ll b[limit_size];
// ll c[limit_size];
// ll freq[limit_size];


void solve() {
    cin >> n;

    vector<ll> nums(n);
    for (auto &i : nums) {
        cin >> i;
    }

    ll prev = nums[0];
    for (ll i = 1; i < n-1; i++) {
        if (nums[i] - prev < 0) {
            cout << "NO" << endl;
            return;
        }

        prev = nums[i] - prev;
    }

    cout << "YES" << endl;
}

int main() {
    one_piece();

    // freopen("input.txt", "r", stdin);

    int t = 1;
    std::cin >> t;
    while (t--) {
    // for (ll test = 1; test <= t; test++) {
        // cout << "Case #" << test << ": ";
        solve();
    }
 
    return 0;
}


Submission (verdict: Accepted):
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <numeric>
#include <ostream>
#include <pthread.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll; 
typedef unsigned long long ull; 

#define pi (2 * acos(0)) 
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)

void one_piece() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

// int freq['z'-'a'+5];
// int freq[105];

ll n, m, k, x, y, z, q;

const ll limit_size = 1e6 + 10; 
const ll MOD = 1e9 + 7;
// ll a[limit_size];
// ll b[limit_size];
// ll c[limit_size];
// ll freq[limit_size];


void solve() {
    cin >> n;

    vector<ll> nums(n);
    for (auto &i : nums) {
        cin >> i;
    }

    ll prev = nums[0];
    for (ll i = 1; i < n; i++) {
        if (nums[i] - prev < 0) {
            cout << "NO" << endl;
            return;
        }

        prev = nums[i] - prev;
    }

    cout << "YES" << endl;
}

int main() {
    one_piece();

    // freopen("input.txt", "r", stdin);

    int t = 1;
    std::cin >> t;
    while (t--) {
    // for (ll test = 1; test <= t; test++) {
        // cout << "Case #" << test << ": ";
        solve();
    }
 
    return 0;
}