CF2164A.Sequence Game

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Sequence Game

Given an integer sequence of length nn denoted as a1,a2,,ana_1,a_2,\ldots,a_n and an integer xx.

You can perform the following operation: select two adjacent numbers aia_i and ai+1a_{i+1} and replace them with an integer yy, which satisfies min(ai,ai+1)ymax(ai,ai+1)\min(a_i,a_{i+1}) \le y \le \max(a_i,a_{i+1}). After the replacement, the original aia_i and ai+1a_{i+1} are removed from the sequence, and the elements are renumbered from 11 to n1n-1.

For example, for a=[1,2,4,5]a=[1,2,4,5] you can select a2=2a_2=2 and a3=4a_3=4, and replace them with 33. After that, aa becomes [1,3,5][1,3,5]. However, you cannot select a1=1a_1=1 and a2=2a_2=2 and replace them with 33 (since yy is bigger than max(ai,ai+1)\max(a_i,a_{i+1}), nor can you select a1=1a_1=1 and a3=4a_3=4 (the selected numbers should be adjacent).

Clearly, after performing n1n-1 operations, only one number will remain. The question is whether this final number can be exactly equal to xx.

Input

Each test contains multiple test cases. The first line contains the number of test cases TT (1T5001 \le T \le 500). The description of the test cases follows.

The first line of each test case contains one integer nn (1n1001 \le n \le 100).

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (109ai109-10^9 \le a_i \le 10^9).

The third line of each test case contains one integer xx (109x109-10^9 \le x \le 10^9).

Output

For each test case, output "YES" (without quotes) if the final number can be exactly equal to xx, and "NO" otherwise.

You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

Note

In the first test case, you can first select a2=7a_2=7 and a3=5a_3=5, and replace them with 66. After that, aa becomes [2,6][2, 6]. Now you can select a1=2a_1=2 and a2=6a_2=6, and replace them with 44.

In the second test case, it can be shown that the final number can never be 88.

Samples

3
3
2 7 5
4
5
-1 3 7 -9 -2
8
6
1 -1 -4 5 1 -4
-2
YES
NO
YES

在线编程 IDE

建议全屏模式获得最佳体验