ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n+1),b(m+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(All(a)),sort(All(b));
    int id=1;
    map<int,int>mp;

    function<bool(int)> dfs=[&](int now){
        if(now==0)return 0;
        if(mp[now]>0)mp[now]--;
        else if(now==1){
            return 0;
        }
        else {
            if(dfs(now/2)==1&&dfs((now+1)/2)==1)return 1;
            else return 0;
        }
        return 1;
    };

    for(int i=1;i<=m;i++){
        if(id<=n){
            while(id<=n&&a[id]<b[i])mp[a[id]]++,id++;
            if(a[id]==b[i]){
                id++;
                continue;
            }
        }
        if(dfs(b[i]));
        else {
            No;
            return;
        }
    }
    int sta=0;
    for(auto [u,v]:mp)if(v>0)sta=1;
    if(id==n+1&&sta==0)Yes
    else No
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n+1),b(m+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(All(a)),sort(All(b));
    int sum=0;
    map<int,int>mp;

    function<bool(int)> dfs=[&](int now){
        if(now==0)return 0;
        if(mp[now]>0)mp[now]--;
        else if(now==1){
            return 0;
        }
        else {
            if(dfs(now/2)==1&&dfs((now+1)/2)==1)return 1;
            else return 0;
        }
        return 1;
    };

    for(int i=1;i<=n;i++)mp[a[i]]++,sum+=a[i];

    for(int i=1;i<=m;i++){
        if(dfs(b[i]))sum-=b[i];
        else {
            No
            return;
        }
    }
    if(sum==0)Yes
    else No
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

const int N=5e5+100;
vector<int>a[N];

void solve(){
    int n;
    cin>>n;
    vector<int>in(n+1);
    for(int i=1;i<=n;i++)a[i].clear();
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        a[u].push_back(v);
        a[v].push_back(u);
        in[u]++,in[v]++;
    }
    int id=0;
    int mx=0;
    for(int i=1;i<=n;i++){
        if(in[i]>mx){
            mx=in[i];
            id=i;
        }
    }
    int ans=mx;
    for(auto v:a[id]){
        in[v]--;
    }
    int res=-1e8;
    for(int i=1;i<=n;i++){
        if(i==id)continue;
        res=max(res,in[i]-1);
    }
    cout<<res+ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

const int N=5e5+100;
vector<int>a[N];

void solve(){
    int n;
    cin>>n;
    vector<int>in(n+1);
    for(int i=1;i<=n;i++)a[i].clear();
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        a[u].push_back(v);
        a[v].push_back(u);
        in[u]++,in[v]++;
    }
    int id=0;
    int mx=0;
    for(int i=1;i<=n;i++){
        if(in[i]>mx){
            mx=in[i];
            id=i;
        }
    }
    int ans=mx;
    for(auto v:a[id]){
        in[v]--;
    }
    int res=-1e8;
    for(int i=1;i<=n;i++){
        if(i==id)continue;
        res=max(res,in[i]-1);
    }
    cout<<res+ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

const int N=5e5+100;
vector<int>a[N];

void solve(){
    int n;
    cin>>n;
    vector<int>in(n+1);
    for(int i=1;i<=n;i++)a[i].clear();
    for(int i=1;i<n;i++){
        int u,v;
        
        cin>>u>>v;
        a[u].push_back(v);
        a[v].push_back(u);
        in[u]++,in[v]++;
    }
    int id=0;
    int mx=0;
    vector<array<int,4>>pos(n+1);
    for(int i=1;i<=n;i++){
        int x=0;
        int num=0;
        for(auto v:a[i]){
            int y=a[v].size();
            if(v>x){
                x=v;
                num=1;
            }
            else if(v==x){
                num++;
            }
        }
        pos[i]={(int)a[i].size(),x,num,i};
    }
    sort(All(pos),[&](array<int,4>x,array<int,4>y){
        if(x[0]!=y[0])return x[0]>y[0];
        if(x[1]!=y[1])return x[1]<y[1];
        if(x[2]!=y[2])return x[2]<y[2];
        return true;
    });
    // for(int i=1;i<=n;i++){
    //     for(int j=0;j<4;j++)cout<<pos[i][j]<<" ";cout<<endl;
    // }
    id=pos[1][3];
    mx=pos[1][0];
    
    int ans=mx;
    for(auto v:a[id]){
        in[v]--;
    }
    int res=-1e8;
    for(int i=1;i<=n;i++){
        if(i==id)continue;
        res=max(res,in[i]-1);
    }
    cout<<res+ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    lli t;
    cin >> t;
    while (t--)
    {
        lli left, right;
        cin >> left >> right;
        // if leading_zeros_left==leading_zeros_right-->choose one number as first odd second number as right and greedy approach to choose third
        // else -->first number as (set bit 1 after min leading zeros and all zeros after that ->and seoond num as first-1 and greedy to choose third)
        // cout << __builtin_clzll(left) << " " << __builtin_clzll(right) << endl;
        if (__builtin_clzll(left) == __builtin_clzll(right))
        {
            lli first = right;
            lli second;
            for (lli i = left; i < right; i++)
            {
                if (i % 2 != 0)
                {
                    second = i;
                    break;
                }
            }
            lli maxi = -1;
            lli third;
            for (lli i = left; i <= right; i++)
            {
                if (i != first && i != second)
                {
                    if (((first ^ i) + (second ^ i)) > maxi)
                    {
                        maxi = (first ^ i) + (second ^ i);
                        third = i;
                    }
                }
            }
            cout << first << " " << second << " " << third << endl;
            // cout << (first ^ second) + maxi << endl;
            // cout << (123 ^ 118) + (123 ^ 121) + (121 ^ 118) << endl;
        }
        else
        {
            lli max_leading = __builtin_clzll(right);
            bitset<64> b;
            b[63 - max_leading] = 1;
            lli first = b.to_ullong();
            lli second = first - 1;
            lli maxi = -1;
            lli third;
            for (lli i = left; i <= right; i++)
            {
                if (i != first && i != second)
                {
                    if (((first ^ i) + (second ^ i)) > maxi)
                    {
                        maxi = (first ^ i) + (second ^ i);
                        third = i;
                    }
                }
            }
            cout << first << " " << second << " " << third << endl;
        }
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        int n; cin >> n; 
        vector<int> v(n); 
        for(int i=0; i<n; i++){
            cin >> v[i]; 
        }

        while(v.size() != 1){
            for(int i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back(); 
        }

        cout << abs(v[0]) << "\n"; 
    }

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        ll n; cin >> n; 
        vector<ll> v(n); 
        for(ll i=0; i<n; i++){
            cin >> v[i]; 
        }   

        if(v.size() == 1){
            cout << v[0] << "\n"; 
            continue; 
        }

        ll ans = -inf; 
        do{
            ll sum = 0; 
            for(ll i=0; i<v.size(); i++){
                sum += v[i]; 
            }
            ans = max(ans, abs(sum)); 


            for(ll i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back(); 
        }
        while(v.size() > 0); 

        cout << ans << "\n"; 
    }

}






Submission (verdict: Accepted):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        ll n; cin >> n; 
        vector<ll> v(n); 
        for(ll i=0; i<n; i++){
            cin >> v[i]; 
        }   

        if(v.size() == 1){
            cout << v[0] << "\n"; 
            continue; 
        }

        ll ans = -inf; 
        ll counter = 0; 
        do{
            ll sum = 0; 
            for(ll i=0; i<v.size(); i++){
                sum += v[i]; 
            }
            if(counter == 0) ans = max(ans, sum); 
            else ans = max(ans, abs(sum)); 

            for(ll i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back();
            counter = 1;  
        }
        while(v.size() > 0); 

        cout << ans << "\n"; 
    }

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        int n; cin >> n; 
        vector<int> v(n); 
        for(int i=0; i<n; i++){
            cin >> v[i]; 
        }

        while(v.size() != 1){
            for(int i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back(); 
        }

        cout << abs(v[0]) << "\n"; 
    }

}






Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        ll n; cin >> n; 
        vector<ll> v(n); 
        for(ll i=0; i<n; i++){
            cin >> v[i]; 
        }   

        if(v.size() == 1){
            cout << v[0] << "\n"; 
            return 0; 
        }

        ll ans = -inf; 
        do{
            ll sum = 0; 
            for(ll i=0; i<v.size(); i++){
                sum += v[i]; 
            }
            ans = max(ans, abs(sum)); 


            for(ll i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back(); 
        }
        while(v.size() > 0); 

        cout << ans << "\n"; 
    }

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        ll n; cin >> n; 
        vector<ll> v(n); 
        for(ll i=0; i<n; i++){
            cin >> v[i]; 
        }   

        if(v.size() == 1){
            cout << v[0] << "\n"; 
            return 0; 
        }

        ll ans = -inf; 
        do{
            ll sum = 0; 
            for(ll i=0; i<v.size(); i++){
                sum += v[i]; 
            }
            ans = max(ans, abs(sum)); 


            for(ll i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back(); 
        }
        while(v.size() > 0); 

        cout << ans << "\n"; 
    }

}






Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
constexpr ll inf = 1e18; 

int main(){
    ll t; cin >> t; 
    while(t--){
        ll n; cin >> n; 
        vector<ll> v(n); 
        for(ll i=0; i<n; i++){
            cin >> v[i]; 
        }   

        if(v.size() == 1){
            cout << v[0] << "\n"; 
            continue; 
        }

        ll ans = -inf; 
        do{
            ll sum = 0; 
            for(ll i=0; i<v.size(); i++){
                sum += v[i]; 
            }
            ans = max(ans, abs(sum)); 


            for(ll i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back(); 
        }
        while(v.size() > 0); 

        cout << ans << "\n"; 
    }

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N_max = 2e5 + 1;

int eea(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = eea(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

// for prime m
ll inv_prime(ll a, ll m) {
  return a <= 1 ? a : m - (ll) (m/a) * inv_prime(m % a, m) % m;
}

ll bipower(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    } 
    return res;
}

class min_queue {
    deque<int> elems;
    deque<int> mins;
    deque<int> idxs;
    int cnt;
public:
    min_queue() {cnt = 0;}
    ~min_queue() {}

    void push(int elem) {
        elems.push_back(elem);
        while (!mins.empty() && mins.back() >= elem) {
            mins.pop_back();
            idxs.pop_back();
        }

        mins.push_back(elem);
        idxs.push_back(cnt++);        
    }

    int pop() {
        if (!elems.empty()) {
            if (!idxs.empty() && idxs.front() == cnt - elems.size()) {
                mins.pop_front();
                idxs.pop_front();
            }

            int el = elems.front();
            elems.pop_front();
            return el;
        }
        return -1;
    }

    int get_min() {
        if (!mins.empty())
            return mins.front();
        return -1;
    }

    size_t size() {
        return elems.size();
    }

    bool empty() {
        return size() == 0;
    }
};

void dfs(vector<vi>& g, vi& subtrees, vi& parents, vector<bool>& vis, int current, int depth, ll& total) {
    vis[current] = true;
    total += depth;
    subtrees[current] = 1;
    for (auto &e : g[current]) {
        if (!vis[e]) {
            parents[e] = current;
            dfs(g, subtrees, parents, vis, e, depth + 1, total);
            subtrees[current] += subtrees[e];
        }
    }
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    for (auto &e : a)
        cin >> e;
    if (n == 1) {
        cout << a[0] << "\n";
        return;
    }

    ll res = 0;
    for (int i = 0; i < n; i++)
        res += a[i];
    res = abs(res);

    ll tmp = 0;
    while (a.size() > 1) {
        tmp = 0;

        for (int i = 0; i < a.size() - 1; i++)
            a[i] = a[i + 1] - a[i];

        a.pop_back();

        for (int i = 0; i < a.size(); i++)
            tmp += a[i];
        
        res = max(res, abs(tmp));
    }

    cout << res << "\n";
}
 
 
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int T = 1;
    cin >> T;
    while(T--)
        solve();
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int u;
    cin>>u;
    while (u--)
    {
        string str;
        cin>>str;
        int n;
        n=str.length();
        vector<int>v;
        int sum=0;
        int count2=0;
        int count3=0;
        for (int i = 0; i < n; i++)
        {
            v.push_back(int(str[i])-48);
            if (v[i]==2)
            {
                count2++;
            }
            else if (v[i]==3)
            {
                count3++;
            }
            sum+=v[i];
        }
        bool flag=false;
        if (sum%9==0)
        {
            cout<<"YES"<<endl;
        }
        // else if ((sum%9)%2!=0)
        // {
        //     cout<<"NO"<<endl;
        // }
        else if (sum%9==2)
        {
            if (count2>=8 || (count2>=5 && count3>=1) || (count2>=1 && count3>=2))
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            
        }
        else if (sum%9==4)
        {
            if (count2>=7 || (count2>=4 && count3>=1) || (count3>=2 && count2>=1))
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            
        }
        else if (sum%9==6)
        {
            if (count3>=2 || (count3>=1 && count2>=3) || (count2>=6))
            {
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if (sum%9==8)
        {
            if (count2>=5 || (count3>=1 && count2>=2))
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            
        }
        else if (sum%9==1)
        {
            if (count2>=4 || (count3>=1 && count2>=1))
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            
        }
        else if (sum%9==3)
        {
            if (count2>=3 || (count3>=1))
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            
        }
        else if (sum%9==5)
        {
            if (count2>=2)
            {
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if (sum%9==7)
        {
            if (count2>=1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            
        }
        
                
        
        // cout<<sum%9<<endl;
        
    }
    
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
const int inf = 9e18;
const int mod = 1e9 + 7;
const int NUM = 1000030;
const int N = 10000000;
#define DEBUG(x) cerr << #x << ": " << x << '\n'

bool isSorted(vi& a){
  for(int i = 1; i<a.size(); i++){
    if(a[i-1] > a[i]) return false;
  }
  return true;
}
void solve()
{
  ll n;
  cin>>n;
  vi a(n);
  for(int i = 0; i<n; i++) cin>>a[i];
  bool flag = true;
  for(int i = 0; i<n-1; i++){
    int mini = min(a[i], a[i+1]);
    a[i]-=mini;
    a[i+1]-=mini;
    if(a[i] > a[i+1]){
      flag = false;
      break;
    } 
    if(mini == 0) break;
  }
  if(flag) cout<<"YES\n";
  else cout<<"NO\n";
  
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
     cin >> t;
    while (t--)
        solve();
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
const int inf = 9e18;
const int mod = 1e9 + 7;
const int NUM = 1000030;
const int N = 10000000;
#define DEBUG(x) cerr << #x << ": " << x << '\n'

bool isSorted(vi& a){
  for(int i = 1; i<a.size(); i++){
    if(a[i-1] > a[i]) return false;
  }
  return true;
}
void solve()
{
  ll n;
  cin>>n;
  vi a(n);
  for(int i = 0; i<n; i++) cin>>a[i];
  bool flag = true;
  for(int i = 0; i<n-1; i++){
    int mini = min(a[i], a[i+1]);
    a[i]-=mini;
    a[i+1]-=mini;
    if(a[i] > a[i+1]){
      flag = false;
      break;
    } 
  }
  if(flag) cout<<"YES\n";
  else cout<<"NO\n";
  
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
     cin >> t;
    while (t--)
        solve();
    return 0;
}