#K49992. Ordered Subsequence Split

    ID: 28765 Type: Default 1000ms 256MiB

Ordered Subsequence Split

Ordered Subsequence Split

You are given a sequence of N integers. Your task is to determine whether it is possible to split the sequence into two non-empty subsequences such that each subsequence is either in strictly increasing order or in strictly decreasing order.

In other words, if the sequence is entirely sorted in strictly increasing order \(a_1 < a_2 < \cdots a_2 > \cdots > a_N\), then the answer is NO. Otherwise, the answer is YES.

Note: A subsequence here means that you can partition the sequence into two non-empty parts (not necessarily contiguous) where each part satisfies one of the monotonic orderings.

inputFormat

The first line of the input contains an integer T (1 ≤ T ≤ 100), representing the number of test cases.

Each test case consists of two lines. The first line contains an integer N (2 ≤ N ≤ 105), indicating the length of the sequence. The second line contains N space-separated integers representing the sequence.

outputFormat

For each test case, output a single line containing either YES or NO. Output YES if the sequence can be split into two non-empty subsequences as described; otherwise, output NO.

## sample
2
5
5 1 4 3 2
4
4 3 2 1
YES

NO

</p>