시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 215 26 21 15.909%

문제

암호문을 만드는 방법에는 여러 가지가 있는데, 보통 이를 위해서 암호화 하려는 글(혹은 파일 등)을 하나의 수열로 나타내게 된다. 이 문제에서는 A[1], A[2], …, A[n]의 수열을 암호화 하려 한다고 하자.

이 수열을 암호화 하는 대단히 효율적인 알고리즘을 발견하였는데, 이 알고리즘에는 약점이 하나 있다. 바로 수열이 특정 조건을 만족할 경우에는 복호화(암호문을 다시 원래의 글로 바꾸는 것)가 유일하지 않게 된다는 점이다.

수열이 주어졌을 때, 이 수열이 우리가 사용하려는 암호화 알고리즘의 약점인지 아닌지를 판별하는 프로그램을 작성하여라.

수열이 1 ≤ p < q < r < s ≤ n 을 만족하는 p, q, r, s 에 대해서 A[q] < A[s] < A[p] < A[r]이나 A[q] > A[s] > A[p] > A[r]를 만족하는 경우가 있다면 이러한 경우가 약점이 된다. 즉, 1 ≤ p < q < r < s ≤ n 이 되도록 p, q, r, s를 어떻게 잘 선택했는데, 이 때 A[q] < A[s] < A[p] < A[r]이 만족되거나, A[q] > A[s] > A[p] > A[r]이 만족되는 경우가 약점이다.

입력

첫째 줄에 데이터의 개수 T(1≤T≤10)가 주어진다. 각각의 데이터의 첫째 줄에는 n(4≤n≤5,000)이 주어진다. 그 다음 줄에는 차례로 A[1], A[2], …, A[n]이 주어진다. 각각의 A[i]는 1이상 10,000 이하이다. 모든 A[i]는 서로 다르다고 가정하자.

출력

T개의 줄에 각각의 데이터에 대한 결과를 출력한다. 약점인 경우에는 Yes를, 아닌 경우에는 No를 출력한다.

예제 입력 1

3
6
10 30 60 40 20 50
8
30 40 10 20 80 50 60 70
4
1 2 20 9

예제 출력 1

Yes
No
No
W3sicHJvYmxlbV9pZCI6IjIyNzEiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWM1NTRcdWQ2MzhcdWQ2NTQgXHVjNTRjXHVhY2UwXHViOWFjXHVjOTk4XHVjNz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