#P1271. Fox'sProblem

Fox'sProblem

     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:
  • seq[0], seq[1], ... , seq[a] forms an arithmetic progression with a positive common difference. An arithmetic progression is a sequence where the difference between successive elements is equal. The difference between successive elements is called the common difference. Note that 0 is neither positive nor negative.
  • seq[a], seq[a+1], ... , seq[b] forms an arithmetic progression with a negative common difference.
  • seq[b], seq[b+1], ... , seq[c] are all equal.
  • seq[c], seq[c+1], ... , seq[d] forms an arithmetic progression with a positive common difference.
  • seq[d], seq[d+1], ... , seq[N-1] forms an arithmetic progression with a negative common difference.

In the following image, the top 3 sequences are fox sequences, while the bottom 3 sequences are not:

You are given a sequence seq. Return "YES" if it is a fox sequence, or "NO" if it is not (all quotes for clarity).

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

HINT

Source