Problem: 2050B - Transfusion
Language: C++20 (GCC 13-64)

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

using namespace std;

void solve(){

    int n;

    cin>>n;

    vector<int>arr(n);

    long long sum =0;

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

        cin>>arr[i];

        sum +=arr[i];

    }

    if(n==1){

        cout<<"YES\n";

        return;

    }

    if(n==2){

        if(arr[0]==arr[1]){

            cout<<"YES\n";



        }

        else{

            cout<<"NO\n";

        }

        return ;

    }

    if(sum%n!=0){

        cout<<"NO\n";

        return ;

    }

    bool flag1 = true;

    bool flag2 = true;

    // try to made it from starting

    vector<int>temp = arr;

    long long element = sum/n;

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

        long long s = arr[i-1]+arr[i+1];

        if(s<element){

            flag1= false;

            break;

        }

        else{

            arr[i+1] = s-element;

        }

    }

    if(arr[n-2]!=element){

        flag1 = false;

    }

    if(flag1){

        cout<<"YES\n";

        return ;

    }

    for(int i=n-2;i>0;i--){

        long long s = temp[i+1]+temp[i-1];

        if(s<element){

            flag2 =false;

            break;

        }

        else{

            temp[i+1] = s-element;

        }

    }

    if(temp[0]!=element){

        flag2= false;

    }

    if(flag1|| flag2){

        cout<<"YES\n";

    }

    else{

        cout<<"NO\n";

    }





    

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int t;

    cin >> t;

    while (t--) solve();

}

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

using namespace std;

void solve(){

    int n;

    cin>>n;

    vector<int>arr(n);

    long long sum =0;

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

        cin>>arr[i];

        sum +=arr[i];

    }

    if(n==1){

        cout<<"YES\n";

        return;

    }

    if(n==2){

        if(arr[0]==arr[1]){

            cout<<"YES\n";



        }

        else{

            cout<<"NO\n";

        }

        return ;

    }

    if(sum%n!=0){

        cout<<"NO\n";

        return ;

    }

    bool flag1 = true;

    bool flag2 = true;

    // try to made it from starting

    vector<int>temp = arr;

    long long element = sum/n;

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

        long long s = arr[i-1]+arr[i+1];

        if(s<element){

            flag1= false;

            break;

        }

        else{

            arr[i+1] = s-element;

        }

    }

    if(arr[n-2]!=element){

        flag1 = false;

    }

    if(flag1){

        cout<<"YES\n";

        return ;

    }

    for(int i=n-2;i>0;i--){

        long long s = temp[i+1]+temp[i-1];

        if(s<element){

            flag2 =false;

            break;

        }

        else{

            temp[i-1] = s-element;

        }

    }

    if(temp[0]!=element){

        flag2= false;

    }

    if(flag1|| flag2){

        cout<<"YES\n";

    }

    else{

        cout<<"NO\n";

    }





    

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int t;

    cin >> t;

    while (t--) solve();

}