#K72197. Rearranging Books to Satisfy Julia
Rearranging Books to Satisfy Julia
Rearranging Books to Satisfy Julia
Julia has a keen interest in her book collection and wishes to rearrange the books so that her favorite book appears in the middle. For an odd number of books, the favorite must be exactly in the center, and for an even number, it can be placed in one of the two central positions. Since any permutation of the books is allowed, the key is to check whether Julia's favorite book is present in the collection.
Your task is to determine whether, given a list of books, it is possible to rearrange them so that the favorite book can be placed in the desired central position.
inputFormat
The input begins with an integer T denoting the number of test cases. Each test case consists of three lines:
- The first line contains an integer N, the number of books.
- The second line contains N space-separated integers representing the book numbers.
- The third line contains an integer F, the number of Julia's favorite book.
Constraints: 1 ≤ N ≤ 10^5 and book numbers are positive integers.
outputFormat
For each test case, output a single line with "Yes" if it is possible to rearrange the books so that Julia's favorite book is in the required middle position; otherwise, output "No".## sample
3
5
3 8 1 7 2
7
4
2 4 6 8
3
1
5
5
Yes
No
Yes
</p>