ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<deque>
using namespace std;
void work(){
    int n;
    cin>>n;
    int check=0;
    vector<int>a(n);
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        a[i-1]-=min(a[i-1],a[i]);
        a[i]-= min(a[i-1],a[i]);
    }
    for(int i=0;i<n-1;i++){
        if(a[i]!=0){
            cout<<"NO"<<"\n";
            return;
        }
    }
    cout<<"YES"<<"\n";

}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        work();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<deque>
using namespace std;
void work(){
    int n;
    cin>>n;
    int check=0;
    vector<int>a(n);
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        int c =min(a[i-1],a[i]);
        a[i-1]-=c;
        a[i]-=c;
    }
    for(int i=0;i<n-1;i++){
        if(a[i]!=0){
            cout<<"NO"<<"\n";
            return;
        }
    }
    cout<<"YES"<<"\n";

}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        work();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<deque>
using namespace std;
void work(){
    int n;
    cin>>n;
    int check=0;
    vector<int>a(n);
    cin>>a[0];
    cin>>a[1];
    if(a[0]>a[1]){
        check=1;
    }
    for(int i=2;i<n;i++){
        cin>>a[i];
        if(a[i]<a[i-1]-a[i-2]){
        check=1;}
        
    }
    if(check!=1){
        cout<<"YES"<<"\n";
    }
    else{
        cout<<"NO"<<"\n";
    }

    
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        work();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<deque>
using namespace std;
void work(){
    int n;
    cin>>n;
    int check=0;
    vector<int>a(n);
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        a[i-1]-=min(a[i-1],a[i]);
        a[i]-= min(a[i-1],a[i]);
    }
    for(int i=0;i<n-1;i++){
        if(a[i]!=0){
            cout<<"NO"<<"\n";
            return;
        }
    }
    cout<<"YES"<<"\n";

}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        work();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#define int long long

const int MAXN = 1e6 + 5;
const int inf = 2147483627;
const int mod = 998244353;
int a[MAXN];
signed main () {

	int N,n,l,r;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		int ans=0;
		for(int i=1;i<=r-l+1;i++)
		{
			ans+=a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}



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

#define int long long

const int MAXN = 1e6 + 5;
const int inf = 2147483627;
const int mod = 998244353;
int a[MAXN],b[MAXN],c[MAXN];
signed main () {

	int N,n,l,r;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
			c[i]=a[i];
		}
		sort(b+1,b+1+r);
		sort(c+1+l,c+1+n);
		int ans1=0,ans2=0;;
		for(int i=1;i<=r-l+1;i++)
		{
			ans1+=b[i];
		}
		for(int i=l;i<=r;i++)
		{
			ans2+=c[i];
		}
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

#define int long long

const int MAXN = 1e6 + 5;
const int inf = 2147483627;
const int mod = 998244353;
int a[MAXN];
signed main () {

	int N,n,l,r;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		int ans=0;
		for(int i=1;i<=r-l+1;i++)
		{
			ans+=a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#define int long long

const int MAXN = 1e6 + 5;
const int inf = 2147483627;
const int mod = 998244353;
int a[MAXN],b[MAXN],c[MAXN];
signed main () {

	int N,n,l,r;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
			c[i]=a[i];
		}
		sort(b+1,b+1+r);
		sort(c+1+l,c+1+n);
		int ans1=0,ans2=0;;
		for(int i=1;i<=r-l+1;i++)
		{
			ans1+=b[i];
		}
		for(int i=l;i<=r;i++)
		{
			ans2+=c[i];
		}
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 1e6 + 5;
const int inf = 2147483627;
const int mod = 998244353;
int a[MAXN],b[MAXN],c[MAXN];
signed main () {

	int N,n,l,r;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
			c[i]=a[i];
		}
		sort(b+1,b+1+r);
		sort(c+l,c+1+n);
		int ans1=0,ans2=0;;
		for(int i=1;i<=r-l+1;i++)
		{
			ans1+=b[i];
		}
		for(int i=l;i<=r;i++)
		{
			ans2+=c[i];
		}
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void f(long long n)
{
    long long sum=0;
    bool f=false;
    int c2=0,c3=0,x=0,y=0;
    int r,m,e,k=0;
    long long t=n;
    while(t!=0)
    {
        r=t%10;
        k++;
        if(r==2)
        c2++;
        else if(r==3)
        c3++;
        sum=sum+0LL+r;
        t=t/10;
    }
    m=sum%9;
    e=9-m;
    if(m==0)
    {
        f=true;
    }
    else
    {
        while(x<=min(10,c2))
        {
            y=0;
            while(y<=min(10,c3))
            {
                if((sum+y*6+x*2)%9==0)
                {
                    f=true;
                    break;
                }
                y++;
            }
            x++;
        }
    }
    if(f)
    cout<<"YES"<<"\n";
    else
    cout<<"NO"<<"\n";
}
int main()
{
    int t,i,j;
    long long n;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        f(n);
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

void solve() {
    string input;
    cin >> input;

    vector<int> s;
    for (char ch : input) {
        s.push_back(ch - '0');
    }

    int sm = 0;
    int twos = 0, threes = 0;

    for (int digit : s) {
        sm += digit;
        if (digit == 2) twos++;
        if (digit == 3) threes++;
    }

    for (int i = 0; i <= min(10, twos); i++) {
        for (int j = 0; j <= min(10, threes); j++) {
            if ((sm + i * 2 + j * 6) % 9 == 0) {
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
}

int main() {
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void f(long long n)
{
    long long sum=0;
    bool f=false;
    int c2=0,c3=0,x=0,y=0;
    int r,m,e,k=0;
    long long t=n;
    while(t!=0)
    {
        r=t%10;
        k++;
        if(r==2)
        c2++;
        else if(r==3)
        c3++;
        sum=sum+0LL+r;
        t=t/10;
    }
    m=sum%9;
    e=9-m;
    if(m==0)
    {
        f=true;
    }
    while(x<=c2)
    {
        y=0;
        while(y<=c3)
        {
            if((sum+y*6+x*2)%9==0)
            {
                f=true;
                break;
            }
            y++;
        }
        x++;
    }
    if(f)
    cout<<"YES"<<"\n";
    else
    cout<<"NO"<<"\n";
}
int main()
{
    int t,i,j;
    long long n;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        f(n);
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void f(long long n)
{
    long long sum=0;
    bool f=false;
    int c2=0,c3=0,x=0,y=0;
    int r,m,e,k=0;
    long long t=n;
    while(t!=0)
    {
        r=t%10;
        k++;
        if(r==2)
        c2++;
        else if(r==3)
        c3++;
        sum=sum+0LL+r;
        t=t/10;
    }
    m=sum%9;
    e=9-m;
    if(m==0)
    {
        f=true;
    }
    else
    {
        while(x<=c2)
        {
            y=0;
            while(y<=c3)
            {
                if((sum+y*6+x*2)%9==0)
                {
                    f=true;
                    break;
                }
                y++;
            }
            x++;
        }
    }
    if(f)
    cout<<"YES"<<"\n";
    else
    cout<<"NO"<<"\n";
}
int main()
{
    int t,i,j;
    long long n;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        f(n);
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void f(long long n)
{
    long long sum=0;
    bool f=false;
    int c2=0,c3=0,x=0,y=0;
    int r,m,e,k=0;
    long long t=n;
    while(t!=0)
    {
        r=t%10;
        k++;
        if(r==2)
        c2++;
        else if(r==3)
        c3++;
        sum=sum+0LL+r;
        t=t/10;
    }
    m=sum%9;
    e=9-m;
    if(m==0)
    {
        f=true;
    }
    while(x<=c2)
    {
        y=0;
        while(y<=c3)
        {
            if((sum+y*6+x*2)%9==0)
            {
                f=true;
                break;
            }
            y++;
        }
        x++;
    }
    if(f)
    cout<<"YES"<<"\n";
    else
    cout<<"NO"<<"\n";
}
int main()
{
    int t,i,j;
    long long n;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        f(n);
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void f(long long n)
{
    long long sum=0;
    bool f=false;
    int c2=0,c3=0,x=0,y=0;
    int r,m,e,k=0;
    long long t=n;
    while(t!=0)
    {
        r=t%10;
        k++;
        if(r==2)
        c2++;
        else if(r==3)
        c3++;
        sum=sum+0LL+r;
        t=t/10;
    }
    m=sum%9;
    e=9-m;
    if(m==0)
    {
        f=true;
    }
    else
    {
        while(x<=c2)
        {
            y=0;
            while(y<=c3)
            {
                if((sum+y*6+x*2)%9==0)
                {
                    f=true;
                    break;
                }
                y++;
            }
            x++;
        }
    }
    if(f)
    cout<<"YES"<<"\n";
    else
    cout<<"NO"<<"\n";
}
int main()
{
    int t,i,j;
    long long n;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        f(n);
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void f(long long n)
{
    long long sum=0;
    bool f=false;
    int c2=0,c3=0,x=0,y=0;
    int r,m,e,k=0;
    long long t=n;
    while(t!=0)
    {
        r=t%10;
        k++;
        if(r==2)
        c2++;
        else if(r==3)
        c3++;
        sum=sum+0LL+r;
        t=t/10;
    }
    m=sum%9;
    e=9-m;
    if(m==0)
    {
        f=true;
    }
    else
    {
        while(x<=min(10,c2))
        {
            y=0;
            while(y<=min(10,c3))
            {
                if((sum+y*6+x*2)%9==0)
                {
                    f=true;
                    break;
                }
                y++;
            }
            x++;
        }
    }
    if(f)
    cout<<"YES"<<"\n";
    else
    cout<<"NO"<<"\n";
}
int main()
{
    int t,i,j;
    long long n;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        f(n);
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

    ll i,n,m,suma=0ll,sumb=0ll;

    cin>>n>>m;

    vector<ll> a(n);

    vector<ll> b(m);

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

    cin>>a[i];

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

    cin>>b[i];

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

    suma=suma+a[i];

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

    sumb=sumb+b[i];

    if(suma!=sumb)

    {

        cout<<"No"<<"\n";

        return;

    }

    multiset<ll> t;

    multiset<ll> c;

    for(auto it:a)

    t.insert(it);

    for(auto it:b)

    c.insert(it);

    while(!t.empty() && !c.empty())

    {

        auto it=c.end();

        it--;

        ll maxi=*it;

        if(t.find(maxi)!=t.end())

        {

            c.erase(maxi);

            t.erase(maxi);

        }

        else

        {

            if(maxi==1)

            {

                cout<<"No"<<"\n";

                return;

            }

            else

            {

                c.erase(maxi);

                c.insert(maxi/2);

                c.insert((maxi+1)/2);

            }

        }

    }

    if(t.empty())

    cout<<"Yes"<<"\n";

    else

    cout<<"No"<<"\n";

}

int main()

{

    int t,i,j;

    cin>>t;

    for(i=0;i<t;i++)

    {

        solve();

    }

    return 0;

}



Submission (verdict: Time limit exceeded on test 5):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

    ll i,n,m,suma=0ll,sumb=0ll;

    cin>>n>>m;

    vector<ll> a(n);

    vector<ll> b(m);

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

    cin>>a[i];

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

    cin>>b[i];

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

    suma=suma+a[i];

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

    sumb=sumb+b[i];

    if(suma!=sumb)

    {

        cout<<"No"<<"\n";

        return;

    }

    multiset<ll> t;

    multiset<ll> c;

    for(auto it:a)

    t.insert(it);

    for(auto it:b)

    c.insert(it);

    while(!t.empty() && !c.empty())

    {

        auto it=c.end();

        it--;

        ll maxi=*it;

        if(t.find(maxi)!=t.end())

        {

            c.erase(c.find(maxi));

            t.erase(t.find(maxi));

        }

        else

        {

            if(maxi==1)

            {

                cout<<"No"<<"\n";

                return;

            }

            else

            {

                c.erase(c.find(maxi));

                c.insert(maxi/2);

                c.insert((maxi+1)/2);

            }

        }

    }

    if(t.empty())

    cout<<"Yes"<<"\n";

    else

    cout<<"No"<<"\n";

}

int main()

{

    int t,i,j;

    cin>>t;

    for(i=0;i<t;i++)

    {

        solve();

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 5):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

    ll i,n,m,suma=0ll,sumb=0ll;

    cin>>n>>m;

    vector<ll> a(n);

    vector<ll> b(m);

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

    cin>>a[i];

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

    cin>>b[i];

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

    suma=suma+a[i];

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

    sumb=sumb+b[i];

    if(suma!=sumb)

    {

        cout<<"No"<<"\n";

        return;

    }

    multiset<ll> t;

    multiset<ll> c;

    for(auto it:a)

    t.insert(it);

    for(auto it:b)

    c.insert(it);

    while(!t.empty() && !c.empty())

    {

        auto it=c.end();

        it--;

        ll maxi=*it;

        if(t.find(maxi)!=t.end())

        {

            c.erase(c.find(maxi));

            t.erase(t.find(maxi));

        }

        else

        {

            if(maxi==1)

            {

                cout<<"No"<<"\n";

                return;

            }

            else

            {

                c.erase(c.find(maxi));

                c.insert(maxi/2);

                c.insert((maxi+1)/2);

            }

        }

    }

    if(t.empty())

    cout<<"Yes"<<"\n";

    else

    cout<<"No"<<"\n";

}

int main()

{

    int t,i,j;

    cin>>t;

    for(i=0;i<t;i++)

    {

        solve();

    }

    return 0;

}



Submission (verdict: Time limit exceeded on test 5):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

    ll i,n,m,suma=0ll,sumb=0ll;

    cin>>n>>m;

    vector<ll> a(n);

    vector<ll> b(m);

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

    cin>>a[i];

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

    cin>>b[i];

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

    suma=suma+a[i];

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

    sumb=sumb+b[i];

    if(suma!=sumb)

    {

        cout<<"No"<<"\n";

        return;

    }

    multiset<ll> t;

    multiset<ll> c;

    for(auto it:a)

    t.insert(it);

    for(auto it:b)

    c.insert(it);

    while(!t.empty() && !c.empty())

    {

        auto it=c.end();

        it--;

        ll maxi=*it;

        if(t.find(maxi)!=t.end())

        {

            c.erase(it);

            t.erase(t.find(maxi));

        }

        else

        {

            if(maxi==1)

            {

                cout<<"No"<<"\n";

                return;

            }

            else

            {

                c.erase(it);

                c.insert(maxi/2);

                c.insert((maxi+1)/2);

            }

        }

    }

    if(t.empty())

    cout<<"Yes"<<"\n";

    else

    cout<<"No"<<"\n";

}

int main()

{

    int t,i,j;

    cin>>t;

    for(i=0;i<t;i++)

    {

        solve();

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 5):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

    ll i,n,m,suma=0ll,sumb=0ll;

    cin>>n>>m;

    vector<ll> a(n);

    vector<ll> b(m);

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

    cin>>a[i];

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

    cin>>b[i];

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

    suma=suma+a[i];

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

    sumb=sumb+b[i];

    if(suma!=sumb)

    {

        cout<<"No"<<"\n";

        return;

    }

    multiset<ll> t;

    multiset<ll> c;

    for(auto it:a)

    t.insert(it);

    for(auto it:b)

    c.insert(it);

    while(!t.empty() && !c.empty())

    {

        auto it=c.end();

        it--;

        ll maxi=*it;

        if(t.find(maxi)!=t.end())

        {

            c.erase(it);

            t.erase(t.find(maxi));

        }

        else

        {

            if(maxi==1)

            {

                cout<<"No"<<"\n";

                return;

            }

            else

            {

                c.erase(it);

                c.insert(maxi/2);

                c.insert((maxi+1)/2);

            }

        }

    }

    if(t.empty())

    cout<<"Yes"<<"\n";

    else

    cout<<"No"<<"\n";

}

int main()

{

    int t,i,j;

    cin>>t;

    for(i=0;i<t;i++)

    {

        solve();

    }

    return 0;

}



Submission (verdict: Memory limit exceeded on test 6):
#include <iostream>

#include <vector>

#include <queue>

#include <set>

using namespace std;

#define ll long long



void solve() {

    ll i, n, m, suma = 0ll, sumb = 0ll;

    cin >> n >> m;

    vector<ll> a(n);

    vector<ll> b(m);

    

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

        cin >> a[i];

        suma += a[i];

    }

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

        cin >> b[i];

        sumb += b[i];

    }

    

    if(suma != sumb) {

        cout << "No" << "\n";

        return;

    }

    

    multiset<ll> t(a.begin(), a.end()); // Target multiset

    priority_queue<ll> pq;             // Max-heap for sequence b

    

    for(auto x : b) 

        pq.push(x);

    

    while(!pq.empty()) {

        ll maxi = pq.top();

        pq.pop();

        

        if(t.find(maxi) != t.end()) {

            // Remove one occurrence from t.

            t.erase(t.find(maxi));

        } else {

            if(maxi == 1) {

                cout << "No" << "\n";

                return;

            }

            // Split the number into two smaller parts.

            pq.push(maxi / 2);

            pq.push((maxi + 1) / 2);

        }

    }

    

    // If all elements in t are matched, output "Yes".

    cout << (t.empty() ? "Yes" : "No") << "\n";

}



int main() {

    int t;

    cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

    ll i,n,m,suma=0ll,sumb=0ll;

    cin>>n>>m;

    vector<ll> a(n);

    vector<ll> b(m);

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

    cin>>a[i];

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

    cin>>b[i];

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

    suma=suma+a[i];

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

    sumb=sumb+b[i];

    if(suma!=sumb)

    {

        cout<<"No"<<"\n";

        return;

    }

    multiset<ll> t;

    multiset<ll> c;

    for(auto it:a)

    t.insert(it);

    for(auto it:b)

    c.insert(it);

    while(!t.empty() && !c.empty())

    {

        auto it=c.end();

        it--;

        ll maxi=*it;

        if(t.find(maxi)!=t.end())

        {

            c.erase(maxi);

            t.erase(maxi);

        }

        else

        {

            if(maxi==1)

            {

                cout<<"No"<<"\n";

                return;

            }

            else

            {

                c.erase(maxi);

                c.insert(maxi/2);

                c.insert((maxi+1)/2);

            }

        }

    }

    if(t.empty())

    cout<<"Yes"<<"\n";

    else

    cout<<"No"<<"\n";

}

int main()

{

    int t,i,j;

    cin>>t;

    for(i=0;i<t;i++)

    {

        solve();

    }

    return 0;

}