ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

int main()

{

 ios::sync_with_stdio(false);

cin.tie(NULL);

long long int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int>a(n);

vector<int>p(n);

//bool m=true;

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

    cin>>a[i];

    p[i]=a[i];

}

sort(p.begin(),p.end());

int mi=0;

bool m=true;

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

   

        if(abs(a[i]-a[i+1])<mi){

            m=false;

                                                  

            break;

        }

        else {

            mi=a[i]-min(a[i],a[i+1]);

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

            }

    }

if(a[n-1]<mi){

  //cout<<a[n-1]<<" "<<mi<<endl;

    m=false;

} 



if(m) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

 return 0;

}



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

using namespace std;

int main()

{

 ios::sync_with_stdio(false);

cin.tie(NULL);

long long int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int>a(n);

vector<int>p(n);

//bool m=true;

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

    cin>>a[i];

}

bool m=true;

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

      int mi=min(a[i],a[i+1]);

            a[i]=a[i]-mi;

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

            

    }

  

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

    if(a[i]>a[i+1]) {

        m=false;

        //cout<<"i="<<i<<" "<<a[i]<<" "<<a[i+1]<<endl;

        break;

    }

}



if(m) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

 return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

int main()

{

 ios::sync_with_stdio(false);

cin.tie(NULL);

long long int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int>a(n);

vector<int>p(n);

//bool m=true;

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

    cin>>a[i];

    p[i]=a[i];

}

sort(p.begin(),p.end());

int mi=10e6;

bool m=true;

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

    if(a[i]>a[i+1]){

        m=false;

        break;

    }

        if(abs(a[i]-a[i+1])>mi){

            m=false;

            break;

        }

        else {

            mi=abs(a[i]-a[i+1]);

            i++;}

    }

  

if(a[n-1]<mi) m=false;



if(m) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

 return 0;

}

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

using namespace std;

int main()

{

 ios::sync_with_stdio(false);

cin.tie(NULL);

long long int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int>a(n);

vector<int>p(n);

//bool m=true;

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

    cin>>a[i];

    p[i]=a[i];

}

sort(p.begin(),p.end());

int mi=0;

bool m=true;

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

   

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

            m=false;

            break;

        }

        else {

            mi=a[i]-min(a[i],a[i+1]);

            i++;}

    }

  

if(a[n-1]<mi) m=false;



if(m) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

 return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;

int main()

{

 ios::sync_with_stdio(false);

cin.tie(NULL);

long long int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int>a(n);

vector<int>p(n);

//bool m=true;

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

    cin>>a[i];

    p[i]=a[i];

}

sort(p.begin(),p.end());

int mi=10e6;

bool m=true;

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

    if(a[i]>a[i+1]){

        m=false;

        break;

    }

        if(abs(a[i]-a[i+1])>mi){

            m=false;

            break;

        }

        else {

            mi=abs(a[i]-a[i+1]);

            i++;}

    }

  

if(a[n-1]<mi) m=false;



if(m) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

 return 0;

}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
//starting with the name of almighty ALLAH
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define mp(x,y) make_pair(x,y)
#define yes cout<<"YES"<<'\n';
#define no cout<<"NO"<<'\n';
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define MOD 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
#define nl '\n'
const int N = 1e5;
using namespace std;
/* #ifndef ONLINE_JUDGE
#include "algo/debug.h"
#else
#define dbg(x...)
#endif */
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r)
{
    return uniform_int_distribution<int>(l, r) (rng);
}
void solve()
{
    int a;
    cin >> a;;
    vector<int>v(a + 1), in(a + 1);
    for (int i = 1; i <= a; i++)
    {
        cin >> v[i];
        in[v[i]] = i;
    }
    vector<pii>an;
    for (int i = 1; i <= a; i++)
    {
        while (in[i] < a)
        {
            int nx = v[in[i] + 1];
            an.push_back({nx, i});
            swap(in[i], in[nx]);
            swap(v[in[i]], v[in[nx]]);
        }
        while (in[i] > i)
        {
            int nx = v[in[i] - 1];
            an.push_back({i, nx});
            swap(in[i], in[nx]);
            swap(v[in[i]], v[in[nx]]);
        }
    }
    cout << (int)an.size() << nl;
    for (auto &it : an)
    {
        cout << it.F << ' ' << it.S << nl;
    }
}
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/
    rj
    //int t;cin>>t;fr(i,1,t) cout<<"Case "<<i<<": ",solve();
    //ll t;scanf("%lld",&t);fr(i,1,t) printf("Case %lld: ",i),solve();
    solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>

using namespace std;



void solve() {

    int t;  // number of test cases

    cin >> t;



    while (t--) {

        string s;

        cin >> s;

        int n = s.length();

        

        // We will go from left to right, attempting to maximize the string

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

            // Try to move digits to the left if they can be reduced and swapped

            if (s[i] != '0') {

                for (int j = i; j > 0; --j) {

                    // Decrease the digit and swap

                    if (s[j] > s[j - 1]) {

                        swap(s[j], s[j - 1]);

                        s[j]--;

                        s[j - 1]++;

                    } else {

                        break;

                    }

                }

            }

        }

        cout << s << endl;

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    solve();

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>

using namespace std;



void solve() {

    int t;  // number of test cases

    cin >> t;



    while (t--) {

        string s;

        cin >> s;

        int n = s.length();

        

        // We will go from left to right, attempting to maximize the string

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

            // Try to move digits to the left if they can be reduced and swapped

            if (s[i] != '0') {

                for (int j = i; j > 0; --j) {

                    // Decrease the digit and swap

                    if (s[j] > s[j - 1]) {

                        swap(s[j], s[j - 1]);

                        s[j]--;

                        s[j - 1]++;

                    } else {

                        break;

                    }

                }

            }

        }

        cout << s << endl;

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    solve();

    return 0;

}



Submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>

using namespace std;



void solve() {

    int t;  // number of test cases

    cin >> t;



    while (t--) {

        string s;

        cin >> s;

        int n = s.length();

        

        // Process each digit starting from index 1

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

            int j = i;

            // Try to move the digit left as far as possible

            while (j > 0 && s[j] != '0') {

                char after_decrement = s[j] - 1;

                // If the decreased digit is greater than the left digit, swap

                if (after_decrement > s[j - 1]) {

                    swap(s[j], s[j - 1]);

                    s[j] = after_decrement;

                    j--;

                } else {

                    break;

                }

            }

        }

        cout << s << endl;

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    solve();

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>

using namespace std;



void solve() {

    int t;  // number of test cases

    cin >> t;



    while (t--) {

        string s;

        cin >> s;

        int n = s.length();

        

        // Process each digit starting from index 1

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

            int j = i;

            // Try to move the digit left as far as possible

            while (j > 0 && s[j] != '0') {

                char after_decrement = s[j] - 1;

                // If the decreased digit is greater than the left digit, swap

                if (after_decrement > s[j - 1]) {

                    swap(s[j], s[j - 1]);

                    s[j] = after_decrement;

                    j--;

                } else {

                    break;

                }

            }

        }

        cout << s << endl;

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    solve();

    return 0;

}



Submission (verdict: Accepted):
#include <iostream>

#include <string>

using namespace std;



void solve() {

    int t;  // number of test cases

    cin >> t;



    while (t--) {

        string s;

        cin >> s;

        int n = s.length();

        

        // Process each digit starting from index 1

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

            int j = i;

            // Try to move the digit left as far as possible

            while (j > 0 && s[j] != '0') {

                // First, decrement the current digit

                char after_decrement = s[j] - 1;

                // If the decremented digit is greater than the left digit, swap

                if (after_decrement > s[j - 1]) {

                    s[j] = after_decrement;

                    swap(s[j], s[j - 1]); // Swap after decrementing

                    j--;

                } else {

                    break;

                }

            }

        }

        cout << s << endl;

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    solve();

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

    for(ll i=01;i<n;i++){

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

    

   

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

        if(a[i]>a[i+1]){

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;



    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

    for(ll i=01;i<n;i++){

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

    

   

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

        if(a[i]>a[i+1]){

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;



    }

    return 0;

}

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

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

    for(ll i=041;i<n;i++){

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

    

   

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

        if(a[i]>a[i+1]){

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;



    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

    for(ll i=041;i<n;i++){

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

    

   

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

        if(a[i]>a[i+1]){

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;



    }

    return 0;

}

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

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

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

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

    

   

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

        if(a[i]>a[i+1]){

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;



    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);

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

    for (int i = 0; i < n - 1; i++) {
        if (a[i] > a[i + 1]) {
            int diff = a[i] - a[i + 1];
            if (diff > min(a[i], a[i + 1])) {
                cout << "NO\n";
                return;
            }
        }
    }
    
    cout << "YES\n";
}
int main(){
    fastread();
    int t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}

Submission (verdict: Compilation error):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);

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

    for(int i = 1; i < n; ++i) {
        int mn = min(a[i], a[i - 1]);
        a[i - 1] -= mn;
        a[i] -= mn;
    }
    int ok = 1;
    for(int i = 1; i < n; ++i) {
        if(a[i] < a[i - 1]) {
            ok = 0;
            break;
        }
    }
    cout << (ok ? "YES" : "NO") << ln;
}
int main(){
    fastread();
    int t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);

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

    for (int i = n - 2; i >= 0; i--) {
        if (a[i] > a[i + 1]) {
            int diff = a[i] - a[i + 1];
            if (diff > min(a[i], a[i + 1])) {
                cout << "NO\n";
                return;
            }
            a[i] -= diff;
            a[i + 1] -= diff;
        }
    }
    
    cout << "YES\n";
}

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

Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);

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

    for (int i = 0; i < n - 1; i++) {
        if (a[i] > a[i + 1]) {
            int diff = a[i] - a[i + 1];
            if (diff > min(a[i], a[i + 1])) {
                cout << "NO\n";
                return;
            }
        }
    }
    
    cout << "YES\n";
}
int main(){
    fastread();
    int t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);

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

    for(int i = 1; i < n; ++i) {
        int mn = min(a[i], a[i - 1]);
        a[i - 1] -= mn;
        a[i] -= mn;
    }
    int ok = 1;
    for(int i = 1; i < n; ++i) {
        if(a[i] < a[i - 1]) {
            ok = 0;
            break;
        }
    }
    cout << (ok ? "YES" : "NO") << ln;
}
int main(){
    fastread();
    int t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (ll c = 0; c < n; c++) {
        cin >> v[c];
    }

    for (ll i = 1; i < n; i++) {
        ll x = min(v[i - 1], v[i]);
        v[i - 1] -= x;
        v[i] -= x;
    }

    bool res = true;
    for (int m = 1; m < n; m++) {
        if (v[m - 1] > v[m]) {
            res = false;
            break;
        }
    }

    cout << (res ? "YES\n" : "NO\n");
}
int main(){
    fastread();
    ll t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define fastread() ios::sync_with_stdio(false); cin.tie(0);

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

    for (int i = n - 2; i >= 0; i--) {
        if (a[i] > a[i + 1]) {
            int diff = a[i] - a[i + 1];
            if (diff > min(a[i], a[i + 1])) {
                cout << "NO\n";
                return;
            }
            a[i] -= diff;
            a[i + 1] -= diff;
        }
    }
    
    cout << "YES\n";
}

int main(){
    fastread();
    int t;
    cin >> t;
    while(t--){
        solve();
    } 
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


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

using namespace std;

using ll = long long;
const long long MOD = 1000000007;

#define all(c) (c).begin(), (c).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 2e5 + 10;
const ll INF = 1e18;

int solve(int i, int j, string &a, string &b, vector<vector<int>> &dp) {
    if (i == a.size() || j == b.size()) return 0;
    if (~dp[i][j]) return dp[i][j];
    int ret = 0;
    if (a[i] == b[j]) ret = max(ret, solve(i + 1, j + 1, a, b, dp) + 1);
    ret = max(ret, solve(i + 1, j, a, b, dp));
    ret = max(ret, solve(i, j + 1, a, b, dp));
    return dp[i][j]= ret;
}
vector<bool> vis(MAXN);
int cnt;
void print(int i, int j, string &a, string &b, vector<vector<int>>&dp) {
    if (i == a.size() || j == b.size()) return;
    int opt = solve(i, j, a, b, dp);
    if (a[i] == b[j] && opt == solve(i + 1, j + 1, a, b, dp) + 1) {
		vis[i] = true;
        return print(i + 1, j + 1, a, b, dp);
    }
    if (opt == solve(i + 1, j, a, b, dp)) return print(i + 1, j, a, b, dp);
    return print(i, j + 1, a, b, dp);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int tc;
    cin >> tc;
    while (tc--) {
        string a, b, c;
        cin >> a >> b >> c;
		int n = a.size(), m = b.size();
		ll dp[n + 1][m + 1];
		memset(dp, n + m + 1, sizeof(dp));
		dp[0][0] = 0;
		for(int i = 0; i <=n; i++){
			for(int j = 0; j <=m; j++){
				int k = i + j;
				if(i < n){
					int cnt = c[k] != a[i];
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
				}
				if(j < m){
					int cnt = c[k] != b[j];
					dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
				}
			}
		}
		cout << dp[n][m] <<endl;
	}

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
//template owner:professor
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(long long int  i=0;i<n;i++)
#define vi std::vector<int> 
const long long int MOD=1e9+7;
#define vli std::vector<long long int>
#define si std::set<int> 
#define sli std::set<long long int > 
#define qi std::queue<int > 
#define qli std::queue<long long int >
#define mli std::map<long long int ,long long int> 
#define mc std::map<char, long long int> 
#define umli std::unordered_map<long long int,long long int>
#define umc std::unordered_map<char,long long int>
#define gap ' '
#define ff first
#define ss second	
#include<cmath>
#include<bits/stdc++.h>
void solve()
{
//  1 5 6 2 3
//  0 4 6 2 3
//  0 0 2 2 3
 
 // odd size pair should 
int n; 
cin>> n;
 int val =1;
 int a[n];
for(int i = 0; i< n; ++i)
{
    cin>>a[i];
}

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

    if(a[i] >=a[i-1]) val ++;
    else {
        if(((val &1) ^1) ){
            cout<<"NO"<<endl;
            return;
        }
        if(i !=n-1 && a[i] > a[i+1]) {
            cout<<"NO"<<endl;
            return;
        }
        val =0;
    }
        a[i] -=a[i-1];
}  
cout<<"YES"<<endl;
  
  
}
 
int main() {
         ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
ll t;
cin>>t;
while(t--)
{
solve();
}
 
	// your code goes here
	return 0;
}