2050B.md (1419B)
1 Source: https://codeforces.com/problemset/problem/2050/B 2 3 B. Transfusion 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given an array $a$ of length $n$. In one operation, you can pick an index $i$ from $2$ to $n-1$ inclusive, and do one of the following actions: 22 23 * Decrease $a_{i-1}$ by $1$, then increase $a_{i+1}$ by $1$. 24 * Decrease $a_{i+1}$ by $1$, then increase $a_{i-1}$ by $1$. 25 26 After each operation, all the values must be non-negative. Can you make all the elements equal after any number of operations? 27 28 Input 29 30 First line of input consists of one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 31 32 First line of each test case consists of one integer $n$ ($3 \le n \le 2\cdot 10^5$). 33 34 Second line of each test case consists of $n$ integers $a_i$ ($1 \le a_i \le 10^9$). 35 36 It is guaranteed that the sum of $n$ of all test cases doesn't exceed $2\cdot 10^5$. 37 38 Output 39 40 For each test case, print "YES" without quotation marks if it is possible to make all the elements equal after any number of operations; otherwise, print "NO" without quotation marks. 41 42 You can print answers in any register: "yes", "YeS", "nO" — will also be considered correct. 43 44 Example 45 46 Input 47 48 ``` 49 8 50 51 3 52 53 3 2 1 54 55 3 56 57 1 1 3 58 59 4 60 61 1 2 5 4 62 63 4 64 65 1 6 6 1 66 67 5 68 69 6 2 1 4 2 70 71 4 72 73 1 4 2 1 74 75 5 76 77 3 1 2 1 3 78 79 3 80 81 2 4 2 82 ``` 83 84 Output 85 86 ``` 87 YES 88 NO 89 YES 90 NO 91 YES 92 NO 93 NO 94 NO 95 ```