atcoder#AGC058C. [AGC058C] Planar Tree
[AGC058C] Planar Tree
Score : points
Problem Statement
There are vertices on a circumference. The vertices are numbered to in clockwise order, and Vertex has an integer written on it, where is , , , or . Here, contains each of , , , and at least once.
Consider making a tree by adding edges connecting these vertices. Here, the following conditions must be satisfied.
- If Vertices and are directly connected by an edge, .
- When the edges are drawn as segments, no two of them intersect except at an endpoint.
For instance, the figure below shows a tree that satisfies the conditions:
Determine whether it is possible to construct a tree that satisfies the conditions.
Solve test cases for each input file.
Constraints
- contains each of , , , and at least once.
- The sum of in one input file does not exceed .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Each case is in the following format:
Output
For each case, print Yes
if it is possible to construct a tree that satisfies the conditions, and No
otherwise.
3
4
1 2 3 4
4
1 3 4 2
4
1 4 2 3
Yes
Yes
No
3
8
4 2 3 4 1 2 2 1
8
3 2 2 3 1 3 3 4
8
2 3 3 2 1 4 1 4
Yes
Yes
No
The first test case corresponds to the figure in the Problem Statement.