Fox Ciel likes sequences. One day, she invented a new type of sequence and named it the fox sequence. A sequence seq containing N elements is called a fox sequence if and only if there exist four integers a, b, c and d such that 0 < a < b <= c < d < N-1 and the following five conditions are met:
In the following image, the top 3 sequences are fox sequences, while the bottom 3 sequences are not:
|
#P1271. Fox'sProblem
Fox'sProblem
Input
The input will consist of several test cases. For each test case, one integer N (3 <= N <= 15) is given in the first line. Second line contains N integers. The input is terminated by a single line with N = 0.
Output
For each test of the input, print the answer.
Sample Input
15
1 3 5 7 5 3 1 1 1 3 5 7 5 3 1
3
6 1 6
0
Sample Output
YES
NO