ShaysXIA/CodeInsightBench huggingface dataset:
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;
#define int long long 
using ll = long long;
using pii = pair<int,int>;
#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)
#define pb push_back
void solve(){
	int n , m; cin >> n >> m;
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<int,vector<int>,greater<int>> q2;
	for(int i = 0; i < n; ++ i){
		int x; cin >> x;
		q1.push(x);
	}
	for(int i = 0; i < m; ++ i){
		int x; cin >> x;
		q2.push(x);
	}
	while(q2.size()){
		auto x = q2.top();
		q2.pop();
		if(q1.size() == 0){
			q2.push(x);
			break;
		}
		int u = q1.top();
		q1.pop();
		if(u == x) continue;
		if(x < u){
			q2.push(x);
			break;
		}else{
			if(q1.size() == 0){
				q2.push(x);
				break;
			}
			int v = q1.top();
			
			q1.pop();
		    q2.push(x);
			if(v - u == 1 || v - u == 0){
		    	q1.push(u + v);
			}
			else{
				break;
			}
		}
	}
	if(q1.size() == 0 && q2.size() == 0){
		cout << "Yes" << endl;
		
	}else cout << "No" << endl;
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int _;cin >> _;
	while(_--){
		solve();
	}
	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/



Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
using ll = long long;
using pii = pair<int,int>;
#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)
#define pb push_back
void solve(){
	int n , m; cin >> n >> m;
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<int,vector<int>,greater<int>> q2;
	vector<int> a(n);
	vector<int> b(m);
	map<int,int> mp1;
	map<int,int> mp2;
	for(auto & v :a) {
		cin >> v;
		mp1[v] ++;
	}
	
	for(auto & v : b) {
		cin >> v; mp2[v] ++;
	}
	for(auto v : a){
		if(mp2[v]){
			mp2[v] --;
			continue;
		}else {
			q1.push(v);
		}
	}
	for(auto v : b){
		if(mp1[v]){
			mp1[v] --; continue;
		}else{
			q2.push(v);
		}
	}
	
	while(q2.size()){
		auto x = q2.top();
		q2.pop();
		if(q1.size() == 0){
			q2.push(x);
			break;
		}
		int u = q1.top();
		q1.pop();
		if(u == x) continue;
		if(x < u){
			q2.push(x);
			break;
		}else{
			if(q1.size() == 0){
				q2.push(x);
				break;
			}
			int v = q1.top();
			
			q1.pop();
		    q2.push(x);
			if(v - u == 1 || v - u == 0){
		    	q1.push(u + v);
			}
			else{
				break;
			}
		}
	}
	if(q1.size() == 0 && q2.size() == 0){
		cout << "Yes" << endl;
		
	}else cout << "No" << endl;
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int _;cin >> _;
	while(_--){
		solve();
	}
	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
using ll = long long;
using pii = pair<int,int>;
#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)
#define pb push_back
void solve(){
	int n , m; cin >> n >> m;
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<int,vector<int>,greater<int>> q2;
	for(int i = 0; i < n; ++ i){
		int x; cin >> x;
		q1.push(x);
	}
	for(int i = 0; i < m; ++ i){
		int x; cin >> x;
		q2.push(x);
	}
	while(q2.size()){
		auto x = q2.top();
		q2.pop();
		if(q1.size() == 0){
			q2.push(x);
			break;
		}
		int u = q1.top();
		q1.pop();
		if(u == x) continue;
		if(x < u){
			q2.push(x);
			break;
		}else{
			if(q1.size() == 0){
				q2.push(x);
				break;
			}
			int v = q1.top();
			
			q1.pop();
		    q2.push(x);
			if(v - u == 1 || v - u == 0){
		    	q1.push(u + v);
			}
			else{
				break;
			}
		}
	}
	if(q1.size() == 0 && q2.size() == 0){
		cout << "Yes" << endl;
		
	}else cout << "No" << endl;
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int _;cin >> _;
	while(_--){
		solve();
	}
	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

const int N = 5000;

char s[N];

void solve(){

	int n; cin >> n; scanf("%s",s + 1);

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

		if(s[i] == 'p' && s[i + 1] == 's') {

			cout << "NO" << endl;

			return ;

		}

	}

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

		if(s[i] == 's' && s[i + 1] == 'p'){

			if(i == 1 || i + 1  == n) continue;

			cout << "NO" << endl;

			return ; 

		} 

	}  cout << "YES" << endl;

	

	return;

}

int main(){

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

const int N = 5000;

char s[N];

void solve(){

	int n; cin >> n; scanf("%s",s + 1);

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

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

			

			for(int j = i - 1; j >= 1; -- j){

				if(s[j] == 'p'){

					

					cout << "NO" << endl;

					return; 

				}

			}

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

				if(s[j] == 'p'){

					if(j != n){

						cout << "NO" << endl;

						return ;

					}

				}

			}

		}

	}

	cout << "YES" << endl;

	return;

}

int main(){

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/





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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

const int N = 5000;

char s[N];

void solve(){

	int n; cin >> n; scanf("%s",s + 1);

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

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

			for(int j = i - 1; j >= 1; -- j){

				if(s[j] == 'p'){

					cout << "NO" << endl;

					return; 

				}

			}

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

				if(s[j] == 'p'){

					if(j != n && (i != 1)){

						cout << "NO" << endl;

						return ;

					}

				}

			}

		}

	}

	cout << "YES" << endl;

	return;

}

int main(){

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

const int N = 5000;

char s[N];

void solve(){

	int n; cin >> n; scanf("%s",s + 1);

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

		if(s[i] == 'p' && s[i + 1] == 's') {

			cout << "NO" << endl;

			return ;

		}

	}

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

		if(s[i] == 's' && s[i + 1] == 'p'){

			if(i == 1 || i + 1  == n) continue;

			cout << "NO" << endl;

			return ; 

		} 

	}  cout << "YES" << endl;

	

	return;

}

int main(){

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/





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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

const int N = 5000;

char s[N];

void solve(){

	int n; cin >> n; scanf("%s",s + 1);

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

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

			

			for(int j = i - 1; j >= 1; -- j){

				if(s[j] == 'p'){

					

					cout << "NO" << endl;

					return; 

				}

			}

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

				if(s[j] == 'p'){

					if(j != n){

						cout << "NO" << endl;

						return ;

					}

				}

			}

		}

	}

	cout << "YES" << endl;

	return;

}

int main(){

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	}  for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/





Submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

	int pos = 100;

	while(pos --){

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	} 

	}

	 for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

		for(auto v : s) cout << v << ' ';

		cout << endl;

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

		cout << i << endl;

		for(auto v : s) cout << v << ' ';

		cout << endl;

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	}  for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

	int pos = 100;

	while(pos --){

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	} 

	}

	 for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/





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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

	int pos = 10;

	while(pos --){

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	} 

	}

	 for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

		for(auto v : s) cout << v << ' ';

		cout << endl;

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

		cout << i << endl;

		for(auto v : s) cout << v << ' ';

		cout << endl;

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	}  for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/





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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)

#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

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

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	}  for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;

std::size_t long_hash(long long x) {
    return x ^ (x * 11);
}

bool merge_for(auto &s, long long x) {
    auto x_iter = s.find(x);
    if (x_iter != s.end()) {
        s.erase(x_iter);
        return true;
    }
    if (x == 1) {
        return false;
    }

    auto l_half = x / 2;
    auto r_half = (x+1) / 2;
    return merge_for(s, l_half) && merge_for(s, r_half);
}

void solve() {
    unordered_multiset<long long, decltype(&long_hash)> s(200000, &long_hash);
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; ++i) {
        long long tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    vector<long long> rq(m);
    for (auto &i : rq) {
        cin >> i;
    }

    bool ok = true;
    for (auto i : rq) {
        if (! merge_for(s, i)) {
            ok = false;
            break;
        }
    }
    if (s.empty() && ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

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

std::size_t long_hash(long long x) {
    return x ^ (x * 11);
}

bool merge_for(auto &s, long long x) {
    auto x_iter = s.find(x);
    if (x_iter != s.end()) {
        s.erase(x_iter);
        return true;
    }
    if (x == 1) {
        return false;
    }

    auto l_half = x / 2;
    auto r_half = (x+1) / 2;
    return merge_for(s, l_half) && merge_for(s, r_half);
}

void solve() {
    // unordered_multiset<long long, decltype(&long_hash)> s(200000, &long_hash);
    multiset<long long> s;
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; ++i) {
        long long tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    vector<long long> rq(m);
    for (auto &i : rq) {
        cin >> i;
    }

    bool ok = true;
    for (auto i : rq) {
        if (! merge_for(s, i)) {
            ok = false;
            break;
        }
    }
    if (s.empty() && ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

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

Previous submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;

bool merge_for(unordered_multiset<long long> &s, long long x) {
    auto x_iter = s.find(x);
    if (x_iter != s.end()) {
        s.erase(x_iter);
        return true;
    }
    if (x == 1) {
        return false;
    }

    auto l_half = x / 2;
    auto r_half = (x+1) / 2;
    return merge_for(s, l_half) && merge_for(s, r_half);
}

void solve() {
    unordered_multiset<long long> s;
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; ++i) {
        long long tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    vector<long long> rq(m);
    for (auto &i : rq) {
        cin >> i;
    }

    bool ok = true;
    for (auto i : rq) {
        if (! merge_for(s, i)) {
            ok = false;
            break;
        }
    }
    if (s.empty() && ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

Submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;

std::size_t long_hash(long long x) {
    return x ^ (x * 11);
}

bool merge_for(auto &s, long long x) {
    auto x_iter = s.find(x);
    if (x_iter != s.end()) {
        s.erase(x_iter);
        return true;
    }
    if (x == 1) {
        return false;
    }

    auto l_half = x / 2;
    auto r_half = (x+1) / 2;
    return merge_for(s, l_half) && merge_for(s, r_half);
}

void solve() {
    unordered_multiset<long long, decltype(&long_hash)> s(200000, &long_hash);
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; ++i) {
        long long tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    vector<long long> rq(m);
    for (auto &i : rq) {
        cin >> i;
    }

    bool ok = true;
    for (auto i : rq) {
        if (! merge_for(s, i)) {
            ok = false;
            break;
        }
    }
    if (s.empty() && ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

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


Submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;

list<long long> merge_for(unordered_multiset<long long> &s, long long x) {
    auto x_iter = s.find(x);
    if (x_iter != s.end()) {
        s.erase(x_iter);
        return {x};
    }
    if (x == 1) {
        return {};
    }

    auto l_half = x / 2;
    auto r_half = (x+1) / 2;
    auto rt = merge_for(s, l_half);
    if (rt.empty()) {
        return {};
    }
    auto r_result = merge_for(s, r_half);
    if (r_result.empty()) {
        for (auto i : rt) {
            s.insert(i);
        }
        return {};
    } else {
        rt.splice(rt.end(), r_result);
        return rt;
    }
}

void solve() {
    unordered_multiset<long long> s;
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; ++i) {
        long long tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    vector<long long> rq(m);
    for (auto &i : rq) {
        cin >> i;
    }

    bool ok = true;
    for (auto i : rq) {
        if (merge_for(s, i).empty()) {
            ok = false;
            break;
        }
    }
    if (s.empty() && ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}