Milya and Two Arrays
Contest: Codeforces Round 1002 (Div. 2)
Difficulty rating: 800
Tags: constructive algorithms, greedy, sortings

An array is called good if for any element $$$x$$$ that appears in this array, it holds that $$$x$$$ appears at least twice in this array. For example, the arrays $$$[1, 2, 1, 1, 2]$$$, $$$[3, 3]$$$, and $$$[1, 2, 4, 1, 2, 4]$$$ are good, while the arrays $$$[1]$$$, $$$[1, 2, 1]$$$, and $$$[2, 3, 4, 4]$$$ are not good.

Milya has two good arrays $$$a$$$ and $$$b$$$ of length $$$n$$$. She can rearrange the elements in array $$$a$$$ in any way. After that, she obtains an array $$$c$$$ of length $$$n$$$, where $$$c_i = a_i + b_i$$$ ($$$1 \le i \le n$$$).

Determine whether Milya can rearrange the elements in array $$$a$$$ such that there are at least $$$3$$$ distinct elements in array $$$c$$$.

Input format:
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$) — the length of the arrays $$$a$$$ and $$$b$$$.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$.

The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 10^9$$$) — the elements of the array $$$b$$$.

Output format:
For each test case, output $$$«$$$YES$$$»$$$ (without quotes) if it is possible to obtain at least $$$3$$$ distinct elements in array $$$c$$$, and $$$«$$$NO$$$»$$$ otherwise.

You can output each letter in any case (for example, $$$«$$$YES$$$»$$$, $$$«$$$Yes$$$»$$$, $$$«$$$yes$$$»$$$, $$$«$$$yEs$$$»$$$ will be recognized as a positive answer).

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first test case, you can swap the second and third elements. Then the array $$$a = [1, 1, 2, 2]$$$, $$$b = [1, 2, 1, 2]$$$, and then $$$c = [2, 3, 3, 4]$$$.

In the second test case, you can leave the elements unchanged. Then $$$c = [2, 3, 4, 4, 3, 2]$$$.

In the third test case, the array $$$a$$$ will not change from rearranging the elements in it. Then $$$c = [2, 2, 2]$$$, so the answer is $$$«$$$NO$$$»$$$.

Example input:
5
4
1 2 1 2
1 2 1 2
6
1 2 3 3 2 1
1 1 1 1 1 1
3
1 1 1
1 1 1
6
1 52 52 3 1 3
59 4 3 59 3 4
4
100 1 100 1
2 2 2 2

Example output:
YES
YES
NO
YES
NO

Editorial:
If there are at least three distinct values in any of the arrays, the answer is $$$yes$$$. We can select any three elements from the other array and arrange them in increasing order, then the corresponding sums will also increase.
If each array contains exactly two distinct values, the answer is also $$$yes$$$. If we find elements $$$x$$$ and $$$y$$$ in the first array, where $$$x < y$$$, and elements $$$a$$$ and $$$b$$$ in the second array, such that $$$a < b$$$, we can match the elements to obtain the sums $$$x + a < x + b < y + b$$$. Since the arrays are good, $$$x$$$ appears at least twice, and all three sums can definitely be obtained.
In the remaining cases, one of the arrays will contain only equal elements. Since the second array contains no more than $$$2$$$ distinct values, it will not be possible to obtain $$$3$$$ distinct sums.