Symmetric Clearing
InterviewTime limit2sMemory limit1024 MB
Given n trees around a circle, each birch or pine, decide whether some line through the center reflects the circle onto itself.
- Level
Medium5 of 10
- Topics
- String, String matching, Array
- Solved
- No attempts yet
Problem
There are many forests, but not every one of them is magical. A forest must satisfy many conditions to be magical. These conditions are not fully studied yet, but one is known for certain: a forest cannot be magical if it has no round symmetric clearing. For simplicity, consider a forest with birch and pine trees. This forest has exactly one round clearing. Around it grow trees. Each tree is either a pine or a birch. An axis of the clearing is a straight line that passes through the center of the clearing and splits it into two halves. If the line passes through a tree, that tree belongs to both halves. If one half is symmetric to the other, the line is a symmetry axis and the clearing is symmetric. The following clearings are symmetric (white circles are birches, black circles are pines):
This clearing is not symmetric no matter which axis we choose: 
Input
The first line contains one integer (), the number of tests. Each test is described by two lines. The first line contains one integer (), the number of trees around the clearing. The second line contains integers (), describing the trees in clockwise order. means birch and means pine.
Output
Print lines. On line , print Yes if the clearing in the -th test has a symmetry axis, and No otherwise.