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

void solv() {
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &i:v) cin>>i;
    int odd=0, even=0, sum = 0;
    for(int i=0;i<n; i++) {
        if(i%2) odd+=v[i];
        else even+=v[i];
        sum+=v[i];
    }
    if(sum % n != 0) {
        cout << "NO\n";
        return;
    }
    int avg = sum / n;
    if(n%2) {
        if(even / ((n+1)/2) == avg && odd / (n/2) == avg) {
            cout<<"YES\n";
        }else cout<< "NO\n";
    }else {
        if(even / (n/2) == avg && odd / (n/2) == avg) {
            cout<<"YES\n";
        }else cout<< "NO\n";
    }
}

int32_t main() {
    int t=1;
    cin >> t;
    while (t--) {
        solv();
    }
    return 0;
}

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

void solv() {
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &i:v) cin>>i;
    int odd=0, even=0, sum = 0;
    for(int i=0;i<n; i++) {
        if(i%2) odd+=v[i];
        else even+=v[i];
        sum+=v[i];
    }
    if(sum % n != 0) {
        cout << "NO\n";
        return;
    } // 6 2 1 4 2
    if(n%2) {
        if(even%((n+1)/2) == 0 && odd % (n/2) == 0) {
            cout<<"YES\n";
        }else cout<< "NO\n";
    }else {
        if(even%(n/2) == 0 && odd % (n/2) == 0) {
            cout<<"YES\n";
        }else cout<< "NO\n";
    }
}

int32_t main() {
    int t=1;
    cin >> t;
    while (t--) {
        solv();
    }
    return 0;
}

Answer: 1


//    بسم الله الرحمن الرحيم  //

//    ███╗   ███╗ █████╗  ██████╗████████╗███████╗██████╗ ███╗   ███╗██╗███╗  ██╗██████╗

//    ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗

//    ██╔████╔██║███████║╚█████╗    ██║   █████╗  ██████╔╝██╔████╔██║██║██╔██╗██║██║  ██║

//    ██║╚██╔╝██║██╔══██║ ╚═══██╗   ██║   ██╔══╝  ██╔══██╗██║╚██╔╝██║██║██║╚████║██║  ██║

//    ██║ ╚═╝ ██║██║  ██║██████╔╝   ██║   ███████╗██║  ██║██  ╚═╝ ██║██║██║ ╚███║██████╔╝

//    ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝    ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚═╝╚═╝  ╚══╝╚═════╝

#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <deque>

#include <list>

#include <iomanip>

#include <functional>

#include <numeric>

#include <bitset>

#include <sstream>

#include <tuple>

#include <cassert>

#include <iterator>

using namespace std;

#define ll long long

#define ull unsigned long long

#define MOD 1000000007

#define PI 3.14159265

// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))

#define nl '\n'

#define pb push_back

#define tc \

    int t; \

    cin >> t;

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

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define sz size()

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

void Mastermind()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

#ifndef ONLINE_JUDGE

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

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

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

#endif

}

bool checkBit(int x, int idx)

{

    return x & (1 << idx);

}

bool checkBit2(int x, int idx)

{

    return (x >> idx) & 1;

}

bool setBitToOne(int x, int idx)

{

    return x | (1 << idx);

}

bool setBitToZero(int x, int idx)

{

    return x & ~(1 << idx);

}

bool flipIdx(int x, int idx)

{

    // bit ^ 1

    // 0^1 (bit= 1)

    // 1^1 (bit= 0)

    return x ^ (1 << idx);

}

int countOns(int x) // or bult in function -> __builtin_popcount(x)

{

    int cnt = 0;

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

        cnt += checkBit(x, i);

}

// ll gcd(ll a, ll b)

// {

//    if(b==0)return a;

//      return gcd(b,b%a);

// }

// ll lcm(ll a, ll b)

// {

//     return a / gcd(a, b) * b;

// }

// // <------------------------------------------------>

ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    return gcd(b, b % a);

}

ll lcm(ll a, ll b)

{

    return a / gcd(a, b) * b;

}

// <------------------------------------------------>

int FAST_POWER(int x, int n)

{

    int result = 1;

    while (n > 0)

    {

        if (n % 2 == 1)

            result = result * x;

        x = x * x;

        n = n / 2;

    }

    return result;

}

// fast power { time : log {n}}

// <------------------------------------------------>

bool isPerfectSquare(int x)

{

    if (x < 0)

        return false;

    int s = sqrt(x);

    return (s * s == x);

}

// <------------------------------------------------>

vector<int> prime_factorization(int n)

{

    vector<int> v;

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

    {

        while (n % i == 0)

        {

            v.push_back(i);

            n /= i;

        }

    }

    if (n > 1)

        v.push_back(n);

    return v;

}

bool comp(const pair<string, int> &a, const pair<string, int> &b)

{

    if (a.second == b.second)

    {

        return a.first > b.first;

    }

    else

    {

        return a.second > b.second;

    }

}

// _____________________________________ Solve. ______________________________________________________

int Ones(vector<int> v)

{

    int c = 0;

    for (auto &i : v)

    {

        if (i == 1)

            c++;

    }

    return c;

}

int main()

{

    // Mastermind();

    fast;

    tc;

    while (t--)

    {

        int n;

        cin >> n;

        vector<int> v(n);

        ll sum = 0;

        for (auto &i : v)

        {

            cin >> i;

            sum += i;

        }

        ll sum_odd = 0, sum_even = 0, c_odd = 0;

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

        {

            if (i & 1)

            {

                sum_odd += v[i];

                c_odd++;

            }

            else

                sum_even += v[i];

        }

        if (!(sum % n) && sum_odd / c_odd == sum_even / (n - c_odd))

        {

            cy;

        }

        else

            cn;

    }

    return 0;

}

//    بسم الله الرحمن الرحيم  //

//    ███╗   ███╗ █████╗  ██████╗████████╗███████╗██████╗ ███╗   ███╗██╗███╗  ██╗██████╗

//    ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗

//    ██╔████╔██║███████║╚█████╗    ██║   █████╗  ██████╔╝██╔████╔██║██║██╔██╗██║██║  ██║

//    ██║╚██╔╝██║██╔══██║ ╚═══██╗   ██║   ██╔══╝  ██╔══██╗██║╚██╔╝██║██║██║╚████║██║  ██║

//    ██║ ╚═╝ ██║██║  ██║██████╔╝   ██║   ███████╗██║  ██║██  ╚═╝ ██║██║██║ ╚███║██████╔╝

//    ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝    ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚═╝╚═╝  ╚══╝╚═════╝

#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <deque>

#include <list>

#include <iomanip>

#include <functional>

#include <numeric>

#include <bitset>

#include <sstream>

#include <tuple>

#include <cassert>

#include <iterator>

using namespace std;

#define ll long long

#define ull unsigned long long

#define MOD 1000000007

#define PI 3.14159265

// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))

#define nl '\n'

#define pb push_back

#define tc \

    int t; \

    cin >> t;

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

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define sz size()

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

void Mastermind()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

#ifndef ONLINE_JUDGE

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

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

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

#endif

}

bool checkBit(int x, int idx)

{

    return x & (1 << idx);

}

bool checkBit2(int x, int idx)

{

    return (x >> idx) & 1;

}

bool setBitToOne(int x, int idx)

{

    return x | (1 << idx);

}

bool setBitToZero(int x, int idx)

{

    return x & ~(1 << idx);

}

bool flipIdx(int x, int idx)

{

    // bit ^ 1

    // 0^1 (bit= 1)

    // 1^1 (bit= 0)

    return x ^ (1 << idx);

}

int countOns(int x) // or bult in function -> __builtin_popcount(x)

{

    int cnt = 0;

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

        cnt += checkBit(x, i);

}

// ll gcd(ll a, ll b)

// {

//    if(b==0)return a;

//      return gcd(b,b%a);

// }

// ll lcm(ll a, ll b)

// {

//     return a / gcd(a, b) * b;

// }

// // <------------------------------------------------>

ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    return gcd(b, b % a);

}

ll lcm(ll a, ll b)

{

    return a / gcd(a, b) * b;

}

// <------------------------------------------------>

int FAST_POWER(int x, int n)

{

    int result = 1;

    while (n > 0)

    {

        if (n % 2 == 1)

            result = result * x;

        x = x * x;

        n = n / 2;

    }

    return result;

}

// fast power { time : log {n}}

// <------------------------------------------------>

bool isPerfectSquare(int x)

{

    if (x < 0)

        return false;

    int s = sqrt(x);

    return (s * s == x);

}

// <------------------------------------------------>

vector<int> prime_factorization(int n)

{

    vector<int> v;

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

    {

        while (n % i == 0)

        {

            v.push_back(i);

            n /= i;

        }

    }

    if (n > 1)

        v.push_back(n);

    return v;

}

bool comp(const pair<string, int> &a, const pair<string, int> &b)

{

    if (a.second == b.second)

    {

        return a.first > b.first;

    }

    else

    {

        return a.second > b.second;

    }

}

// _____________________________________ Solve. ______________________________________________________

int Ones(vector<int> v)

{

    int c = 0;

    for (auto &i : v)

    {

        if (i == 1)

            c++;

    }

    return c;

}

int main()

{

    // Mastermind();

    fast;

    tc;

    while (t--)

    {

        int n;

        cin >> n;

        vector<int> v(n);

        ll sum = 0;

        for (auto &i : v)

        {

            cin >> i;

            sum += i;

        }

        // cerr << Ones(v) << " ";

        if (!(sum % n) && Ones(v) < 2)

        {

            cy;

        }

        else

            cn;

    }

    return 0;

}

Answer: 1


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

#define ll long long

void solve()
{
    int n;
    cin >> n;
    ll a[2] = {0};
    for (int i = 0, tt; i < n; ++i)
    {
        cin >> tt;
        a[i % 2] += tt;
    }
    if (a[0] % (n + 1 >> 1) == 0 && a[1] % (n >> 1) == 0 && a[0] / (n + 1 >> 1) == a[1] / (n >> 1))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

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

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

void solve()
{
    int n;
    cin >> n;
    ll a[2] = {0};
    for (int i = 0, tt; i < n; ++i)
    {
        cin >> tt;
        a[i % 2] += tt;
    }
    if (a[0] % (n + 1 >> 1) == 0 && a[1] % (n >> 1) == 0 && a[0] / (n + 1 >> 1) == a[1] / (n >> 1))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

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

Answer: 1


#include<bits/stdc++.h>

using namespace std;

typedef long long w;

int main(){

int t;

cin>>t;

while(t--){

    w n;

    cin>>n; w a[n];w sum=0;

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

        cin>>a[i];

        sum+=a[i];

    }

    int b=sum/n;

    if(sum%n==0){

        int r=1;

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

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

                    w c=a[i-1]-b;

                    a[i-1]=b;

                    a[i+1]=a[i+1]+c;

                }

                else if(a[i-1]<b){

                    w c=b-a[i-1];

                    a[i-1]=b;

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

                }

                if(a[i-1]<0 || a[i+1]<0){

                int r=0;

                break;}

    }

        if(r==1 && a[n-1]==b && a[n-2]==b)

        cout<<"YES"<<endl;

        else

        cout<<"NO"<<endl;

}

    else{

        cout<<"NO"<<endl;

    }

}

}

#include<bits/stdc++.h>

using namespace std;

typedef long long w;

int main(){

int t;

cin>>t;

while(t--){

    w n;

    cin>>n; vector<w> a(n);w sum=0;

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

        cin>>a[i];

        sum+=a[i];

    }

    int b=sum/n;

    if(sum%n==0){

        int r=1;

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

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

                    w c=a[i-1]-b;

                    a[i-1]=b;

                    a[i+1]=a[i+1]+c;

                }

                else if(a[i-1]<b){

                    w c=b-a[i-1];

                    a[i-1]=b;

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

                }

                if(a[i-1]<0 || a[i+1]<0){

                int r=0;

                break;}

    }

        if(r==1 && a[n-1]==b && a[n-2]==b)

        cout<<"YES"<<endl;

        else

        cout<<"NO"<<endl;

}

    else{

        cout<<"NO"<<endl;

    }

}

}

Answer: 2


 import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Scanner sc= new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
            long ceve = 0;
            long codd = 0;
            long eve = 0;
            long odd = 0;
            for(int j =0;j<n;j++){
                long num = sc.nextLong();
                if(j%2==0){
                    odd = odd + num;
                    codd++;
                }
                else{
                    eve = eve + num;
                    ceve++;
                }
            }
            if(eve%ceve == 0 && odd%codd==0){
            long m = eve/ceve;
            long l = odd/codd;
            if(m==l){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }
        else{
            System.out.println("NO");
        }
        }
    }
}
class Scanner {
  StringTokenizer st;
  BufferedReader br;

  public Scanner(InputStream s) {
      br = new BufferedReader(new InputStreamReader(s));
  }

  public Scanner(File s) throws FileNotFoundException {
      br = new BufferedReader(new FileReader(s));
  }

  public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
      return st.nextToken();
  }

  public int nextInt() throws IOException {
      return Integer.parseInt(next());
  }

  public long nextLong() throws IOException {
      return Long.parseLong(next());
  }

  public String nextLine() throws IOException {
      return br.readLine();
  }
  public int[] nextArr(int n) throws IOException {
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
          a[i] = nextInt();
      }
      return a;
  }

  public double nextDouble() throws IOException {
      String x = next();
      StringBuilder sb = new StringBuilder("0");
      double res = 0, f = 1;
      boolean dec = false, neg = false;
      int start = 0;
      if (x.charAt(0) == '-') {
          neg = true;
          start++;
      }
      for (int i = start; i < x.length(); i++)
          if (x.charAt(i) == '.') {
              res = Long.parseLong(sb.toString());
              sb = new StringBuilder("0");
              dec = true;
          } else {
              sb.append(x.charAt(i));
              if (dec) f *= 10;
          }
      res += Long.parseLong(sb.toString()) / f;
      return res * (neg ? -1 : 1);
  }

  public boolean ready() throws IOException {
      return br.ready();
  }

}
class Pair implements Comparable{
    long a;
    long b;
    public Pair(long a,long b){
        this.a = a;
        this.b = b;
    }
    public int compareTo(Object o) {
        if(((Pair)o).a > a){
            return -1;
        }
        else if(((Pair)o).a < a){
            return 1;
        }
        else{
            if(((Pair)o).b > b){
                return 1;
            }
            else if(((Pair)o).b < b){
                return -1;
            }
            else{
                return 0;
            }

        }
    }
    public String toString(){
        return a + " " + b;
    }
}

 import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Scanner sc= new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
            int ceve = 0;
            int codd = 0;
            int eve = 0;
            int odd = 0;
            for(int j =0;j<n;j++){
                int num = sc.nextInt();
                if(j%2==0){
                    odd = odd + num;
                    codd++;
                }
                else{
                    eve = eve + num;
                    ceve++;
                }
            }
            if(eve%ceve == 0 && odd%codd==0){
            int m = eve/ceve;
            int l = odd/codd;
            if(m==l){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }
        else{
            System.out.println("NO");
        }
        }
    }
}
class Scanner {
  StringTokenizer st;
  BufferedReader br;

  public Scanner(InputStream s) {
      br = new BufferedReader(new InputStreamReader(s));
  }

  public Scanner(File s) throws FileNotFoundException {
      br = new BufferedReader(new FileReader(s));
  }

  public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
      return st.nextToken();
  }

  public int nextInt() throws IOException {
      return Integer.parseInt(next());
  }

  public long nextLong() throws IOException {
      return Long.parseLong(next());
  }

  public String nextLine() throws IOException {
      return br.readLine();
  }
  public int[] nextArr(int n) throws IOException {
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
          a[i] = nextInt();
      }
      return a;
  }

  public double nextDouble() throws IOException {
      String x = next();
      StringBuilder sb = new StringBuilder("0");
      double res = 0, f = 1;
      boolean dec = false, neg = false;
      int start = 0;
      if (x.charAt(0) == '-') {
          neg = true;
          start++;
      }
      for (int i = start; i < x.length(); i++)
          if (x.charAt(i) == '.') {
              res = Long.parseLong(sb.toString());
              sb = new StringBuilder("0");
              dec = true;
          } else {
              sb.append(x.charAt(i));
              if (dec) f *= 10;
          }
      res += Long.parseLong(sb.toString()) / f;
      return res * (neg ? -1 : 1);
  }

  public boolean ready() throws IOException {
      return br.ready();
  }

}
class Pair implements Comparable{
    long a;
    long b;
    public Pair(long a,long b){
        this.a = a;
        this.b = b;
    }
    public int compareTo(Object o) {
        if(((Pair)o).a > a){
            return -1;
        }
        else if(((Pair)o).a < a){
            return 1;
        }
        else{
            if(((Pair)o).b > b){
                return 1;
            }
            else if(((Pair)o).b < b){
                return -1;
            }
            else{
                return 0;
            }

        }
    }
    public String toString(){
        return a + " " + b;
    }
}

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 i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    c=[0*t for m in range(t)]
    count=0
    count2=0
    mean=2*sum(a)//n
    if sum(a)%n!=0:
        print("NO")
    else:
        for j in range(n-2):
            b.append(abs(a[j]+a[j+2]))
        for k in range(n-2):
            if b[k]%2==0:
                count+=2
            else:
                c[i]+=1
        if mean in b:
                if (count+c[i])%2==0:
                    print("YES")
                else:
                    print("NO")
        else:
            print("NO")

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define forr(i,x,n) for(int i = x; i < n ; i ++ )

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n ;
        cin >> n;
        int a[n] ;
        int s=0;
        forr(i,0, n){
            cin >> a[i] ;
            s+=a[i];
        }
        bool ok = false ;
        if(s%n==0){ok = true ;}
        else { ok = false ;}

        if(ok) {
        int x = s/n;
        forr(i,1,n-1) {

            if(a[i-1] >= x && a[i+1] > x ) {
                ok = false ;
            }
            else if(a[i-1] > x && a[i+1] >= x) ok = false ;
            else if(a[i-1] <= x && a[i+1] < x ) {
                ok = false;
            }

            else if(a[i-1] < x && a[i+1] <= x) ok = false ;
            else {
                if(a[i-1] > x && a[i+1] < x) {
                    a[i+1]+= a[i-1] - x ;
                }
                else if(a[i-1] < x && a[i+1] > x ){
                    a[i-1]+= a[i+1] - x ;
                    a[i+1] = x ; }
            }
        }
        }

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

    }

}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define forr(i,x,n) for(int i = x; i < n ; i ++ )

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n ;
        cin >> n;
        int a[n] ;
        int s=0;
        int pe=0 , le = 0 ;
        int po=0 , lo = 0 ;
        forr(i,0, n){
            cin >> a[i] ;
            s+=a[i];
        }
        bool ok = false ;
        if(s%n==0){ok = true ;}
        else { ok = false ;}

        if(ok) {
        int x = s/n;
        forr(i,0,n) {

            if(i%2==0) {
                if (a[i] > x) {
                    pe+= a[i] - x;
                }
                else le+= x - a[i];
            }
            else {
                if(a[i]>x) po+=  a[i] - x;
                else lo+=  x - a[i];
            }

        }
        }
        if(ok && po == lo && pe == le  ) cout << "YES" << endl ;
        else cout<< "NO" << endl ;

       // if(ok) cout<< "YES" << endl ;
      //  else cout << "NO" << endl ;

    }

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

void solve(){

    int n;cin>>n;

    vector <int> vec(n+1);

    vec[0]=0;

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

        cin>>vec[i];

    }

    int odd=0,even=0;

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

        if(i&1) odd+=vec[i];

        else even+=vec[i];

    }

    if(n%2==0){

        if(even==odd && even%(n/2)==0){

            cout<<"YES"<<endl;

        }

        else {

            cout<<"NO"<<endl;

        }

    }

    else{

        if(odd%((n+1)/2)==0 && even%(n/2)==0 && odd/((n+1)/2)==even/(n/2)){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }

}

int main(){

int t;cin>>t;

    while(t--){

        solve();

    };

}

#include <bits/stdc++.h>

using namespace std;

void solve(){

    int n;cin>>n;

    vector <int> vec(n+1);

    vec[0]=0;

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

        cin>>vec[i];

    }

    long long int odd=0,even=0;

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

        if(i&1) odd+=vec[i];

        else even+=vec[i];

    }

    if(n%2==0){

        if(even==odd && even%(n/2)==0){

            cout<<"YES"<<endl;

        }

        else {

            cout<<"NO"<<endl;

        }

    }

    else{

        if(odd%((n+1)/2)==0 && even%(n/2)==0 && odd/((n+1)/2)==even/(n/2)){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }

}

int main(){

int t;cin>>t;

    while(t--){

        solve();

    };

}

Answer: 2


Answer: 2


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

void solve(){
    int n;
    cin>>n;
    int sum_odd = 0;
    int sum_even = 0;
    int cnt_odd = 0;
    int cnt_even = 0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(i%2==0){
            sum_even+=x;
            cnt_even++;
        }else{
            sum_odd+=x;
            cnt_odd++;
        }
    }

    if(sum_even%cnt_even==0 && sum_odd%cnt_odd==0 && sum_even/cnt_even == sum_odd/cnt_odd){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

}

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

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

void solve(){
    int n;
    cin>>n;
    int sum_odd = 0;
    int sum_even = 0;
    int cnt_odd = 0;
    int cnt_even = 0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(i%2==0){
            sum_even+=x;
            cnt_even++;
        }else{
            sum_odd+=x;
            cnt_odd++;
        }
    }

    if(sum_even%cnt_even==0 && sum_odd%cnt_odd==0 && sum_even/cnt_even == sum_odd/cnt_odd){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

}

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

Answer: 2


def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0
    odd= (_size+1)/2
    sum2 = 0
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]
        else :
           sum2+=a[i]
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
         print("NO")
         return
    else:
      print("NO")

t = int(input())
for _ in range(t):
       process_array()

def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0
    odd= (_size+1)//2
    sum2 = 0
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]

        else :
           sum2+=a[i]
   # print(sum1, sum2, odd ,even)
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
          print("NO")
          return
    else:
      print("NO")

t = int(input())
for _ in range(t):
       process_array()

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+1)) {

                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;

        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';

            }

        }

    }

}

Answer: 2


// Problem: B. Transfusion

// Contest: Codeforces - Codeforces Round 991 (Div. 3)

// URL: https://codeforces.com/contest/2050/problem/B

// Memory Limit: 256 MB

// Time Limit: 2000 ms

//

// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("O3")

//#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define pii pair<int, int>

#define pdd pair<double, double>

#define lowbit(x) (x & -x)

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

#define Rep(i, x) for(auto &i : x)

#define L(i, x, y) for(int i = x; i <= y; ++ i)

#define R(i, x, y) for(int i = x; i >= y; -- i)

#define rd(x) scanf("%lld", &(x))

#define p_b push_back

#define ft first

#define sd second

using namespace std;

template <class T> using vc = vector<T>;

template <class T> using _pq = priority_queue<T, vector<T>, greater<T>>;

using i64 = long long;

using u64 = unsigned long long;

using u32 = unsigned;

const int N = 2e5 + 10;

void solve() {

	int n; cin >> n;

	vc<int> a(n);

	L(i, 0, n - 1) cin >> a[i];

	i64 sum = reduce(a.begin(), a.end());

	if(sum % n) {

		cout << "NO\n";

		return;

	}

	int sd = sum / n;

	//cout << sd << "\n";

	L(i, 0, n - 1) {

		//cout << i << " " << a[i] << "\n";

		if(i >= n - 2 && a[i] != sd) {

			cout << "NO\n";

			return;

		}

		if(a[i] == sd) continue;

		else {

			if((a[i] + a[i + 2]) / 2 != sd || (a[i] + a[i + 2]) % 2) {

				if(a[i] < sd) {

					int dif = sd - a[i];

					a[i] = sd;

					if(a[i + 2] >= dif) a[i + 2] -= dif;

					else {

						cout << "NO\n";

						return;

					}

				}

				else {

					int dif = a[i] - sd;

					a[i] = sd;

					a[i + 2] += dif;

				}

			}

			else {

				a[i] = (a[i] + a[i + 2]) / 2;

				a[i + 2] = a[i];

			}

		}

	}

	//L()

	cout << "YES\n";

}

int main() {

	Begin;

	int _; _ = 1;

	cin >> _;

	while(_--) solve();

	return 0;

}

// Problem: B. Transfusion

// Contest: Codeforces - Codeforces Round 991 (Div. 3)

// URL: https://codeforces.com/contest/2050/problem/B

// Memory Limit: 256 MB

// Time Limit: 2000 ms

//

// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("O3")

//#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define pii pair<int, int>

#define pdd pair<double, double>

#define lowbit(x) (x & -x)

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

#define Rep(i, x) for(auto &i : x)

#define L(i, x, y) for(int i = x; i <= y; ++ i)

#define R(i, x, y) for(int i = x; i >= y; -- i)

#define rd(x) scanf("%lld", &(x))

#define p_b push_back

#define ft first

#define sd second

using namespace std;

template <class T> using vc = vector<T>;

template <class T> using _pq = priority_queue<T, vector<T>, greater<T>>;

using i64 = long long;

using u64 = unsigned long long;

using u32 = unsigned;

const int N = 2e5 + 10;

void solve() {

	int n; cin >> n;

	vc<int> a(n);

	L(i, 0, n - 1) cin >> a[i];

	i64 sum = reduce(a.begin(), a.end());

	if(sum % n) {

		cout << "NO\n";

		return;

	}

	int sd = sum / n;

	//cout << sd << "\n";

	L(i, 0, n - 1) {

		//cout << i << " " << a[i] << "\n";

		if(i >= n - 2 && a[i] != sd) {

			cout << "NO\n";

			return;

		}

		if(a[i] == sd) continue;

		else {

			if((a[i] + a[i + 2]) / 2 != sd || (a[i] + a[i + 2]) % 2) {

				int dif = a[i] - sd;

				a[i + 2] += dif;

				continue;

			}

			else {

				a[i] = (a[i] + a[i + 2]) / 2;

				a[i + 2] = a[i];

			}

		}

	}

	cout << "YES\n";

}

int main() {

	Begin;

	int _; _ = 1;

	cin >> _;

	while(_--) solve();

	return 0;

}

Answer: 1


#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&& sum_o%c2==0){

            cout<<"YES"<<endl;

        }

        else

            cout<<"NO"<<endl;

    }

}

Answer: 1


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int even= (n+1)/2;
        int odd= n/2;
        int x,y;
        x=0;
        y=0;
        for(int i=0;i<n;i++){
            if(i%2==0){
                x+=a[i];
            }
            else{
                y+=a[i];
            }
        }
        if(y%odd==0 && x%even==0 && x/even==y/odd ){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }

    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int even= (n+1)/2;
        int odd= n/2;
        long long x,y;
        x=0;
        y=0;
        for(int i=0;i<n;i++){
            if(i%2==0){
                x+=a[i];
            }
            else{
                y+=a[i];
            }
        }
        if(y%odd==0 && x%even==0 && x/even==y/odd ){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;
#define int long long

void helper()
{
    int n;
    cin >> n;

    int odd = 0, even = 0;
    for(int i =0; i<n ; i++){
        int x ; cin>>x;
        if(i%2) odd += x;
        else even += x;
    }
    int odc = n/2 , evc = n/2 ;
    if(n&1) evc +=1 ;

    if(odd%odc != 0 || even%evc != 0 || odd/odc != even/evc){
        cout<<"NO"<<endl;
    }else {
        cout<<"YES"<<endl;
    }
}

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

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

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
#define int long long

void helper()
{
    int n;
    cin >> n;
    vector<long long> v(n);

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

    for (int i = 1; i < n-1; i += 1)
    {
        long long sum = v[i - 1];
        sum += v[i + 1];
        long long div = sum /2 ;
        if(sum%2 == 0){
        v[i - 1] = div;
        v[i + 1] = div;
        }else {
        v[i - 1] = div;
        v[i + 1] = div+1;
        }
    }

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

        if (v[i - 1] != v[i])
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

signed main()
{
    if (1)
    {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
    }
    int t;
    cin >> t;
    while (t--)
    {
        helper();
    }
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

typedef long long ll;

vector<ll> num(N);

void solve()

{

    int n;

    cin >> n;

    ll sum = 0;

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

    {

        cin >> num[i];

        sum += num[i];

    }

    if ((sum % n) != 0)

    {

        cout << "NO" << endl;

        return;

    }

    ll p = sum / n;

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

    {

        if (num[i] < p)

        {

            num[i + 2] -= (p - num[i]);

        }

        else

        {

            num[i + 2] += (num[i] - p);

        }

        num[i] = p;

    }

    if (num[n] == p && num[n - 1] == p)

        cout << "YES" << endl;

    else

        cout << "NO" << endl;

}

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

}

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

typedef long long ll;

vector<ll> num(N);

void solve()

{

    int n;

    cin >> n;

    ll sum = 0;

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

    {

        cin >> num[i];

        sum += num[i];

    }

    if ((sum % n) != 0)

    {

        cout << "NO" << endl;

        return;

    }

    ll p = sum / n;

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

    {

        if (num[i] < p)

        {

            num[i + 2] -= (p - num[i]);

        }

        else

        {

            num[i + 2] += (num[i] - p);

        }

        if(num[i+2] < 0)

        {

            cout << "NO" << endl;

            return;

        }

    }

    if (num[n] == p && num[n - 1] == p)

        cout << "YES" << endl;

    else

        cout << "NO" << endl;

}

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

}

Answer: 1


//    بسم الله الرحمن الرحيم  //

//    ███╗   ███╗ █████╗  ██████╗████████╗███████╗██████╗ ███╗   ███╗██╗███╗  ██╗██████╗

//    ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗

//    ██╔████╔██║███████║╚█████╗    ██║   █████╗  ██████╔╝██╔████╔██║██║██╔██╗██║██║  ██║

//    ██║╚██╔╝██║██╔══██║ ╚═══██╗   ██║   ██╔══╝  ██╔══██╗██║╚██╔╝██║██║██║╚████║██║  ██║

//    ██║ ╚═╝ ██║██║  ██║██████╔╝   ██║   ███████╗██║  ██║██  ╚═╝ ██║██║██║ ╚███║██████╔╝

//    ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝    ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚═╝╚═╝  ╚══╝╚═════╝

#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <deque>

#include <list>

#include <iomanip>

#include <functional>

#include <numeric>

#include <bitset>

#include <sstream>

#include <tuple>

#include <cassert>

#include <iterator>

using namespace std;

#define ll long long

#define ull unsigned long long

#define MOD 1000000007

#define PI 3.14159265

// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))

#define nl '\n'

#define pb push_back

#define tc \

    int t; \

    cin >> t;

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

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define sz size()

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

void Mastermind()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

#ifndef ONLINE_JUDGE

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

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

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

#endif

}

bool checkBit(int x, int idx)

{

    return x & (1 << idx);

}

bool checkBit2(int x, int idx)

{

    return (x >> idx) & 1;

}

bool setBitToOne(int x, int idx)

{

    return x | (1 << idx);

}

bool setBitToZero(int x, int idx)

{

    return x & ~(1 << idx);

}

bool flipIdx(int x, int idx)

{

    // bit ^ 1

    // 0^1 (bit= 1)

    // 1^1 (bit= 0)

    return x ^ (1 << idx);

}

int countOns(int x) // or bult in function -> __builtin_popcount(x)

{

    int cnt = 0;

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

        cnt += checkBit(x, i);

}

// ll gcd(ll a, ll b)

// {

//    if(b==0)return a;

//      return gcd(b,b%a);

// }

// ll lcm(ll a, ll b)

// {

//     return a / gcd(a, b) * b;

// }

// // <------------------------------------------------>

ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    return gcd(b, b % a);

}

ll lcm(ll a, ll b)

{

    return a / gcd(a, b) * b;

}

// <------------------------------------------------>

int FAST_POWER(int x, int n)

{

    int result = 1;

    while (n > 0)

    {

        if (n % 2 == 1)

            result = result * x;

        x = x * x;

        n = n / 2;

    }

    return result;

}

// fast power { time : log {n}}

// <------------------------------------------------>

bool isPerfectSquare(int x)

{

    if (x < 0)

        return false;

    int s = sqrt(x);

    return (s * s == x);

}

// <------------------------------------------------>

vector<int> prime_factorization(int n)

{

    vector<int> v;

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

    {

        while (n % i == 0)

        {

            v.push_back(i);

            n /= i;

        }

    }

    if (n > 1)

        v.push_back(n);

    return v;

}

bool comp(const pair<string, int> &a, const pair<string, int> &b)

{

    if (a.second == b.second)

    {

        return a.first > b.first;

    }

    else

    {

        return a.second > b.second;

    }

}

// _____________________________________ Solve. ______________________________________________________

int Ones(vector<int> v)

{

    int c = 0;

    for (auto &i : v)

    {

        if (i == 1)

            c++;

    }

    return c;

}

int main()

{

    // Mastermind();

    fast;

    tc;

    while (t--)

    {

        int n;

        cin >> n;

        vector<int> v(n);

        ll sum = 0;

        for (auto &i : v)

        {

            cin >> i;

            sum += i;

        }

        // cerr << Ones(v) << " ";

        if (!(sum % n) && Ones(v) % 2 != 0)

        {

            cy;

        }

        else

            cn;

    }

    return 0;

}

//    بسم الله الرحمن الرحيم  //

//    ███╗   ███╗ █████╗  ██████╗████████╗███████╗██████╗ ███╗   ███╗██╗███╗  ██╗██████╗

//    ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗

//    ██╔████╔██║███████║╚█████╗    ██║   █████╗  ██████╔╝██╔████╔██║██║██╔██╗██║██║  ██║

//    ██║╚██╔╝██║██╔══██║ ╚═══██╗   ██║   ██╔══╝  ██╔══██╗██║╚██╔╝██║██║██║╚████║██║  ██║

//    ██║ ╚═╝ ██║██║  ██║██████╔╝   ██║   ███████╗██║  ██║██  ╚═╝ ██║██║██║ ╚███║██████╔╝

//    ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝    ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚═╝╚═╝  ╚══╝╚═════╝

#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <deque>

#include <list>

#include <iomanip>

#include <functional>

#include <numeric>

#include <bitset>

#include <sstream>

#include <tuple>

#include <cassert>

#include <iterator>

using namespace std;

#define ll long long

#define ull unsigned long long

#define MOD 1000000007

#define PI 3.14159265

// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))

#define nl '\n'

#define pb push_back

#define tc \

    int t; \

    cin >> t;

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

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define sz size()

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

void Mastermind()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

#ifndef ONLINE_JUDGE

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

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

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

#endif

}

bool checkBit(int x, int idx)

{

    return x & (1 << idx);

}

bool checkBit2(int x, int idx)

{

    return (x >> idx) & 1;

}

bool setBitToOne(int x, int idx)

{

    return x | (1 << idx);

}

bool setBitToZero(int x, int idx)

{

    return x & ~(1 << idx);

}

bool flipIdx(int x, int idx)

{

    // bit ^ 1

    // 0^1 (bit= 1)

    // 1^1 (bit= 0)

    return x ^ (1 << idx);

}

int countOns(int x) // or bult in function -> __builtin_popcount(x)

{

    int cnt = 0;

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

        cnt += checkBit(x, i);

}

// ll gcd(ll a, ll b)

// {

//    if(b==0)return a;

//      return gcd(b,b%a);

// }

// ll lcm(ll a, ll b)

// {

//     return a / gcd(a, b) * b;

// }

// // <------------------------------------------------>

ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    return gcd(b, b % a);

}

ll lcm(ll a, ll b)

{

    return a / gcd(a, b) * b;

}

// <------------------------------------------------>

int FAST_POWER(int x, int n)

{

    int result = 1;

    while (n > 0)

    {

        if (n % 2 == 1)

            result = result * x;

        x = x * x;

        n = n / 2;

    }

    return result;

}

// fast power { time : log {n}}

// <------------------------------------------------>

bool isPerfectSquare(int x)

{

    if (x < 0)

        return false;

    int s = sqrt(x);

    return (s * s == x);

}

// <------------------------------------------------>

vector<int> prime_factorization(int n)

{

    vector<int> v;

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

    {

        while (n % i == 0)

        {

            v.push_back(i);

            n /= i;

        }

    }

    if (n > 1)

        v.push_back(n);

    return v;

}

bool comp(const pair<string, int> &a, const pair<string, int> &b)

{

    if (a.second == b.second)

    {

        return a.first > b.first;

    }

    else

    {

        return a.second > b.second;

    }

}

// _____________________________________ Solve. ______________________________________________________

int Ones(vector<int> v)

{

    int c = 0;

    for (auto &i : v)

    {

        if (i == 1)

            c++;

    }

    return c;

}

int main()

{

    // Mastermind();

    fast;

    tc;

    while (t--)

    {

        int n;

        cin >> n;

        vector<int> v(n);

        ll sum = 0;

        for (auto &i : v)

        {

            cin >> i;

            sum += i;

        }

        ll sum_odd = 0, sum_even = 0, c_odd = 0;

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

        {

            if (i & 1)

            {

                sum_odd += v[i];

                c_odd++;

            }

            else

                sum_even += v[i];

        }

        if (!(sum % n) && sum_odd / c_odd == sum_even / (n - c_odd))

        {

            cy;

        }

        else

            cn;

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--)

    {

        long long int n;

        cin>>n;

        long long int a[n];

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

        {

            cin>>a[i];

        }

        long long int sum=0;

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

        {

            sum+=a[i];

        }

        if(sum%n==0)

        {

            long long int value = sum/n;

            long long int cnt1=0;

            long long int cnt2=0;

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

            {

                if(i%2==0)

                {

                   cnt1+=a[i]-value;

                }

                else

                {

                    cnt2+=a[i]-value;

                }

            }

            if(cnt1==0&&cnt2==0)

            {

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

            }

            else

            {

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

            }

        }

        else

        {

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

        }

    }

}

#include <bits/stdc++.h>

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)

        {

            int value = sum/n;

            int cnt1=0;

            int cnt2=0;

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

            {

                if(i%2==0)

                {

                   cnt1+=a[i]-value;

                }

                else

                {

                    cnt2+=a[i]-value;

                }

            }

            if(cnt1==0&&cnt2==0)

            {

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

            }

            else

            {

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

            }

        }

        else

        {

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

        }

    }

}

Answer: 1


'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;
}

'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 i = 0; i < runs; ++i) {
        const len = parseInt(readline());
        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");
                break;
            }

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

            console.log("YES");
            break
    }

    return;
}

Answer: 1


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;

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

        while((line = reader.readLine()) != null) {
            inputs.add(line);
        }

        String[] result = new String[t];

        int j = 0;

        for(int i = 0; i < t; i++){
            int n = Integer.parseInt(inputs.get(j));
            String[] strings = inputs.get(j+1).split(" ");
            j += 2;

            int[] data = new int[n];

            for(int k = 0; k < n; k++){
                data[k] = Integer.parseInt(strings[k]);
            }

            result[i] = solution(data);
        }

        for(String r: result){
            System.out.println(r);
        }
    }

    public static String solution(int[] nums){
        double oddT = 0;
        int o = 0;

        double evenT = 0;
        int e = 0;

        for(int i = 0; i < nums.length; i++){
            if(i%2 == 0){
                evenT += nums[i];
                e += 1;
            }
            else{
                oddT += nums[i];
                o += 1;
            }
        }

        if((oddT+evenT) % nums.length != 0){
            return "NO";
        }

        boolean ans = oddT/o == evenT/e;

        if(ans){
            return "YES";
        }
        return "NO";

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;

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

        while((line = reader.readLine()) != null) {
            inputs.add(line);
        }

        String[] result = new String[t];

        int j = 0;

        for(int i = 0; i < t; i++){
            int n = Integer.parseInt(inputs.get(j));
            String[] strings = inputs.get(j+1).split(" ");
            j += 2;

            int[] data = new int[n];

            for(int k = 0; k < n; k++){
                data[k] = Integer.parseInt(strings[k]);
            }

            result[i] = solution(data);
        }

        for(String r: result){
            System.out.println(r);
        }
    }

    public static String solution(int[] nums){
        int oddT = 0;
        int o = 0;

        int evenT = 0;
        int e = 0;

        for(int i = 0; i < nums.length; i++){
            if(i%2 == 0){
                evenT += nums[i];
                e += 1;
            }
            else{
                oddT += nums[i];
                o += 1;
            }
        }

        if((oddT+evenT) % nums.length != 0){
            return "NO";
        }

        boolean ans = oddT/o == evenT/e;

        if(ans){
            return "YES";
        }
        return "NO";

    }

}

Answer: 1


#include <iostream>
#include <string>

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;
            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;
            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


import java.util.*;

public class transfusion {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-->0) {

            int n = sc.nextInt();

            long a[] = new long[n];

            long avg = 0;

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

                a[i] = sc.nextLong();

                avg+=a[i];

            }

            avg/=n;

            long odd = a[0]-avg, even = a[1]-avg;

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

                if(i%2!=0) {

                    odd+=a[i+1]-avg;

                }else {

                    even+=a[i+1]-avg;

                }

            }

            if(odd==0 && even==0) {

                System.out.println("YES");

            }else {

                System.out.println("NO");

            }

        }

        sc.close();

    }

}

import java.util.*;

public class transfusion {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-->0) {

            int n = sc.nextInt();

            int a[] = new int[n];

            int avg = 0;

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

                a[i] = sc.nextInt();

                avg+=a[i];

            }

            avg/=n;

            int odd = a[0]-avg, even = a[1]-avg;

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

                if(i%2!=0) {

                    odd+=a[i+1]-avg;

                }else {

                    even+=a[i+1]-avg;

                }

            }

            if(odd==0 && even==0) {

                System.out.println("YES");

            }else {

                System.out.println("NO");

            }

        }

        sc.close();

    }

}

Answer: 1


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

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for(auto &it : arr){
            cin >> it;
        }

        long long sum_odd = 0, sum_even = 0;
        int n_odd = (n%2 == 0)? n/2 : n/2 + 1, n_even = n/2;

        for(int i = 0; i < n; i += 2){
            sum_odd += arr[i];
        }
        for(int j = 1; j < n; j += 2){
            sum_even += arr[j];
        }

        if(sum_odd % n_odd == 0 && sum_even % n_even == 0 && (sum_odd/n_odd) == (sum_even/n_even)){
            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> arr(n);
        for(auto &it : arr){
            cin >> it;
        }
        int diff;
        for(int i = 1; i < n-1; i++){
            diff = arr[i-1] - arr[i+1];
            if(diff == 0){continue;}
            if(diff % 2 == 0){
                arr[i+1] += diff/2;
                arr[i-1] -= diff/2;
            }else{
                arr[i-1] -= (diff+1)/2;
                arr[i+1] += (diff+1)/2;
            }
        }

        int num = arr[0];
        bool flag = true;
        for(int i = 1; i < n; i++){
            if(arr[i] != num){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Answer: 1


#include <iostream>

using namespace std;

#define int long long

int num[200010];

#include <cstring>

void solve() {

	int n = 0;

	cin >> n;

	int sum = 0;

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

		cin >> num[i];

		sum += num[i];

	}

	int t = sum / n;

	if (sum % n != 0){

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

		return;

	}

	else {

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

			if (num[i - 1] > t) {

				num[i + 1] += num[i - 1] - t;

				num[i - 1] = t;

			}

			else if (num[i + 1] > t) {

				num[i - 1] += num[i + 1] - t;

				num[i + 1] = t;

			}

		}

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

			if (num[i] != t) {

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

				return;

			}

		}

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

		return;

	}

}

signed main() {

	int t = 0;

	cin >> t;

	while (t--) {

		solve();

	}

	return 0;

}

#include <iostream>

using namespace std;

#define int long long

int num[200010];

#include <cstring>

void solve() {

	int n = 0;

	cin >> n;

	int sum = 0;

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

		cin >> num[i];

		sum += num[i];

	}

	int t = sum / n;

	if (sum % n != 0){

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

		return;

	}

	else {

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

			if (num[i - 1] > t) {

				num[i + 1] += num[i - 1] - t;

				num[i - 1] = t;

			}

			else  {

				num[i + 1] -= t - num[i - 1];

				num[i - 1] = t;

			}

		}

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

			if (num[i] != t) {

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

				return;

			}

		}

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

		return;

	}

}

signed main() {

	int t = 0;

	cin >> t;

	while (t--) {

		solve();

	}

	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++){

        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;

}

#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,s=0;

        cin>>n;

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

            int a;

            cin>>a;

            s+=a;

        }

        if(s%2){cout<<"NO"<<'\n';}

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

    }

    return 0;

}

Answer: 1


#include<iostream>

#include<bits/stdc++.h>

using namespace std;

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];

        int od = 0;

        int ev = 0;

        int od_sum = 0;

        int ev_sum = 0;

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

            od++;

            od_sum+=arr[i];

        }

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

            ev++;

            ev_sum+=arr[i];

        }

        if (od_sum%od==0 && ev_sum%ev==0 && od_sum/od == ev_sum/ev)

        cout << "YES" << endl;

        else

        cout << "NO" << endl;

    }

}

#include<iostream>

#include<bits/stdc++.h>

using namespace std;

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];

        int od = 0;

        int ev = 0;

        long long int od_sum = 0;

        long long int ev_sum = 0;

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

            od++;

            od_sum+=arr[i];

        }

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

            ev++;

            ev_sum+=arr[i];

        }

        if (od_sum%od==0 && ev_sum%ev==0 && od_sum/od == ev_sum/ev)

        cout << "YES" << endl;

        else

        cout << "NO" << endl;

    }

}

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;

#define x27pert              \

    ios::sync_with_stdio(0); \

    cin.tie(0);              \

    cout.tie(0);             \

    cout << setiosflags(ios::fixed) << setprecision(15);

using ll = long long;

using ld = long double;

// Define the PBDS type with pairs (value, frequency)

typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

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

#define mp make_pair

#define pb push_back

#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++)

#define rrep(i, n, m) for (ll i = (ll)(m) - 1; i >= (ll)(n); i--)

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

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

const ll MOD = 1e9 + 7;

const ld pi = 3.1415926535897932384626433832795;

using gint = greater<int>;

vector<pair<int,int>>d={{-1,0},{0,1},{1,0},{0,-1}};

bool isvalid(int n, int m,int i ,int j,vector<vector<char>>&v,vector<vector<bool>>&visited)

{

  return i<n && i>=0 && j<m && j>=0  && v[i][j]!='*' && !visited[i][j]  ;

}

void solve() {

           int n;

           cin>>n;

           vector<int>v(n);

           int sum=0;

           int ans=0;

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

           {

             cin>>v[i];

             if(i%2==0)

             {

               sum+=v[i];

             }

             else{

               ans+=v[i];

             }

           }

           int m=n/2;

           int l=m;

           if(n%2==1)

           {

             l++;

           }

           if(sum/l == ans/m && sum%l==0 && ans%l==0)

           {

             yes;

           }

           else{

             no;

           }

}

signed main()

{

    x27pert;

    int _;

    _ = 1;

  cin >> _;

    while (_--)

    {

        solve();

    }

    return 0;

}

// ll exp(ll x, ll n)

// {

//     assert(n >= 0);

//     // note: m * m must be less than 2^63 to avoid ll overflow

//     ll res = 1;

//     while (n > 0)

//     {

//         if (n % 2 == 1)

//         {

//             res = res * x ;

//         }

//         x = x * x ;

//         n /= 2;

//     }

//     return res;

// }

//

// bool isvalid(int i ,int j , vector<vector<ll>>&v,vector<vector<bool>>&visited)

// {

//   return i>=0 && i<n && j>=0 && j<m && !visited[i][j] && v[i][j]>0;

// }

// vector<pair<int,int>>dx={{-1,0},{0,-1},{1,0},{0,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;

#define x27pert              \

    ios::sync_with_stdio(0); \

    cin.tie(0);              \

    cout.tie(0);             \

    cout << setiosflags(ios::fixed) << setprecision(15);

using ll = long long;

using ld = long double;

// Define the PBDS type with pairs (value, frequency)

typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

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

#define mp make_pair

#define pb push_back

#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++)

#define rrep(i, n, m) for (ll i = (ll)(m) - 1; i >= (ll)(n); i--)

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

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

# define int long long

const ll MOD = 1e9 + 7;

const ld pi = 3.1415926535897932384626433832795;

using gint = greater<int>;

vector<pair<int,int>>d={{-1,0},{0,1},{1,0},{0,-1}};

bool isvalid(int n, int m,int i ,int j,vector<vector<char>>&v,vector<vector<bool>>&visited)

{

  return i<n && i>=0 && j<m && j>=0  && v[i][j]!='*' && !visited[i][j]  ;

}

void solve() {

           int n;

           cin>>n;

           vector<int>v(n);

           int sum=0;

           int ans=0;

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

           {

             cin>>v[i];

             if(i%2==0)

             {

               sum+=v[i];

             }

             else{

               ans+=v[i];

             }

           }

           int m=n/2;

           int l=m;

           if(n%2==1)

           {

             l++;

           }

           if(sum/l == ans/m && sum%l==0 && ans%m==0)

           {

             yes;

           }

           else{

             no;

           }

}

signed main()

{

    x27pert;

    int _;

    _ = 1;

  cin >> _;

    while (_--)

    {

        solve();

    }

    return 0;

}

// ll exp(ll x, ll n)

// {

//     assert(n >= 0);

//     // note: m * m must be less than 2^63 to avoid ll overflow

//     ll res = 1;

//     while (n > 0)

//     {

//         if (n % 2 == 1)

//         {

//             res = res * x ;

//         }

//         x = x * x ;

//         n /= 2;

//     }

//     return res;

// }

//

// bool isvalid(int i ,int j , vector<vector<ll>>&v,vector<vector<bool>>&visited)

// {

//   return i>=0 && i<n && j>=0 && j<m && !visited[i][j] && v[i][j]>0;

// }

// vector<pair<int,int>>dx={{-1,0},{0,-1},{1,0},{0,1}};

Answer: 2


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;

#define int long long
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define read(x,a,b) rep(i, a, b) cin>>x[i];
#define vi vector<int>
#define all(l) l.begin(), l.end()

typedef long long ll;
constexpr int N=1e6, mod=1e9+7, INF=1e18+5;

void solve()
{
    int n; cin >> n;
    vi a(n); read(a,0,n-1)
    int sum{0},even{0},odd{0};
    rep(i,0,n-1)
    {
        if (i&1) odd+=a[i];
        else even+=a[i];
    }
    int e{n/2},o{n/2};
    if (n&1) e++;
    if (odd%o || even%e || odd/o!=even/e) cout << "NO\n";
    else cout << "YES\n";
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t{1};
    cin >> t;
    while (t--) solve();
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;

#define int long long
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define read(x,a,b) rep(i, a, b) cin>>x[i];
#define vi vector<int>
#define all(l) l.begin(), l.end()

typedef long long ll;
constexpr int N=1e6, mod=1e9+7, INF=1e18+5;

void solve()
{
    int n; cin >> n;
    vi a(n); read(a,0,n-1)
    int sum{accumulate(all(a),0)};
    if (sum/n!=(sum+n-1)/n) {cout << "NO\n"; return;}
    int target{sum/n};
    rep(i,1,n-2)
    {
        int diff{target-a[i-1]};
        a[i-1]+=diff,a[i+1]-=diff;
    }
    rep(i,0,n-1)
    {
        if (a[i]!=target) {cout << "NO\n"; return;}
    }
    cout << "YES\n";
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t{1};
    cin >> t;
    while (t--) solve();
}

Answer: 1


def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0
    odd= (_size+1)//2
    sum2 = 0
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]

        else :
           sum2+=a[i]
   # print(sum1, sum2, odd ,even)
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
          print("NO")
          return
    else:
      print("NO")

t = int(input())
for _ in range(t):
       process_array()

def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0
    odd= (_size+1)/2
    sum2 = 0
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]
        else :
           sum2+=a[i]
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
          print("NO")
          return
    else:
      print("NO")

t = int(input())
for _ in range(t):
       process_array()

Answer: 1


OUT=[]
for i in range(int(input())):
    n=int(input())
    L=list(map(int,input().split()))
    s=sum(L)
    if s%n==0 :
        p=s//n
        k=1
        b=True
        while k<n-1 and b:
            if L[k-1]!= p:
                if L[k+1]-(p-L[k-1])<0:
                    b=False
                else:
                    L[k+1]-=p-L[k-1]
                    L[k-1]=p

            k+=1
        if b and L[-1]==p and L[-2]==p:
            OUT.append('YES')
        else:
            OUT.append('NO')

    else:
        OUT.append('NO')

for i in OUT:
    print(i)

OUT=[]
for i in range(int(input())):
    n=int(input())
    L=list(map(int,input().split()))
    s=sum(L)
    if s%n==0 :
        p=s//n
        k=1
        b=True
        while k<n-1 and b:
            if L[k-1]!= p:

                L[k+1]-=p-L[k-1]
                L[k-1]=p

            k+=1
        if b and L[-1]==p and L[-2]==p:
            OUT.append('YES')
        else:
            OUT.append('NO')

    else:
        OUT.append('NO')

for i in OUT:
    print(i)

Answer: 2


#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)))) z=true;
        }

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

}

}

// #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;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main()

{

  double t, n, a;

  cin >> t;

  while (t--)

  {

    cin >> n;

    double sum = 0, sum1 = 0, sum2 = 0;

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

    {

      cin >> a;

      sum += a;

      if (i % 2 == 0)

        sum1 += a;

      else

        sum2 += a;

    }

    double test = sum / (float)n;

    if ((int)sum % (int)n == 0 && sum1 == test * ceil(n / 2) && sum2 == test * int(n / 2))

      cout << "YES\n";

    else

      cout << "NO\n";

  }

}

#include <bits/stdc++.h>

using namespace std;

int main()

{

  long long t, n, a, b;

  cin >> t;

  while (t--)

  {

    cin >> n;

    long long sum = 0, sum1 = 0, sum2 = 0;

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

    {

      cin >> a;

      sum += a;

      if (i % 2 == 0)

        sum1 += a;

      else

        sum2 += a;

    }

    if (n % 2 == 0)

    {

      a = n / 2;

      b = n / 2;

    }

    else

    {

      a = n / 2 + 1;

      b = n / 2;

    }

    if (sum % n == 0 && sum1 == a * sum / n && sum2 == b * sum / n)

      cout << "YES\n";

    else

      cout << "NO\n";

  }

}

Answer: 2


#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define _test int _TEST; cin >> _TEST; while (_TEST--)
#define ll long long
#define all(a) (a).begin(), (a).end()

void solve() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  int even=0,odd=0;
  int n1=0,n2=0;
  for(int i = 0; i < n; i++)
  {
    if(i&1){
      even+=a[i];
      n1++;
    }else{
      odd+=a[i];
      n2++;
    }
  }
  if(even%n1==0 && odd%n2==0 && even/n1==odd/n2) cout<<"YES\n";
  else cout<<"NO\n";
}
int main() {
  _test {
solve();
 }
  return 0;
}

#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define _test int _TEST; cin >> _TEST; while (_TEST--)
#define ll long long
#define all(a) (a).begin(), (a).end()

void solve() {
  ll n;
  cin>>n;
  vector<ll>a(n);
  for(int i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  ll even=0,odd=0;
  ll n1=0,n2=0;
  for(int i = 0; i < n; i++)
  {
    if(i&1){
      even+=a[i];
      n1++;
    }else{
      odd+=a[i];
      n2++;
    }
  }
  if(even%n1==0 && odd%n2==0 && even/n1==odd/n2) cout<<"YES\n";
  else cout<<"NO\n";
}
int main() {
  _test {
solve();
 }
  return 0;
}

Answer: 2


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;

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

        while((line = reader.readLine()) != null) {
            inputs.add(line);
        }

        String[] result = new String[t];

        int j = 0;

        for(int i = 0; i < t; i++){
            int n = Integer.parseInt(inputs.get(j));
            String[] strings = inputs.get(j+1).split(" ");
            j += 2;

            int[] data = new int[n];

            for(int k = 0; k < n; k++){
                data[k] = Integer.parseInt(strings[k]);
            }

            result[i] = solution(data);
        }

        for(String r: result){
            System.out.println(r);
        }
    }

    public static String solution(int[] nums){
        int oddT = 0;
        int o = 0;

        int evenT = 0;
        int e = 0;

        for(int i = 0; i < nums.length; i++){
            if(i%2 == 0){
                evenT += nums[i];
                e += 1;
            }
            else{
                oddT += nums[i];
                o += 1;
            }
        }

        if((oddT+evenT) % nums.length != 0){
            return "NO";
        }

        int target = (oddT+evenT)/nums.length;
        boolean ans = oddT/o == target && evenT/e == target;

        if(ans){
            return "YES";
        }
        return "NO";

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;

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

        while((line = reader.readLine()) != null) {
            inputs.add(line);
        }

        String[] result = new String[t];

        int j = 0;

        for(int i = 0; i < t; i++){
            int n = Integer.parseInt(inputs.get(j));
            String[] strings = inputs.get(j+1).split(" ");
            j += 2;

            int[] data = new int[n];

            for(int k = 0; k < n; k++){
                data[k] = Integer.parseInt(strings[k]);
            }

            result[i] = solution(data);
        }

        for(String r: result){
            System.out.println(r);
        }
    }

    public static String solution(int[] nums){
        double oddT = 0;
        int o = 0;

        double evenT = 0;
        int e = 0;

        for(int i = 0; i < nums.length; i++){
            if(i%2 == 0){
                evenT += nums[i];
                e += 1;
            }
            else{
                oddT += nums[i];
                o += 1;
            }
        }

        if((oddT+evenT) % nums.length != 0){
            return "NO";
        }

        boolean ans = oddT/o == evenT/e;

        if(ans){
            return "YES";
        }
        return "NO";

    }

}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

void gotoo(){

    long long n;

    cin>>n;

    long long a[n],i,sum=0;

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

        cin>>a[i];

        sum+=a[i];

    }

    if(sum%n!=0){

        cout<<"NO"<<endl;

        return;

    }

    long long ch=sum/n;

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

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

            long long ne1=a[i-1]-ch;

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

            a[i+1]=a[i+1]+ne1;

        }

        else if(a[i-1]<ch){

            long long nee=ch-a[i-1];

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

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

        }

    }

    if(a[n-2]==ch && a[n-1]==ch)

        cout<<"YES"<<endl;

    else

        cout<<"NO"<<endl;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        gotoo();

    }

}

#include<bits/stdc++.h>

using namespace std;

void gotoo(){

    int n;

    cin>>n;

    int a[n],i,sum=0;

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

        cin>>a[i];

        sum+=a[i];

    }

    if(sum%n!=0){

        cout<<"NO"<<endl;

        return;

    }

    int ch=sum/n;

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

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

            int ne1=a[i-1]-ch;

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

            a[i+1]=a[i+1]+ne1;

        }

        else if(a[i-1]<ch){

            int nee=ch-a[i-1];

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

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

        }

    }

    if(a[n-2]==ch && a[n-1]==ch)

        cout<<"YES"<<endl;

    else

        cout<<"NO"<<endl;

}

int main(){

    int t;

    cin>>t;

    while(t--){

        gotoo();

    }

}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
void solve(vector<long long> finder, long long n){
    long long sum_even = 0;
    long long count_even = 0;
    long long sum_odd = 0;
    long long count_odd = 0;
    for(long long i = 0; i<n; i++){
        if(i%2 == 0){
            sum_even+=finder[i];
            count_even++;
        }
        else{
            sum_odd+=finder[i];
            count_odd++;
        }
    }
    if(sum_odd%count_odd!=0 || sum_even%count_even!=0){
        cout<<"NO"<<endl;
        return;
    }
    else if(sum_odd/count_odd!=sum_even/count_even){
        cout<<"NO"<<endl;
        return;
    }
    else {
        cout<<"YES"<<endl;
        return ;
    }
}
int main() {
    long long t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        vector<long long> finder(n);
        for(long long i = 0; i<n; i++){
            cin>>finder[i];
        }
        solve(finder,n);
    }
}

#include <bits/stdc++.h>
using namespace std;
void solve(vector<int>finder, int n){
    int sum_even = 0;
    int count_even = 0;
    int sum_odd = 0;
    int count_odd = 0;
    for(int i = 0; i<n; i++){
        if(i%2 == 0){
            sum_even+=finder[i];
            count_even++;
        }
        else{
            sum_odd+=finder[i];
            count_odd++;
        }
    }
    if(sum_odd%count_odd!=0 || sum_even%count_even!=0){
        cout<<"NO"<<endl;
        return;
    }
    else if(sum_odd/count_odd!=sum_even/count_even){
        cout<<"NO"<<endl;
        return;
    }
    else {
        cout<<"YES"<<endl;
        return ;
    }

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

}

Answer: 1


#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, 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 = A[i - 1] - d;

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

                    A[i - 1] = d;

                }

                else

                {

                    k = d - A[i - 1];

                    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)

#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;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n,oddsm=0,evensm=0,oddcnt=0,evencnt=0;

        cin>>n;

        int arr[n];

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

            cin>>arr[i];

            if(i%2==0){

                evensm+=arr[i];

                evencnt++;

            }

            else{

                oddsm+=arr[i];

                oddcnt++;

            }

        }

        if(evensm%evencnt!=0 || oddsm%oddcnt !=0 || evensm/evencnt!=oddsm/oddcnt)

            cout<<"NO\n";

        else cout<<"YES\n";

    }

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        int arr[n];

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

            cin>>arr[i];

        }

        long long oddsm=0,evensm=0,oddcnt=0,evencnt=0;

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

            if(i%2==0){

                evensm+=arr[i];

                evencnt++;

            }

            else{

                oddsm+=arr[i];

                oddcnt++;

            }

        }

        if (oddsm%oddcnt == 0 && evensm%evencnt == 0 && oddsm * evencnt == evensm * oddcnt)

            cout << "YES" << endl;

        else

            cout << "NO" << endl;

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define nl "\n"
#define INF 1e18

void mainCode(){
    ll n=0,k;
    cin >> n ;
    vector<ll> v(n);
    ll sum=0;
    for(ll i=0;i<n;i++) {
        cin >> v[i];
        sum+=v[i];
    }
    if(sum%3==0) cout << "YES\n";
    else cout << "NO\n";

}

int main()
{
    int tc=0;
    cin >> tc;
    while(tc--)
    {
        mainCode();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define nl "\n"
#define INF 1e18

void mainCode(){
    ll n=0,k;
    cin >> n ;
    vector<ll> v(n);
    ll odd=0,even=0;
    for(ll i=0;i<n;i++) {
        cin >> v[i];
        if(i &1) odd+=v[i];
        else even+=v[i];
    }
    ll nodd=n/2,neven=n/2;
    if(n&1) neven++;

    if(odd % nodd != 0 || even % neven != 0 || odd / nodd != even / neven){
        cout << "NO\n";
    }
    else cout << "YES\n";

}

int main()
{
    int tc=0;
    cin >> tc;
    while(tc--)
    {
        mainCode();
    }
    return 0;
}

Answer: 2


a=int(input())
for _ in range(a):
    b=int(input())
    c=list(map(int,input().split()))
    if sum(c)%b!=0:
        print('NO')
    else:
        t=sum(c)//b
        w=[]
        l=[]
        for i in range(b):
            if i%2==0:
                w.append(c[i])
            else:
                l.append(c[i])
        if sum(l)//len(l)==t==sum(w)//len(w):
            print('YES')
        else:
            print('NO')

a=int(input())
for _ in range(a):
    b=int(input())
    c=list(map(int,input().split()))
    if sum(c)%b!=0:
        print('NO')
        exit()
    t=sum(c)//b
    w=[]
    l=[]
    for i in range(b):
        if i%2==0:
            w.append(c[i])
        else:
            l.append(c[i])
    if sum(l)//len(l)==t==sum(w)//len(w):
        print('YES')
    else:
        print('NO')

Answer: 1


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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <ll> v(n);
        set <ll> st;
        for (int i=0; i<n; i++) {
            cin >> v[i];
            st.insert(v[i]);
        }
        if (st.size() == 1) {
            cout << "yes\n";
            continue;
        }
        ll mn = INT_MAX;
        int pos = -1;
        for (int i=2; i<n; i ++) {
            ll diff = abs(v[i] - v[i-2]);
            if (diff > 0 && diff % 2 == 0 && diff < mn) {
                mn = diff;
                pos = i;
            }
        }
        if (pos == -1) {
            cout << "no\n";
            continue;
        }
        //cout << pos << " ";
        ll target;
        if (v[pos] > v[pos - 2]) target = v[pos] - mn/2;
        else target = v[pos] + mn/2;
        ll tot = 0;
        for (ll num: v) {
            tot += num - target;
        }
        if (tot == 0) cout << "yes\n";
        else cout << "no\n";
    }
}

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        ll od = 0, ev = 0;
        for (int i=0; i<n; i++) {
            int x;
            cin >> x;
            if (i%2 == 0) ev += x;
            else od += x;
        }
        ll eve = n / 2, ode = n / 2;
        if (n%2 != 0) eve ++;
        if (ev % eve == 0 && od % ode == 0 && ev / eve == od / ode) cout << "yes\n";
        else cout << "no\n";
    }
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define int long long int

const int N = 2 * 100010;

#define M 1000000007

void print_vect(vector<int> &v) {

    for (auto i : v) {

        cout << i << " ";

    }

    cout << endl;

}

vector<int> seg;

void build_seg(int ind, int low, int high, vector<int> &a) {

    if (low == high) {

        seg[ind] = a[low];

        return;

    }

    int mid = (low + high) / 2;

    build_seg(2 * ind + 1, low, mid, a);

    build_seg(2 * ind + 2, mid + 1, high, a);

    seg[ind] = __gcd(seg[2 * ind + 1], seg[2 * ind + 2]);

}

int seg_queries(int ind, int low, int high, int l, int r) {

    if (low >= l && high <= r)

        return seg[ind];

    if (high < l || low > r)

        return 0;

    int mid = (low + high) / 2;

    int left = seg_queries(2 * ind + 1, low, mid, l, r);

    int right = seg_queries(2 * ind + 2, mid + 1, high, l, r);

    return __gcd(left, right);

}

void point_update(int ind, int low, int high, int node, int val) {

    if (low == high && low == node) {

        seg[ind] = val;

        return;

    }

    int mid = (low + high) / 2;

    if (node <= mid && node >= low) {

        point_update(2 * ind + 1, low, mid, node, val);

    } else {

        point_update(2 * ind + 2, mid + 1, high, node, val);

    }

    seg[ind] = min(seg[2 * ind + 1], seg[2 * ind + 2]);

}

int binexp(int a, int b, int m) {

    int ans = 1;

    while (b) {

        if (b & 1) {

            ans *= a;

            ans = ans % m;

        }

        a = a * a;

        a = a % m;

        b = b / 2;

    }

    return ans % m;

}

int mod_inverse(int a, int b) {

    return binexp(a, b - 2, b);

}

int sol(int a, int b, int c) {

    int gcd = __gcd(a, b);

    int k1 = a / gcd;

    int k2 = b / gcd;

    return (mod_inverse(k1, k2) * (c / gcd)) % k2;

}

void dfs(vector<vector<int>> &graph, int node, vector<int> &par, vector<int> &vis) {

    if (vis[node] == 1) {

        return;

    }

    vis[node] = 1;

    for (auto child : graph[node]) {

        if (vis[child] == 1) {

            continue;

        }

        par[child] = node;

        dfs(graph, child, par, vis);

    }

}

int32_t main() {

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin>>n;

        vector<int>v;

        int sum = 0;

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

            int x;

            cin>>x;

            v.push_back(x);

            sum += x;

        }

        if(sum%n!= 0 ){

            cout<<"NO"<<endl;

        }

        else{

            int k = sum/n;

            int fl = 0;

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

                int l = abs(v[i-1] - k);

                if(v[i-1]>=k){

                    v[i+1] += l;

                }

                else{

                    v[i+1]-=l;

                    if(v[i+1]<0){

                        fl = 1;

                        break;

                    }

                }

                v[i-1] = k;

            }

            //print_vect(v);

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

                if(v[i]!=k){

                    fl = 1;

                }

            }

            if(fl == 0){

                cout<<"YES"<<endl;

            }

            else{

                cout<<"NO"<<endl;

            }

        }

    }

}

#include <bits/stdc++.h>

using namespace std;

#define int long long int

const int N = 2 * 100010;

#define M 1000000007

void print_vect(vector<int> &v) {

    for (auto i : v) {

        cout << i << " ";

    }

    cout << endl;

}

vector<int> seg;

void build_seg(int ind, int low, int high, vector<int> &a) {

    if (low == high) {

        seg[ind] = a[low];

        return;

    }

    int mid = (low + high) / 2;

    build_seg(2 * ind + 1, low, mid, a);

    build_seg(2 * ind + 2, mid + 1, high, a);

    seg[ind] = __gcd(seg[2 * ind + 1], seg[2 * ind + 2]);

}

int seg_queries(int ind, int low, int high, int l, int r) {

    if (low >= l && high <= r)

        return seg[ind];

    if (high < l || low > r)

        return 0;

    int mid = (low + high) / 2;

    int left = seg_queries(2 * ind + 1, low, mid, l, r);

    int right = seg_queries(2 * ind + 2, mid + 1, high, l, r);

    return __gcd(left, right);

}

void point_update(int ind, int low, int high, int node, int val) {

    if (low == high && low == node) {

        seg[ind] = val;

        return;

    }

    int mid = (low + high) / 2;

    if (node <= mid && node >= low) {

        point_update(2 * ind + 1, low, mid, node, val);

    } else {

        point_update(2 * ind + 2, mid + 1, high, node, val);

    }

    seg[ind] = min(seg[2 * ind + 1], seg[2 * ind + 2]);

}

int binexp(int a, int b, int m) {

    int ans = 1;

    while (b) {

        if (b & 1) {

            ans *= a;

            ans = ans % m;

        }

        a = a * a;

        a = a % m;

        b = b / 2;

    }

    return ans % m;

}

int mod_inverse(int a, int b) {

    return binexp(a, b - 2, b);

}

int sol(int a, int b, int c) {

    int gcd = __gcd(a, b);

    int k1 = a / gcd;

    int k2 = b / gcd;

    return (mod_inverse(k1, k2) * (c / gcd)) % k2;

}

void dfs(vector<vector<int>> &graph, int node, vector<int> &par, vector<int> &vis) {

    if (vis[node] == 1) {

        return;

    }

    vis[node] = 1;

    for (auto child : graph[node]) {

        if (vis[child] == 1) {

            continue;

        }

        par[child] = node;

        dfs(graph, child, par, vis);

    }

}

int32_t main() {

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin>>n;

        vector<int>v;

        int sum = 0;

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

            int x;

            cin>>x;

            v.push_back(x);

            sum += x;

        }

        if(sum%n!= 0 ){

            cout<<"NO"<<endl;

        }

        else{

            int k = sum/n;

            int fl = 0;

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

                int l = abs(v[i-1] - k);

                if(v[i-1]>=k){

                    v[i+1] += l;

                }

                else{

                    v[i+1]-=l;

                }

                v[i-1] = k;

            }

            //print_vect(v);

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

                if(v[i]!=k){

                    fl = 1;

                }

            }

            if(fl == 0){

                cout<<"YES"<<endl;

            }

            else{

                cout<<"NO"<<endl;

            }

        }

    }

}

Answer: 2


#include "bits/stdc++.h"
using namespace std;
const int N = 2e5+5;
int t,n,a[N],d[N];
int main(){
	cin >> t; while(t--){
		cin >> n;
		for(int i=1;i<=n;i++){
			cin >> a[i];
			d[i] = a[i] - a[i-1];
//			printf("%d ",d[i]);
		}
//		cout << endl;
		for(int i=2;i<n;i++){
			if(i!=n-1){
				int b = d[i] - (d[i] - d[i+1])/2;
				d[i-1] += b;
				d[i] -= b;
				d[i+1] -= b;
				d[i+2] += b;
			}else{
				int b = d[i];
				d[i-1] += b;
				d[i] -= b;
				d[i+1] -= b;
			}
		}
		int ans = 0;
		for(int i=2;i<=n;i++){
			ans += d[i]==0;
//			printf("%d ",d[i]);
		}
//		cout << endl;

		if(ans==n-1)cout<<"Yes\n";
		else cout<<"No\n";
	}

	return 0;
}

#include "bits/stdc++.h"
using namespace std;
int t,n,a;
int main(){
	cin >> t; while(t--){
		cin >> n;
		long long dan=0,dann=0,shuang=0,shuangn=0;
		for(int i=1;i<=n;i++){
			cin >> a;
			if(i%2){
				dan += a;
				dann++;
			}else{
				shuang += a;
				shuangn++;
			}
		}
		if(dan%dann==0 and shuang%shuangn==0 and dan/dann == shuang/shuangn) cout<<"yes\n";
		else cout<<"no\n";

	}

}

Answer: 2