ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

int dp(int i, int j, int n, string a, string b, string c) {
    if (i + j >= n) return 0;
    return min(dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1), dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1));
}

void solve() {
    int na, nb, nc;
    string a, b, c;
    cin >> a >> b >> c;
    na = a.length();
    nb = b.length();
    nc = c.length();
    // vector<vector<int>> dp(1001, vector<int>(1001, 0));
    // for (int i = na; i >= 0; i--) {
    //     for (int j = nb; j >= 0; j--) {
    //         if (i + j >= nc) continue;
    //         dp[i][j] = min(dp[i + 1][j] + ((a[i] == c[i + j]) ? 0 : 1), dp[i][j + 1] + ((b[j] == c[i + j]) ? 0 : 1));
    //     }
    // }
    // cout << dp[0][0] << "\n";
    cout << dp(0, 0, nc, a, b, c) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}


Submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

int dp(int i, int j, int n, string a, string b, string c) {
    if (i + j >= n) return 0;
    if (i == a.length()) return dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1);
    if (j == b.length()) return dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1);
    return min(dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1), dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1));
}

void solve() {
    int na, nb, nc;
    string a, b, c;
    cin >> a >> b >> c;
    na = a.length();
    nb = b.length();
    nc = c.length();
    // vector<vector<int>> dp(1001, vector<int>(1001, 0));
    // for (int i = na; i >= 0; i--) {
    //     for (int j = nb; j >= 0; j--) {
    //         if (i + j >= nc) continue;
    //         dp[i][j] = min(dp[i + 1][j] + ((a[i] == c[i + j]) ? 0 : 1), dp[i][j + 1] + ((b[j] == c[i + j]) ? 0 : 1));
    //     }
    // }
    // cout << dp[0][0] << "\n";
    cout << dp(0, 0, nc, a, b, c) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
/*
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define modulo(S, N) ((S) & (N-1))   
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) (1<<lround(log2(S)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
*/
#define pb push_back
#define sqr(x) ((x) * (x))
#define gcd(a,b) __gcd(a,b)
#define FAST_IO ios::sync_with_stdio(0);cin.tie(0);
#define MOD 1000000007
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rep0(i,n) for(int i = 0; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define int_max INT_MAX
#define int_min INT_MIN
#define endl "\n"
#define LSOne(S) ((S) & (-S))
#define ceros(v) __builtin_ctzll(v)
#define debug(x) cout << #x << " = " << x << "\n";
#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n";
typedef  long long ll;
typedef pair<int,int> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef tuple <int,string,string> iss;
typedef tuple <int,int,int> iii;
#pragma GCC optimize("Ofast,unroll-loops,fast-math,prefetch-loop-arrays,tree-vectorize,omit-frame-pointer,no-peephole")
//mt19937_64 qrand(chrono::steady_clock::now().time_since_epoch().count());



main() {
    FAST_IO;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int tt;
    cin >> tt;
    while(tt -- ){
        int n;
        cin >> n;
        vi datos(n);
        for(int &i:datos) cin >> i;
        int newN=n;
        int ans=int_min;
        for(int i=0;i<n;i++){
            int sum=0;
            for(int i=0;i<newN;i++)sum += datos[i];
            if(i==0){
                ans = sum; 
            }else{
                ans = max(ans, max(sum, - sum));
            }
            newN--;
            for(int i=0;i<newN;i++){
                datos[i]=datos[i+1]-datos[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 8):
                    //INCLUDING..

#include "bits/stdc++.h"



//DEFINING..

#define LL               long long

#define ull              unsigned long long

#define LD               long double

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

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

#define pb               push_back

#define sz(s)            (int)s.size()

#define SET(n,i)         memset(n,i,sizeof(n))

#define cy               cout<<"YES\n";

#define cn               cout<<"NO\n";

#define vl               vector<LL>

#define pll              pair<LL,LL>

#define pii              pair<int,int>

#define F                first

#define S                second

#define sq(x)            (x)*(x)

#define FIX(n)           fixed<<setprecision(n)

#define fast             ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);

//#define endl             '\n'



using namespace std;

template<class T, class T2> bool MAX(T& a, const T2& b) {return a < b ? a=b,1:0 ;}

template<class T, class T2> bool MIN(T& a, const T2& b) {return a > b ? a=b,1:0 ;}



//FUNCTION..



int dx[] = {+0,+1,+0,-1,-1,+1,-1,+1};

int dy[] = {-1,+0,+1,+0,-1,+1,+1,-1};

char direction[]={'L','D','R','U'};

const LL N=3e5+7, mod=1e9+7, oo=0x3f3f3f3f3f3f3f3f;

const long double pi = acos(-1), eps=1e-9 ;

LL Mul(LL x, LL y){x%=mod; y%=mod; return (x * y) % mod;}

LL Add(LL x, LL y){x%=mod; y%=mod; return (x + y) % mod;}

LL fix(LL x,LL m=mod){return (x%m+m)%m;}





LL n,m,i,j,x,y,z,l,r,q,p,k,f,d,sum,cnt,ans;

LL ar[N],br[N],vis[N];

map<LL,LL> mp,mp1;

string s,t;

vector<LL>g[N];





void SOLVE(){

cin>>s;

n=sz(s);

string ans="";

vector<int>vis(n);

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

if(vis[i])continue;

int j=i+1 , cnt=0 ;

int now=s[i]-'0';

int id=-1;

int mx=0;

for(int _=0;_-cnt<10 && j<n;_++,j++){

if(vis[j]){

cnt++;

continue;

}

int cur=s[j]-'0';

if(cur-(j-i)+cnt>now){

if(mx<cur-(j-i)+cnt){

mx=cur-(j-i)+cnt;

id=j;

}

}



}

if(id!=-1){

vis[id]=1;

ans+=mx+'0';

i--;

}else{

vis[i]=1;

ans+=s[i];

}

}

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

//        if(vis[i]==0)ans+=s[i];

//    }

cout<<ans<<endl;

}





//MAINING..

signed main(){

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

//    freopen("output.txt","w",stdout);

fast

int T=1;

cin>>T;

while(T--)SOLVE();



return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
// C++ program to demonstrate working of 

// extended Euclidean Algorithm 

#include <bits/stdc++.h> 

using namespace std;

typedef long long l1;

int main()  { 

  int t;

  cin>>t;

  while(t--){

    l1 n,l,r;

    cin>>n>>l>>r;

    vector<l1> v(n);

    for(int i=0;i<n;i++) cin>>v[i];

    l1 sum=0;

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

    l1 j=0;

    for(int i=l;i<=r;i++){

       sum+=v[j++];

    }

    cout<<sum<<endl;

}

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
// C++ program to demonstrate working of 

// extended Euclidean Algorithm 

#include <bits/stdc++.h> 

using namespace std;

typedef long long l1;

int main()  { 

  int t;

  cin>>t;

  while(t--){

    l1 n,l,r;

    cin>>n>>l>>r;

    vector<l1> v(n);

    for(int i=0;i<n;i++) cin>>v[i];

    l1 sum=0;

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

    l1 j=0;

    for(int i=l;i<=r;i++){

       sum+=v[j++];

    }

    cout<<sum<<endl;

}

}



Submission (verdict: Wrong answer on test 1):
// C++ program to demonstrate working of 

// extended Euclidean Algorithm 

#include <bits/stdc++.h> 

using namespace std;

typedef long long l1;

int main()  { 

  int t;

  cin>>t;

  while(t--){

    l1 n,l,r;

    cin>>n>>l>>r;

    vector<l1> v(n);

    vector<l1> a(n);

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

      cin>>v[i];

      a[i]=v[i];

    }

    

    l1 sum1=0,sum2=0;

    sort(a.begin(),a.begin()+r);

    sort(v.begin()+l,v.end());

    // for(int i=0;i<n;i++) cout<<v[i]<<" ";

    // cout<<endl;

    l1 j=0,p=l-1;

    for(int i=l;i<=r;i++){

       sum1+=a[j++];

       sum2+=v[p++];

      // cout<<sum2<<" ";

    }

   // cout<<sum2<<endl;

    cout<<min(sum1,sum2)<<endl;

}

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
// C++ program to demonstrate working of 

// extended Euclidean Algorithm 

#include <bits/stdc++.h> 

using namespace std;

typedef long long l1;

int main()  { 

  int t;

  cin>>t;

  while(t--){

    l1 n,l,r;

    cin>>n>>l>>r;

    vector<l1> v(n);

    vector<l1> a(n);

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

      cin>>v[i];

      a[i]=v[i];

    }

    

    l1 sum1=0,sum2=0;

    sort(a.begin(),a.begin()+r);

    sort(v.begin()+l,v.end());

    // for(int i=0;i<n;i++) cout<<v[i]<<" ";

    // cout<<endl;

    l1 j=0,p=l-1;

    for(int i=l;i<=r;i++){

       sum1+=a[j++];

       sum2+=v[p++];

      // cout<<sum2<<" ";

    }

   // cout<<sum2<<endl;

    cout<<min(sum1,sum2)<<endl;

}

}



Submission (verdict: Accepted):
// C++ program to demonstrate working of 

// extended Euclidean Algorithm 

#include <bits/stdc++.h> 

using namespace std;

typedef long long l1;

int main()  { 

  int t;

  cin>>t;

  while(t--){

    l1 n,l,r;

    cin>>n>>l>>r;

    vector<l1> v(n);

    vector<l1> a(n);

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

      cin>>v[i];

      a[i]=v[i];

    }

    

    l1 sum1=0,sum2=0;

    sort(a.begin(),a.begin()+r);

    sort(v.begin()+l-1,v.end());

    // for(int i=0;i<n;i++) cout<<v[i]<<" ";

    // cout<<endl;

    l1 j=0,p=l-1;

    for(int i=l;i<=r;i++){

       sum1+=a[j++];

       sum2+=v[p++];

      // cout<<sum2<<" ";

    }

   // cout<<sum2<<endl;

    cout<<min(sum1,sum2)<<endl;

}

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

Previous submission (verdict: Wrong answer on test 2):

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0);
        if(i==0)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        for(int i=0; i<now-1; i++)
            a[i]=a[i+1]-a[i];
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0LL);
        if(i==0)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        for(int i=0; i<now-1; i++)
            a[i]=a[i+1]-a[i];
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.end(), 0);
        if(i==1)
            rez=max(rez, s);
        else
            rez=max(rez, max(sum, -sum));
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}
}

Submission (verdict: Wrong answer on test 1):

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0);
        if(i==1)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0);
        if(i==1)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        for(int i=0; i<now-1; i++)
            a[i]=a[i+1]-a[i];
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}

Submission (verdict: Wrong answer on test 2):

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0);
        if(i==0)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        for(int i=0; i<now-1; i++)
            a[i]=a[i+1]-a[i];
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0);
        if(i==1)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}

Submission (verdict: Wrong answer on test 1):

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0);
        if(i==1)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        for(int i=0; i<now-1; i++)
            a[i]=a[i+1]-a[i];
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Compilation error):
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.end(), 0);
        if(i==1)
            rez=max(rez, s);
        else
            rez=max(rez, max(sum, -sum));
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <random>
#include <bitset>
#include <cmath>
#include <cassert>
#include <sstream>
 
using namespace std;
 
#define ll long long
#define vec vector
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cerr << (#x) << " = " << (x) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define time (double)clock() / CLOCKS_PER_SEC
#define forn(i, n) for (int i = 0; i < n; i++)
#define each(i, a) for (auto& i : a)
 
template <typename T>
void print(const vec<T> & a) {
    each(e, a)
        cout << e << " ";
    cout << endl;
}
 
template <typename T>
void scan(vec<T> & a) {
    each(e, a) 
        cin >> e;
}

void scan_graph(int n, int m, vec<vec<int>> & g) {
    forn(i, m) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
}

void scan_graph(int n, int m, vec<vec<pii>> & g) {
    forn(i, m) {
        int a, b, c; cin >> a >> b >> c; a--; b--;
        g[a].eb(b, c);
        g[b].eb(a, c);
    }
}
 
template <typename T>
T sum(const vec<T> & a) {
    T sum = 0;
    each(e, a) 
        sum += e;
    return sum;
}
 
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
 
const int inf = 1e9 + 1;
const ll llinf = 1e18; 
 
const ll mod = 998244353;
 
inline int sm(int a, int b) {
    if (a + b >= mod) return a + b - mod;
    return a + b;
}
 
inline int dif(int a, int b) {
    if (a < b) return a + mod - b;
    return a - b;
}
 
int mul(int a, int b) {
    return (ll)a * b % mod;
}

void bool_ans(bool fl) {
    if (fl)
        cout << "YES\n";
    else
        cout << "NO\n";
}

void solve() {
    int n; cin >> n;
    vec<vec<int>> g(n);
    scan_graph(n, n - 1, g);
    int mx1 = 0, mx2 = 1;
    if (g[mx1].size() < g[mx2].size()) swap(mx1, mx2);
    for (int i = 2; i < n; i++) {
        if (g[i].size() > g[mx1].size()) mx2 = mx1, mx1 = i;
        else if (g[i].size() > g[mx2].size()) mx2 = i; 
    }
    int best = g[mx1].size() + g[mx2].size() - 1;
    if (find(all(g[mx1]), mx2) == g[mx1].end()) {
        cout << best << endl;
        return;
    }
    if (g[mx1].size() != g[mx2].size()) {
        cout << best - 1 << endl;
        return;
    }
    int cnt = 0;
    forn (i, n) if (g[i].size() == g[mx1].size()) cnt++;
    if (cnt > 2) {
        cout << best << endl;
    } else {
        cout << best - 1 << endl;
    }

    return;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int t_cases = 1;
    cin >> t_cases;
    while (t_cases--) {
        solve();
        cerr << "----------\n";
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

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

    while(t--){
        ll n;
        cin >> n;

        vector<ll> a(n);
        for(ll i=0; i<n; i++) cin >> a[i];

        if(n==2){
            if(a[0] <= a[1]){
                cout << "YES" << endl;
            }
            else cout << "NO" << endl;
            continue;
        }

        ll l = 0;
        while(l<n-1){
            while(min(a[l], a[l+1]) == 0) l++;
            if(l>=n) break;
            ll mini = min(a[l], a[l+1]);
            a[l] -= mini, a[l+1] -= mini;
            l++;
        }

        bool possible = true;
        for(ll i=0; i<n; i++){
            if(a[i]!=0){
                if(i!=n-1){
                    possible = false;
                    break;
                }
            }
        }

        if(possible) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

using ll = long long;

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

    while(t--){
        ll n;
        cin >> n;

        vector<ll> a(n);
        for(ll i=0; i<n; i++) cin >> a[i];

        if(n==2){
            if(a[0] <= a[1]){
                cout << "YES" << endl;
            }
            else cout << "NO" << endl;
            continue;
        }

        ll l = 0;
        while(l<n-1){
            while(l<n-1 && min(a[l], a[l+1]) == 0) l++;
            if(l>=n-1) break;
            ll mini = min(a[l], a[l+1]);
            a[l] -= mini, a[l+1] -= mini;
            l++;
        }

        bool possible = true;
        for(ll i=0; i<n; i++){
            if(a[i]!=0){
                if(i!=n-1){
                    possible = false;
                    break;
                }
            }
        }

        if(possible) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

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

    while(t--){
        ll n;
        cin >> n;

        vector<ll> a(n);
        for(ll i=0; i<n; i++) cin >> a[i];

        ll l = 0;
        while(l<n-1){
            while(min(a[l], a[l+1]) == 0) l++;
            if(l>=n) break;
            ll mini = min(a[l], a[l+1]);
            a[l] -= mini, a[l+1] -= mini;
            l++;
        }

        bool possible = true;
        for(ll i=0; i<n; i++){
            if(a[i]!=0){
                if(i!=n-1){
                    possible = false;
                    break;
                }
            }
        }

        if(possible) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

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

    while(t--){
        ll n;
        cin >> n;

        vector<ll> a(n);
        for(ll i=0; i<n; i++) cin >> a[i];

        if(n==2){
            if(a[0] <= a[1]){
                cout << "YES" << endl;
            }
            else cout << "NO" << endl;
            continue;
        }

        ll l = 0;
        while(l<n-1){
            while(min(a[l], a[l+1]) == 0) l++;
            if(l>=n) break;
            ll mini = min(a[l], a[l+1]);
            a[l] -= mini, a[l+1] -= mini;
            l++;
        }

        bool possible = true;
        for(ll i=0; i<n; i++){
            if(a[i]!=0){
                if(i!=n-1){
                    possible = false;
                    break;
                }
            }
        }

        if(possible) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}