ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}



void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	int l1=s.length();

	char last=s[0];

	bool can=true;

	if(last=='.'){

		bool pf=false;

		bool sf=false;

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

			if(s[i]=='p')pf=true;

			if(s[i]=='s')sf=true;

			}

		if(sf && pf)can=false;

		}

	else{

		bool pf=false;

		bool sf=false;

		int countp=0;

		int counts=0;

		for(auto x:s){

			if(x=='p'){pf=true;countp++;}

			if(x=='s'){

				sf=true;

				counts++;

				if(pf){can=false;break;}

				}		

			}

		if(countp>1 && counts>1){

			can=false;

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}



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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    char last = s[0];

    bool can = true;



    if (last == '.') {

        bool pf = false, sf = false;

        for (int i = 0; i < l1; i++) {  // Start from i = 0 to consider all characters

            if (s[i] == 'p') pf = true;

            if (s[i] == 's') sf = true;

        }

        if (sf && pf) can = false;

    } else {

        bool pf = false, sf = false;

        int countp = 0, counts = 0;



        for (auto x : s) {

            if (x == 'p') {

                pf = true;

                countp++;

            }

            if (x == 's') {

                sf = true;

                counts++;

                if (pf) { 

                    can = false; 

                    break; 

                }

            }

        }

        if (countp > 1 && counts > 1) {

            can = false;

        }

    }



    if (can) {

        cout << "yes" << endl;

    } else {

        cout << "no" << endl;

    }

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

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

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    bool can = true;

    bool pf=false;

    bool sf=false;

	

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

		char x=s[i];

		if(x=='s'){

			sf=true;

			if(pf){

				can=false;

				break;

				}

			}

		if(x=='p'){

			pf=true;

			if(sf){

				if(i!=1 && i!=l1-1){can=false;break;}

				}

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}



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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    bool can = true;

    bool pf=false;

    bool sf=false;

	int s_found=-1;

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

		char x=s[i];

		if(x=='s'){

			sf=true;

			s_found=i;

			if(pf){

				can=false;

				break;

				}

			}

		if(x=='p'){

			pf=true;

			if(sf){

				if(s_found!=0 && i!=l1-1){can=false;break;}

				}

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

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

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    char last = s[0];

    bool can = true;



    if (last == '.') {

        bool pf = false, sf = false;

        int countp = 0, counts = 0;



        for (auto x : s) {

            if (x == 'p') {

                pf = true;

                countp++;

            }

            if (x == 's') {

                sf = true;

                counts++;

                if (pf) { 

                    can = false; 

                    break; 

                }

            }

        }

        if (countp > 1 && counts > 1) {

            can = false;

        }

        if(s[l1-1]=='.' && pf && sf){can=false;}

    }

     else {

        bool pf = false, sf = false;

        int countp = 0, counts = 0;



        for (auto x : s) {

            if (x == 'p') {

                pf = true;

                countp++;

            }

            if (x == 's') {

                sf = true;

                counts++;

                if (pf) { 

                    can = false; 

                    break; 

                }

            }

        }

        if (countp > 1 && counts > 1) {

            can = false;

        }

    }



    if (can) {

        cout << "yes" << endl;

    } else {

        cout << "no" << endl;

    }

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}



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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    bool can = true;

    bool pf=false;

    bool sf=false;

	

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

		char x=s[i];

		if(x=='s'){

			sf=true;

			if(pf){

				can=false;

				break;

				}

			}

		if(x=='p'){

			pf=true;

			if(sf){

				if(i!=1 && i!=l1-1){can=false;break;}

				}

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}
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;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}

int findMex(int a, int b, int c) {

    set<int> s = {a, b, c}; // Store unique numbers

    

    for (int i = 0; ; i++) { // Check from 0 upwards

        if (s.find(i) == s.end()) return i;

    }

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		int a1=a[y%n];

		int b1=a[y-2];

		int c1=a[x-1];

		a[y-1]=findMex(a1,b1,c1);

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}



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

using namespace std;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}

int findMex(int a, int b, int c) {

    set<int> s = {a, b, c}; // Store unique numbers

    

    for (int i = 0; ; i++) { // Check from 0 upwards

        if (s.find(i) == s.end()) return i;

    }

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		if(n%2==1 && y-1==n-2){

			swap(a[n-1],a[n-2]);

			}

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}
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;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}

int findMex(int a, int b, int c) {

    set<int> s = {a, b, c}; // Store unique numbers

    

    for (int i = 0; ; i++) { // Check from 0 upwards

        if (s.find(i) == s.end()) return i;

    }

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		if(n%2==1 && y-1==n-2){

			swap(a[n-1],a[n-2]);

			}

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}



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

using namespace std;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}

int findMex(int a, int b, int c) {

    set<int> s = {a, b, c}; // Store unique numbers

    

    for (int i = 0; ; i++) { // Check from 0 upwards

        if (s.find(i) == s.end()) return i;

    }

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		if(n%2==1 && y-1==n-2){

			swap(a[n-1],a[n-2]);

			}

		else{

			a[y-1]=2;

			}

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}
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;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}



void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		a[y-1]=2;

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}



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

using namespace std;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}

int findMex(int a, int b, int c) {

    set<int> s = {a, b, c}; // Store unique numbers

    

    for (int i = 0; ; i++) { // Check from 0 upwards

        if (s.find(i) == s.end()) return i;

    }

}

void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		int a1=a[y%n];

		int b1=a[y-2];

		int c1=a[x-1];

		a[y-1]=findMex(a1,b1,c1);

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

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


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

using namespace std;

typedef long long ll;

bool compareByFirst(const pair<int, int>& a, const pair<int, int>& b) {

    return a.first < b.first;

}



void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	

	vector<int>a(n);

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

		a[i]=1;

		}

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

		a[i]=0;

		}

	if(n%2==1){

		a[n-1]=2;

		}

	if((y-x)%2==0){

		a[y-1]=2;

		}

	for(auto t:a){

		cout<<t<<" ";

		}

	cout<<endl;

	}



int main(){

	int t;

	cin>>t;

	while(t--){

		solve();

		}

	}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   maxi = max(sum,maxi);

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
} 



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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;



   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   if(n == 1)
   {
      cout<<ans[0]<<"\n";
      return;
   }

   maxi = max(sum,maxi);

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   maxi = max(sum,maxi);

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,ans[0]);

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
} 



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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   maxi = max(sum,maxi);

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   maxi = max(sum,maxi);

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,ans[0]);

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   if(n == 1)
   {
      cout<<ans[0]<<"\n";
      return;
   }

   maxi = max(sum,maxi);
   reverse(ans.begin(),ans.end());

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
} 



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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   if(n == 1)
   {
      cout<<ans[0]<<"\n";
      return;
   }

   maxi = max(sum,maxi);
   reverse(ans.begin(),ans.end());

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += temp[i];
      }

      ans = temp;

      maxi = max(maxi,abs(sum));
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;



   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   if(n == 1)
   {
      cout<<ans[0]<<"\n";
      return;
   }

   maxi = max(sum,maxi);

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

   return 0;
} 



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

void solve()
{
   int n;
   cin>>n;
   vector<int> ans(n);
   int maxi = INT_MIN , sum = 0;

   for(int i=0;i<n;i++) 
   {
      int val;
      cin>>val;
      ans[i] = val;
      sum += val;
   }

   if(n == 1)
   {
      cout<<ans[0]<<"\n";
      return;
   }

   maxi = max(sum,maxi);
   reverse(ans.begin(),ans.end());

   while(ans.size() > 1)
   {
      vector<int> temp;

      for(int i=1;i<ans.size();i++)
      {
           int val = ans[i] - ans[i-1];
           temp.push_back(val);
      }
      
      sum = 0;
      for(int i=0;i<temp.size();i++)
      {
          sum += abs(temp[i]);
      }

      ans = temp;

      maxi = max(maxi,sum);
   }
    
   maxi = max(maxi,abs(ans[0]));

   cout<<maxi<<"\n";
   return;
}
int32_t main()
{
   int t;
   cin>>t;
   //int t = 1;
   while(t--)
   {
      solve();
   }

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


Submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
#define ll long long
#define li long
#define cn(n) cin >> n
#define py cout << "YES" << endl
#define pn cout << "NO" << endl
#define ct(c) cout << c << endl
#define fr(dt, a, b) for (dt i = a; i < b; i++)
#define in(a, n) \
    fr(ll, 0, n) { cn(a[i]); }
#define out(a, n)                         \
    fr(ll, 0, n) { cout << a[i] << " "; } \
    cout << endl;
#define sort(a) sort(a.begin(), a.end());
#define vin(a, n)    \
    vector<ll> a(n); \
    in(a, n);
const int MOD = 1e9 + 7;

using namespace std;

void solve()
{
    // Your code here
    int n, m;
    cin >> n >> m;
    unordered_map<int, int> fa, fb;
    set<int> a, b;
    for (int i = 0; i < n; i++)
    {
        int x;
        cn(x);
        fa[x]++;
        a.insert(x);
    }
    for (int i = 0; i < m; i++)
    {
        int x;
        cn(x);
        fb[x]++;
        b.insert(x);
    }
    while (1)
    {
        if (a.size() == 0 && b.size() == 0)
        {
            py;
            return;
        }
        if (a.size() == 0 || b.size() == 0)
        {
            pn;
            return;
        }
        int mxa = *a.rbegin();
        int mxb = *b.rbegin();
        if (mxa > mxb)
        {
            pn;
            return;
        }
        if (mxa == mxb)
        {
            int mn = min(fa[mxa], fb[mxa]);
            fa[mxa] -= mn;
            fb[mxa] -= mn;
            if (fa[mxa] == 0)
            {
                a.erase(mxa);
            }
            if (fb[mxa] == 0)
            {
                b.erase(mxb);
            }
        }
        else
        {
            b.erase(mxb);
            b.insert(mxb / 2);
            b.insert((mxb + 1) / 2);
            fb[mxb / 2] += fb[mxb];
            fb[(mxb + 1) / 2] += fb[mxb];
            fb[mxb] = 0;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout.setf(ios::fixed);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


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

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    long long sum_a = 0, sum_b = 0;
    for (int &x : a) {
        cin >> x;
        sum_a += x;
    }
    for (int &x : b) {
        cin >> x;
        sum_b += x;
    }
    if (sum_a != sum_b) {
        cout << "No\n";
        return;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    unordered_map<int, int> freq;
    int total = n;
    for (int x : a) {
        freq[x]++;
    }
    priority_queue<int> pq;
    for (int x : b) {
        pq.push(x);
    }
    bool possible = true;
    while (!pq.empty()) {
        int s = pq.top();
        pq.pop();
        auto it = freq.find(s);
        if (it != freq.end() && it->second > 0) {
            it->second--;
            total--;
            if (it->second == 0) {
                freq.erase(it);
            }
        } else {
            if (s == 1) {
                possible = false;
                break;
            }
            int x = (s + 1) / 2;
            int y = s / 2;
            pq.push(x);
            pq.push(y);
            if (pq.size() > total) {
                possible = false;
                break;
            }
        }
    }
    if (possible && total == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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