import java.io.*;
import java.util.*;

public class Main {
    public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353;
    public static void main(String args[]){
        try {
            PrintWriter o = new PrintWriter(System.out);
            boolean multiTest = true;
            // init
            if(multiTest) {
                int t = nextInt(), loop = 0;
                while (loop < t) {loop++;solve(o);}
            } else solve(o);
            o.close();
        } catch (Exception e) {e.printStackTrace();}
    }
    static void solve(PrintWriter o) {
        try {
            int n = nextInt(), m = nextInt(), k = n-m;
            int[] a = new int[n];
            int[] b = new int[m];
            Map<Integer, Integer> map = new HashMap<>();
            for(int i=0;i<n;i++) {
                a[i] = nextInt();
                map.put(a[i], map.getOrDefault(a[i], 0)+1);
            }
            PriorityQueue<Integer> pq = new PriorityQueue<>((x,y)->Integer.compare(y,x));
            for(int i=0;i<m;i++) {
                b[i] = nextInt();
                pq.offer(b[i]);
            }
            while(!pq.isEmpty()) {
                int x = pq.poll();
                if(map.get(x) != null) {
                    map.put(x, map.get(x)-1);
                    if(map.get(x) == 0) map.remove(x);
                }
                else if(k-- > 0) {
                    pq.offer(x/2);
                    pq.offer((x+1)/2);
                }
                else {
                    o.println("No");
                    return;
                }
            }
            if(k > 0) o.println("No");
            else o.println("Yes");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static int lower_bound(Integer[] a, long val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(List<Integer> li, long val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid) < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(long[] preSum, long val){
        int l = 0, r = preSum.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(preSum[mid] <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(List<int[]> li, long val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid)[0] <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(List<Integer> li, int val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid) <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(int[] a, long val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid] <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(List<int[]> li, int val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid)[0] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(int[] a, int val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(long[][] a, long val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid][0] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a%b);
    }
    public static long[] extgcd(long a, long b) {
        if(b == 0) return new long[]{1, 0};
        long[] it = extgcd(b, a%b);
        long x = it[1], y = it[0];
        y -= a/b*x;
        return new long[]{x, y};
    }
    public static long lcm(long a, long b){
        return a / gcd(a,b)*b;
    }
    public static long qpow(long a, long n){
        long ret = 1l;
        while(n > 0){
            if((n & 1) == 1) ret = ret * a;
            n >>= 1;
            a = a * a;
        }
        return ret;
    }
    public static long qpow(long a, long n, int md){
        a %= md;
        long ret = 1l;
        while(n > 0){
            if((n & 1) == 1) ret = ret * a % md;
            n >>= 1;
            a = a * a % md;
        }
        return ret;
    }
    public static class FenWick {
        int n;
        long[] a;
        long[] tree;
        public FenWick(int n){
            this.n = n;
            a = new long[n+1];
            tree = new long[n+1];
        }
        private void add(int x, long val){
            while(x <= n){
                tree[x] += val;
                x += x&-x;
            }
        }
        private void addMx(int x, long val) {
            a[x] += val;
            tree[x] = a[x];
            while(x <= n) {
                for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.max(tree[x], tree[x-i]);
                x += x&-x;
            }
        }
        private void addMn(int x, long val) {
            a[x] += val;
            tree[x] = a[x];
            while(x <= n) {
                for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.min(tree[x], tree[x-i]);
                x += x&-x;
            }
        }
        private long query(int x){
            long ret = 0l;
            while(x > 0){
                ret += tree[x];
                x -= x&-x;
            }
            return ret;
        }
        private long queryMx(int l, int r) {
            long res = 0l;
            while(l <= r) {
                if(r-(r&-r) >= l) {
                    res = Math.max(res, tree[r]);
                    r -= r&-r;
                }
                else {
                    res = Math.max(res, a[r]);
                    r--;
                }
            }
            return res;
        }
        private long queryMn(int l, int r) {
            long res = 1l<<55;
            while(l <= r) {
                if(r-(r&-r) >= l) {
                    res = Math.min(res, tree[r]);
                    r -= r&-r;
                }
                else {
                    res = Math.min(res, a[r]);
                    r--;
                }
            }
            return res;
        }
    }
    static class Pair {
        Integer p1, p2;
        public Pair(Integer p1, Integer p2) {
            this.p1 = p1;
            this.p2 = p2;
        }
        @Override
        public int hashCode() {
            int prime = 31, ret = 0;
            ret = ret*prime+p1.hashCode();
            ret = ret*prime+p2.hashCode();
            return ret;
        }
        @Override
        public boolean equals(Object o) {
            if(o instanceof Pair pair) {
                return p1.equals(pair.p1) && p2.equals(pair.p2);
            }
            return false;
        }
    }
    static class DSU {
        int[] parent;
        int[] size;
        public DSU(int n) {
            parent = new int[n];
            size = new int[n];
            for(int i=0;i<n;i++) {
                parent[i] = i;
                size[i] = 1;
            }
        }
        public int find(int x) {
            if(parent[x] != x) parent[x] = find(parent[x]);
            return parent[x];
        }
        public void union(int x, int y) {
            int root_x = find(x);
            int root_y = find(y);
            if(root_x == root_y) return;
            parent[root_x] = root_y;
            size[root_y] += size[root_x];
            size[root_x] = 0;
        }
    }
    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer tokenizer = new StringTokenizer("");
    private static String next() throws IOException{
        while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());}
        return tokenizer.nextToken();
    }
    public static int nextInt() throws IOException {return Integer.parseInt(next());}
    public static Long nextLong() throws IOException {return Long.parseLong(next());}
    public static double nextDouble() throws IOException {return Double.parseDouble(next());}
    public static char nextChar() throws IOException {return next().toCharArray()[0];}
    public static String nextString() throws IOException {return next();}
    public static String nextLine() throws IOException {return reader.readLine();}
}

import java.io.*;
import java.util.*;

public class Main {
    public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353;
    public static void main(String args[]){
        try {
            PrintWriter o = new PrintWriter(System.out);
            boolean multiTest = true;
            // init
            if(multiTest) {
                int t = nextInt(), loop = 0;
                while (loop < t) {loop++;solve(o);}
            } else solve(o);
            o.close();
        } catch (Exception e) {e.printStackTrace();}
    }
    static Map<Integer, Integer> map;
    static void solve(PrintWriter o) {
        try {
            int n = nextInt(), m = nextInt();
            int[] a = new int[n];
            int[] b = new int[m];
            long sum1 = 0l, sum2 = 0l;
            map = new HashMap<>();
            for(int i=0;i<n;i++) {
                a[i] = nextInt();
                sum1 += a[i];
                map.put(a[i], map.getOrDefault(a[i], 0)+1);
            }
            for(int i=0;i<m;i++) {
                b[i] = nextInt();
                sum2 += b[i];
            }
            if(sum1 != sum2) {
                o.println("No");
                return;
            }
            for(int i=0;i<m;i++) {
                boolean ok = dfs(b[i]);
                if(!ok) {
                    o.println("No");
                    return;
                }
            }
            o.println("Yes");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    static boolean dfs(int x) {
        if(map.get(x) != null) {
            map.put(x, map.get(x)-1);
            if(map.get(x) == 0) map.remove(x);
            return true;
        }
        else if(x <= 1) return false;
        int l = x/2, r = x/2;
        if((x&1) == 1) r = x/2+1;
        boolean okl = dfs(l);
        boolean okr = dfs(r);
        return okl&okr;
    }
    public static int lower_bound(Integer[] a, long val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(List<Integer> li, long val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid) < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(long[] preSum, long val){
        int l = 0, r = preSum.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(preSum[mid] <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(List<int[]> li, long val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid)[0] <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(List<Integer> li, int val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid) <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int upper_bound(int[] a, long val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid] <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(List<int[]> li, int val){
        int l = 0, r = li.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(li.get(mid)[0] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(int[] a, int val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(long[][] a, long val){
        int l = 0, r = a.length;
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a[mid][0] < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a%b);
    }
    public static long[] extgcd(long a, long b) {
        if(b == 0) return new long[]{1, 0};
        long[] it = extgcd(b, a%b);
        long x = it[1], y = it[0];
        y -= a/b*x;
        return new long[]{x, y};
    }
    public static long lcm(long a, long b){
        return a / gcd(a,b)*b;
    }
    public static long qpow(long a, long n){
        long ret = 1l;
        while(n > 0){
            if((n & 1) == 1) ret = ret * a;
            n >>= 1;
            a = a * a;
        }
        return ret;
    }
    public static long qpow(long a, long n, int md){
        a %= md;
        long ret = 1l;
        while(n > 0){
            if((n & 1) == 1) ret = ret * a % md;
            n >>= 1;
            a = a * a % md;
        }
        return ret;
    }
    public static class FenWick {
        int n;
        long[] a;
        long[] tree;
        public FenWick(int n){
            this.n = n;
            a = new long[n+1];
            tree = new long[n+1];
        }
        private void add(int x, long val){
            while(x <= n){
                tree[x] += val;
                x += x&-x;
            }
        }
        private void addMx(int x, long val) {
            a[x] += val;
            tree[x] = a[x];
            while(x <= n) {
                for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.max(tree[x], tree[x-i]);
                x += x&-x;
            }
        }
        private void addMn(int x, long val) {
            a[x] += val;
            tree[x] = a[x];
            while(x <= n) {
                for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.min(tree[x], tree[x-i]);
                x += x&-x;
            }
        }
        private long query(int x){
            long ret = 0l;
            while(x > 0){
                ret += tree[x];
                x -= x&-x;
            }
            return ret;
        }
        private long queryMx(int l, int r) {
            long res = 0l;
            while(l <= r) {
                if(r-(r&-r) >= l) {
                    res = Math.max(res, tree[r]);
                    r -= r&-r;
                }
                else {
                    res = Math.max(res, a[r]);
                    r--;
                }
            }
            return res;
        }
        private long queryMn(int l, int r) {
            long res = 1l<<55;
            while(l <= r) {
                if(r-(r&-r) >= l) {
                    res = Math.min(res, tree[r]);
                    r -= r&-r;
                }
                else {
                    res = Math.min(res, a[r]);
                    r--;
                }
            }
            return res;
        }
    }
    static class Pair {
        Integer p1, p2;
        public Pair(Integer p1, Integer p2) {
            this.p1 = p1;
            this.p2 = p2;
        }
        @Override
        public int hashCode() {
            int prime = 31, ret = 0;
            ret = ret*prime+p1.hashCode();
            ret = ret*prime+p2.hashCode();
            return ret;
        }
        @Override
        public boolean equals(Object o) {
            if(o instanceof Pair pair) {
                return p1.equals(pair.p1) && p2.equals(pair.p2);
            }
            return false;
        }
    }
    static class DSU {
        int[] parent;
        int[] size;
        public DSU(int n) {
            parent = new int[n];
            size = new int[n];
            for(int i=0;i<n;i++) {
                parent[i] = i;
                size[i] = 1;
            }
        }
        public int find(int x) {
            if(parent[x] != x) parent[x] = find(parent[x]);
            return parent[x];
        }
        public void union(int x, int y) {
            int root_x = find(x);
            int root_y = find(y);
            if(root_x == root_y) return;
            parent[root_x] = root_y;
            size[root_y] += size[root_x];
            size[root_x] = 0;
        }
    }
    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer tokenizer = new StringTokenizer("");
    private static String next() throws IOException{
        while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());}
        return tokenizer.nextToken();
    }
    public static int nextInt() throws IOException {return Integer.parseInt(next());}
    public static Long nextLong() throws IOException {return Long.parseLong(next());}
    public static double nextDouble() throws IOException {return Double.parseDouble(next());}
    public static char nextChar() throws IOException {return next().toCharArray()[0];}
    public static String nextString() throws IOException {return next();}
    public static String nextLine() throws IOException {return reader.readLine();}
}

Answer: 1


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
multiset<int> s;
int find(int x){
    int y = x / 2;
    int z = ceil(x / 2.0);
    if(y == z){
        auto xx = s.lower_bound(y);
        if(xx != s.end() && *xx == y){
            s.erase(xx);
            auto yy = s.lower_bound(y);
            if(yy != s.end() && *yy == y) return 1;
            int f = find(y);
            if(f) return 1;
            return 0;
        }
        int f = find(y);
        if(f){
            f = find(y);
            if(f) return 1;
            return 0;
        }
        return 0;
    }
    auto yy = s.lower_bound(y);
    auto zz = s.lower_bound(z);
    int fy = 0, fz = 0;
    if(yy == s.end() || *yy != y) fy = 1;
    if(zz == s.end() || *zz != z) fz = 1;
    if(fy && y < *(s.begin())) return 0;
    if(fz && z < *(s.begin())) return 0;
    if(fy && fz){
        int f = find(y), g = find(z);
        if(f && g) return 1;
        return 0;
    }
    else if(fy && !fz){
        s.erase(zz);
        int f = find(y);
        if(f) return 1;
        return 0;
    }
    else if(!fy && fz){
        s.erase(yy);
        int g = find(z);
        if(g) return 1;
        return 0;
    }
    else{
        s.erase(yy); s.erase(zz);
        return 1;
    }
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t --){
        int n, m;
        cin >> n >> m;
        s.clear();
        ll s1 = 0, s2 = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            s1 += a[i];
            s.insert(a[i]);
        }
        for (int i = 1; i <= m; i++) cin >> b[i], s2 += b[i];
        if(s1 != s2){cout << "No" << '\n'; continue;}
        sort(b + 1, b + m);
        int res = 0;
        for (int i = m; i >= 1; i--){
            int x = b[i];
            int f = 0;
            auto y = s.lower_bound(x);
            if(y == s.end()){
                int f = find(x);
                if(!f) {res = 1; break;}
            }
            else{
                s.erase(y);
            }

        }
        if(!res) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
multiset<int> s;
int find(int x){
    int y = x / 2;
    int z = ceil(x / 2.0);
    // cout << y << ' ' << z << '\n';
    if(y == z){
        auto xx = s.lower_bound(y);
        if(xx != s.end() && *xx == y){
            s.erase(xx);
            auto yy = s.lower_bound(y);
            if(y < *(s.begin())) return 0;
            if(yy != s.end() && *yy == y) {
                s.erase(yy);
                return 1;
            }
            int f = find(y);
            if(f) return 1;
            return 0;
        }
        if(y < *(s.begin())) return 0;
        int f = find(y);
        if(f){
            f = find(y);
            if(f) return 1;
            return 0;
        }
        return 0;
    }
    auto yy = s.lower_bound(y);
    auto zz = s.lower_bound(z);
    int fy = 0, fz = 0;
    if(yy == s.end() || *yy != y) fy = 1;
    if(zz == s.end() || *zz != z) fz = 1;
    if(fy && y < *(s.begin())) return 0;
    if(fz && z < *(s.begin())) return 0;
    if(fy && fz){
        int f = find(y), g = find(z);
        if(f && g) return 1;
        return 0;
    }
    else if(fy && !fz){
        s.erase(zz);
        int f = find(y);
        if(f) return 1;
        return 0;
    }
    else if(!fy && fz){
        s.erase(yy);
        int g = find(z);
        if(g) return 1;
        return 0;
    }
    else{
        s.erase(yy); s.erase(zz);
        return 1;
    }
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t --){
        int n, m;
        cin >> n >> m;
        s.clear();
        ll s1 = 0, s2 = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            s1 += a[i];
            s.insert(a[i]);
        }
        for (int i = 1; i <= m; i++) cin >> b[i], s2 += b[i];
        if(s1 != s2){cout << "No" << '\n'; continue;}
        sort(b + 1, b + m + 1);
        int res = 0;
        for (int i = m; i >= 1; i--){
            int x = b[i];
            int f = 0;
            auto y = s.lower_bound(x);
            if(y == s.end() || *y != x){
                int f = find(x);
                if(!f) {res = 1; break;}
            }
            else{
                s.erase(y);
            }

        }
        if(!res) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define nl "\n"
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pair<ll,ll>>vpll;
#define pb                push_back
#define fori(n)           for (ll i=0; i<n; i++)
#define forj(n)           for (ll j=0; j<n; j++)
#define isort(v)          sort(v.begin(),v.end())
#define dsort(v)          sort(v.rbegin(),v.rend())
#define all(x)            (x).begin(), (x).end()

const ll M = 1e9+7;

void solve(){
	ll n,m;
	cin>>n>>m;
	vll v(n);
	fori(n){
		cin>>v[i];
	}
	isort(v);
	priority_queue<ll>pq;
    fori(m){
		ll a;cin>>a;
        pq.push(a);
	}
	ll p = n-1;
	while(p>=0){
		if(pq.size()>p+1 || pq.empty()){
			cout<<"No"<<nl;
			return;
		}
		if(pq.top()>v[p]){
			ll element = pq.top();
			pq.pop();
			pq.push(element/2);
			pq.push(element/2+element%2);
		}else if(pq.top()<v[p]){
			cout<<"No"<<nl;
			return;
		}else{
			pq.pop();
			p--;
		}
	}
	cout<<"Yes"<<nl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt;cin >> tt;for (int i=1; i<=tt; i++){solve();}
    // solve();
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define nl "\n"
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pair<ll,ll>>vpll;
#define pb                push_back
#define fori(n)           for (ll i=0; i<n; i++)
#define forj(n)           for (ll j=0; j<n; j++)
#define isort(v)          sort(v.begin(),v.end())
#define dsort(v)          sort(v.rbegin(),v.rend())
#define all(x)            (x).begin(), (x).end()

const ll M = 1e9+7;

bool f(int n,map<ll,ll>&mp){
	// cout<<n<<nl;
	if(mp.find(n)!=mp.end()){
		mp[n]--;
		if(mp[n]==0){
			mp.erase(n);
		}
		return true;
	}
	if(n<=1 || mp.empty())return false;
	if(n%2){
        if(!(f(n/2,mp)&f(n/2+1,mp)))return false;
	}else{
		if(!(f(n/2,mp)&f(n/2,mp)))return false;
	}
	return true;
}

void solve(){
	ll n,m;
	cin>>n>>m;
	map<ll,ll>mp;
	fori(n){
		ll a;
		cin>>a;
		mp[a]++;
	}
	vll v(m);
	fori(m){
		cin>>v[i];
	}
	ll ans = true;
    for(int i=0; i<m; i++){
		if(mp.size()==0){
			cout<<"No"<<nl;
			return;
		}
		if((!(f(v[i],mp)))){
			cout<<"No"<<nl;
			return;
		}
	}
	if(mp.size()!=0){
		cout<<"No"<<nl;
		return;
	}
	cout<<"Yes"<<nl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt;cin >> tt;for (int i=1; i<=tt; i++){solve();}
    // solve();
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve () {
  int n, m;
  cin >> n >> m;
  multiset<int> a, b;
  for (int i = 0; i < n; i++) {
     int x;
     cin >> x;
     a.insert(x);
   }
  for (int i = 0; i < m; i++) {
      int x;
      cin >> x;
      b.insert(x);
   }
  for (int i = 0; i < n; i++) {
    if (a.size() <= b.size()) {
      // cout << "No\n";
      break;
    }
    int x , y;
    x = *a.begin();  a.erase(a.find(x));
    if (a.size() > 0) y = *a.begin(), a.erase(a.find(y));

    if (x == *b.begin()) {
      a.insert(y);
      b.erase(b.find(x));
    } else {
      if (abs(x - y) <= 1) a.insert(x + y);
      else break;
    }
  }
  if (a.size() == 0 || b.size() == 0 || a.size() < b.size()) {
    cout << "No\n";
  } else {
    while (1) {
     if (a.size() == 0 || b.size() == 0) break;
     int x = *a.begin(), y = *b.begin();
      if (x != y) {
        cout <<"No\n";
        return;
      } else {
        a.erase(a.find(x));
        b.erase(b.find(y));
      }
    }
    cout << "Yes\n";
  }
}

int main() {
  auto begin = std::chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  //freopen("in",  "r", stdin);
  //freopen("out", "w", stdout);
  int T = 1;
  cin >> T;
  for(int i = 1; i <= T; i++) {
     // cout << "Case #" << i << ": ";
      solve();
  }
  auto end = std::chrono::high_resolution_clock::now();
  auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
  cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
const int N = 3e5 + 10, M = 110, mod = 998244353;
const long long INF = 2e18;
typedef pair<int, int> pt;
typedef long long ll;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n + 1), b(m + 1);
	map<int, int> cnt, cnt2;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		if (cnt[a[i]] == 1) sum++;
	}
	map<int, int> mp;
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		mp[b[i]]++;
	}
	while (!mp.empty()) {
		auto [x, t] = *mp.rbegin();
		mp.erase(mp.rbegin()->first);
		if (cnt[x] >= t) {
			cnt[x] -= t;
			if (cnt[x] == 0) sum--;
			continue;
		}
		else if (cnt[x] > 0) {
			t -= cnt[x];
			cnt[x] = 0;
			sum--;
		}
		if (x == 1) {
			cout << "No" << endl;
			return;
		}
		if (x & 1) {
			mp[x / 2] += t, mp[x / 2 + 1] += t;
		}
		else {
			mp[x / 2] += 2 * t;
		}
	}
	if (sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

signed main() {
    //freopen("data.in", "r", stdin);
    //freopen("std.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Answer: 1


#include<iostream>

#include<unordered_map>

using namespace std;

#define INF 2147483647

int t,n,m,a;

unordered_map<int,int>mp;

bool solve(int x)

{

    if(mp[x])

    {

        mp[x]--;

        return true;

    }

    else if(!x)return false;

    else return solve(x/2)&&solve((x+1)/2);

}

int main()

{

    scanf("%d",&t);

    while(t--)

    {

        mp.clear();

        scanf("%d%d",&n,&m);

        long long cnt=0;

        for(int i=0;i<n;i++)

        {

            scanf("%d",&a);

            mp[a]++;

            cnt+=a;

        }

        bool flag=true;

        for(int i=0;i<m;i++)

        {

            scanf("%d",&a);

            cnt-=a;

            if(flag&&!solve(a))flag=false;

        }

        if(flag&&!cnt)printf("Yes\n");

        else printf("No\n");

    }

    return 0;

}

#include<iostream>

#include<map>

using namespace std;

int t,n,m,a;

map<int,int>mp;

bool solve(int x)

{

    if(mp[x])

    {

        mp[x]--;

        return true;

    }

    else if(!x)return false;

    else return solve(x/2)&&solve((x+1)/2);

}

int main()

{

    scanf("%d",&t);

    while(t--)

    {

        mp.clear();

        scanf("%d%d",&n,&m);

        long long cnt=0;

        for(int i=0;i<n;i++)

        {

            scanf("%d",&a);

            mp[a]++;

            cnt+=a;

        }

        bool flag=true;

        for(int i=0;i<m;i++)

        {

            scanf("%d",&a);

            cnt-=a;

            if(flag&&!solve(a))flag=false;

        }

        if(flag&&!cnt)printf("Yes\n");

        else printf("No\n");

    }

    return 0;

}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int, int> mpa;
int cf(int x,int con)
{
	if(x==0)return 1;
	if (con>mpa[x])
	{
		con -= mpa[x];
		mpa[x] = 0;
		if (x % 2 == 0)
		{
			if (cf(x / 2, 2 * con))return 1;
		}
		else
		{
			if (cf(x/2, con))return 1;
			if (cf(x/2+1,con))return 1;
		}
	}
	else
	{
		mpa[x] -= con;
	}
	return 0;
}
int solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	mpa.clear();
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		mpa[a[i]]++;
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int ans = 0;
	for (int i = 0; i < m; i++)
	{
		if (cf(b[i], 1))
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	for (auto i : mpa)
	{
		if (i.second > 0)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 1;
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int, int> mpa;
int cf(int x,int con)
{
	if(x==0)return 1;
	if (con>mpa[x])
	{
		con -= mpa[x];
		mpa[x] = 0;
		if (x % 2 == 0)
		{
			if (cf(x / 2, 2 * con))return 1;
		}
		else
		{
			if (cf(x/2, con))return 1;
			if (cf(x/2+1,con))return 1;
		}
	}
	else
	{
		mpa[x] -= con;
	}
	return 0;
}
int solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	mpa.clear();
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		mpa[a[i]]++;
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int ans = 0;
	for (int i = 0; i < m; i++)
	{
		if (cf(b[i], 1))
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	for (auto i : mpa)
	{
		if (i.second > 0)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

Answer: 1


// #pragma GCC optimize(2)

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

#define all(x) (x).begin(), (x).end()

constexpr int MOD = 1e9 + 7;

// -9.2e18 ~ 9.2e18

void solve()

{

    int n, m;

    cin >> n >> m;

    vector<int> a(n), b(m);

    for (int i = 0; i < n; i++)

    {

        cin >> a[i];

    }

    for (int i = 0; i < m; i++)

    {

        cin >> b[i];

    }

    priority_queue<int, vector<int>> pqa, pqb;

    for (int i = 0; i < n; i++)

    {

        pqa.push(a[i]);

    }

    for (int i = 0; i < m; i++)

    {

        pqb.push(b[i]);

    }

    int k = n - m;

    while (pqa.size() and k)

    {

        auto amax = pqa.top();

        pqa.pop();

        auto bmax = pqb.top();

        pqb.pop();

        if (amax == bmax)

        {

            continue;

        }

        else if (amax > bmax)

        {

            cout << "No";

            return;

        }

        else

        {

            pqa.push(amax);

            auto num1 = bmax / 2, num2 = (bmax + 1) / 2;

            pqb.push(num1);

            pqb.push(num2);

        }

        k--;

    }

    while (pqa.size() and pqb.size())

    {

        auto amax = pqa.top();

        pqa.pop();

        auto bmax = pqb.top();

        pqb.pop();

        if (amax == bmax)

        {

            continue;

        }

        else

        {

            cout << "No";

            return;

        }

    }

    cout << (pqa.size() or pqb.size() ? "No" : "Yes");

}

signed main()

{

    cin.tie(0)->ios::sync_with_stdio(0);

    cout << setiosflags(ios::fixed) << setprecision(2);

    int TT = 1;

    cin >> TT;

    while (TT--)

    {

        solve();

        cout << endl;

    }

}

// #pragma GCC optimize(2)

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

#define all(x) (x).begin(), (x).end()

constexpr int MOD = 1e9 + 7;

// -9.2e18 ~ 9.2e18

void solve()

{

    int n, m;

    cin >> n >> m;

    priority_queue<int, vector<int>> pqa, pqb;

    for (int i = 0; i < n; i++)

    {

        int num;

        cin >> num;

        pqa.push(num);

    }

    for (int i = 0; i < m; i++)

    {

        int num;

        cin >> num;

        pqb.push(num);

    }

    while (pqa.size() and pqb.size())

    {

        if (pqa.size() < pqb.size())

        {

            cout << "No";

            return;

        }

        if (pqa.top() == pqb.top())

        {

            pqb.pop();

            pqa.pop();

            continue;

        }

        if (pqa.top() > pqb.top())

        {

            cout << "No";

            return;

        }

        else

        {

            auto num1 = pqb.top() >> 1, num2 = (pqb.top() + 1) >> 1;

            pqb.pop();

            pqb.push(num1);

            pqb.push(num2);

        }

    }

    cout << (pqa.empty() and pqb.empty() ? "Yes" : "No");

}

signed main()

{

    cin.tie(0)->ios::sync_with_stdio(0);

    cout << setiosflags(ios::fixed) << setprecision(2);

    int TT = 1;

    cin >> TT;

    while (TT--)

    {

        solve();

        cout << endl;

    }

}

Answer: 2


#include <bits/stdc++.h>

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> qa, qb;
    ll sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty() && !qb.empty())
    {
        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qa.pop(), qb.pop();
        if(a < b){
            qa.push(a);
            while(!qa.empty())
            {
                auto t1 = qa.top();
                qa.pop();

                if(t1 == b) break;

                auto t2 = qa.top();
                qa.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qa.push(t1 + t2);
            }
        }else if(a > b){
            qb.push(b);
            while(!qb.empty())
            {
                auto t1 = qb.top();
                qb.pop();

                if(t1 == a) break;

                auto t2 = qb.top();
                qb.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qb.push(t1 + t2);
            }
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int> qa, qb;
    ll sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty())
    {
        if(qb.empty()) break;

        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qb.pop();

        if(b < a){
            cout << "NO" << endl;
            return;
        }
        if(b == a) qa.pop();
        else{
            qb.push(b / 2);
            qb.push((b + 1) / 2);
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

void solve() {

    int n, m;

    cin >> n >> m;

    vector<int> a(n);

    vector<int> b(m);

    map<int, int> mpa;

    map<int, int> mpb;

	set<int,greater<int>> s1;

    set<int,greater<int>> s2;

    for (int i = 0; i < n; i++) {

        cin >> a[i];

        mpa[a[i]]++;

        s1.insert(a[i]);

    }

    for (int i = 0; i < m; i++) {

        cin >> b[i];

        mpb[b[i]]++;

        s2.insert(b[i]);

    }

    while (true) {

        if (s1.empty() && s2.empty()) {

            cout << "Yes" << endl;

            return;

        }

        if (s1.empty() || s2.empty()) {

            cout << "No" << endl;

            return;

        }

        int mxa = *s1.rbegin();

        int mxb = *s2.rbegin(); // Get the largest element in s2

        if (mxa > mxb) {

            cout << "No" << endl;

            return;

        } else if (mxa == mxb) {

            int minifre = min(mpa[mxa], mpb[mxb]);

            mpa[mxa] -= minifre;

            mpb[mxb] -= minifre;

            if (mpa[mxa] == 0) s1.erase(mxa);

            if (mpb[mxb] == 0) s2.erase(mxb);

        } else { // mxa < mxb

            int sl = mxb / 2;

            int sb = (mxb + 1) / 2;

			mpb[sl]+=mpb[mxb];

            s2.insert(sl);

            mpb[sb]+=mpb[mxb];

            s2.insert(sb);

			mpb[mxb]=0;

            if (mpb[mxb] == 0) s2.erase(mxb);

        }

    }

}

int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}

#include <bits/stdc++.h>

using namespace std;

void solve() {

    int n, m;

    cin >> n >> m;

    vector<int> a(n), b(m);

    map<int, int> mpa, mpb;

    set<int> s1, s2;

    for (int i = 0; i < n; ++i) {

        cin >> a[i];

        mpa[a[i]]++;

        s1.insert(a[i]);

    }

    for (int i = 0; i < m; ++i) {

        cin >> b[i];

        mpb[b[i]]++;

        s2.insert(b[i]);

    }

    while (true) {

        if (s1.empty() && s2.empty()) {

            cout << "Yes\n";

            return;

        }

        if (s1.empty() || s2.empty()) {

            cout << "No\n";

            return;

        }

        int mxa = *s1.rbegin();

        int mxb = *s2.rbegin();

        if (mxa > mxb) {

            cout << "No\n";

            return;

        }

        if (mxa == mxb) {

            int common = min(mpa[mxa], mpb[mxb]);

            mpa[mxa] -= common;

            mpb[mxb] -= common;

            if (mpa[mxa] == 0) s1.erase(mxa);

            if (mpb[mxb] == 0) s2.erase(mxb);

        }

        else {

            if (mpb[mxb] == 0) {

                s2.erase(mxb);

                continue;

            }

            int count = mpb[mxb];

            mpb[mxb] = 0;

            s2.erase(mxb);

            int part1 = mxb / 2;

            int part2 = (mxb + 1) / 2;

            mpb[part1] += count;

            s2.insert(part1);

            mpb[part2] += count;

            s2.insert(part2);

        }

    }

}

int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}

Answer: 2


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define SMIT_FEFAR                  \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define MOD 1000000007
#define MOD2 998244353

#define pb push_back
#define ppb pop_back
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vvc vector<vector<char>>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp make_pair
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define vll vector<ll>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define minus cout<<-1<<"\n";
#define rep(l,r,i) for(ll i = l;i<r;i++)
#define repr(l,r,i) for(ll i = l;i>=r;i--)
#define print cout<<
#define nline "\n"
ll inf= 1e16;
ll expo(ll a,ll b){ll res=1;while(b>0){if(b&1){res=res*a;}b=b>>1;a*=a;}return res;}
ll expomod(ll a, ll b, ll mod){
  ll res=1;while(b>0){if(b&1){res=(res*a)%mod;}b=b>>1;a= (a*a)%mod;}return res;
}
struct triplet{
    ll x,y,gcd;
};

struct triplet extended_Euclid(ll a, ll b){
    if(b == 0){
        triplet ans;
        ans.gcd = a;
        ans.x = 1;
        ans.y = 0;
        return ans;
    }

    triplet ans2 = extended_Euclid(b, a%b);
    triplet finalAns;
    /*
    ax + by = gcd(a, b)
    gcd(a, b) = gcd(b, a%b)
    gcd(b, a%b) = bx1 + (a%b)y1
    a%b = a − (a/b) ∗ b
    so...
    ax + by = bx1 + (a%b)y1
    ax + by = bx1 + (a − (a/b) ∗ b)y1
    ax + by = ay1 + b(x1 − (a/b) ∗ y1)

    so...

    x = y1
    y = x1 − (a/b) ∗ y1
    */
    finalAns.gcd = ans2.gcd;
    finalAns.x = ans2.y;
    finalAns.y = (ans2.x) - (a/b)*(ans2.y);
    return finalAns;
}

ll moduloInverse(ll num1, ll modulo){
triplet ans = extended_Euclid(num1,modulo);
//return ans.x; // for negative values allowed
return (ans.x + modulo)%modulo; // for only positive values
}

ll endNumber = 1000001;
vll smallestPrimeFactors(endNumber,0);
//O(N*log(log(n)))
void sieveMethodSmallesPrimeFactors(){
    rep(1,endNumber,i){
        smallestPrimeFactors[i] = i;
    }
    for(ll j = 2; j <= endNumber-1 ; j++){
        if(smallestPrimeFactors[j] == j){
            for(ll k = j*j;k < endNumber; k += j){
                if(smallestPrimeFactors[k] == k)
                smallestPrimeFactors[k] = j;
            }
        }
    }
}

class DSU{
public:
    long long n;
    vector<long long> size, par;
    vector<bool> vis;

    DSU(long long n){
        this -> n = n;
        size.resize(n);
        par.resize(n);
        vis.resize(n);

        for(long long i = 0; i < n; ++i){
            par[i] = i;
            size[i] = 1;
            vis[i] = 0;
        }
    }

    long long find_leader(long long u){
        if (u == par[u])
            return u;
        return par[u] = find_leader(par[u]);
    }

    void merge(long long u, long long v){
        vis[u] = 1;
        vis[v] = 1;
        u = find_leader(u); v = find_leader(v);
        if (u == v) return;

        if (size[u] < size[v]){
            swap(u, v);
        }
        size[u] += size[v];
        par[v] = u;
    }

    long long count_components(){
        long long cnt = 0;
        for (long long i = 0; i < n; ++i){
            if (par[i] == i) ++cnt;
        }

        return cnt;
    }
};struct segNode
{
    long long sum;

    segNode()
    {
        sum = 0;
    }

    void merge(segNode &x, segNode &y, ll ind)
    {
        if(ind%2 == 1)
        sum = x.sum | y.sum;
        else
        sum = x.sum & y.sum;
    }

    void update(long long val)
    {
        sum = val;
    }
};

class segTree
{
    long long n;
    vector<segNode> tree;

public:
    segTree() {}

    segTree(long long n)
    {
        this->n = n;
        tree.resize(4 * n);
    }

    segTree(vector<long long> &v, long long n)
    {
        this->n = n;
        tree.resize(4 * n);
        fill(all(tree), segNode());

        build(1, 0, n - 1, v);
    }

    void build(long long node, long long l, long long r, vector<long long> &v)
    {
        if (l == r)
        {
            tree[node].update(v[l]);
            return;
        }

        long long mid = l + (r - l) / 2;
        build(node << 1, l, mid, v);
        build(node << 1 | 1, mid + 1, r, v);

        tree[node].merge(tree[node << 1], tree[node << 1 | 1],mid);
    }

    void update(long long pos, long long val)
    {
        update(1, 0, n - 1, pos, val);
    }

    void update(long long node, long long l, long long r, long long pos, long long val)
    {
        if (l == r)
        {
            tree[node].update(val);
            return;
        }

        long long mid = l + (r - l) / 2;
        if (pos <= mid)
        {
            update(node << 1, l, mid, pos, val);
        }
        else
        {
            update(node << 1 | 1, mid + 1, r, pos, val);
        }

        tree[node].merge(tree[node << 1], tree[node << 1 | 1], mid);
    }

    long long query(long long s, long long e)
    {
        segNode ans = query(1, 0, n - 1, s, e);

        return ans.sum;
    }

    segNode query(long long node, long long l, long long r, long long s, long long e)
    {
        if (l >= s && r <= e)
            return tree[node];

        if (l > e || r < s)
            return segNode();

        long long mid = l + (r - l) / 2;

        segNode ans, left, right;
        left = query(node << 1, l, mid, s, e);
        right = query(node << 1 | 1, mid + 1, r, s, e);
        ans.merge(left, right, mid);

        return ans;
    }
};

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    sort(a.begin(), a.end());
    multiset<int> s;
    for (int i = 0; i < m; i++) {
      s.insert(b[i]);
    }
    int lft = n;
    while (lft > 0 && !s.empty() && int(s.size()) <= lft) {
      auto it = prev(s.end());
      int x = *it;
      s.erase(it);
      if (x == a[lft - 1]) {
        lft -= 1;
        continue;
      }
      if (x < a[lft - 1]) {
        break;
      }
      s.insert(x / 2);
      s.insert((x + 1) / 2);
    }
    if (lft == 0 && s.size() == 0) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }
}

int main()
{
  // sieveMethodSmallesPrimeFactors();
  SMIT_FEFAR;
  bool test_cases = 1;
  ll t=1;
  if(test_cases)cin>>t;
  while (t--) solve();
  return 0;
}

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define SMIT_FEFAR                  \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define MOD 1000000007
#define MOD2 998244353

#define pb push_back
#define ppb pop_back
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vvc vector<vector<char>>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp make_pair
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define vll vector<ll>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define minus cout<<-1<<"\n";
#define rep(l,r,i) for(ll i = l;i<r;i++)
#define repr(l,r,i) for(ll i = l;i>=r;i--)
#define print cout<<
#define nline "\n"
ll inf= 1e16;
ll expo(ll a,ll b){ll res=1;while(b>0){if(b&1){res=res*a;}b=b>>1;a*=a;}return res;}
ll expomod(ll a, ll b, ll mod){
  ll res=1;while(b>0){if(b&1){res=(res*a)%mod;}b=b>>1;a= (a*a)%mod;}return res;
}
struct triplet{
    ll x,y,gcd;
};

struct triplet extended_Euclid(ll a, ll b){
    if(b == 0){
        triplet ans;
        ans.gcd = a;
        ans.x = 1;
        ans.y = 0;
        return ans;
    }

    triplet ans2 = extended_Euclid(b, a%b);
    triplet finalAns;
    /*
    ax + by = gcd(a, b)
    gcd(a, b) = gcd(b, a%b)
    gcd(b, a%b) = bx1 + (a%b)y1
    a%b = a − (a/b) ∗ b
    so...
    ax + by = bx1 + (a%b)y1
    ax + by = bx1 + (a − (a/b) ∗ b)y1
    ax + by = ay1 + b(x1 − (a/b) ∗ y1)

    so...

    x = y1
    y = x1 − (a/b) ∗ y1
    */
    finalAns.gcd = ans2.gcd;
    finalAns.x = ans2.y;
    finalAns.y = (ans2.x) - (a/b)*(ans2.y);
    return finalAns;
}

ll moduloInverse(ll num1, ll modulo){
triplet ans = extended_Euclid(num1,modulo);
//return ans.x; // for negative values allowed
return (ans.x + modulo)%modulo; // for only positive values
}

ll endNumber = 1000001;
vll smallestPrimeFactors(endNumber,0);
//O(N*log(log(n)))
void sieveMethodSmallesPrimeFactors(){
    rep(1,endNumber,i){
        smallestPrimeFactors[i] = i;
    }
    for(ll j = 2; j <= endNumber-1 ; j++){
        if(smallestPrimeFactors[j] == j){
            for(ll k = j*j;k < endNumber; k += j){
                if(smallestPrimeFactors[k] == k)
                smallestPrimeFactors[k] = j;
            }
        }
    }
}

class DSU{
public:
    long long n;
    vector<long long> size, par;
    vector<bool> vis;

    DSU(long long n){
        this -> n = n;
        size.resize(n);
        par.resize(n);
        vis.resize(n);

        for(long long i = 0; i < n; ++i){
            par[i] = i;
            size[i] = 1;
            vis[i] = 0;
        }
    }

    long long find_leader(long long u){
        if (u == par[u])
            return u;
        return par[u] = find_leader(par[u]);
    }

    void merge(long long u, long long v){
        vis[u] = 1;
        vis[v] = 1;
        u = find_leader(u); v = find_leader(v);
        if (u == v) return;

        if (size[u] < size[v]){
            swap(u, v);
        }
        size[u] += size[v];
        par[v] = u;
    }

    long long count_components(){
        long long cnt = 0;
        for (long long i = 0; i < n; ++i){
            if (par[i] == i) ++cnt;
        }

        return cnt;
    }
};struct segNode
{
    long long sum;

    segNode()
    {
        sum = 0;
    }

    void merge(segNode &x, segNode &y, ll ind)
    {
        if(ind%2 == 1)
        sum = x.sum | y.sum;
        else
        sum = x.sum & y.sum;
    }

    void update(long long val)
    {
        sum = val;
    }
};

class segTree
{
    long long n;
    vector<segNode> tree;

public:
    segTree() {}

    segTree(long long n)
    {
        this->n = n;
        tree.resize(4 * n);
    }

    segTree(vector<long long> &v, long long n)
    {
        this->n = n;
        tree.resize(4 * n);
        fill(all(tree), segNode());

        build(1, 0, n - 1, v);
    }

    void build(long long node, long long l, long long r, vector<long long> &v)
    {
        if (l == r)
        {
            tree[node].update(v[l]);
            return;
        }

        long long mid = l + (r - l) / 2;
        build(node << 1, l, mid, v);
        build(node << 1 | 1, mid + 1, r, v);

        tree[node].merge(tree[node << 1], tree[node << 1 | 1],mid);
    }

    void update(long long pos, long long val)
    {
        update(1, 0, n - 1, pos, val);
    }

    void update(long long node, long long l, long long r, long long pos, long long val)
    {
        if (l == r)
        {
            tree[node].update(val);
            return;
        }

        long long mid = l + (r - l) / 2;
        if (pos <= mid)
        {
            update(node << 1, l, mid, pos, val);
        }
        else
        {
            update(node << 1 | 1, mid + 1, r, pos, val);
        }

        tree[node].merge(tree[node << 1], tree[node << 1 | 1], mid);
    }

    long long query(long long s, long long e)
    {
        segNode ans = query(1, 0, n - 1, s, e);

        return ans.sum;
    }

    segNode query(long long node, long long l, long long r, long long s, long long e)
    {
        if (l >= s && r <= e)
            return tree[node];

        if (l > e || r < s)
            return segNode();

        long long mid = l + (r - l) / 2;

        segNode ans, left, right;
        left = query(node << 1, l, mid, s, e);
        right = query(node << 1 | 1, mid + 1, r, s, e);
        ans.merge(left, right, mid);

        return ans;
    }
};

void solve()
{
    ll n,m; cin >> n >> m;
    vll a(n),b(m);
    rep(0,n,i){
        cin>>a[i];
    }
    rep(0,m,i)cin>>b[i];
    sort(all(a));
    sort(all(b));
    map<ll,ll> m2;
    rep(0,m,i){
        m2[b[i]]++;
    }
    vll at;
    map<ll,ll> ma;
    rep(0,n,i){
        if(m2.find(a[i]) != m2.end()){
            // m[b[i]]--;
            ma[a[i]]++;
            if(m2[a[i]] > 1)m2[a[i]]--;
            else m2.erase(a[i]);
        }
    }
    rep(0,n,i){
        if(ma.find(a[i]) != ma.end()){
            if(ma[a[i]] > 1)ma[a[i]]--;
            else ma.erase(a[i]);
        }
        else{
            at.pb(a[i]);
        }
    }
    ll l1 = 0;
    ll l2 = 0;
    n = at.size();
    vll bt;
    for(auto i : m2){
        ll num = i.second;
        rep(0, num ,j){
            bt.pb((ll)i.first);
        }
    }
    m = bt.size();
    while(l1 < n && l2 < m){
        if(at[l1] > bt[l2]){
            no
            return;
        }
        else{
            if(l1 == n-1){
                no
                return;
            }
            else{
                if(at[l1] + at[l1+1] < bt[l2]){
                    if(abs(at[l1] - at[l1+1]) <= 1){
                        at[l1+1] = at[l1]+at[l1+1];
                    }
                    else{
                       no
                       return;
                    }
                    l1++;
                }
                else if(at[l1] + at[l1+1] > bt[l2]){
                    no
                    return;
                }
                else{
                    if(abs(at[l1] - at[l1+1]) <= 1){
                        l1++;
                        l1++;
                        l2++;
                    }
                    else{
                        no
                        return;
                    }
                }
            }
        }
    }
    if(l1 ==n && l2 == m){
        yes
        return;
    }
    no
}

int main()
{
  // sieveMethodSmallesPrimeFactors();
  SMIT_FEFAR;
  bool test_cases = 1;
  ll t=1;
  if(test_cases)cin>>t;
  while (t--) solve();
  return 0;
}

Answer: 1


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int N=200005;

int a[N],b[N];
void solve(){
    int n,m;cin>>n>>m;
    priority_queue<int>qe1,qe2;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
        qe1.push(a[i]);
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
        sum-=b[i];
        qe2.push(b[i]);
    }
    if(sum){
        cout<<"NO"<<endl;
        return;
    }
    while(!qe1.empty()&&!qe2.empty()){
        int x=q1.top();
        int y=q2.top();
        if(y==x){
            q1.pop();
            q2.pop();
        }
        if(y>x){
            q2.pop();
            q2.push((y+1)/2);
            q2.push(y/2);
        }
        if(y<x){
            cout<<"NO"<<endl;
            return;
        }
    }
    if(q1.empty()&&q2.empty())cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _=1;cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int N=200005;

int a[N],b[N];
void solve(){
    int n,m;cin>>n>>m;
    priority_queue<int>qe1,qe2;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
        qe1.push(a[i]);
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
        sum-=b[i];
        qe2.push(b[i]);
    }
    if(sum){
        cout<<"NO"<<endl;
        return;
    }
    while(!qe1.empty()&&!qe2.empty()){
        int x=qe1.top();
        int y=qe2.top();
        if(y==x){
            qe1.pop();
            qe2.pop();
        }
        if(y>x){
            qe2.pop();
            qe2.push((y+1)/2);
            qe2.push(y/2);
        }
        if(y<x){
            cout<<"NO"<<endl;
            return;
        }
    }
    if(qe1.empty()&&qe2.empty())cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _=1;cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

Answer: 2


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 6;

int n, m;
int a[N], b[N];

void solve()
{
    cin >> n >> m;
    multiset<int> s;
    for(int i = 1; i <= n; i ++) cin >> a[i], s.insert(a[i]);
    for(int i = 1; i <= m; i ++) cin >> b[i];

    auto dfs = [&](auto self, int u) -> bool
    {
        if(u == 0) return false;
        if(s.count(u))
        {
            s.erase(s.find(u));
            return true;
        }
        return (self(self, u / 2) && self(self, u - u / 2));
    };
    for(int i = 1; i <= m; i ++)
        if(!dfs(dfs, b[i])) {cout << "No\n"; return;}
    if(s.empty()) cout << "Yes\n";
    else cout << "No\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int testcase = 1;
    cin >> testcase;
    while(testcase --) solve();
    return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 6;

int n, m;
int a[N], b[N];

void solve()
{
    cin >> n >> m;
    multiset<int> s;
    for(int i = 1; i <= n; i ++) cin >> a[i], s.insert(a[i]);
    for(int i = 1; i <= m; i ++) cin >> b[i];

    auto dfs = [&](auto self, int u) -> bool
    {
        if(u == 0) return false;
        if(s.contains(u))
        {
            s.erase(s.find(u));
            return true;
        }
        return (self(self, u / 2) && self(self, u - u / 2));
    };
    for(int i = 1; i <= m; i ++)
        if(!dfs(dfs, b[i])) {cout << "No\n"; return;}
    if(s.empty()) cout << "Yes\n";
    else cout << "No\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int testcase = 1;
    cin >> testcase;
    while(testcase --) solve();
    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
#define take(x)       \
    for (auto &y : x) \
        cin >> y;
#define show(x)           \
    for (auto y : x)      \
        cout << y << " "; \
    cout << endl;
#define pb push_back
#define max3(a, b, c) max(max((a), (b)), (c))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min(min((a), (b)), (c))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define all(v) v.begin(), v.end()
ll M = 998244353;
ll mod = 1e9 + 7;

void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    map<ll,ll> mp;
    priority_queue<ll> pq;
    for(int i = 0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(all(a));
    for(int i = 0;i<m;i++)
    {
        cin>>b[i];
        pq.push(b[i]);
    }
    int used = 0;
    while(!pq.empty() && used <= n)
    {
        if(pq.size() > n){
            cout<<"No"<<endl;
            return;
        }
        if(pq.top() < a[0])
        {
            cout<<"No"<<endl;
            return;
        }
        ll tp = pq.top();
        pq.pop();
        if(mp[tp]>=1)
        {
            mp[tp]--;
            used++;
            continue;
        }
        if(tp&1)
        {
            ll x = (tp+1)/2;
            ll y = tp - x;
            if(mp[x]>=1 && mp[y]>=1)
            {
                used += 2;
                mp[x]--;
                mp[y]--;
                continue;
            }
            else if(mp[x]>=1)
            {
                used+=1;
                mp[x]--;
                pq.push(y);
                continue;
            }
            else if(mp[y]>=1)
            {
                used+=1;
                mp[y]--;
                pq.push(x);
                continue;
            }
            else
            {
                pq.push(x);
                pq.push(y);
                continue;
            }
        }
        else
        {
            ll x = (tp+1)/2;
            ll y = tp - x;
            // cout<<x<<" "<<y<<" "<<mp[x]<<" "<<mp[y]<<endl;
            // return;
            if(mp[x]>=1 && mp[y]>=1)
            {
                used += 2;
                mp[x]--;
                mp[y]--;
                continue;
            }
            else if(mp[x]>=1)
            {
                used+=1;
                mp[x]--;
                pq.push(y);
                continue;
            }
            else if(mp[y]>=1)
            {
                used+=1;
                mp[y]--;
                pq.push(x);
                continue;
            }
            else
            {
                pq.push(x);
                pq.push(y);
                continue;
            }
        }

    }
    if(pq.empty() && n == used)
    {
        cout<<"Yes"<<endl;
        return;
    }
    cout<<"No"<<endl;
    return;
}

int main()
{
    int tt;
    cin >> tt;
    while (tt--)
    {
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
#define take(x)       \
    for (auto &y : x) \
        cin >> y;
#define show(x)           \
    for (auto y : x)      \
        cout << y << " "; \
    cout << endl;
#define pb push_back
#define max3(a, b, c) max(max((a), (b)), (c))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min(min((a), (b)), (c))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define all(v) v.begin(), v.end()
ll M = 998244353;
ll mod = 1e9 + 7;

void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    map<ll,ll> mp;
    priority_queue<ll> pq;
    for(int i = 0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(all(a));
    for(int i = 0;i<m;i++)
    {
        cin>>b[i];
        pq.push(b[i]);
    }
    int used = 0;
    while(!pq.empty() && used <= n)
    {
        if(pq.size() > n){
            cout<<"No"<<endl;
            return;
        }
        if(pq.top() < a[0])
        {
            cout<<"No"<<endl;
            return;
        }
        ll tp = pq.top();
        pq.pop();
        if(mp[tp]>=1)
        {
            mp[tp]--;
            used++;
            continue;
        }
        if(tp&1)
        {
            ll x = (tp+1)/2;
            ll y = tp - x;
            if(mp[x]>=1 && mp[y]>=1)
            {
                used += 2;
                mp[x]--;
                mp[y]--;
                continue;
            }
            else if(mp[x]>=1)
            {
                used+=1;
                mp[x]--;
                pq.push(y);
                // mp[y]++;
                continue;
            }
            else if(mp[y]>=1)
            {
                used+=1;
                mp[y]--;
                pq.push(x);
                // mp[x]++;
                continue;
            }
            else
            {
                pq.push(x);
                pq.push(y);
                // mp[x]++;
                // mp[y]++;
                continue;
            }
        }
        else
        {
            ll x = (tp+1)/2;
            ll y = tp - x;
            // cout<<x<<" "<<y<<" "<<mp[x]<<" "<<mp[y]<<endl;
            // return;
            if(mp[x]>=2)
            {
                used += 2;
                mp[x]--;
                mp[x]--;
                continue;
            }
            else if(mp[x]>=1)
            {
                used+=1;
                mp[x]--;
                pq.push(x);
                // mp[y]++;
                continue;
            }
            else
            {
                pq.push(x);
                pq.push(x);
                // mp[x]++;
                // mp[y]++;
                continue;
            }
        }

    }
    if(pq.empty())
    {
        for(auto i:mp)
        {
            if(i.second)
            {
                cout<<"No"<<endl;
                return;
            }
        }
        cout<<"Yes"<<endl;
        return;
    }
    cout<<"No"<<endl;
    return;
}

int main()
{
    int tt;
    cin >> tt;
    while (tt--)
    {
        solve();
    }

    return 0;
}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

#ifdef LOCAL

#include "debug.h"

#else

#define debug()

#define db(x)

#endif

#define INF 1e18

#define endl '\n'

#define ff first

#define ss second

#define pb push_back

#define int long long

#define mod 1000000007

#define pii  2 * acos(0.0)

#define double long double

#define sz(x) ((int)(x).size())

#define all(x) (x).begin(), (x).end()

#define rall(a) (a).rbegin(),(a).rend()

#define deci(x) cout << fixed << setprecision(x);

#define rmv(x,a) x.erase(remove(x.begin(),x.end(),a),x.end())

#define unq(x) {x.erase(unique(x.begin(),x.end()),x.end());}

#define shera() ios_base::sync_with_stdio(1);cin.tie(NULL);cout.tie(NULL)

template<typename T1>istream &operator>>(istream &cin, vector<T1>&a) {for (auto&x : a)cin >> x; return cin;}

int32_t main() {

    shera();

    debug();

    int tc; tc = 1;

    cin >> tc;

    for (int ii = 1; ii <= tc; ii++) {

        int n, m ; cin >> n >> m;

        vector<int>a(n); cin >> a;

        vector<int>b(m); cin >> b;

        map<int, int>mp;

        priority_queue<int, vector<int>, greater<int>>as;

        for (int i = 0; i < m ; i++) {

            mp[b[i]]++;

        }

        for (int i = 0; i < n ; i++) {

            if (!mp[a[i]]) {

                as.push(a[i]);

            }

            else {

                mp[a[i]]--;

            }

        }

        db(as)

        while (!as.empty()) {

            int x1 = as.top();

            as.pop();

            db(x1)

            if (mp[x1] ) {

                mp[x1]--;

                continue;

            }

            if (as.empty()) {

                as.push( x1);

                break;

            }

            int x2 = as.top();

            as.pop();

            if (x2 - x1 > 1)break;

            as.push(x2 + x1);

        }

        bool ok = 0;

        for (int i = 0; i < m ; i++) {

            if (mp[b[i]])ok = 1;

        }

        if (!ok && as.empty())cout << "Yes" << endl;

        else cout << "No" << endl;

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

#ifdef LOCAL

#include "debug.h"

#else

#define debug()

#define db(x)

#endif

#define INF 1e18

#define endl '\n'

#define ff first

#define ss second

#define pb push_back

#define int long long

#define mod 1000000007

#define pii  2 * acos(0.0)

#define double long double

#define sz(x) ((int)(x).size())

#define all(x) (x).begin(), (x).end()

#define rall(a) (a).rbegin(),(a).rend()

#define deci(x) cout << fixed << setprecision(x);

#define rmv(x,a) x.erase(remove(x.begin(),x.end(),a),x.end())

#define unq(x) {x.erase(unique(x.begin(),x.end()),x.end());}

#define shera() ios_base::sync_with_stdio(1);cin.tie(NULL);cout.tie(NULL)

template<typename T1>istream &operator>>(istream &cin, vector<T1>&a) {for (auto&x : a)cin >> x; return cin;}

bool solve(multiset<int>& a, int n) {

    if (a.empty()) return false;

    if (a.count(n)) {

        a.erase(a.find(n));

        return true;

    } else {

        if (n == 1)return false;

    }

    int left = n / 2;

    int right = n - left;

    if (solve(a, left) && solve(a, right)) return true;

    return false;

}

int32_t main() {

    shera();

    debug();

    int tc; tc = 1;

    cin >> tc;

    for (int ii = 1; ii <= tc; ii++) {

        int n, m ; cin >> n >> m;

        multiset<int>a, b;

        vector<int>v(n);

        for (int i = 0; i < n ; i++) {

            int x; cin >> x;

            v[i] = x;

            a.insert(x);

        }

        for (int i = 0; i < m ; i++) {

            int x; cin >> x;

            b.insert(x);

        }

        for (int i = 0; i < n ; i++) {

            if (b.find(v[i]) != b.end()) {

                a.erase(a.find(v[i]));

                b.erase(b.find(v[i]));

            }

        }

        if (a.empty()) {

            if (b.empty()) {

                cout << "Yes" << endl;

            }

            else {

                cout << "No" << endl;

            }

            continue;

        }

        if (b.empty()) {

            cout << "No" << endl;

            continue;

        }

        bool ok = 1;

        db(a)

        db(b)

        for (auto u : b ) {

            ok &= solve(a, u);

            db(ok)

        }

        if (ok && a.empty()) {

            cout << "Yes" << endl;

        } else {

            cout << "No" << endl;

        }

    }

    return 0;

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

// Function to check if sequence a can be transformed into sequence b
string canTransform(vector<int>& a, vector<int>& b) {
    long long sum_a = 0, sum_b = 0;

    // Calculate the sum of elements in a and b
    for (int x : a) sum_a += x;
    for (int x : b) sum_b += x;

    // If sums are not equal, transformation is impossible
    if (sum_a != sum_b) {
        return "No";
    }

    // Count frequencies of elements in a and b
    map<int, int> count_a, count_b;
    for (int x : a) count_a[x]++;
    for (int x : b) count_b[x]++;

    // Try to reduce count_a to count_b
    while (!count_a.empty()) {
        // Find the smallest element in count_a
        int min_a = count_a.begin()->first;

        bool found = false;
        for (auto& [target, cnt] : count_b) {
            if (abs(min_a - target) <= 1) {
                if (count_a[min_a] > 0) {
                    count_a[min_a]--;
                    if (count_a[min_a] == 0) {
                        count_a.erase(min_a);
                    }

                    if (target == min_a) {
                        count_b[target]--;
                        if (count_b[target] == 0) {
                            count_b.erase(target);
                        }
                        found = true;
                        break;
                    } else {
                        // Combine min_a with another element to form target
                        int needed = target - min_a;
                        if (count_a.count(needed) && count_a[needed] > 0) {
                            count_a[needed]--;
                            if (count_a[needed] == 0) {
                                count_a.erase(needed);
                            }

                            count_b[target]--;
                            if (count_b[target] == 0) {
                                count_b.erase(target);
                            }
                            found = true;
                            break;
                        }
                    }
                }
            }
        }

        if (!found) {
            return "No";
        }
    }

    if (!count_b.empty()) {
        return "No";
    }

    return "Yes";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;

        vector<int> a(n), b(m);
        for (int i = 0; i < n; ++i) cin >> a[i];
        for (int i = 0; i < m; ++i) cin >> b[i];

        cout << canTransform(a, b) << '\n';
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
unordered_map<int,int>umap;

bool dfs(int val) {
    if (umap.find(val) != umap.end()) {
        if (umap[val] > 0) {
            umap[val]-=1;
            return true;
        }
    }
    if (val==1) {
        return false;
    }
    if (val%2==0) {
        return dfs(val/2) && dfs(val/2);
    } else {
        return dfs(val/2) && dfs((val/2)+1);
    }
}

void solve() {
    umap.clear();
    int n; int m; ll suma = 0; ll sumb = 0;
    cin >> n >> m;
    int a[n];

    for (int i=0; i < n; i++) {
        cin >> a[i];
        suma += a[i];
    }

    int b[m];
    for (int i=0; i < m; i++) {
        cin >> b[i];
        sumb += b[i];
    }

    if (suma != sumb) {
        cout << "No\n";
        return;
    }
    for (int i = 0; i < n; i++) {
        umap[a[i]]+=1;
    }

    for (int i = 0; i < m; i++) {
        if (!dfs(b[i])) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";

    umap.clear();
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i < n; i++)
#define vi vector<int>
int hcf(int a, int g)
{
    if (g == 0)
        return a;
    else
        return hcf(g, a % g);
}
int lcm(int a, int g) { return (a * g) / hcf(a, g); }
int modInverse(int a, int mod) {
    int res = 1, p = mod - 2;
    while (p > 0) {
        if (p & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        p >>= 1;
    }
    return res;
}
int N=1e6;
vi f(N+1,1),inv_f(N+1,1);
void precompute() {
    for (int i = 2; i <= N; ++i) {
        f[i] = (f[i - 1] * i) % mod;
    }
    inv_f[N] = modInverse(f[N], mod);
    for (int i = N - 1; i >= 1; --i) {
        inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod;
    }
}
int ncr(int n, int r) {
    if (r > n) return 0;
    return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    vi a(n);
    vi b(m);
    fr(i,n) cin>>a[i];
    fr(i,m) cin>>b[i];
    map<int,int> ma,mb;
    fr(i,m){
        mb[b[i]]++;
    }
    fr(i,n){
        ma[a[i]]++;
    }
    sort(a.begin(),a.end());
    fr(i,m){
        if(ma[b[i]]>0 && mb[b[i]]>0){
            int y=min(ma[b[i]],mb[b[i]]);
            ma[b[i]]-=y;
            mb[b[i]]-=y;
        }
    }
    int f=0,x=0;

    for(int i=0;i<n;i++){
        if(ma[a[i]]==0) continue;
        else{
            if(f==0){
                x=a[i];
                ma[x]--;
                f=1;
            }
            else if(a[i]-x<=1){
                if(mb[x+a[i]]>0){
                mb[x+a[i]]--;
                f=0;
                x=0;
                }
                else x=x+a[i];
                ma[a[i]]--;
            }

        }
    }
    if(x!=0){
        cout<<"NO"<<endl;
        return;
    }
    fr(i,m){
        if(mb[b[i]]==0 && ma[b[i]]==0) continue;
        else{
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;

}
signed main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i < n; i++)
#define vi vector<int>
int hcf(int a, int g)
{
    if (g == 0)
        return a;
    else
        return hcf(g, a % g);
}
int lcm(int a, int g) { return (a * g) / hcf(a, g); }
int modInverse(int a, int mod) {
    int res = 1, p = mod - 2;
    while (p > 0) {
        if (p & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        p >>= 1;
    }
    return res;
}
int N=1e6;
vi f(N+1,1),inv_f(N+1,1);
void precompute() {
    for (int i = 2; i <= N; ++i) {
        f[i] = (f[i - 1] * i) % mod;
    }
    inv_f[N] = modInverse(f[N], mod);
    for (int i = N - 1; i >= 1; --i) {
        inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod;
    }
}
int ncr(int n, int r) {
    if (r > n) return 0;
    return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    priority_queue<int> a,b;
    fr(i,n){
        int x;
        cin>>x;
        a.push(x);
    }
    fr(i,m){
        int x;
        cin>>x;
        b.push(x);
    }
    while(!a.empty()){
        if(b.empty() || b.size()>a.size()){
            cout<<"no"<<endl;
            return;
        }
        int y=b.top();
        b.pop();
        if(a.top()>y){
             cout<<"no"<<endl;
            return;
        }
        if(a.top()==y){
            a.pop();
        }
        else{
            b.push(y/2);
            b.push((y+1)/2);
        }

    }
    if(!b.empty()){
         cout<<"no"<<endl;
            return;
    }
    cout<<"yes"<<endl;

}
signed main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using i128 = __int128;

int n,m;
void solve(){
    cin>>n>>m;
    vector<int> a(n),b(m);
    multiset<int> se1,se2;
    for(auto &i:a) cin>>i,se1.insert(i);
    for(auto &i:b) cin>>i,se2.insert(i);
        //int now = 0;
    while(!se2.empty()&&se2.size()<se1.size()){
        //cout<<now<<"\n";
        multiset<int> tmp;
        for(auto i:se2){
            if(se1.find(i)==se1.end()){
                if(i/2<=0) continue;
                tmp.insert(i/2);
                tmp.insert((i+1)/2);
            }else se1.erase(se1.find(i));
        }
        se2.swap(tmp);
    }
    if(se1.size()==se2.size()){
        for(auto i:se2){
            if(se1.find(i)==se1.end()){
                cout<<"No\n";
                return;
            }
        }
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using i128 = __int128;

int n,m;
void solve(){
    cin>>n>>m;
    vector<int> a(n),b(m);
    priority_queue<int> q;
    i64 sa=0,sb=0;
    for(auto &i:a) cin>>i,sa+=i;
    for(auto &i:b) cin>>i,sb+=i;
    if(sa!=sb){
        cout<<"No\n";
        return;
    }
    for(auto i:b) q.push(i);
    sort(a.begin(),a.end(),greater<int>());
    int idx = 0;
    //cout<<"check 1\n";
    while(!q.empty()){
       // cout<<idx<<"\n";
        if(q.top()<a[idx]){
            cout<<"No\n";
            return;
        }else if(q.top()==a[idx]){
            idx++;
            q.pop();
        }else{
            int x = q.top();
            q.pop();
            q.push(x/2);
            q.push((x+1)/2);
        }
    }
    cout<<"Yes\n";
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
#define int long long
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define tkv(vec,sz) rep(i,0,sz) cin>>vec[i]
#define srv(vec) sort(vec.begin(), vec.end())
#define all(x) x.begin(), x.end()
#define pvc(vec) for(auto x:vec) cout<<x<<" "; cout<<endl;
#define put(x) cout << (x)<< endl;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
inline int ctz(int x) { return __builtin_ctzll(x);}
inline int pc(int x) {return  __builtin_popcount(x);}
inline int hset(int x) {return __lg(x);}
/*
    NOT use unordered map use map
    NOT use seg tree use fenwick tree
    THINK before you code
*/

const int MOD = 1e9+7; // change me for god sake look at problem mod
const int INF = 1e16+5;
void testcase(){
    int n,m;
    cin >> n >> m;
    map<int,int> a,b;
    rep(i,0,n){
        int x;
        cin >> x;
        a[x]++;
    }
    rep(i,0,m){
        int x;
        cin >> x;
        b[x]++;
    }
    while (!b.empty()) {
    auto it = b.begin();
    auto req = *it;  // Store value before erasing
    b.erase(it);

    int d = min(req.second, a[req.first]);
    a[req.first] -= d;
    req.second -= d;

    if (req.second) {
        if (req.first == 1) {
            put("No");
            return;
        }
        if (req.first % 2) {
            b[req.first / 2] += req.second;
            b[req.first / 2 + 1] += req.second;
        } else {
            b[req.first / 2] += 2 * req.second;
        }
    }
}

    int rem = 0;
    for(auto x:a){
        if(x.second!=0){
            put("No");
            return;
        }
    }
    put("Yes");

}
int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    // freopen("input.in","r",stdin);
    // freopen("output.out","w",stdout);
    int T=1;
    cin>>T;
    while(T--) testcase();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
#define int long long
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define tkv(vec,sz) rep(i,0,sz) cin>>vec[i]
#define srv(vec) sort(vec.begin(), vec.end())
#define all(x) x.begin(), x.end()
#define pvc(vec) for(auto x:vec) cout<<x<<" "; cout<<endl;
#define put(x) cout << (x)<< endl;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
inline int ctz(int x) { return __builtin_ctzll(x);}
inline int pc(int x) {return  __builtin_popcount(x);}
inline int hset(int x) {return __lg(x);}
/*
    NOT use unordered map use map
    NOT use seg tree use fenwick tree
    THINK before you code
*/

const int MOD = 1e9+7; // change me for god sake look at problem mod
const int INF = 1e16+5;
void testcase(){
    int n,m;
    cin >> n >> m;
    map<int,int> a,b;
    rep(i,0,n){
        int x;
        cin >> x;
        a[x]++;
    }
    int mx = 0;
    rep(i,0,m){
        int x;
        cin >> x;
        b[x]++;
        mx = max(x,mx);
    }
    while (b.size())
    {
        auto it = b.begin();
        b.erase(it);
        auto req = *it;
        int d = min(req.second,a[req.first]);
        a[req.first] -=d;
        req.second-=d;
        if(req.second){
            if(req.first==1){
                put("No");
                return;
            }
            if(req.first%2) {b[req.first/2]+=req.second;b[req.first/2+1]+=req.second;}
            else {b[req.first/2] += 2*req.second;}
        }

    }
    int rem = 0;
    for(auto x:a){
        if(x.second!=0){
            put("No");
            return;
        }
    }
    put("Yes");

}
int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    // freopen("input.in","r",stdin);
    // freopen("output.out","w",stdout);
    int T=1;
    cin>>T;
    while(T--) testcase();

    return 0;
}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

#define pb push_back

#define dbg(x) //cerr<<#x<<": "<<x<<"\n";

void code(){

    int n,m;

    cin>>n>>m;

    ll a[n], b[m];

    for(int i=0;i<n;i++){

        cin>>a[i];

    }

    multiset<ll>ms;

    for(int i=0;i<m;i++){

        cin>>b[i];

        ms.insert(b[i]);

    }

    sort(a,a+n);

    sort(b,b+m);

    ll sum=0;

    for(int i=0;i<n;i++){

        sum+=a[i];

        if(ms.count(sum)){

            ms.erase(ms.find(sum));

            sum=0;

        }

        else if(i<n && a[i+1]-sum>1){

            cout<<"No\n";

            return;

        }

    }

    if(ms.empty()){

        cout<<"Yes\n";

    }

    else{

        cout<<"No\n";

    }

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //cout.tie(NULL);

    cout.precision(10);

    cout<<fixed;

    int t=1;

    cin>>t;

    for(int i=1;i<=t;i++){

        dbg("case"+to_string(i));

        //cout<<"Case "<<i<<":\n";

        code();

    }

}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

#define pb push_back

#define dbg(x) //cerr<<#x<<": "<<x<<"\n";

map<ll,int>mp;

bool ok(ll x){

    if(mp.count(x) && mp[x]>0){

        mp[x]--;

        return true;

    }

    if(x==1){

        return false;

    }

    if(ok(x/2)&&ok((x+1)/2)){

        return true;

    }

    return false;

}

void code(){

    mp.clear();

    int n,m;

    cin>>n>>m;

    ll a[n],b[m];

    for(int i=0;i<n;i++){

        cin>>a[i];

        mp[a[i]]++;

    }

    for(int i=0;i<m;i++){

        cin>>b[i];

    }

    for(int i=0;i<m;i++){

        if(!ok(b[i])){

            cout<<"No\n";

            mp.clear();

            return;

        }

    }

    for(auto it:mp){

        if(it.second>0){

            cout<<"No\n";

            mp.clear();

            return;

        }

    }

    cout<<"Yes\n";

    mp.clear();

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //cout.tie(NULL);

    cout.precision(10);

    cout<<fixed;

    int t=1;

    cin>>t;

    for(int i=1;i<=t;i++){

        dbg("case"+to_string(i));

        //cout<<"Case "<<i<<":\n";

        code();

    }

}

Answer: 2


//bismillah
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define rep(a, i) for (int i = 0; i < (a); i++)
#define read(a, n) for (int i = 0; i < (n); i++) { cin >> a[i]; }
#define pB pop_back
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define int long long
#define pi pair<long long, long long>
int mod = 998244353;

void solve(){
    int n, m; cin >> n >> m;
    multiset<int> a;
    rep(n, i){
        int aa; cin >> aa;
        a.insert(aa);
    }
    multiset<int> b;
    rep(m, i){
        int aa; cin >> aa;
        b.insert(aa);
    }

    rep(2*n-m, i){
        if(b.empty()){
            cout << "NO";
            return;
        }

        int cur = *prev(b.end());
        b.erase(prev(b.end()));

        if(a.find(cur) != a.end()){
            a.erase(a.find(cur));
        }
        else{
            if(cur & 1){
                b.insert(cur/2);
                b.insert(cur/2 + 1);
            }

            else{
                b.insert(cur/2);
                b.insert(cur/2);
            }
        }

    }

    if(b.empty()) cout << "YES";
    else
    cout << "NO";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

//bismillah
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define rep(a, i) for (int i = 0; i < (a); i++)
#define read(a, n) for (int i = 0; i < (n); i++) { cin >> a[i]; }
#define pB pop_back
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define int long long
#define pi pair<long long, long long>
int mod = 998244353;

void solve(){
    int n, m; cin >> n >> m;
    multiset<int> a;
    rep(n, i){
        int aa; cin >> aa;
        a.insert(aa);
    }
    vector<int> b(m);
    rep(m, i){
        cin >> b[i];
    }

    vector<int> baru;
    for(auto u : b){
        if(!a.empty() && a.find(u) != a.end()){
            a.erase(a.find(u));
        }
        else baru.pb(u);
    }

    sort(all(baru));

    //cout << a.size();
    for(auto e : baru){
        if(a.size() < 2){
            cout << "NO";
            return;
        }
        int cur = e;
        int satu = cur/2;
        int dua = satu;
        if(cur & 1) dua++;

        while(a.size() > 1 && *a.begin() < satu){
            auto it = a.begin();
            int f = *a.begin();
            it++;
            int s = *it;
            if(s - f > 1){
                cout << "NO";
                return;
            }
            a.erase(a.begin());
            a.erase(it);
            a.insert(f + s);
        }

        if(a.find(satu) == a.end() || a.find(dua) == a.end()){
            // cout << cur << ' ';
            // cout << "NO";
            cout << "NO";
            return;
        }
        else{
            a.erase(a.find(satu));
            a.erase(a.find(dua));
        }
    }

    if(!a.empty()) cout << "NO";
    else
    cout << "YES";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long t,n,m,i,x;
	cin>>t;
	while(t--){
		cin>>n>>m;
		multiset<long long> a;
		stack<long long> b;
		for(i=0;i<n;i++){
			cin>>x;
			a.insert(x);
		}
		for(i=0;i<m;i++){
			cin>>x;
			b.push(x);
		}
		while(!b.empty()){
			x=b.top();
			b.pop();
			if(a.find(x)!=a.end())
				a.erase(a.find(x));
			else if(x==1){
				b.push(x);
				break;
			}
			else{
				b.push(x/2);
				b.push((x+1)/2);
			}
		}
		cout<<(b.empty()&&a.empty()?"Yes\n":"No\n");
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long t,n,m,i,x,y;
	cin>>t;
	while(t--){
		cin>>n>>m;
		priority_queue<long long,vector<long long>,greater<long long>> a;
		vector<long long> b;
		for(i=0;i<n;i++){
			cin>>x;
			a.push(x);
		}
		for(i=0;i<m;i++){
			cin>>x;
			b.push_back(x);
		}
		sort(b.begin(),b.end());
		i=0;
		while(!a.empty()){
			x=a.top();
			a.pop();
			if(i>=m)
				break;
			else if(x==b[i])
				i++;
			else{
				if(a.empty())
					break;
				else{
					y=a.top();
					a.pop();
					if(y-x>1)
						break;
					else
						a.push(x+y);
				}
			}
		}
		if(i==m&&a.empty())
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
	return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+10;
const ll INF=1e17+10;
const ll MOD=1e9+7;
ll n,m;
ll a[N],b[N];

void solve(void){
	cin>>n>>m;
	multiset<ll,greater<ll>>st1,st2;
	ll sum1=0,sum2=0;
	for(ll i=1;i<=n;++i){
		cin>>a[i];
		sum1+=a[i];
		st2.insert(a[i]);
	}
	for(ll i=1;i<=m;++i){
		cin>>b[i];
		sum2+=b[i];
		if(st2.count(b[i])){
			st2.erase(st2.find(b[i]));
		}
		else st1.insert(b[i]);
	}
	if(sum1!=sum2){
		cout<<"No\n";
		return;
	}
	ll f=1;
	while(st2.size()&&st1.size()&&st2.size()>=st1.size()){
		auto it=st1.begin();
		ll tmp=*it;
		ll x=tmp/2;
		ll y=tmp-x;
		ll mmax=*st2.begin();
		if(x>mmax||y>mmax){
			break;
		}
		st1.erase(it);
		if(st2.count(x)){
			st2.erase(st2.find(x));
		}else{
			st1.insert(x);
		}
		if(st2.count(y)){
			st2.erase(st2.find(y));
		}else{
			st1.insert(y);
		}
	}
	if(st1.size()==0&&st2.size()==0)cout<<"Yes\n";
	else cout<<"No\n";

}
int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll times=1;
	cin>>times;
	while(times--)solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+10;
const ll INF=1e17+10;
const ll MOD=1e9+7;
ll n,m;
ll a[N],b[N];

void solve(void){
	cin>>n>>m;
	multiset<ll>st1,st2;
	ll sum1=0,sum2=0;
	for(ll i=1;i<=n;++i){
		cin>>a[i];
		sum1+=a[i];
		st1.insert(a[i]);
	}
	for(ll i=1;i<=m;++i){
		cin>>b[i];
		sum2+=b[i];
		if(st1.count(b[i])){
			st1.erase(st1.find(b[i]));
		}
		else st2.insert(b[i]);
	}
	if(sum1!=sum2){
		cout<<"No\n";
		return;
	}
	ll f=1;
	while(st1.size()&&st2.size()){
		ll x=*st1.rbegin(),y=*st2.rbegin();
		if(x>y)break;
		if(x==y){
			st1.erase(st1.find(x));
			st2.erase(st2.find(y));
		}else {
			st2.erase(st2.find(y));
			st2.insert(y/2);
			st2.insert((y+1)/2);
		}
	}
	if(st1.size()==0&&st2.size()==0)cout<<"Yes\n";
	else cout<<"No\n";

}
int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll times=1;
	cin>>times;
	while(times--)solve();
	return 0;
}

Answer: 2