## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Equate Multisets Codeforces Solution

F. Equate Multisets
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Multiset —is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. Two multisets are equal when each value occurs the same number of times. For example, the multisets $\left\{2,2,4\right\}$ and $\left\{2,4,2\right\}$ are equal, but the multisets $\left\{1,2,2\right\}$ and $\left\{1,1,2\right\}$ — are not.

You are given two multisets $a$ and $b$, each consisting of $n$ integers.

In a single operation, any element of the $b$ multiset can be doubled or halved (rounded down). In other words, you have one of the following operations available for an element $x$ of the $b$ multiset:

• or replace $x$ with $x\cdot 2$,
• or replace $x$ with $⌊\frac{x}{2}⌋$ (round down).

Note that you cannot change the elements of the $a$ multiset.

Solution Click Below:-  👉
👇👇👇👇👇

See if you can make the multiset $b$ become equal to the multiset $a$ in an arbitrary number of operations (maybe $0$).

For example, if $n=4$$a=\left\{4,24,5,2\right\}$$b=\left\{4,1,6,11\right\}$, then the answer is yes. We can proceed as follows:

Input

The first line of input data contains a single integer $t$ ($1\le t\le {10}^{4}$) —the number of test cases.

Round Down the Price Codeforces Solution

Polycarp Writes a String from Memory Codeforces Solution

Train and Queries Codeforces Solution

Not a Cheap String Codeforces Solution

Split Into Two Sets Codeforces Solution

Equate Multisets Codeforces Solution

Passable Paths (easy version) Codeforces Solution

Passable Paths (hard version) Codeforces Solution

Each test case consists of three lines.

The first line of the test case contains an integer $n$ ($1\le n\le 2\cdot {10}^{5}$) —the number of elements in the multisets $a$ and $b$.

The second line gives $n$ integers: ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{1}\le {a}_{2}\le \cdots \le {a}_{n}\le {10}^{9}$) —the elements of the multiset $a$. Note that the elements may be equal.

The third line contains $n$ integers: ${b}_{1},{b}_{2},\dots ,{b}_{n}$ ($1\le {b}_{1}\le {b}_{2}\le \cdots \le {b}_{n}\le {10}^{9}$) — elements of the multiset $b$. Note that the elements may be equal.

It is guaranteed that the sum of $n$ values over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case, print on a separate line:

• YES if you can make the multiset $b$ become equal to $a$,
• NO otherwise.

You can output YES and NO in any case (for example, strings yEsyesYes and YES will be recognized as positive answer).