ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(n == 1){
        cout << a[0] << endl;
        return;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        int sum = 0;
        for(int j=0;j<n-i;j++){
            if(i != 0){
                a[j] = a[j+1] - a[j];
            }
            sum += a[j];
        }
        ans = max(ans, abs(sum));
    }
    cout << ans << endl;
}

// ababa

// baba                  aaba
// bba aba              aba    
// ba   ba  aa         ba   aa
// a b  a b a  

// 9  

// abcde

// acde    bcde
// ade cde  bde 
// ae de  ce  be 

// a b c d e

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




Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n;
    cin >> n;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(n == 1){
        cout << a[0] << endl;
        return;
    }
    long long int ans = 0;
    for(int i=0;i<n;i++){
        long long int sum = 0;
        for(int j=0;j<n-i;j++){
            if(i != 0){
                a[j] = a[j+1] - a[j];
            }
            sum += a[j];
        }
        ans = max(ans, abs(sum));
    }
    cout << ans << endl;
}

// ababa

// baba                  aaba
// bba aba              aba    
// ba   ba  aa         ba   aa
// a b  a b a  

// 9  

// abcde

// acde    bcde
// ade cde  bde 
// ae de  ce  be 

// a b c d e

int main(){
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define prll(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << '\n';
#define FOR(a, b, i) for (long long i = a; i < b; i++)
#define FORR(a, b, i) for (long long i = a; i > b; --i)
#define FOR_vec(vec, i) for (auto &i : vec)
#define OUT(a) FOR_vec(a, i) cout << i << ' '; cout << "\n";
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define inf INT_MAX

using namespace std;
using ll = long long;
using db = long double;
using str = string;

const ll mod = 998244353;

bool rec(ll a, multiset<ll> &vec){
    auto it = find(all(vec), a);
    if (it != vec.end()){
        vec.erase(it);
        return 1;
    }
    if (a == 1) return 0;
    if (a % 2) return (rec(a/2, vec) && rec(a/2+1, vec));
    else return (rec(a/2, vec) && rec(a/2, vec));
}

void logik(){
    ll n, m;
    cin >> n >> m;
    multiset<ll> vec;
    FOR(0, n, i){
        ll a;
        cin >> a;
        vec.insert(a);
    }
    FOR(0, m, j){
        ll a;
        cin >> a;
        if (!rec(a, vec)){
            cout << "No\n";
            return;
        }
    }
    if (vec.size() == 0) cout << "Yes\n";
    else cout << "No\n";
//    cout.flush();
}

int main() {
    FAST;
//    OUT(vec);
    ll t;
    cin >> t;
    while (t--){
        logik();
    }
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 16):
#pragma GCC optimize("O3")
//#pragma gcc target("avx,avx2,fma")
//#pragma gcc optimization ("unroll-loops")
//#pragma gcc target("avx,avx2,sse,sse2,sse3,sse4,popcnt")
#include <bitset>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <queue>
#include <deque>
#include <iterator>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <stack>
#include <random>
#include <string>
#include <functional>
#include <chrono>
#include <numeric>
#include <climits>
#include <tuple>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;


typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> pii;

const LL DIM = 1007;
const LL INF = 999999999999999999;
const LL OFFSET = 250000;
const LL MAX_SUM = 500007;

LL F[DIM][DIM];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    LL n, m, t;
    string a, b, s;
    cin >> t;
    for (int T = 1; T <= t; T++) {
        cin >> a >> b >> s;

        n = a.length();
        m = b.length();

        F[0][0] = b[0] == s[0] ? 0 : 1;
        F[0][1] = a[0] == s[0] ? 0 : 1;
        //cout << F[0][0] << " " << F[0][1] << endl;
        for (int i = 2; i < n; i++) {
            F[0][i] = -1;
        }
        for (int l = 1; l < n + m; l++) {
            if (l < m) {
                LL c = b[l] == s[l] ? 0 : 1;
                F[l][0] = F[l - 1][0] + c;
            }
            else F[l][0] = -1;
            //cout << F[l][0] << " ";
            for (int i = 1; i <= l + 1; i++) {
                if (l - i > m || i > n) {
                    F[l][i] = -1;

                    //cout << F[l][i] << " ";
                    continue;
                }
                
                if (l - i < 0) {
                    LL c2 = a[i - 1] == s[l] ? 0 : 1;
                    F[l][i] = F[l - 1][i - 1] + c2;
                }
                else if (i - 1 < 0) {
                    LL c1 = b[l - i] == s[l] ? 0 : 1;
                    F[l][i] = F[l - 1][i] + c1;
                }
                else {
                    LL c1 = b[l - i] == s[l] ? 0 : 1;
                    LL c2 = a[i - 1] == s[l] ? 0 : 1;

                    //if(i == 2 && l == 2) cout << F[l - 1][i] << endl;

                    if (F[l - 1][i] == -1) F[l][i] = F[l - 1][i - 1] + c2;
                    else F[l][i] = min(F[l - 1][i] + c1, F[l - 1][i - 1] + c2);
                }

                //cout << F[l][i] << " ";
            }
            //cout << endl;
            for (int i = l + 2; i < n; i++) F[l][i] = -1;
        }
        cout << F[s.length() - 1][n] << endl;
    }


    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

int teamIndependence(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void solve()
{
    int l,r,maxInd=-1,a=l; cin>>l>>r;
    for(int i=l; i<=r; i++)
    {
        int ind=teamIndependence(i,i+1,i == l ? r : l);
        if(ind>maxInd)
        {
            a=i;
        }
    }
    int b = a + 1, c = (a == l ? r : l);
    cout << a << " " << b << " " << c << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

int teamIndependence(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void solve()
{
    int l,r,maxInd=-1,a=l; cin>>l>>r;
    for(int i=l; i<r; i++)
    {
        int ind=teamIndependence(i,i+1,i == l ? r : l);
        if(ind>maxInd)
        {
            a=i;
        }
    }
    int b = a + 1, c = (a == l ? r : l);
    cout << a << " " << b << " " << c << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

int teamIndependence(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void solve()
{
    int l,r,maxInd=-1,a=l; cin>>l>>r;
    for(int i=l; i<r; i++)
    {
        int ind=teamIndependence(i,i+1,i == l ? r : l);
        if(ind>maxInd)
        {
            a=i;
        }
    }
    int b = a + 1, c = (a == l ? r : l);
    cout << a << " " << b << " " << c << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    int l,r; cin>>l>>r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
    cout << a << " " << b << " " << c << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

int teamIndependence(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void solve()
{
    int l, r;
    cin >> l >> r;

    if (r - l <= 8) {
        // Brute force for small ranges
        int maxVal = -1;
        int a_res = l, b_res = l, c_res = l;
        for (int a = l; a <= r; ++a) {
            for (int b = a + 1; b <= r; ++b) {
                for (int c = b + 1; c <= r; ++c) {
                    int val = teamIndependence(a, b, c);
                    if (val > maxVal) {
                        maxVal = val;
                        a_res = a;
                        b_res = b;
                        c_res = c;
                    }
                }
            }
        }
        cout << a_res << " " << b_res << " " << c_res << endl;
    } else {
        // Large range: choose r, r-1, r-2
        cout << r << " " << r - 1 << " " << r - 2 << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

int teamIndependence(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void solve()
{
    int l,r,maxInd=-1,a=l; cin>>l>>r;
    for(int i=l; i<=r; i++)
    {
        int ind=teamIndependence(i,i+1,i == l ? r : l);
        if(ind>maxInd)
        {
            a=i;
        }
    }
    int b = a + 1, c = (a == l ? r : l);
    cout << a << " " << b << " " << c << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define ll long long
#define MOD 1000000007
#define heeho(n) ((((n) % MOD) + MOD) % MOD)
#define CEILDIV(m, n) (((m) + (n) -1) / (n))
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set [[maybe_unused]] = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;//find_by_order, order_of_key
template<typename T>
using ordered_multiset [[maybe_unused]] = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

int teamIndependence(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}

void solve()
{
    int l, r;
    cin >> l >> r;

    if (r - l <= 8) {
        // Brute force for small ranges
        int maxVal = -1;
        int a_res = l, b_res = l, c_res = l;
        for (int a = l; a <= r; ++a) {
            for (int b = a + 1; b <= r; ++b) {
                for (int c = b + 1; c <= r; ++c) {
                    int val = teamIndependence(a, b, c);
                    if (val > maxVal) {
                        maxVal = val;
                        a_res = a;
                        b_res = b;
                        c_res = c;
                    }
                }
            }
        }
        cout << a_res << " " << b_res << " " << c_res << endl;
    } else {
        // Large range: choose r, r-1, r-2
        cout << r << " " << r - 1 << " " << r - 2 << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 9):
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define int long long
#define endl "\n"
#define fi first
#define se second
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int,int>
#define eb emplace_back
const int mod=1e9+7;
const int inf=1e18;
void solve(){
	int n,m;
	cin>>n>>m;
	map<int,int>c;
	vi a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int f=1;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		if(c[b[i]]) c[b[i]]--;
		else{
			map<int,int> c2=c;
			int cnt=n;
			function<bool(int)> sch=[&](int k){
				if(c2[k]){
					c2[k]--;
					cnt--;
					return true;
				}
				if(k==1||k==0) return false;
				if(k%2==0){
					if(sch(k/2)&&sch(k/2)) return true;
					else return false;
				}
				else{
					if(sch(k/2)&&sch(k/2+1)) return true;
					else return false;
				}
			};
			if(sch(b[i])){
				c=c2;
				n=cnt+1;
			}
			else{
				f=0;
				break;	
			}
		}		
	}
	if(f&&n==m) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Time limit exceeded on test 9):
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define int long long
#define endl "\n"
#define fi first
#define se second
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int,int>
#define eb emplace_back
const int mod=1e9+7;
const int inf=1e18;
void solve(){
	int n,m;
	cin>>n>>m;
	map<int,int>c;
	vi a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int f=1;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<m;i++){
		if(c[b[i]]) c[b[i]]--;
		else{
			map<int,int> c2=c;
			int cnt=n;
			function<bool(int)> sch=[&](int k){
				if(c2[k]){
					c2[k]--;
					cnt--;
					return true;
				}
				if(k==1||k==0) return false;
				if(k%2==0){
					if(sch(k/2)){
						if(sch(k/2)){
							return true;
						}
						else return false;
					} 
					else return false;
				}
				else{
					if(sch(k/2)){
						if(sch(k/2+1)) return true;
						else return false;
					}
					else return false;
				}
			};
			if(sch(b[i])){
				c=c2;
				n=cnt+1;
			}
			else{
				f=0;
				break;	
			}
		}		
	}
	if(f&&n==m) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 9):
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define int long long
#define endl "\n"
#define fi first
#define se second
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int,int>
#define eb emplace_back
const int mod=1e9+7;
const int inf=1e18;
void solve(){
	int n,m;
	cin>>n>>m;
	map<int,int>c;
	vi a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int f=1;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		if(c[b[i]]) c[b[i]]--;
		else{
			map<int,int> c2=c;
			int cnt=n;
			function<bool(int)> sch=[&](int k){
				if(c2[k]){
					c2[k]--;
					cnt--;
					return true;
				}
				if(k==1||k==0) return false;
				if(k%2==0){
					if(sch(k/2)&&sch(k/2)) return true;
					else return false;
				}
				else{
					if(sch(k/2)&&sch(k/2+1)) return true;
					else return false;
				}
			};
			if(sch(b[i])){
				c=c2;
				n=cnt+1;
			}
			else f=0;
		}		
	}
	if(f&&n==m) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 9):
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define int long long
#define endl "\n"
#define fi first
#define se second
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int,int>
#define eb emplace_back
const int mod=1e9+7;
const int inf=1e18;
void solve(){
	int n,m;
	cin>>n>>m;
	map<int,int>c;
	vi a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int f=1;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	int cnt;
	map<int,int> c2;
    function<bool(int)> sch=[&](int k){
		if(c2[k]){
			c2[k]--;
			cnt--;
			return true;
		}
		if(k==1||k==0) return false;
		if(k%2==0){
			if(sch(k/2)){
				if(sch(k/2)) return true;
				else return false;
			}
			else return false;
		}
		else{
			if(sch(k/2)){
				if(sch(k/2+1)) return true;
				else return false;
			}
			else return false;
		}
	};	
	for(int i=0;i<m;i++){
		if(n<m){
			f=0;
			break;
		}
		if(c[b[i]]) c[b[i]]--;
		else{
			c2=c;
			cnt=n;
			if(sch(b[i])){
				c=c2;
				n=cnt+1;
			}
			else{
				f=0;
				break;	
			}
		}		
	}
	if(f&&n==m) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define int long long
#define endl "\n"
#define fi first
#define se second
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int,int>
#define eb emplace_back
const int mod=1e9+7;
const int inf=1e18;
void solve(){
	int n,m;
	cin>>n>>m;
	map<int,int>c;
	vi a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int f=1;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	int cnt;
    function<bool(int)> sch=[&](int k){
		if(c[k]){
			c[k]--;
			cnt--;
			return true;
		}
		if(k==1||k==0) return false;
		if(k%2==0){
			if(sch(k/2)){
				if(sch(k/2)) return true;
				else return false;
			}
			else return false;
		}
		else{
			if(sch(k/2)){
				if(sch(k/2+1)) return true;
				else return false;
			}
			else return false;
		}
	};	
	for(int i=0;i<m;i++){
		if(n<m){
			f=0;
			break;
		}
		if(c[b[i]]) c[b[i]]--;
		else{
			cnt=n;
			if(sch(b[i])){
				n=cnt+1;
			}
			else{
				f=0;
				break;	
			}
		}		
	}
	if(f&&n==m) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}