Melody
Time limit1sMemory limit1024 MB
Given counts a_1 to a_N for notes 1 to N, decide whether a sequence starting at note 1 can visit each note a_i times, moving to an adjacent note at each step.
- Level
Medium6 of 10
- Topics
- Math, Graph, Prefix sum
- Solved
- No attempts yet
Problem
Seonghyeon, who likes composing, wants to make a melody using only notes. The notes are numbered from to . Arranging all notes in the order you want makes a melody.
Seonghyeon wants to build the melody under these rules.
- The first note of the melody must be note .
- To keep the melody natural, note must be followed by note or note .
- The melody must contain notes times respectively.
Given , determine whether a melody that satisfies the rules above can be made.
Input
The first line contains the number of test cases .
The first line of each test case contains an integer .
The second line of each test case contains integers separated by spaces.
The sum of over all test cases is at most .
Output
For each test case, print YES if a melody that satisfies the rules can be made, and NO otherwise.