Four Season
View as PDFAfter extreme changes in the Earth's climate, Parsa started studying temperatures in different countries. In each country, the number of days in a year may be different.
If each season in a country lasts days, then the whole year has
days.
The temperature pattern of each country is periodic with period . In other words, the
temperature of any day is the same as the temperature
days later.
Parsa observed the temperatures of consecutive days and gives them to you. Note that he did
not necessarily start collecting data from the first day of spring.
The seasons of each country are, in order:
- Spring
- Summer
- Autumn
- Winter
A summer is called hellish if the sum of temperatures in that summer is not smaller than the
sum of temperatures of any other consecutive days in the year.
A winter is called freezing if the sum of temperatures in that winter is not greater than the
sum of temperatures of any other consecutive days in the year.
From Parsa's point of view, a country is a four-season country if its summer is hellish and its winter is freezing.
For each test case, determine whether it is possible that the given list is a sequence of
consecutive days from such a country. Equivalently, determine whether it is possible to rotate the
cyclic sequence so that:
- the year is split into spring, summer, autumn, and winter, each of length
- the chosen summer is hellish
- the chosen winter is freezing
Print Yes if such a rotation exists, otherwise print No.
Input
The first line contains an integer , the number of test cases.
Each test case consists of two lines:
- The first line contains an integer
- The second line contains
integers
Here, is the temperature of the
-th day in the given cyclic order.
Output
For each test case, print:
Yesif the sequence can represent such a countryNootherwise
Constraints
- the sum of
over all test cases does not exceed
.
Example 1
Input
3
1
1 2 3 4
1
1 3 4 2
2
1 2 3 4 4 3 2 1
Output
No
Yes
Yes
Comments