Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || हर हर महादेव!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
#define yep               \
   cout << "Yes" << endl; \
   return;
#define nope             \
   cout << "No" << endl; \
   return;
#define pb push_back
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define sq(a) a *a
#define nl endl;
#define inf (1LL << 60)
const int Mod = 1e9 + 7;
#define all(x) x.begin(), x.end()

int inv(ll i)
{
   if (i == 1)
     return 1;
   return (Mod - ((Mod / i) * inv(Mod % i)) % Mod) % Mod;
}
int mod(int a, int m)
{
   return (a % m + m) % m;
}
int mod_mul(int a, int b, int m = Mod) { return mod(mod(a, m) * mod(b, m), m); }
int mod_pow(int a, int b, int m)
{
   if (b == 0)
      return 1;
   else
      return mod_mul(a, mod_pow(a, b - 1, m), m);
}
int mod_div(int a, int b, int d = Mod)
{
   return mod_mul(a, mod_pow(b, d - 2, d));
}
ll power(ll a, ll b, int M = Mod)
{
   a = a % M;
   int result = 1;
   while (b > 0)
   {
      if (b & 1)
         result = (result * 1LL * a) % M;
      a = (a * 1LL * a) % M;
      b >>= 1;
   }
   return result;
}
// uint64_t ; for 64 bits
// uint32_t ; for 32 bits
// no of subarrays if atleast k elements are required from an array of size n = (n+1-k)*(n+2-k)/2;
//__builtin_popcount(x) = returns set bits
void solve()
{
   ll n;
   cin >> n;
   int m;
   cin >> 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);
   }
   vector<int> rem;
   for(auto i : a){
      if(b.find(i) != b.end()){
         rem.push_back(i);
         b.erase(b.find(i));
      }
   }
   for(auto i : rem){
      a.erase(a.find(i));
   }
   while(b.size() && a.size()){

      int ind = *(b.begin());
      b.erase(b.begin());
      // cout << ind << endl;
      int one = (ind + 1) / 2;
      int two = ind / 2;
      if(one == 0 || two == 0){
         nope;
      }
      if(a.find(two) != a.end()){
         a.erase(a.find(two));
      }else{
         b.insert(two);
      }
      if(a.find(one) != a.end()){
         a.erase(a.find(one));
      }else{
         b.insert(two);
      }
   }
   if(a.size() == 0 && b.size() == 0){
      yep;
   }else{
      nope;
   }

}
signed main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t = 1;
   cin >> t;
   while (t--)
   {
      solve();
   }
}
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || जय शिव शम्भू !
*/

Submission (verdict: Accepted):
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || हर हर महादेव!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
#define yep               \
   cout << "Yes" << endl; \
   return;
#define nope             \
   cout << "No" << endl; \
   return;
#define pb push_back
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define sq(a) a *a
#define nl endl;
#define inf (1LL << 60)
const int Mod = 1e9 + 7;
#define all(x) x.begin(), x.end()

int inv(ll i)
{
   if (i == 1)
     return 1;
   return (Mod - ((Mod / i) * inv(Mod % i)) % Mod) % Mod;
}
int mod(int a, int m)
{
   return (a % m + m) % m;
}
int mod_mul(int a, int b, int m = Mod) { return mod(mod(a, m) * mod(b, m), m); }
int mod_pow(int a, int b, int m)
{
   if (b == 0)
      return 1;
   else
      return mod_mul(a, mod_pow(a, b - 1, m), m);
}
int mod_div(int a, int b, int d = Mod)
{
   return mod_mul(a, mod_pow(b, d - 2, d));
}
ll power(ll a, ll b, int M = Mod)
{
   a = a % M;
   int result = 1;
   while (b > 0)
   {
      if (b & 1)
         result = (result * 1LL * a) % M;
      a = (a * 1LL * a) % M;
      b >>= 1;
   }
   return result;
}
// uint64_t ; for 64 bits
// uint32_t ; for 32 bits
// no of subarrays if atleast k elements are required from an array of size n = (n+1-k)*(n+2-k)/2;
//__builtin_popcount(x) = returns set bits
void solve()
{
   ll n;
   cin >> n;
   int m;
   cin >> 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);
   }
   vector<int> rem;
   for(auto i : a){
      if(b.find(i) != b.end()){
         rem.push_back(i);
         b.erase(b.find(i));
      }
   }
   for(auto i : rem){
      a.erase(a.find(i));
   }
   while(b.size() && a.size()){

      int ind = *(b.begin());
      b.erase(b.begin());
      // cout << ind << endl;
      int one = (ind + 1) / 2;
      int two = ind / 2;
      if(one == 0 || two == 0){
         nope;
      }
      if(a.find(two) != a.end()){
         a.erase(a.find(two));
      }else{
         b.insert(two);
      }
      if(a.find(one) != a.end()){
         a.erase(a.find(one));
      }else{
         b.insert(one);
      }
   }
   if(a.size() == 0 && b.size() == 0){
      yep;
   }else{
      nope;
   }

}
signed main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t = 1;
   cin >> t;
   while (t--)
   {
      solve();
   }
}
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || जय शिव शम्भू !
*/