Question
Array Level
Bob receives an array A of length N in a programming contest. He can select any index i (1 < i < N) and reduce A[i] if it’s not less than both neighbors (A[i] ≥ A[i − 1] and A[i] ≥ A[i + 1]).
Determine if Bob can make all elements in A equal through repeated operations.
Determine if Bob can make all elements in A equal through repeated operations.
Input
The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of two lines of input.
The first line of each test case contains N - the number of elements in A.
The second line of each test case contains N space-separated integers, denoting the array A.
Each test case consists of two lines of input.
The first line of each test case contains N - the number of elements in A.
The second line of each test case contains N space-separated integers, denoting the array A.
Output
For each test case, output on a new line the answer: "Yes" if it is possible to make all the elements of A equal, and "No" otherwise (without quotes).
Example
Sample Input
3
1
1
4
1 3 2 1
7
2 4 5 1 4 5 3
Sample Output
Yes
Yes
No
Explanation
Test case 1: A contains only a single element, so all its elements are already equal.
Test case 2: Perform operations as follows:
Choose i = 2, and decrease it, to get [1, 2, 2, 1].
Choose i = 2 again and decrease it, to get [1, 1, 2, 1].
Choose i = 3 and decrease it, to get [1, 1, 1, 1].
All elements are equal now.
3
1
1
4
1 3 2 1
7
2 4 5 1 4 5 3
Sample Output
Yes
Yes
No
Explanation
Test case 1: A contains only a single element, so all its elements are already equal.
Test case 2: Perform operations as follows:
Choose i = 2, and decrease it, to get [1, 2, 2, 1].
Choose i = 2 again and decrease it, to get [1, 1, 2, 1].
Choose i = 3 and decrease it, to get [1, 1, 1, 1].
All elements are equal now.