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

Previous submission (verdict: Wrong answer on test 2):
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)

#define debug0(x) std::cout << #x << " = " << x << '\n'
#define debug1(f, a, b) std::cout << #f << ": "; for (int i = (a); i <= (b); i++) std::cout << (f)[i] << " \n"[i == (b)]
#define debug2(f, a, b, c, d) std::cout << #f << ":\n"; for (int i = (a); i <= (b); i++) for (int j = (c); j <= (d); j++) std::cout << (f)[i][j] << " \n"[j == (d)]
#define debug3(q) std::cout << #q << ": "; for (auto it : (q)) std::cout << it << ' '; std::cout << '\n'

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
const int N = 1e5 + 10;

typedef long long ll;

void solve () {
    int n, m;
    std::cin >> n >> m;

    std::deque<int> a;
    std::deque<int> b;

    std::multiset<int> A;
    std::multiset<int> B;
    
    for (int i = 1; i <= n; i++) {
        int x;
        std::cin >> x;

        a.push_back(x);
        A.insert(x);
    }
    for (int i = 1; i <= m; i++) {
        int x;
        std::cin >> x;

        b.push_back(x);
        B.insert(x);
    }

    if (n == m) {
        if (A == B) std::cout << "Yes\n";
        else std::cout << "No\n";
        return;
    }

    int cnt = 0;
    while (a.size() > b.size()) {
        if (cnt >= 10000) break;

        if (a.front() == b.front()) {
            a.push_back(a.front());
            b.push_back(b.front());

            a.pop_front();
            b.pop_front();
        }
        else {
            if (std::abs(a[0] - a[1]) <= 1) {
                a.push_back(a[0] + a[1]);
                a.pop_front(); a.pop_front();
            }
        }

        cnt++;
    }
    // debug3(a), debug3(b);

    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    
    if (a == b) std::cout << "Yes\n";
    else std::cout << "No\n";
}

int main () {
    std::ios::sync_with_stdio(false); 
    std::cin.tie(0), std::cout.tie(0);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

Submission (verdict: Wrong answer on test 2):
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)

#define debug0(x) std::cout << #x << " = " << x << '\n'
#define debug1(f, a, b) std::cout << #f << ": "; for (int i = (a); i <= (b); i++) std::cout << (f)[i] << " \n"[i == (b)]
#define debug2(f, a, b, c, d) std::cout << #f << ":\n"; for (int i = (a); i <= (b); i++) for (int j = (c); j <= (d); j++) std::cout << (f)[i][j] << " \n"[j == (d)]
#define debug3(q) std::cout << #q << ": "; for (auto it : (q)) std::cout << it << ' '; std::cout << '\n'

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
const int N = 1e5 + 10;

typedef long long ll;

void solve () {
    int n, m;
    std::cin >> n >> m;

    std::deque<int> a;
    std::deque<int> b;

    // std::unordered_map<int, int> count_of_a;
    // std::unordered_map<int, int> count_of_b;

    for (int i = 1; i <= n; i++) {
        int x;
        std::cin >> x;

        a.push_back(x);
        // count_of_a[x]++;
    }
    for (int i = 1; i <= m; i++) {
        int x;
        std::cin >> x;

        b.push_back(x);
        // count_of_b[x]++;
    }
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    int cnt = 0;
    while (a.size() > b.size()) {
        if (cnt >= 10000) break;

        if (a.front() == b.front()) {
            a.push_back(a.front());
            b.push_back(b.front());

            a.pop_front();
            b.pop_front();
        }
        else {
            if (std::abs(a[0] - a[1]) <= 1) {
                a.push_back(a[0] + a[1]);
                a.pop_front(); a.pop_front();
            }
        }

        cnt++;
    }
    // debug3(a), debug3(b);

    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    if (a == b) std::cout << "Yes\n";
    else std::cout << "No\n";
}

int main () {
    std::ios::sync_with_stdio(false); 
    std::cin.tie(0), std::cout.tie(0);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}