ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 3):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][10];

int n;

string s;

int rec(int i, int sum) {

  if (i == n) {

    return (sum % 9 == 0);

  }

  if (sum % 9 == 0) {

    return 1;

  }

  sum %= 9;

  int &ret = dp[i][sum];

  ret = 0;

  if (s[i] == '2') {

    ret |= rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    ret |= rec(i + 1, sum + 6);

  }

  ret |= rec(i + 1, sum);

  return ret;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) {

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum % 9) ? "YES" : "NO") << '\n';

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

      for (int j = 0; j <= 9; j++) {

        dp[i][j] = -1;

      }

    }

  }

}

Submission (verdict: Accepted):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][10];

int n;

string s;

int rec(int i, int sum) {

  if (i == n) {

    return (sum % 9 == 0);

  }

  if (sum % 9 == 0) {

    return 1;

  }

  sum %= 9;

  int &ret = dp[i][sum];

  if(~ret){

    return ret;

  }

  ret = 0;

  if (s[i] == '2') {

    ret |= rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    ret |= rec(i + 1, sum + 6);

  }

  ret |= rec(i + 1, sum);

  return ret;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) {

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum % 9) ? "YES" : "NO") << '\n';

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

      for (int j = 0; j <= 9; j++) {

        dp[i][j] = -1;

      }

    }

  }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 3):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][13];

int n;

string s;

int rec(int i, int sum) {

  if (sum % 9 == 0) {

    return 1;

  }

  if (i == n) {

    return 0;

  }

  sum %= 9;

  int op1 = 0, op2 = 0, op3 = 0;

  if (s[i] == '2') {

    op1 = rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    op2 = rec(i + 1, sum + 6);

  }

  op3 = rec(i + 1, sum);

  return op1 | op2 | op3;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) {

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum) ? "YES" : "NO") << '\n';

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

      for (int j = 0; j <= 9; j++) {

        dp[i][j] = -1;

      }

    }

  }

}

Submission (verdict: Time limit exceeded on test 3):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][13];

int n;

string s;

int rec(int i, int sum) {

  if (sum % 9 == 0) {

    return 1;

  }

  if (i == n) {

    return 0;

  }

  int &ret = dp[i][sum];

  sum %= 9;

  int op1 = 0, op2 = 0, op3 = 0;

  if (s[i] == '2') {

    op1 = rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    op2 = rec(i + 1, sum + 6);

  }

  op3 = rec(i + 1, sum);

  return ret = op1 | op2 | op3;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) {

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum) ? "YES" : "NO") << '\n';

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

      for (int j = 0; j <= 9; j++) {

        dp[i][j] = -1;

      }

    }

  }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 3):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][13];

int n;

string s;

int rec(int i, int sum) {

  if (sum % 9 == 0) {

    return 1;

  }

  if (i == n) {

    return 0;

  }

  int &ret = dp[i][sum];

  sum %= 9;

  int op1 = 0, op2 = 0, op3 = 0;

  if (s[i] == '2') {

    op1 = rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    op2 = rec(i + 1, sum + 6);

  }

  op3 = rec(i + 1, sum);

  return ret = op1 | op2 | op3;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) {

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum) ? "YES" : "NO") << '\n';

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

      for (int j = 0; j <= 9; j++) {

        dp[i][j] = -1;

      }

    }

  }

}

Submission (verdict: Time limit exceeded on test 3):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][10];

int n;

string s;

int rec(int i, int sum) {

  if (i == n) {

    return (sum % 9 == 0);

  }

  if (sum % 9 == 0) {

    return 1;

  }

  sum %= 9;

  int &ret = dp[i][sum];

  ret = 0;

  if (s[i] == '2') {

    ret |= rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    ret |= rec(i + 1, sum + 6);

  }

  ret |= rec(i + 1, sum);

  return ret;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) {

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum % 9) ? "YES" : "NO") << '\n';

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

      for (int j = 0; j <= 9; j++) {

        dp[i][j] = -1;

      }

    }

  }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

       int n;

       cin>>n;

       int x=n;

       if(n%9==0) cout<<"YES\n";

       else{

           unordered_map<int,int>mpp(10);

           int sum=0;

           while(n>0){

                 int j=n%10;

                 sum+=j;

                 mpp[j]++;

                 n=n/10;

           }

           

           bool lolu=false;

           n=x;

           for(int i=0;i<=mpp[2];i++){

               for(int j=0;j<=mpp[3];j++){

                   if((sum+i*2+j*6)%9==0){

                       lolu=true;

                       break;

                   }

               }

               if(lolu) break;

           }

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }

}

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

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

        string s;

        cin>>s;

       long long currSum=0;

       unordered_map<int,int>mpp(10);

        long long two=0,three=0;

        for(auto& c:s){

            currSum+=c-'0';

            if(c=='2') two++;

            if(c=='3') three++;

        }

       mpp[2]=two;

       mpp[3]=three;

        if(currSum%9==0){

            cout<<"YES"<<endl;

            continue;

        }

        int sum=currSum;

        

           

           bool lolu=false;

           //n=x;

           for(int i=0;i<=mpp[2];i++){

               for(int j=0;j<=mpp[3];j++){

                   if((sum+i*2+j*6)%9==0){

                       lolu=true;

                       break;

                   }

               }

               if(lolu) break;

           }

           //cerr<<sum<<"\n";

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

       int n;

       cin>>n;

       int x=n;

       if(n%9==0) cout<<"YES\n";

       else{

           unordered_map<int,int>mpp(10);

           int sum=0;

           while(n>0){

                 int j=n%10;

                 sum+=j;

                 mpp[j]++;

                 n=n/10;

           }

           

           bool lolu=false;

           n=x;

           int y=sum/9;

           y++;

           int k=y*9-sum;

           //cerr<<sum<<"\n";

           if(k==1){

               if(mpp[2]>4 || (mpp[3]>2 && mpp[2]>1)){

                   lolu=true;

               }

           }

           else if(k==2 && mpp[2]>2 && mpp[3]>1) lolu=true;

           else if(k==3 && (mpp[2]>3||mpp[3]>1)) lolu=true;

           else if(k==4 && mpp[3]>1 && mpp[2]>1) lolu=true;

           else if(k==5 && mpp[2]>2) lolu=true;

           else if(k==6 && mpp[3]>1) lolu=true;

           else if(k==7 && mpp[2]>1) lolu=true;

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }

}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

       int n;

       cin>>n;

       int x=n;

       if(n%9==0) cout<<"YES\n";

       else{

           unordered_map<int,int>mpp(10);

           int sum=0;

           while(n>0){

                 int j=n%10;

                 sum+=j;

                 mpp[j]++;

                 n=n/10;

           }

           

           bool lolu=false;

           n=x;

           for(int i=0;i<=mpp[2];i++){

               for(int j=0;j<=mpp[3];j++){

                   if((sum+i*2+j*6)%9==0){

                       lolu=true;

                       break;

                   }

               }

           }

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

       int n;

       cin>>n;

       int x=n;

       if(n%9==0) cout<<"YES\n";

       else{

           unordered_map<int,int>mpp(10);

           int sum=0;

           while(n>0){

                 int j=n%10;

                 sum+=j;

                 mpp[j]++;

                 n=n/10;

           }

           

           bool lolu=false;

           n=x;

           for(int i=0;i<=mpp[2];i++){

               for(int j=0;j<=mpp[3];j++){

                   if((sum+i*2+j*6)%9==0){

                       lolu=true;

                       break;

                   }

               }

           }

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }

}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

       int n;

       cin>>n;

       int x=n;

       if(n%9==0) cout<<"YES\n";

       else{

           unordered_map<int,int>mpp(10);

           int sum=0;

           while(n>0){

                 int j=n%10;

                 sum+=j;

                 mpp[j]++;

                 n=n/10;

           }

           

           bool lolu=false;

           n=x;

           for(int i=0;i<=mpp[2];i++){

               for(int j=0;j<=mpp[3];j++){

                   if((sum+i*2+j*6)%9==0){

                       lolu=true;

                       break;

                   }

               }

               if(lolu) break;

           }

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


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

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

       int n;

       cin>>n;

       int x=n;

       if(n%9==0) cout<<"YES\n";

       else{

           unordered_map<int,int>mpp(10);

           int sum=0;

           while(n>0){

                 int j=n%10;

                 sum+=j;

                 mpp[j]++;

                 n=n/10;

           }

           

           bool lolu=false;

           n=x;

           int y=sum/9;

           y++;

           int k=y*9-sum;

           //cerr<<sum<<"\n";

           if(k==1){

               if(mpp[2]>4 || (mpp[3]>2 && mpp[2]>1)){

                   lolu=true;

               }

           }

           else if(k==2 && mpp[2]>2 && mpp[3]>1) lolu=true;

           else if(k==3 && (mpp[2]>3||mpp[3]>1)) lolu=true;

           else if(k==4 && mpp[3]>1 && mpp[2]>1) lolu=true;

           else if(k==5 && mpp[2]>2) lolu=true;

           else if(k==6 && mpp[3]>1) lolu=true;

           else if(k==7 && mpp[2]>1) lolu=true;

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

    }

}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int64_t> arr(n);
    for (int64_t& v : arr) {
        cin >> v;
    }
    int64_t sum = 0;
    for (int64_t v: arr) sum += v;
    int64_t ans = sum;
    if (n > 1) ans = max(ans, -sum);
    while (arr.size() > 1) {
        vector<int64_t> newarr(arr.size() - 1);
        for (int i = 1; i < arr.size(); ++i) {
            newarr[i - 1] = arr[i] - arr[i - 1];
        }
        sum = 0;
        for (int64_t v : newarr) sum += v;
        ans = max(ans, sum);
        ans = max(ans, -sum);
        arr = newarr;
    }
    ans = max(ans, arr[0]);
    cout << ans << '\n';
}

int main() {
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int64_t> arr(n);
    for (int64_t& v : arr) {
        cin >> v;
    }
    int64_t sum = 0;
    for (int64_t v: arr) sum += v;
    int64_t ans = sum;
    if (n == 1) {
        cout << ans << '\n';
        return;
    }
    while (arr.size()) {
        vector<int64_t> newarr(arr.size() - 1);
        for (int i = 1; i < arr.size(); ++i) {
            newarr[i - 1] = arr[i] - arr[i - 1];
        }
        sum = 0;
        for (int64_t v : newarr) sum += v;
        ans = max(ans, sum);
        ans = max(ans, -sum);
        arr = newarr;
    }
    cout << ans << '\n';
}

int main() {
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int64_t> arr(n);
    for (int64_t& v : arr) {
        cin >> v;
    }
    int64_t sum = 0;
    for (int64_t v: arr) sum += v;
    int64_t ans = sum;
    if (n > 1) ans = min(ans, -sum);
    while (arr.size() > 1) {
        vector<int64_t> newarr(arr.size() - 1);
        for (int i = 1; i < arr.size(); ++i) {
            newarr[i - 1] = arr[i] - arr[i - 1];
        }
        sum = 0;
        for (int64_t v : newarr) sum += v;
        ans = max(ans, sum);
        ans = max(ans, -sum);
        arr = newarr;
    }
    ans = max(ans, arr[0]);
    cout << ans << '\n';
}

int main() {
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int64_t> arr(n);
    for (int64_t& v : arr) {
        cin >> v;
    }
    int64_t sum = 0;
    for (int64_t v: arr) sum += v;
    int64_t ans = sum;
    if (n > 1) ans = max(ans, -sum);
    while (arr.size() > 1) {
        vector<int64_t> newarr(arr.size() - 1);
        for (int i = 1; i < arr.size(); ++i) {
            newarr[i - 1] = arr[i] - arr[i - 1];
        }
        sum = 0;
        for (int64_t v : newarr) sum += v;
        ans = max(ans, sum);
        ans = max(ans, -sum);
        arr = newarr;
    }
    ans = max(ans, arr[0]);
    cout << ans << '\n';
}

int main() {
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int64_t> arr(n);
    for (int64_t& v : arr) {
        cin >> v;
    }
    int64_t sum = 0;
    for (int64_t v: arr) sum += v;
    int64_t ans = sum;
    if (n > 1) ans = min(ans, -sum);
    while (arr.size() > 1) {
        vector<int64_t> newarr(arr.size() - 1);
        for (int i = 1; i < arr.size(); ++i) {
            newarr[i - 1] = arr[i] - arr[i - 1];
        }
        sum = 0;
        for (int64_t v : newarr) sum += v;
        ans = max(ans, sum);
        ans = max(ans, -sum);
        arr = newarr;
    }
    ans = max(ans, arr[0]);
    cout << ans << '\n';
}

int main() {
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

using pii = pair<int,int>;

using pll = pair<long long,long long>;



mt19937_64 rnd(time(nullptr));

const int maxn = 2e5+100;

const int mod = 998'244'353;

//const int mod = 1e+9+7;

//const i64 inf = 1e18;

//const int inf = 1e9;



int n,m;



void Main(){

    cin>>n>>m;

    multiset<int> a,b;

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

        int x; cin>>x;

        a.insert(x);

    }

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

        int x; cin>>x;

        auto it = a.find(x);

        if(it!=a.end()) a.erase(it);

        else b.insert(x);

    }

    while(!b.empty()){

        int cur = *b.begin(); b.erase(b.begin());

        while(a.size()>=2 && *a.begin() < cur){

            int x=*a.begin(); a.erase(a.begin());

            int y=*a.begin();a.erase(a.begin());

            if(abs(x-y)>1) break;

            a.insert(x+y);

        }

        if(a.empty() || *a.begin() != cur) return cout <<"NO\n",void();

        a.erase(a.begin());

    }

    cout << (a.empty() ? "YES" : "NO") << '\n';

}

int main(){

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int T = 1;

    cin >> T;

    while(T--) Main();

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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

using pii = pair<int,int>;

using pll = pair<long long,long long>;



mt19937_64 rnd(time(nullptr));

const int maxn = 2e5+100;

const int mod = 998'244'353;

//const int mod = 1e+9+7;

//const i64 inf = 1e18;

//const int inf = 1e9;



int n,m;



bool solve(int x,multiset<int> & mst){

    if(mst.empty() || *mst.begin() > x) return false;

//    printf("solve %d\n",mst.find(x)==mst.end());

    if(mst.find(x) != mst.end()){

        mst.erase(mst.find(x));

        return true;

    }

    int mid = x>>1;

    return solve(mid,mst) && solve(mid+(x&1),mst);

}

void Main(){

    cin>>n>>m;

    multiset<int> a,b;

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

        int x; cin>>x;

        a.insert(x);

    }

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

        int x; cin>>x;

        if(!solve(x,a)) return cout<<"NO\n",void();

    }

    cout << (a.empty() ? "YES" : "NO" ) << '\n';

}

int main(){

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int T = 1;

    cin >> T;

    while(T--) Main();

}

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

using namespace std;

using i64 = long long;

using u64 = unsigned long long;

using pii = pair<int,int>;

using pll = pair<long long,long long>;



mt19937_64 rnd(time(nullptr));

const int maxn = 2e5+100;

const int mod = 998'244'353;

//const int mod = 1e+9+7;

//const i64 inf = 1e18;

//const int inf = 1e9;



int n,m;



bool solve(int x,multiset<int> & mst){

    if(mst.empty() || *mst.begin() > x) return false;

//    printf("solve %d\n",mst.find(x)==mst.end());

    if(mst.find(x) != mst.end()){

        mst.erase(mst.find(x));

        return true;

    }

    int mid = x>>1;

    return solve(mid,mst) && solve(mid+(x&1),mst);

}

void Main(){

    cin>>n>>m;

    multiset<int> a;

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

        int x; cin>>x;

        a.insert(x);

    }

    bool ok = true;

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

        int x; cin>>x;

        if(!solve(x,a)) ok=false;

    }

    cout << (ok && a.empty() ? "YES" : "NO" ) << '\n';

}

int main(){

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int T = 1;

    cin >> T;

    while(T--) Main();

}