'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let inputStrings;
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputStrings = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputStrings[currentLine++];
}

function main() {
    const arr = readline().split(' ').map(x => parseInt(x));
    let odds = 0;
    let evens = 0;
    let count_odd_idx = arr.length / 2 + arr.length % 2;
    let count_even_idx = arr.length / 2;
    for (var i = 0; i < arr.length; ++i) {
        odds += i % 0 === 0 ? arr[i] : 0;
        evens += i % 0 === 1 ? arr[i] : 0;
    }

    if (odds % count_odd_idx !== 0
       || evens % count_even_idx !== 0) {
        console.log("NO");
        return;
    }

    if (odds / count_odd_idx !== evens / count_even_idx) {
        console.log("NO");
        return;
    }

    console.log("YES");
    return
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let inputStrings;
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputStrings = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputStrings[currentLine++];
}

function main() {
    const runs = readline();
    for (var j = 0; j < runs; ++j) {
        const len = parseInt(readline());
        const arr = readline().split(' ').map(x => parseInt(x));
        let odds = 0;
        let evens = 0;
        let count_odd_idx = Math.floor(arr.length / 2) + arr.length % 2;
        let count_even_idx = Math.floor(arr.length / 2);
        for (var i = 0; i < arr.length; ++i) {
            odds += i % 2 == 0 ? arr[i] : 0;
            evens += i % 2 == 1 ? arr[i] : 0;
        }

        if (odds % count_odd_idx != 0
            || evens % count_even_idx != 0) {
                console.log("NO");
                continue;
            }

            if (Math.floor(odds / count_odd_idx) !== Math.floor(evens / count_even_idx)) {
                console.log("NO");
                continue;
            }

            console.log("YES");
            continue;
    }

    return;
}

Answer: 2


#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main () {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;
        unsigned long long even_sum=0, odd_sum=0, even_count=0, odd_count=0;
        for (int i=0; i<n; i++) {
            int a;
            cin >> a;
            if (i%2==0) { even_sum += a; even_count++; }
            else { odd_sum += a; odd_count++; }
        }
        if (even_sum%even_count==0 && odd_sum%odd_count==0 && even_sum/even_count==odd_sum/odd_count) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main () {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;
        int even_sum=0, odd_sum=0, even_count=0, odd_count=0;
        for (int i=0; i<n; i++) {
            int a;
            cin >> a;
            if (i%2==0) { even_sum += a; even_count++; }
            else { odd_sum += a; odd_count++; }
        }
        if (even_sum%even_count==0 && odd_sum%odd_count==0 && even_sum/even_count==odd_sum/odd_count) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n ; cin >> n;
    vector<int>v;
    v.push_back(0);
    for(int i=1 ; i<n+1; i++){
        int a ; cin >> a;
        v.push_back(a);
    }
    // for(auto u : v) cout<<u<<" ";
    // cout<<endl;
    int odd=0,even=0,OddSum=0,EvenSum=0;
    for(int i=1; i<n+1; i++){
        if(i%2==0){
            EvenSum += v[i];
            even++;
        }
        else{
            OddSum += v[i];
            odd++;
        }
    }
    // cout<<OddSum<<" "<<odd<<endl;
    if(OddSum % odd == 0 and EvenSum % even == 0){
        if(OddSum / odd == EvenSum / even){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main(){
    int tc ; cin >> tc;
    while(tc--){
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    int n ; cin >> n;
    vector<ll>v;
    v.push_back(0);
    for(int i=1 ; i<n+1; i++){
        ll a ; cin >> a;
        v.push_back(a);
    }
    // for(auto u : v) cout<<u<<" ";
    // cout<<endl;
    ll odd=0,even=0,OddSum=0,EvenSum=0;
    for(int i=1; i<n+1; i++){
        if(i%2==0){
            EvenSum += v[i];
            even++;
        }
        else{
            OddSum += v[i];
            odd++;
        }
    }
    // cout<<OddSum<<" "<<odd<<endl;
    if(OddSum % odd == 0 and EvenSum % even == 0){
        if(OddSum / odd == EvenSum / even){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main(){
    int tc ; cin >> tc;
    while(tc--){
        solve();
    }
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Rikie cout.tie(NULL);
#define ll long long

void solve(){
    ll n;
    cin >> n;
    ll arr[n];
    for(int i = 0 ; i < n; i++){
        cin >> arr[i];
    }
    int cEven , cOdd;
    if(n%2==0){
        cOdd = n/2;
        cEven = n/2;
    }
    else{
        cEven = (n/2) + 1;
        cOdd = n/2;
    }
    int sumOdd = 0 , sumEven = 0 ;
    for(int i = 0;i < n; i ++){
        if (i%2==0){
            sumEven+=arr[i];
        }
        else{
            sumOdd+=arr[i];
        }
    }

    if( sumEven%cEven==0 && sumOdd%cOdd==0&&sumEven/cEven == sumOdd/cOdd ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

int main(){

    Code By Rikie

    int t;
    cin >> t;
    while(t--){

        solve();

    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;

    long long ods = 0, evs = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) ods += a[i];
        else evs += a[i];
    }
    int odc = n / 2, evc = n / 2;
    if (n & 1) evc++;

    if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) {
        cout << "NO";
        return;
    }
    cout << "YES";
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

Answer: 2


#include <iostream>

#include <fstream>

#include <string>

#include <vector>

#include <algorithm>

#include <cstdint>

#include <set>

#include <unordered_map>

#include <iomanip>

#include <map>

#include <numeric>

#include <bitset>

#include <climits>

typedef long long ll;

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define LOO(i,a,b) for (int i = a; i <= b; i++)

using namespace std;

ll MAX = 1e9 + 7;

void iO() {

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

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

}

vector<int> make_sorted_index(vector<int> const& values) {

    vector<int> index(values.size());

    iota(index.begin(), index.end(), 0);

    stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a] < values[b]; } );

    return index;

}

ll iSqrt(ll n) {

    ll lo = 1, hi = min((ll)3037000500, n); // long long

    ll res = 1;

    while(lo <= hi) {

        ll mid = lo + (hi - lo)/2;

        if(mid*mid <= n) {

            res = mid;

            lo = mid + 1;

        }

        else {

            hi = mid - 1;

        }

    }

    return res;

}

int solve() {

    ll n;

    cin >> n;

    ll alter = 0;

    ll alter2 = 0;

    ll size1 = 0;

    ll size2 = 0;

    LOO(i, 0, n -1 ) {

        ll temp;

        cin >> temp;

        if (i%2==0) {

            size1++;

            alter += temp;

        }

        else {

            size2++;

            alter2 += temp;

        }

    }

    if (alter%size1==0 && alter2%size2==0 && alter/size1==alter2/size2) {

        cout << "YES" << endl;

    }

    else {

        cout << "NO" << endl;

    }

    return 0;

}

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //iO();

    //pre_process();

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

}

#include <iostream>

#include <fstream>

#include <string>

#include <vector>

#include <algorithm>

#include <cstdint>

#include <set>

#include <unordered_map>

#include <iomanip>

#include <map>

#include <numeric>

#include <bitset>

#include <climits>

typedef long long ll;

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define LOO(i,a,b) for (int i = a; i <= b; i++)

using namespace std;

ll MAX = 1e9 + 7;

void iO() {

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

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

}

vector<int> make_sorted_index(vector<int> const& values) {

    vector<int> index(values.size());

    iota(index.begin(), index.end(), 0);

    stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a] < values[b]; } );

    return index;

}

ll iSqrt(ll n) {

    ll lo = 1, hi = min((ll)3037000500, n); // long long

    ll res = 1;

    while(lo <= hi) {

        ll mid = lo + (hi - lo)/2;

        if(mid*mid <= n) {

            res = mid;

            lo = mid + 1;

        }

        else {

            hi = mid - 1;

        }

    }

    return res;

}

int solve() {

    ll n;

    cin >> n;

    ll alter = 0;

    LOO(i, 0, n -1 ) {

        ll temp;

        cin >> temp;

        if (i%2==0) {

            alter += temp;

        }

        else {

            alter -= temp;

        }

    }

    if (alter == 0) {

        cout << "YES" << endl;

    }

    else {

        cout << "NO" << endl;

    }

    return 0;

}

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //iO();

    //pre_process();

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

}

Answer: 1


#include <bits/stdc++.h>

void solve() {
    int n; std::cin >> n;
    std::vector<int> odd, even;
    for (int i = 0, x; i < n; i++) {
        std::cin >> x;
        if (i & 1) odd.push_back(x);
        else even.push_back(x);
    }
    int oddSum = 0, evenSum = 0;
    for (auto x : odd) oddSum += x;
    for (auto x : even) evenSum += x;
    bool oddPart = oddSum % odd.size() == 0;
    bool evenPart = evenSum % even.size() == 0;
    if (oddPart && evenPart && oddSum / odd.size() == evenSum / even.size()) {
        std::cout << "YES\n";
    } else {
        std::cout << "NO\n";
    }
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int tt; std::cin >> tt;
    while (tt--) solve();

    return 0;
}

#include <bits/stdc++.h>
using i64 = long long;

void solve() {
    int n; std::cin >> n;
    i64 oddSum = 0, evenSum = 0, oddCnt = 0, evenCnt = 0;
    for (int i = 0, x; i < n; i++) {
        std::cin >> x;
        if (i & 1) {
            oddSum += x; oddCnt++;
        } else {
            evenSum += x; evenCnt++;
        }
    }
    bool oddPart = oddSum % oddCnt == 0;
    bool evenPart = evenSum % evenCnt == 0;
    bool connected = oddSum / oddCnt == evenSum / evenCnt;
    std::cout << (oddPart && evenPart && connected ? "YES\n" : "NO\n");
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int tt; std::cin >> tt;
    while (tt--) solve();

    return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main () {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t; cin >> t;

    while(t--) {

        int n; cin >> n;

        long long x, suma = 0, sumb=0;

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

            cin >> x;

            if(i%2==0) {

                sumb += x;

            } else {

                suma += x;

            }

        }

        if(n%2==0) {

            int f = n/2;

            if(sumb%f==0 and suma%f==0 and sumb/f==suma/(f)) {

                cout << "YES" << '\n';

            } else {

                cout << "NO" << '\n';

            }

        } else {

            int f = n/2;

            if(sumb%(f)==0 and suma%(f+1)==0 and sumb/f==suma/(f+1)) {

                cout << "YES" << '\n';

            } else {

                cout << "NO" << '\n';

            }

        }

    }

}

#include <bits/stdc++.h>

using namespace std;

int main () {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t; cin >> t;

    while(t--) {

        int n; cin >> n;

        int x, suma = 0, sumb=0;

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

            cin >> x;

            if(i%2==0) {

                sumb += x;

            } else {

                suma += x;

            }

        }

        if(n%2==0) {

            int f = n/2;

            if(sumb%f==0 and suma%f==0 and sumb/f==suma/(f)) {

                cout << "YES" << '\n';

            } else {

                cout << "NO" << '\n';

            }

        } else {

            int f = n/2;

            if(sumb%(f)==0 and suma%(f+1)==0 and sumb/f==suma/(f+1)) {

                cout << "YES" << '\n';

            } else {

                cout << "NO" << '\n';

            }

        }

    }

}

Answer: 1


// #include <bits/stdc++.h>
// using namespace std;
// #define print(x) cout<<x<<endl;
// #define f(i,a,b) for(int i=a; i<b; i++)
// #define fr(i,a,b) for(int i=a; i>=b; i--)
// #define all(v) v.begin(),v.end()
// #define pb(x) push_back(x)
// #define w(t) int t; cin>>t; while(t--)
// #define ll long long

// int main(){
// w(t){
//     int n ; cin>>n;
//     vector<int> arr(n);
//     long long even=0,odd=0;
//     f(i,0,n) {
//         int x; cin>>x;
//         if(i%2) odd+=x;
//         else even+=x;
//     }
//     bool z=false;
//     if(n%2 ) {
//         if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2))) && (even/(n/2) == ceil((double) even/(n/2 + 1)))) z=true;
//         }

//     else {
//             if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2))) &&(even/(n/2) == ceil((double) even/(n/2))))
//             z=true;
//             }
//     if(z) print("YES")
//     else print("NO")

// }

// }
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;

    long long ods = 0, evs = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) ods += a[i];
        else evs += a[i];
    }
    int odc = n / 2, evc = n / 2;
    if (n & 1) evc++;

    if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) {
        cout << "NO";
        return;
    }
    cout << "YES";
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define f(i,a,b) for(int i=a; i<b; i++)
#define fr(i,a,b) for(int i=a; i>=b; i--)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define w(t) int t; cin>>t; while(t--)
#define ll long long

int main(){
w(t){
    int n ; cin>>n;
    vector<int> arr(n);
    long long even=0,odd=0;
    f(i,0,n) {
        int x; cin>>x;
        if(i%2) odd+=x;
        else even+=x;
    }
    bool z=false;
    if(n%2 ) {
        if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2))) && (even/(n/2) == ceil((double) even/(n/2 + 1)))) z=true;
        }

    else {
            if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2))) &&(even/(n/2) == ceil((double) even/(n/2))))
            z=true;
            }
    if(z) print("YES")
    else print("NO")

}

}

Answer: 1


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = [a[i] for i in range(n) if i % 2 == 0]
    c=[a[i] for i in range(n) if i % 2 != 0]

    if sum(b)%len(b)==0:
        if sum(c)%len(c)==0 and sum(b)//len(b)==sum(c)//len(c):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    count = 0
    mean = 2 * sum(a) // n

    if sum(a) % n != 0:
        print("NO")
    else:
        for j in range(n - 2):
            b.append(a[j] + a[j + 2])

        for value in b:
            if value % 2 == 0:
                count += 2

        if mean in b and count % 2 == 0:
            print("YES")
        else:
            print("NO")

Answer: 1


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[1001000];
void solve(){
    int n;
    cin>>n;
    ll sum = 0;
    ll sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    ll sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }

}

int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[100100];
void solve(){
    int n;
    cin>>n;
    int sum = 0;
    int sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    int sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }

}

int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }

    return 0;
}

Answer: 1


// **************** MBRAHUL ***************
#include<bits/stdc++.h>
#define ll long long
#define pn cout<<"NO"<<endl
#define py cout<<"YES"<<endl
#define vll vector<long long>
#define vi vector<int>
#define vb vector<bool>
#define u_map unordered_map
#define pll pair<long long,long long>
#define pii pair<int,int>
#define inf INT_MAX
#define pb push_back
#define mod 998244353
#define MOD 1000000007
#define ld long double
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define loop(i,n) for(int i=0;i<n;i++)
#define rloop(i, n) for(int i=n-1;i>=0;i--)
using namespace std;

void input(vector<ll>&arr,ll n){
for(ll i =0;i<n;i++)cin>>arr[i];
}

void printArr(vector<ll>&arr, ll i,ll j){
for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";
cout<<endl;
}

void find(){
  int n;
  cin>>n;
  vll arr(n);
  ll sum = 0;
  loop(i,n){
    cin>>arr[i];
    sum+=arr[i];
  }
  if(sum%n){
    pn;
    return;
  }
  ll target = sum/n;
  for(int i = 0;i<n-2;i++){
    if(arr[i]<0){
      pn;
      return;
    }
    if(arr[i]==target)continue;
    else{
      arr[i+2]-=target-arr[i];
    }
  }
  if(arr[n-2]==target && arr[n-1]==target)py;
  else pn;
}

int main(){
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
ll test;
cin>>test;
while(test--){
find();
}
return 0;
}

// **************** MBRAHUL ***************
#include<bits/stdc++.h>
#define ll long long
#define pn cout<<"NO"<<endl
#define py cout<<"YES"<<endl
#define vll vector<long long>
#define vi vector<int>
#define vb vector<bool>
#define u_map unordered_map
#define pll pair<long long,long long>
#define pii pair<int,int>
#define inf INT_MAX
#define pb push_back
#define mod 998244353
#define MOD 1000000007
#define ld long double
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define loop(i,n) for(int i=0;i<n;i++)
#define rloop(i, n) for(int i=n-1;i>=0;i--)
using namespace std;

void input(vector<ll>&arr,ll n){
for(ll i =0;i<n;i++)cin>>arr[i];
}

void printArr(vector<ll>&arr, ll i,ll j){
for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";
cout<<endl;
}

void find(){
  int n;
  cin>>n;
  vll arr(n);
  ll sum = 0;
  loop(i,n){
    cin>>arr[i];
    sum+=arr[i];
  }
  if(sum%n){
    pn;
    return;
  }
  ll target = sum/n;
  for(int i = 0;i<n-2;i++){
    if(arr[i]==target)continue;
    else{
      arr[i+2]-=target-arr[i];
    }
  }
  if(arr[n-2]==target && arr[n-1]==target)py;
  else pn;
}

int main(){
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
ll test;
cin>>test;
while(test--){
find();
}
return 0;
}

Answer: 2


#include <bits/stdc++.h>

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        long long n;cin >> n;

        vector<int>v(n);

        vector<int>v2(n);

        long long count = 0;

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

        for (int i = 0;i < v.size();i++)v2[i] = v[i];

        if (count % n){cout << "NO" << endl;continue;}

        long long sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            long long j1,j2;

            if (v[i - 1] < sum && v[i + 1] > sum) {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }else if (v[i - 1] > sum && v[i + 1] < sum){

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

            else {

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        for (int i = 1;i < v.size() - 1;i++) {

            int j1,j2;

            if (v[i - 1] < sum && v[i + 1] > sum) {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }else if (v[i - 1] > sum && v[i + 1] < sum){

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

            else {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }

        }

        bool t = true;

        for (int i = 0;i < v2.size();i++) {

            if (v2[i] != sum){t = false;break;}

        }

        if (f || t)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();v2.clear();

    }

}

#include <bits/stdc++.h>

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        int n;cin >> n;

        vector<int>v(n);

        int count = 0;

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

        if (count % n){cout << "NO" << endl;continue;}

        int sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            while (v[i - 1] != sum) {

                if (v[i - 1] < sum) {

                    v[i - 1]++;v[i + 1]--;

                }else {

                    v[i - 1]--;v[i + 1]++;

                }

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        if (f)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();

    }

}

Answer: 1


Answer: 1


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int

main(void)

{

        ios::sync_with_stdio(0);

        cin.tie(0);

        ll t; cin >> t;

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

                ll n; cin >> n;

                ll arr[n];

                ll flag = 0;

                for (ll j = 0; j < n; j++)

                        cin >> arr[j];

                ll target = (arr[0] + arr[2]) / 2;

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

                        ll *m1 = &arr[j - 1], *m2 = &arr[j + 1];

                        while (*m1 < target) {

                                *m1 += 1;

                                *m2 -= 1;

                        }

                        while (*m1 > target) {

                                *m1 -= 1;

                                *m2 += 1;

                        }

                }

        if (arr[n - 2] != arr[n - 1] || arr[n - 3] != arr[n - 1])

                flag = 1;

        if (flag)

                cout << "NO" << endl;

        else

                cout << "YES" << endl;

        }

        return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int

main(void)

{

        ios::sync_with_stdio(0);

        cin.tie(0);

        ll t; cin >> t;

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

                ll n; cin >> n;

                ll arr[n];

                ll flag = 0;

                for (ll j = 0; j < n; j++)

                        cin >> arr[j];

                ll target = (arr[0] + arr[2]) / 2;

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

                        ll *m1 = &arr[j - 1], *m2 = &arr[j + 1];

                        while (*m1 < target) {

                                *m1 += 1;

                                *m2 -= 1;

                        }

                        while (*m1 > target) {

                                *m1 -= 1;

                                *m2 += 1;

                        }

                        if (*m1 < 0 || *m2 < 0) {

                                flag = 1;

                                break;

                        }

                }

        if (arr[n - 2] != arr[n - 1] || arr[n - 3] != arr[n - 1])

                flag = 1;

        if (flag)

                cout << "NO" << endl;

        else

                cout << "YES" << endl;

        }

        return 0;

}

Answer: 1


t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 1:

        if even_sum/(n//2+1) == odd_sum*(n-n//2-1):

            print("YES")

        else:

            print("NO")

    else:

        if even_sum == odd_sum:

            print("YES")

        else:

            print("NO")

t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 0:

        even = odd = n/2

    else:

        even = n//2+1

        odd = n - even

    if even_sum/even == int(even_sum/even) and odd_sum/odd == int(odd_sum/odd):

        if even_sum/even == odd_sum/odd:

            print("YES")

        else:

            print("NO")

    else:

        print("NO")

Answer: 2


import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());

        while (t-->0)

        {

            int n=Integer.parseInt(br.readLine());

            StringTokenizer st=new StringTokenizer(br.readLine());

            int k=0;

            int[] a=new int[n];

            // Set<Integer> set=new HashSet<>();

            long evensum=0,oddsum=0;

            while(st.hasMoreTokens())

            {

                a[k]=Integer.parseInt(st.nextToken());

                if(k%2==0)

                    evensum+=a[k];

                else

                    oddsum+=a[k];

                k++;

            }

            if(evensum%((n+1)/2)!=0 || oddsum%(n/2)!=0 || (evensum+oddsum)%n!=0)

                System.out.println("No");

            else

                System.out.println("Yes");

        }

    }

}

// class ListComparator implements Comparator<List<Integer>>

// {

//     int index=0;

//     public ListComparator(int i)

//     {

//         index=i;

//     }

//     @Override

//     public int compare(List<Integer> o1,List<Integer> o2)

//     {

//         return Integer.compare(o1.get(index), o2.get(index));

//     }

// }

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());

        while (t-->0)

        {

            int n=Integer.parseInt(br.readLine());

            StringTokenizer st=new StringTokenizer(br.readLine());

            int k=0;

            int[] a=new int[n];

            // Set<Integer> set=new HashSet<>();

            long evensum=0,oddsum=0;

            while(st.hasMoreTokens())

            {

                a[k]=Integer.parseInt(st.nextToken());

                if(k%2==0)

                    evensum+=a[k];

                else

                    oddsum+=a[k];

                k++;

            }

            if(evensum%((n+1)/2)!=0 || oddsum%(n/2)!=0 || evensum/((n+1)/2)!=oddsum/(n/2))

                System.out.println("No");

            else

                System.out.println("Yes");

        }

    }

}

// class ListComparator implements Comparator<List<Integer>>

// {

//     int index=0;

//     public ListComparator(int i)

//     {

//         index=i;

//     }

//     @Override

//     public int compare(List<Integer> o1,List<Integer> o2)

//     {

//         return Integer.compare(o1.get(index), o2.get(index));

//     }

// }

Answer: 2


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while(t--)
    {
       ll n;
       cin>>n;
       vector<ll> v(n);

       ll s0=0,s1=0,c1=0,c0=0;
       for(ll  i = 0; i < n; i++){
        cin>>v[i];
        if(i%2==0){
            s0+=v[i];
            c0++;
        }
        else {
            s1+=v[i];
            c1++;
        }
       }

       if(s0*c1== s1*c0 && (s1+s0)%(c0+c1)==0){
         cout<<"YES"<<endl;
       }
       else cout<<"NO"<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while(t--)
    {
       ll n;
       cin>>n;
       vector<int> v(n);

       int s0=0,s1=0,c1=0,c0=0;
       for(int  i = 0; i < n; i++){
        cin>>v[i];
        if(i%2==0){
            s0+=v[i];
            c0++;
        }
        else {
            s1+=v[i];
            c1++;
        }
       }

       if(s0*c1== s1*c0 && (s1+s0)%n==0){
         cout<<"YES"<<endl;
       }
       else cout<<"NO"<<endl;
    }
}

Answer: 1


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long

typedef vector<int> vi;

typedef vector<long long> vll;

#define REP(i, a, b) for(int i=a; i<b; i++)

#define REPI(a) for(auto &it : a)

#define PB push_back

#define F first

#define S second

#define MB make_pair

#define ln '\n'

void solve() {

    ll n;

    cin >> n;

    vll a(n);

    for (ll &x : a) cin >> x;

    vll even, odd;

    ll sumEven = 0, sumOdd = 0;

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

        if (i % 2 == 0) {

            even.push_back(a[i]);

            sumEven += a[i];

        } else {

            odd.push_back(a[i]);

            sumOdd += a[i];

        }

    }

    bool one = ceil(double(sumEven) / double(even.size())) == floor(double(sumEven) / double(even.size()));

    bool two = ceil(double(sumOdd) / double(odd.size())) == floor(double(sumOdd) / double(odd.size()));

    if (one == true && two == true && sumEven / even.size() == sumOdd / odd.size()) {

        cout << "YES" << endl;

    } else cout << "NO" << endl;

}

int main() {

#ifndef ONLINE_JUDGE

    //for getting input from input1.txt

    freopen("input1.txt", "r", stdin);

    //for writing output to output1.txt

    freopen("output1.txt", "w", stdout);

#endif

    ios::sync_with_stdio(0);

    cin.tie(0);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long

typedef vector<int> vi;

typedef vector<long long> vll;

#define REP(i, a, b) for(int i=a; i<b; i++)

#define REPI(a) for(auto &it : a)

#define PB push_back

#define F first

#define S second

#define MB make_pair

#define ln '\n'

void solve() {

    ll n;

    cin >> n;

    vll a(n);

    for (ll &x : a) cin >> x;

    vll even, odd;

    ll sumEven = 0, sumOdd = 0;

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

        if (i % 2 == 0) {

            even.push_back(a[i]);

            sumEven += a[i];

        } else {

            odd.push_back(a[i]);

            sumOdd += a[i];

        }

    }

    bool one = ceil(float(sumEven) / float(even.size())) == floor(float(sumEven) / float(even.size()));

    bool two = ceil(float(sumOdd) / float(odd.size())) == floor(float(sumOdd) / float(odd.size()));

    if (one == true && two == true && sumEven / even.size() == sumOdd / odd.size()) {

        cout << "YES" << endl;

    } else cout << "NO" << endl;

}

int main() {

#ifndef ONLINE_JUDGE

    //for getting input from input1.txt

    freopen("input1.txt", "r", stdin);

    //for writing output to output1.txt

    freopen("output1.txt", "w", stdout);

#endif

    ios::sync_with_stdio(0);

    cin.tie(0);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

int main()

{

   int t;

   cin>>t;

   while(t--){

       int n;

       cin>>n;

      long long a[n];

      int sumodd=0;

       int sumeve=0;

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

          cin>>a[i];

          if(i%2)sumodd+=a[i];

          else sumeve+=a[i];

      }

      int eve=n/2,odd=n/2;

      if(n%2)eve++;

      if(sumodd%odd!=0 || sumeve%eve!=0 || sumodd/odd!=sumeve/eve){

          cout<<"NO"<<endl;

      }

         else cout<<"Yes"<<endl;

   }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int tt;

    cin >> tt;

    while (tt--)

    {

        int n;

        cin >> n;

        vector<long long> nums(n);

        long long sum=0;

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

        {

            cin >> nums[i];

            sum+=nums[i];

        }

        if (n >= 3)

        {

            if(n==3)

            {

                long long num=nums[1];

                long long diff1=num-nums[0];

                long long diff2=num-nums[2];

                if((diff1>0&&diff2>0)||(diff1<0&&diff2<0)||abs(diff1)!=abs(diff2))cout<<"NO"<<endl;

                else cout<<"YES"<<endl;

            }

            else

            {

                long long sumodd = 0;

                long long sumeven = 0;

                int count = 0;

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

                {

                    sumeven += nums[i];

                    count++;

                }

                sumodd=sum-sumeven;

                int count2 = n - count;

                if (sumeven % count == 0 && sumodd % count2 == 0)

                    cout << "YES" << endl;

                else

                    cout << "NO" << endl;

            }

        }

    }

    return 0;

}

Answer: 1


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n;;cin>>n;int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int check=0;
    for(int i=0;i<n;i++){
        check+=arr[i];
    }
    if(check%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        int ceven=0,codd=0;
        check=check/n;
        for(int i=0;i<n;i++){
            if(i%2==0){
                ceven+=(arr[i]-check);
            }
            else{
                codd+=(arr[i]-check);
            }
        }
        if(ceven==0 && codd==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }

}

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

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

void solve(){
    long long int n;;cin>>n;int arr[n];
    for(long long int i=0;i<n;i++){
        cin>>arr[i];
    }
    long long int check=0;
    for(long long int i=0;i<n;i++){
        check+=arr[i];
    }
    if(check%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        long long int ceven=0,codd=0;
        check=check/n;
        for(long long int i=0;i<n;i++){
            if(i%2==0){
                ceven+=(arr[i]-check);
            }
            else{
                codd+=(arr[i]-check);
            }
        }
        if(ceven==0 && codd==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }

}

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

Answer: 2


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <vector>
using namespace std;

template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? ", " : "")), ...); }, t); return os << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef NEAL_DEBUG
#define dbg(...) cerr << '[' << __FILE__ << ':' << __LINE__ << "] (" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

void run_case() {
    int N;
    cin >> N;
    array<int64_t, 2> sums = {};

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        sums[i % 2] += a;
    }

    bool ans = (sums[0] + sums[1]) % N == 0;
    int64_t avg = (sums[0] + sums[1]) / N;
    ans &= sums[0] == avg * ((N + 1) / 2);
    cout << (ans ? "YES" : "NO") << '\n';
}

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int tests;
    cin >> tests;

    while (tests-- > 0)
        run_case();
}

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> a(n);
    array<int64_t, 2> sum = {0, 0};
    array<int64_t, 2> cnt = {0, 0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum[i % 2] += a[i];
      cnt[i % 2] += 1;
    }
    if (sum[0] % cnt[0] == 0 && sum[1] % cnt[1] == 0 && sum[0] / cnt[0] == sum[1] / cnt[1]) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
  return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

    for(int gt=0;gt<t;gt++){

        int n,k1=0,k2=0,s1=0,s2=0;

        cin>>n;

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

            int a;

            cin>>a;

            if(i%2==1){k1++;s1+=a;}

            else{k2++;s2+=a;}

        }

        if(s1%k1!=0 || s2%k2!=0){cout<<"NO"<<'\n';}

        else if(s1/k1==s2/k2){cout<<"YES"<<'\n';}

        else{cout<<"NO"<<'\n';}

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

    for(int gt=0;gt<t;gt++){

        long long n,k1=0,k2=0,s1=0,s2=0;

        cin>>n;

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

            int a;

            cin>>a;

            if(i%2==1){k1++;s1+=a;}

            else{k2++;s2+=a;}

        }

        if(s1%k1!=0 || s2%k2!=0){cout<<"NO"<<'\n';}

        else if(s1/k1==s2/k2){cout<<"YES"<<'\n';}

        else{cout<<"NO"<<'\n';}

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		int n;
        cin>>n;
        int arr[n];
        for(int i =0;i<n;i++){
            cin>>arr[i];
        }
        int od_,ev_;
        if(n%2 == 0){
            od_ = n/2;
            ev_ = n/2;
        }
        else{
            od_ = n/2 + 1;
            ev_ = n/2;
        }
        int od =0;
        int ev =0;
        for(int i =0;i<n;i++){
            if((i + 1)%2 == 0){
                ev += arr[i];
            }
            else{
                od += arr[i];
            }
        }
        if ((od/od_) == (ev/ev_) && od%od_ == 0 && ev%ev_ == 0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		int n;
        cin>>n;
        int arr[n];
        for(int i =0;i<n;i++){
            cin>>arr[i];
        }
        int od_,ev_;
        if(n%2 == 0){
            od_ = n/2;
            ev_ = n/2;
        }
        else{
            od_ = n/2 + 1;
            ev_ = n/2;
        }
        long long int od =0;
        long long int ev =0;
        for(int i =0;i<n;i++){
            if((i + 1)%2 == 0){
                ev += arr[i];
            }
            else{
                od += arr[i];
            }
        }
        if ((od/od_) == (ev/ev_) && od%od_ == 0 && ev%ev_ == 0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

	}

	return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

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

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

		if(sum % 3 == 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

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

    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);

        long long sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i % 2 == 0)
            {
                sum1 += a[i];
                ctr1++;
            }
            else
            {
                sum2 += a[i];
                ctr2++;
            }
        }

        if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % (ctr1 + ctr2) == 0)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }

    return 0;
}

Answer: 2


#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n;
const int maxn=2e5+5;
int a[maxn];
signed main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int ans=0,sum=0;
        for(int i=1;i<=n;i+=2)
            ans+=a[i];
        for(int i=2;i<=n;i+=2)
            sum+=a[i];
        if(n%2==0){
            if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans==sum) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }else{
            if(ans%(n/2+1)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans/(n/2+1)==sum/(n/2)) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }
    }
    return 0;
}

/*
Welcome to JDoodle!

You can execute code here in 88 languages. Right now you’re in the C++ IDE.

  1. Click the orange Execute button ▶ to execute the sample code below and see how it works.

  2. Want help writing or debugging code? Type a query into JDroid on the right hand side ---------------->

  3. Try the menu buttons on the left. Save your file, share code with friends and open saved projects.

Want to change languages? Try the search bar up the top.
*/

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int tc; cin>>tc;
    while(tc--){
        ll n; cin>>n;
        ll arr[n];
        ll sum=0;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            sum += arr[i];
        }
        if(sum%n !=0 ){
            cout<<"NO"<<endl;
            continue;
        }
        ll val = sum/n;
        int f=0;
        for(int i=1;i<n-1;i++){

            ll diff = abs(val-arr[i-1]);
            if(arr[i-1]>=val){
                arr[i-1] = val;
                arr[i+1] += diff;
            }else{
                arr[i-1] = val;
                if(arr[i+1] - diff <=0){
                    cout<<"NO"<<endl;
                    f=1;
                    break;
                }
                arr[i+1] -= diff;
            }
        }
        if(f==1){
            continue;
        }
        for(int i=0;i<n;i++){
            if(arr[i]!=val){
                cout<<"NO"<<endl;
                f=1;
                break;
            }
        }
        if(f==0){
            cout<<"YES"<<endl;
        }
    }
}

Answer: 1


#include <iostream>

using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, c = 0, l = 0, cc=0, cl=0;

        cin >> n;
        for (int i = 0; i < n; i++) {
            int p;
            cin >> p;
            if (i % 2 == 0) {
                l += p;
                cl++;
            }
            else {
                c += p;
                cc++;
            }

        }
        if (l % cl == 0 and c % cc == 0 and l / cl == c / cc) {
            cout << "YES";
     }
        else {
            cout << "NO";
        }
        cout << endl;
    }
    return 0;
}

#include <iostream>

using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n, c = 0, l = 0, cc=0, cl=0;

        cin >> n;
        for (int i = 0; i < n; i++) {
            int p;
            cin >> p;
            if (i % 2 == 0) {
                l += p;
                cl++;
            }
            else {
                c += p;
                cc++;
            }

        }
        if (l % cl == 0 and c % cc == 0 and l / cl == c / cc) {
            cout << "YES";
     }
        else {
            cout << "NO";
        }
        cout << endl;
    }
    return 0;
}

Answer: 2


#include <iostream>

using namespace std;

int main()
{
    int t; cin >> t;
    while(t)
    {
        int n; cin >> n;
        int a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        int sum = 0;
        for(int i = 0; i < n; i++) sum += a[i];
        if(sum % n != 0)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }

        int unit = sum / n;
        int req_sum = 0; int test_sum = 0;
        for(int i = 0; i < n; i += 2)
        {
            req_sum += unit;
            test_sum += a[i];
        }
        if(test_sum != req_sum)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }
        cout << "YES" << endl;
        t--;
    }
}

#include <iostream>

using namespace std;

int main()
{
    int t; cin >> t;
    while(t)
    {
        int n; cin >> n;
        int a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        unsigned long long sum = 0;
        for(int i = 0; i < n; i++) sum += a[i];
        if(sum % n != 0)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }

        unsigned long long unit = sum / n;
        unsigned long long req_sum = 0, test_sum = 0;
        for(int i = 0; i < n; i += 2)
        {
            req_sum += unit;
            test_sum += a[i];
        }
        if(test_sum != req_sum)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }
        cout << "YES" << endl;
        t--;
    }
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define vi vector<int>

#define vll vector<long long>

#define vvi vector<vector<int>>

#define pb push_back

#define all(x) begin(x), end(x)

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

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

#define ull unsigned long long

#define fr(i, a, b) for (long long i = a; i < b; i++)

#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)

// Debugging function

template <typename Arg1>

void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; }

template <typename Arg1, typename... Args>

void __f(const char *names, Arg1 &&arg1, Args &&...args) {

    const char *comma = strchr(names + 1, ',');

    cout.write(names, comma - names) << " : " << arg1 << " | ";

    __f(comma + 1, args...);

}

// Input and Output Overloads for Vectors

template <typename T>

istream &operator>>(istream &istream, vector<T> &vec) {

    for (auto &a : vec) cin >> a;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, const vector<T> &vec) {

    for (auto &a : vec) cout << a << " ";

    return ostream;

}

void to_lower(string &s) { transform(all(s), s.begin(), ::tolower); }

void to_upper(string &s) { transform(all(s), s.begin(), ::toupper); }

string helper(string a, string b) {

    if (a + b != b + a) return "";

    int Gcd_len = __gcd(a.size(), b.size());

    return a.substr(0, Gcd_len);

}

//-----------------------------------------------------------------

vi factors(int n) {

    vi ans;

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

        if (n % i == 0) {

            ans.pb(i);

            if (i != n / i) ans.pb(n / i);

        }

    }

    return ans;

}

 bool bit(int mask, int pos){

        return (mask >> pos ) &1;

 }

 bool check(int k , vi &v ,int h){

    vi tmp;

       fr(i,0,k){

            tmp.pb(v[i]);

       }

       sort(all(tmp));

       reverse(all(tmp));

       int t = 0;

          for(int i = 0 ; i < k ;i+=2) t += tmp[i];

      return t <= h;

 }

 void solve() {

    int n;

    cin >> n;

    vi v(n);

    for (int &x : v) cin >> x;

    int Odd_sum = 0, Even_sum = 0;

    fr(i,0,n){

          if(i &1) Odd_sum += v[i];

          else Even_sum += v[i];

    }

    int odd = n/2, eve = n/2;

    if( n&1) eve++;

   if( (Odd_sum % odd != 0 || Even_sum % eve != 0 ) ||  Odd_sum/odd != Even_sum/eve ){

      cout << "NO" << endl;

      return;

   }

     cout << "YES" << endl;

 }

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int tc; cin >> tc;

    while(tc--){

    solve();

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define vi vector<int>

#define vll vector<long long>

#define vvi vector<vector<int>>

#define pb push_back

#define all(x) begin(x), end(x)

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

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

#define ull unsigned long long

#define fr(i, a, b) for (long long i = a; i < b; i++)

#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)

// Debugging function

template <typename Arg1>

void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; }

template <typename Arg1, typename... Args>

void __f(const char *names, Arg1 &&arg1, Args &&...args) {

    const char *comma = strchr(names + 1, ',');

    cout.write(names, comma - names) << " : " << arg1 << " | ";

    __f(comma + 1, args...);

}

// Input and Output Overloads for Vectors

template <typename T>

istream &operator>>(istream &istream, vector<T> &vec) {

    for (auto &a : vec) cin >> a;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, const vector<T> &vec) {

    for (auto &a : vec) cout << a << " ";

    return ostream;

}

void to_lower(string &s) { transform(all(s), s.begin(), ::tolower); }

void to_upper(string &s) { transform(all(s), s.begin(), ::toupper); }

string helper(string a, string b) {

    if (a + b != b + a) return "";

    int Gcd_len = __gcd(a.size(), b.size());

    return a.substr(0, Gcd_len);

}

//-----------------------------------------------------------------

vi factors(int n) {

    vi ans;

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

        if (n % i == 0) {

            ans.pb(i);

            if (i != n / i) ans.pb(n / i);

        }

    }

    return ans;

}

 bool bit(int mask, int pos){

        return (mask >> pos ) &1;

 }

 bool check(int k , vi &v ,int h){

    vi tmp;

       fr(i,0,k){

            tmp.pb(v[i]);

       }

       sort(all(tmp));

       reverse(all(tmp));

       int t = 0;

          for(int i = 0 ; i < k ;i+=2) t += tmp[i];

      return t <= h;

 }

 void solve() {

    int n;

    cin >> n;

    vi a(n);

    for (int &x : a) cin >> x;

    long long ods = 0, evs = 0;

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

        if (i & 1) ods += a[i];

        else evs += a[i];

    }

    int odc = n / 2, evc = n / 2;

    if (n & 1) evc++;

    if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) {

        cout << "NO" << endl;

        return;

    }

    cout << "YES" << endl;

 }

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int tc; cin >> tc;

    while(tc--){

    solve();

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using vi = vector<int>;

using vll = vector<ll>;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using vpii = vector<pii>;

void fast_io() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

}

int main() {

    fast_io();

	int tc;

	cin>>tc;

	while(tc--){

	    int n;

	    cin>>n;

	    vi a(n,0);

	    int total = 0;

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

	        cin>>a[i];

	        total += a[i];

	    }

	    ll esum=0,osum=0;

	    ll epos=n/2,opos=(n+1)/2;

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

	        if(i%2 == 0) osum += a[i];

	        else esum += a[i];

	    }

	    ll x = total/n;

	    if(osum == opos * x && esum == epos * x)

            cout << "YES\n";

        else

            cout << "NO\n";

	}

}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using vi = vector<int>;

using vll = vector<ll>;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using vpii = vector<pii>;

void fast_io() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

}

int main() {

    fast_io();

	int tc;

	cin>>tc;

	while(tc--){

	    int n;

	    cin>>n;

	    vi a(n,0);

	    ll total = 0;

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

	        cin>>a[i];

	        total += a[i];

	    }

	    ll esum=0,osum=0;

	    ll epos=n/2,opos=(n+1)/2;

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

	        if(i%2 == 0) osum += a[i];

	        else esum += a[i];

	    }

	    ll x = total/n;

	    if(osum == opos * x && esum == epos * x)

            cout << "YES\n";

        else

            cout << "NO\n";

	}

}

Answer: 2


#include <bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;

typedef unsigned long long ull;

typedef long double lld;

ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}

ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}

ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}

ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m

#define fr(i,n) for (ll i=0;i<n;i++)

#define pb push_back

#define ite vector<int>::iterator

#define sz(x) x.size()

#define ff first

#define ss second

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

#define fv(x,v) for(auto &x:v)

typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;

#else

#define debug(x)

#endif

#define mod (ll)(1e9+7)

void _print(ll t) {cerr << t;}

void _print(int t) {cerr << t;}

void _print(string t) {cerr << t;}

void _print(char t) {cerr << t;}

void _print(lld t) {cerr << t;}

void _print(double t) {cerr << t;}

void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T, class V> void _print(map <T, V> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

#pragma GCC optimize("unroll-loops,O3,Ofast") //even 10^8+ also works with this

//#pragma GCC target("avx2,avx,fma,bmi,bmi2,lzcnt,popcnt")

int knightx[8]={-1,-2,-2,-1,1,2,2,1};

int knighty[8]={-2,-1,1,2,2,1,-1,-2};

//...............................................................................................................................................

// lambda dfs------------->

// function<int(int,int)> dfs = [&](int node,int par){

// };

// dfs(0,-1);

// ---------------------------------------------------------------------------------------

// //__builtin_popcount(a) number of set bits for int

// //__builtin_popcountll(a) number of set bits for long long

// //<<left shift *2

// //>>Right shift /2

// //char a='A'|(1<<5); in uppercase 5th bit is not set and in lower case 5th bit is set

// //char a='A'|' ';

// //char A='a'&(~(1<<5)); unset the 5th bit

// //char A='a'& '_';

// //if(n&(n-1)==0) then number is power of two

//..................................................................................................

//0xAAAAAAAA

//0x55555555

//if (x.find(s) != string::npos)

//auto lastElement = *--mySet.end();

//mySet.erase(--mySet.end());

//else if (b % a == 0 && c % a == 0 && (b / a - 1) + (c / a - 1) <= 3)

//if rope have to be divide by equal;

//maxSum = *max_element(all(v));

// when modulo comes check for same number

// when we do difference check if its is negative

//__int128 cal = (__int128)n * mid * mid + (__int128)k * mid;

// most number of divisor less than equal to n in vector

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

//       for(int j = i; j <= n; j += i) mx[j] += cnt[i];

//    }

// if(a<b) ans b is prime number than gcd(a,b) is 1 ;

// for (int i = n; i >= 1; i--) {

//     while (b.size() < a[i]) {

//         b.push_back(i);

//     }

// for(int i=(s[0]=='0');i<s.size();

//cout<<(i>=p?'0':s[i]);

// upper bound give just greater than

// lower bound give equal or greater

//                // Need to handle re-insertion since multimap does not support direct modification.

                //mp.erase(it);

                //mp.emplace(it->first, 'A');

// sum of 1+2+3+4+5.... odd time is exactly divisible by n;

//cout << (char)(digits[i] < 4 ? (digits[i] + '0') : (digits[i] + '1'));

// auto getSum = [&](int l, int r) -> int {

//     return (r * (r + 1) / 2) - (l * (l - 1) / 2);

// };

//        result.insert(result.end(), levelNodes.begin(), levelNodes.end());

//        leftToRight = !leftToRight;

// do {

//             string concatenated = "";

//             for (const string& bin : perm) {

//                 concatenated += bin;

//             }

//             maxValue = max(maxValue, binaryToDecimal(concatenated));

//         } while (next_permutation(perm.begin(), perm.end()));

#define vin(v) for(auto &x : v) cin >> x;

int binaryToDecimal(const string& binary) {

        return stoi(binary, nullptr, 2);

    }

string toBinary(int n) {

        string binary = "";

        while (n > 0) {

            binary = to_string(n % 2) + binary;

            n /= 2;

        }

        return binary.empty() ? "0" : binary;

    }

class DisjointSet {

    vector<int> rank, parent, size;

public:

    DisjointSet(int n) {

        rank.resize(n+1, 0);

        parent.resize(n+1);

        size.resize(n+1);

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

            parent[i] = i;

            size[i] = 1;

        }

    }

    int findUPar(int node) {

        if(node == parent[node])

            return node;

        return parent[node] = findUPar(parent[node]); // Path compression

    }

    void unionByRank(int u, int v) {

        int ulp_u = findUPar(u);

        int ulp_v = findUPar(v);

        if(ulp_u == ulp_v) return;

        if(rank[ulp_u] < rank[ulp_v]) {

            parent[ulp_u] = ulp_v;

        }

        else if(rank[ulp_v] < rank[ulp_u]) {

            parent[ulp_v] = ulp_u;

        }

        else {

            parent[ulp_v] = ulp_u;

            rank[ulp_u]++;

        }

    }

    void unionBySize(int u, int v) {

        int ulp_u = findUPar(u);

        int ulp_v = findUPar(v);

        if(ulp_u == ulp_v) return;

        if(size[ulp_u] < size[ulp_v]) {

            parent[ulp_u] = ulp_v;

            size[ulp_v] += size[ulp_u];

        }

        else {

            parent[ulp_v] = ulp_u;

            size[ulp_u] += size[ulp_v];

        }

    }

    vector<vector<int>> groups() {

        int n = parent.size();

        vector<int> leader_buf(n), group_size(n);

        // Find leaders for each node

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

            leader_buf[i] = findUPar(i);

            group_size[leader_buf[i]]++;

        }

        // Create groups

        vector<vector<int>> result(n);

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

            result[i].reserve(group_size[i]);

        }

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

            result[leader_buf[i]].push_back(i);

        }

        // Remove empty groups

        result.erase(

            remove_if(result.begin(), result.end(),

                      [](const vector<int>& v) { return v.empty(); }),

            result.end()

        );

        return result;

    }

};

class Solution

{

public:

    //Function to find sum of weights of edges of the Minimum Spanning Tree.

    int spanningTree(int V, vector<vector<int>> adj[])

    {

        // 1 - 2 wt = 5

        /// 1 - > (2, 5)

        // 2 -> (1, 5)

        // 5, 1, 2

        // 5, 2, 1

        vector<pair<int, pair<int, int>>> edges;

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

            for (auto it : adj[i]) {

                int adjNode = it[0];

                int wt = it[1];

                int node = i;

                edges.push_back({wt, {node, adjNode}});

            }

        }

        DisjointSet ds(V);

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

        int mstWt = 0;

        for (auto it : edges) {

            int wt = it.first;

            int u = it.second.first;

            int v = it.second.second;

            if (ds.findUPar(u) != ds.findUPar(v)) {

                mstWt += wt;

                ds.unionBySize(u, v);

            }

        }

        return mstWt;

    }

};

void solve() {

    int n; cin >> n;

    vector<int> v(n);

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

    ll sum = accumulate(v.begin(), v.end(), 0LL);

    if (sum % n != 0) {

        cout << "NO" << endl;

        return;

    }

    ll p = sum / n;

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

        if (v[i - 1] < p) {

            int diff = p - v[i - 1];

            v[i + 1] -= diff;

            v[i - 1] = p;

        } else if (v[i - 1] > p) {

            int diff = v[i - 1] - p;

            v[i + 1] += diff;

            v[i - 1] = p;

        }

    }

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

        if (v[i] != p) {

            cout << "NO" << endl;

            return;

        }

    }

    cout << "YES" << endl;

}

int main(){

#ifndef ONLINE_JUDGE

    freopen("Error.txt","w",stderr);

#endif

    int t=1;

    cin>>t;

    while(t--){

        solve();

    }

}

#include <bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;

typedef unsigned long long ull;

typedef long double lld;

ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}

ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}

ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}

ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m

#define fr(i,n) for (ll i=0;i<n;i++)

#define pb push_back

#define ite vector<int>::iterator

#define sz(x) x.size()

#define ff first

#define ss second

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

#define fv(x,v) for(auto &x:v)

typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;

#else

#define debug(x)

#endif

#define mod (ll)(1e9+7)

void _print(ll t) {cerr << t;}

void _print(int t) {cerr << t;}

void _print(string t) {cerr << t;}

void _print(char t) {cerr << t;}

void _print(lld t) {cerr << t;}

void _print(double t) {cerr << t;}

void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T, class V> void _print(map <T, V> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

#pragma GCC optimize("unroll-loops,O3,Ofast") //even 10^8+ also works with this

//#pragma GCC target("avx2,avx,fma,bmi,bmi2,lzcnt,popcnt")

int knightx[8]={-1,-2,-2,-1,1,2,2,1};

int knighty[8]={-2,-1,1,2,2,1,-1,-2};

//...............................................................................................................................................

// lambda dfs------------->

// function<int(int,int)> dfs = [&](int node,int par){

// };

// dfs(0,-1);

// ---------------------------------------------------------------------------------------

// //__builtin_popcount(a) number of set bits for int

// //__builtin_popcountll(a) number of set bits for long long

// //<<left shift *2

// //>>Right shift /2

// //char a='A'|(1<<5); in uppercase 5th bit is not set and in lower case 5th bit is set

// //char a='A'|' ';

// //char A='a'&(~(1<<5)); unset the 5th bit

// //char A='a'& '_';

// //if(n&(n-1)==0) then number is power of two

//..................................................................................................

//0xAAAAAAAA

//0x55555555

//if (x.find(s) != string::npos)

//auto lastElement = *--mySet.end();

//mySet.erase(--mySet.end());

//else if (b % a == 0 && c % a == 0 && (b / a - 1) + (c / a - 1) <= 3)

//if rope have to be divide by equal;

//maxSum = *max_element(all(v));

// when modulo comes check for same number

// when we do difference check if its is negative

//__int128 cal = (__int128)n * mid * mid + (__int128)k * mid;

// most number of divisor less than equal to n in vector

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

//       for(int j = i; j <= n; j += i) mx[j] += cnt[i];

//    }

// if(a<b) ans b is prime number than gcd(a,b) is 1 ;

// for (int i = n; i >= 1; i--) {

//     while (b.size() < a[i]) {

//         b.push_back(i);

//     }

// for(int i=(s[0]=='0');i<s.size();

//cout<<(i>=p?'0':s[i]);

// upper bound give just greater than

// lower bound give equal or greater

//                // Need to handle re-insertion since multimap does not support direct modification.

                //mp.erase(it);

                //mp.emplace(it->first, 'A');

// sum of 1+2+3+4+5.... odd time is exactly divisible by n;

//cout << (char)(digits[i] < 4 ? (digits[i] + '0') : (digits[i] + '1'));

// auto getSum = [&](int l, int r) -> int {

//     return (r * (r + 1) / 2) - (l * (l - 1) / 2);

// };

//        result.insert(result.end(), levelNodes.begin(), levelNodes.end());

//        leftToRight = !leftToRight;

// do {

//             string concatenated = "";

//             for (const string& bin : perm) {

//                 concatenated += bin;

//             }

//             maxValue = max(maxValue, binaryToDecimal(concatenated));

//         } while (next_permutation(perm.begin(), perm.end()));

#define vin(v) for(auto &x : v) cin >> x;

int binaryToDecimal(const string& binary) {

        return stoi(binary, nullptr, 2);

    }

string toBinary(int n) {

        string binary = "";

        while (n > 0) {

            binary = to_string(n % 2) + binary;

            n /= 2;

        }

        return binary.empty() ? "0" : binary;

    }

class DisjointSet {

    vector<int> rank, parent, size;

public:

    DisjointSet(int n) {

        rank.resize(n+1, 0);

        parent.resize(n+1);

        size.resize(n+1);

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

            parent[i] = i;

            size[i] = 1;

        }

    }

    int findUPar(int node) {

        if(node == parent[node])

            return node;

        return parent[node] = findUPar(parent[node]); // Path compression

    }

    void unionByRank(int u, int v) {

        int ulp_u = findUPar(u);

        int ulp_v = findUPar(v);

        if(ulp_u == ulp_v) return;

        if(rank[ulp_u] < rank[ulp_v]) {

            parent[ulp_u] = ulp_v;

        }

        else if(rank[ulp_v] < rank[ulp_u]) {

            parent[ulp_v] = ulp_u;

        }

        else {

            parent[ulp_v] = ulp_u;

            rank[ulp_u]++;

        }

    }

    void unionBySize(int u, int v) {

        int ulp_u = findUPar(u);

        int ulp_v = findUPar(v);

        if(ulp_u == ulp_v) return;

        if(size[ulp_u] < size[ulp_v]) {

            parent[ulp_u] = ulp_v;

            size[ulp_v] += size[ulp_u];

        }

        else {

            parent[ulp_v] = ulp_u;

            size[ulp_u] += size[ulp_v];

        }

    }

    vector<vector<int>> groups() {

        int n = parent.size();

        vector<int> leader_buf(n), group_size(n);

        // Find leaders for each node

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

            leader_buf[i] = findUPar(i);

            group_size[leader_buf[i]]++;

        }

        // Create groups

        vector<vector<int>> result(n);

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

            result[i].reserve(group_size[i]);

        }

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

            result[leader_buf[i]].push_back(i);

        }

        // Remove empty groups

        result.erase(

            remove_if(result.begin(), result.end(),

                      [](const vector<int>& v) { return v.empty(); }),

            result.end()

        );

        return result;

    }

};

class Solution

{

public:

    //Function to find sum of weights of edges of the Minimum Spanning Tree.

    int spanningTree(int V, vector<vector<int>> adj[])

    {

        // 1 - 2 wt = 5

        /// 1 - > (2, 5)

        // 2 -> (1, 5)

        // 5, 1, 2

        // 5, 2, 1

        vector<pair<int, pair<int, int>>> edges;

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

            for (auto it : adj[i]) {

                int adjNode = it[0];

                int wt = it[1];

                int node = i;

                edges.push_back({wt, {node, adjNode}});

            }

        }

        DisjointSet ds(V);

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

        int mstWt = 0;

        for (auto it : edges) {

            int wt = it.first;

            int u = it.second.first;

            int v = it.second.second;

            if (ds.findUPar(u) != ds.findUPar(v)) {

                mstWt += wt;

                ds.unionBySize(u, v);

            }

        }

        return mstWt;

    }

};

void solve(){

    int n;cin>>n;

    vector<int>v(n);

    vin(v);

    ll sum=accumulate(v.begin(),v.end(),0);

    set<int>s;

    if(sum%n)

    {

        cout<<"NO"<<endl;

        return;

    }

    else

    {

        ll p=sum/n;

        debug(p)

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

        {

            if(v[i-1]<p)

            {

                v[i+1]-=(p-v[i-1]);

                v[i-1]=p;

                s.insert({v[i-1]});

            }

            else

            {

                v[i+1]+=(v[i-1]-p);

                v[i-1]=p;

                s.insert({v[i-1]});

            }

        }

        s.insert({v[n-1]});

        if(s.size()>1)

        {

            debug(v)

            cout<<"NO"<<endl;

        }

        else

        {

            cout<<"YES"<<endl;

        }

    }

}

int main(){

#ifndef ONLINE_JUDGE

    freopen("Error.txt","w",stderr);

#endif

    int t=1;

    cin>>t;

    while(t--){

        solve();

    }

}

Answer: 1


#include<iostream>

#include<bits/stdc++.h>

using namespace std;

int ceiling(int a, int b){

    if (a%b==0)

    return a/b;

    else

    return a/b+1;

}

void transfusion(vector<int>&arr, int n){

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

        int diff = ceiling(abs(arr[i+1]-arr[i-1]),2);

        if (arr[i-1]<=arr[i+1]){

            arr[i-1]+=diff;

            arr[i+1]-=diff;

        }

        else{

            arr[i-1]-=diff;

            arr[i+1]+=diff;

        }

    }

}

bool check(vector<int> arr, int n){

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

        if (arr[i]!=arr[i-1])

        return 0;

    }

    return 1;

}

int main()

{

    int t;

    cin >> t;

    while(t--){

    int n;

    cin >> n;

    vector<int> arr(n);

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

    cin >> arr[i];

    transfusion(arr,n);

    if (!check(arr,n))

    cout << "NO" << endl;

    else

    cout << "YES" <<endl;

    }

}

#include<iostream>

#include<bits/stdc++.h>

using namespace std;

int ceiling(int a, int b){

    if (a%b==0)

    return a/b;

    else

    return a/b+1;

}

void transfusion(vector<int>&arr, int n){

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

        int diff = abs(arr[i+1]-arr[i-1]);

        if (arr[i-1]<=arr[i+1])

        {

            if (abs(arr[i]-(arr[i-1]+diff/2)<abs(arr[i]-(arr[i-1]+ceiling(diff,2))))){

                arr[i-1]+=diff/2;

                arr[i+1]-=diff/2;

            }

            else {

                arr[i-1]+=ceiling(diff,2);

                arr[i+1]-=ceiling(diff,2);

            }

        }

        else{

            if (abs(arr[i]-(arr[i-1]-diff/2))<abs(arr[i]-(arr[i-1]-ceiling(diff,2)))){

                arr[i-1]-=diff/2;

                arr[i+1]+=diff/2;

            }

            else{

                arr[i-1]-=ceiling(diff,2);

                arr[i+1]+=ceiling(diff,2);

            }

        }

    }

}

bool check(vector<int> arr, int n){

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

        if (arr[i]!=arr[i-1])

        return 0;

    }

    return 1;

}

int main()

{

    int t;

    cin >> t;

    while(t--){

    int n;

    cin >> n;

    vector<int> arr(n);

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

    cin >> arr[i];

    transfusion(arr,n);

    if (!check(arr,n))

    cout << "NO" << endl;

    else

    cout << "YES" <<endl;

    }

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

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

    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);

        int sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i % 2 == 0)
            {
                sum1 += a[i];
                ctr1++;
            }
            else
            {
                sum2 += a[i];
                ctr2++;
            }
        }

        if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % n == 0)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    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 odd_sum = 0, even_sum = 0;

        for (ll i = 0; i < n; ++i) {
            if (i % 2 == 0) {
                even_sum += a[i];
            } else {
                odd_sum += a[i];
            }
        }

        ll odd_count = n / 2;
        ll even_count = (n + 1) / 2;

        if (odd_sum * even_count != even_sum * odd_count) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    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 odd_sum = 0, even_sum = 0;

        for (ll i = 0; i < n; ++i)
        {
            if (i % 2 == 0)
            {
                even_sum += a[i];
            }
            else
            {
                odd_sum += a[i];
            }
        }

        ll odd_count = n / 2;
        ll even_count = (n + 1) / 2;

        if ((odd_sum % odd_count != 0) || (even_sum % even_count != 0) ||
            (odd_sum / odd_count != even_sum / even_count))
        {
            cout << "NO\n";
        }
        else
        {
            cout << "YES\n";
        }
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long
#define f first
#define s second
const ll N = 1e5 + 5;
int X[4] = {0, 0, 1, -1};
int Y[4] = {1, -1, 0, 0};
#define inf 9223372036854775807
void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.pb(x);
        sum += x;
    }
    if (sum % n)
    {
        cout << "NO" << endl;
        return;
    }
    sum = sum / n;
    for (int i = 1; i < n - 1; i++)
    {
        if (v[i - 1] > sum)
        {
            int temp = v[i - 1] - sum;
            v[i - 1] -= temp;
            v[i + 1] += temp;
        }
        else
        {
            int temp = sum - v[i - 1];
            v[i - 1] += temp;
            v[i + 1] -= temp;
        }
    }
    if(v[n-1]==sum){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long
#define f first
#define s second
const ll N = 1e5 + 5;
int X[4] = {0, 0, 1, -1};
int Y[4] = {1, -1, 0, 0};
#define inf 9223372036854775807
void solve()
{
    ll n;
    cin >> n;
    vector<ll> v;
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
        sum += x;
    }
    if (sum % n)
    {
        cout << "NO" << endl;
        return;
    }
    sum = sum / n;
    for (int i = 1; i < n - 1; i++)
    {
        if (v[i - 1] > sum)
        {
            ll temp = v[i - 1] - sum;
            v[i - 1] -= temp;
            v[i + 1] += temp;
        }
        else
        {
            ll temp = sum - v[i - 1];
            v[i - 1] += temp;
            v[i + 1] -= temp;
        }
    }
    if(v[n-1]==sum){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

Answer: 2


#include <bits/stdc++.h>

#define fast                     \

    ios::sync_with_stdio(false); \

    cin.tie(nullptr)

#define ll long long

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        ll k = 0, d, n, sum = 0;

        bool flag = true;

        cin >> n;

        vector<int> A(n);

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

            cin >> A[i];

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

            sum += A[i];

        if (sum % n != 0)

            flag = false;

        else

        {

            d = sum / n;

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

            {

                if (A[i - 1] < d && A[i - 1] > 0)

                {

                    k = d - A[i - 1];

                    A[i + 1] = A[i + 1] - k;

                    A[i - 1] = d;

                }

                else

                {

                    k = A[i - 1] - d;

                    A[i + 1] = A[i + 1] + k;

                    A[i - 1] = d;

                }

            }

        }

        for (int j = 0; j < n; j++)

            if (A[j] != d)

                flag = false;

        cout << (flag ? "YES" : "NO") << endl;

    }

    return 0;

}

#include <bits/stdc++.h>

#define fast                     \

    ios::sync_with_stdio(false); \

    cin.tie(nullptr)

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int k = 0, d, n, sum = 0;

        bool flag = true;

        cin >> n;

        vector<int> A(n);

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

            cin >> A[i];

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

            sum += A[i];

        if (sum % n != 0)

            flag = false;

        else

        {

            d = sum / n;

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

            {

                if (A[i - 1] < d && A[i - 1] > 0)

                {

                    k = d - A[i - 1];

                    A[i + 1] = A[i + 1] - k;

                    A[i - 1] = d;

                }

                else

                {

                    k = A[i - 1] - d;

                    A[i + 1] = A[i + 1] + k;

                    A[i - 1] = d;

                }

            }

        }

        for (int j = 0; j < n; j++)

            if (A[j] != d)

                flag = false;

        cout << (flag ? "YES" : "NO") << endl;

    }

    return 0;

}

Answer: 1


#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

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

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

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

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

				if(l[i+2]<0){

					flag = false;

					break;

				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}

#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

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

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

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

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

//				if(l[i+2]<0){

//					flag = false;

//					break;

//				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int seq_len; cin >> seq_len;
        int odd_sum = 0;
        int even_sum = 0;
        int odd_seq_len = (seq_len / 2) + (seq_len % 2);
        int even_seq_len = (seq_len / 2);
        for (int j = 0; j < seq_len; j++) {
            int val;
            cin >> val;
            if (j % 2 == 0) {
                odd_sum += val;
            }
            else even_sum += val;
        }
        int desired = (odd_sum + even_sum) / seq_len;
        if (odd_sum / odd_seq_len == desired && even_sum / even_seq_len == desired && odd_sum % odd_seq_len == 0 && even_sum % even_seq_len == 0) {
            cout << "YES\n";
        }
        else cout << "NO\n";
    }
}

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int seq_len; cin >> seq_len;
        long long odd_sum = 0;
        long long even_sum = 0;
        int odd_seq_len = (seq_len / 2) + (seq_len % 2);
        int even_seq_len = (seq_len / 2);
        for (int j = 0; j < seq_len; j++) {
            int val;
            cin >> val;
            if (j % 2 == 0) {
                odd_sum += val;
            }
            else even_sum += val;
        }
        long long desired = (odd_sum + even_sum) / seq_len;
        if (odd_sum / odd_seq_len == desired && even_sum / even_seq_len == desired && odd_sum % odd_seq_len == 0 && even_sum % even_seq_len == 0) {
            cout << "YES\n";
        }
        else cout << "NO\n";
    }
}

Answer: 2


t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 1:

        if even_sum/(n//2+1) == odd_sum*(n-n//2-1):

            print("YES")

        else:

            print("NO")

    else:

        if even_sum/(n//2) == odd_sum*(n-n//2):

            print("YES")

        else:

            print("NO")

t = int(input())

for i in range(t):

    n = int(input())

    inputs = list(map(int, input().split()))

    even_sum = 0

    odd_sum = 0

    for i in range(n):

        if i%2 == 0:

            even_sum += inputs[i]

        else:

            odd_sum += inputs[i]

    if n%2 == 0:

        even = odd = n/2

    else:

        even = n//2+1

        odd = n - even

    if even_sum/even == int(even_sum/even) and odd_sum/odd == int(odd_sum/odd):

        if even_sum/even == odd_sum/odd:

            print("YES")

        else:

            print("NO")

    else:

        print("NO")

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        long long int n;

        cin>>n;

        vector<int>ritik(n);

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

        cin>>ritik[i];

        long long int sum_o=0,sum_e=0;

        long long int c1=0,c2=0;

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

            if(i%2==0){

              sum_e+=ritik[i];

              c1++;

            }

            else{

                sum_o+=ritik[i];

                c2++;

            }

        }

        if(sum_e/c1==sum_o/c2 && sum_e%c1==0&& sum_o%c2==0){

            cout<<"YES"<<endl;

        }

        else

            cout<<"NO"<<endl;

    }

}

#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        vector<int>ritik(n);

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

        cin>>ritik[i];

        int sum_o=0,sum_e=0;

        int c1=0,c2=0;

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

            if(i%2==0){

              sum_e+=ritik[i];

              c1++;

            }

            else{

                sum_o+=ritik[i];

                c2++;

            }

        }

        if(sum_e/c1==sum_o/c2 && sum_e%c1==0){

            cout<<"YES"<<endl;

        }

        else

            cout<<"NO"<<endl;

    }

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

#define ll long long

signed solve()

{

	ll n;

	cin>>n;

	vector<ll> arr(n);

	ll sum=0;

	ll odd_sum=0,odd_cnt=0;

	ll eve_sum=0,eve_cnt=0;

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

	{

		cin>>arr[i];

		sum+=arr[i];

		if(i%2==0)

			{

				eve_sum+=arr[i];

				eve_cnt++;

			}

			else

			{

				odd_sum+=arr[i];

				odd_cnt++;

			}

	}

	if(sum%n==0)

	{

		ll eve_avg=eve_sum/eve_cnt;

		ll odd_avg=odd_sum/odd_cnt;

		if(eve_avg==odd_avg)

		{

			cout<<"YES"<<endl;

		}

		else

		{

			cout<<"NO"<<endl;

		}

	}

	else

	{

		cout<<"NO"<<endl;

	}

    return 0;

}

signed main()

{

    int t;

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>t;

    //t=1;

    while(t--)

    {

        solve();

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

#define ll long long

signed solve()

{

	ll n;

	cin>>n;

	vector<ll> arr(n);

	ll sum=0;

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

	{

		cin>>arr[i];

		sum+=arr[i];

	}

	if(sum%n==0)

	{

		ll ans=sum/n;

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

		{

			int avg=(arr[i]+arr[i+2]);

			if(avg%2==0)

			{

				arr[i+2]=avg/2;

			}

			else

			{

				arr[i+2]=(avg/2)+1;

			}

			arr[i]=avg/2;

		}

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

		// {

		// 	cout<<arr[i]<<" ";

		// }

		// cout<<endl;

		bool flag=true;

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

		{

			if(arr[i]!=ans)

			{

				flag=false;

				break;

			}

		}

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

		else cout<<"NO"<<endl;

	}

	else

	{

		cout<<"NO"<<endl;

	}

    return 0;

}

signed main()

{

    int t;

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>t;

    //t=1;

    while(t--)

    {

        solve();

    }

    return 0;

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    cout<<"NO"<<endl;

  }

  return 0 ;

}

#include<bits/stdc++.h>

using namespace std;

int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    long long sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    long long sum0 = 0;

    long long sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    cout<<"NO"<<endl;

  }

  return 0 ;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ll long long
#define ld long double
#define fr(i, n) for (int i = 0; i < n; i++)
#define vi vector<ll>
#define pii pair<int, int>
#define mii map<int, int>
#define pb push_back
#define int long long
#define endl "\n"

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vi a(n);
        fr(i, n) cin >> a[i];
        int x = 0;
        int b = 0;
        int y = 0;
        int z = 0;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0)
            {
                x += a[i];
                y++;
            }
            else
            {
                b += a[i];
                z++;
            }
        }
        if (x / y == b / z && x % y == 0 && b % z == 0)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ll long long
#define ld long double
#define fr(i, n) for (int i = 0; i < n; i++)
#define vi vector<ll>
#define pii pair<int, int>
#define mii map<int, int>
#define pb push_back
#define int long long
#define endl "\n"

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vi a(n);
        fr(i, n) cin >> a[i];
        if (a[0] < a[1] && a[1] < a[2])
        {
            cout << "yes" << endl;
        }
        else if (a[0] > a[1] && a[1] > a[2])
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }
    return 0;
}

Answer: 1


#include<iostream>

#include<vector>

using namespace std;

void Solve(){

    int n;

    cin>>n;

    vector<long long int> vec(n);

    int sodd=0,seven=0,countodd=0,counteven=0;

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

        cin>>vec[i];

        if(i%2==0){

            sodd+=vec[i];

            countodd+=1;

        }

        else{

            seven+=vec[i];

            counteven+=1;

        }

    }

    if(seven*countodd==sodd*counteven && (seven+sodd)%(countodd+counteven)==0){

        cout<<"YES"<<endl;

    }else{cout<<"NO"<<endl;}

}

int main(){

    int t;

    cin>>t;

    while(t--){

        Solve();

    }

    return 0;

}

#include<iostream>

#include<vector>

using namespace std;

void Solve(){

    int n;

    cin>>n;

    vector<long long> vec(n);

    long long sodd=0,seven=0,countodd=0,counteven=0;

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

        cin>>vec[i];

        if(i%2==0){

            sodd+=vec[i];

            countodd++;

        }

        else{

            seven+=vec[i];

            counteven++;

        }

    }

    if((seven*countodd)==(sodd*counteven) && ((seven+sodd)%(countodd+counteven))==0){

        cout<<"YES"<<endl;

    }else{cout<<"NO"<<endl;}

}

int main(){

    int t;

    cin>>t;

    while(t--){

        Solve();

    }

    return 0;

}

Answer: 2