ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    ll i=0,n=s.size();
    while(i<n){
    for(ll j=n-1;j>i;j--){
      if(s[j]>s[j-1]+1) {
        s[j]-=1;
        swap(s[j],s[j-1]);
      }
    }
    i++;
}
cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    ll i=0,n=s.size();
    while(i<n){
    for(ll j=n-1;j>i;j--){
      if(s[j]=='0') continue;
      if(s[j]>s[j-1]+1) {
        s[j]-=1;
        swap(s[j],s[j-1]);
      }
    }
    i++;
}
cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    int i=0,n=s.size();
    while(i<n){
    for(int j=n-1;j>i;j--){
      if(s[j]>s[j-1]+1) {
        s[j]-=1;
        swap(s[j],s[j-1]);
      }
    }
    i++;
}
cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    ll i=0,n=s.size();
    while(i<n){
    for(ll j=n-1;j>i;j--){
      if(s[j]>s[j-1]+1) {
        s[j]-=1;
        swap(s[j],s[j-1]);
      }
    }
    i++;
}
cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    int i=0,n=s.size();
    while(i<n){
    for(int j=n-1;j>i;j--){
      if(s[j]>s[j-1]+1) {
        s[j]-=1;
        swap(s[j],s[j-1]);
      }
    }
    i++;
}
cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    ll i=0,n=s.size();
    while(i<n){
    for(ll j=n-1;j>i;j--){
      if(s[j]=='0') continue;
      if(s[j]>s[j-1]+1) {
        s[j]-=1;
        swap(s[j],s[j-1]);
      }
    }
    i++;
}
cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    return 0;
}

Submission (verdict: Accepted):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void f(){
    string s;
    cin>>s;
    
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }

cout<<s<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        f();
    }

    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;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        

        vector<int> groups(n + 1);

        

        // First, set all values to 0

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

            if (i == y) {

                groups[i] = 2;  // The MEX position is always 2

            } else {

                groups[i] = 1;  // Start with all 1s except y

            }

        }

        

        // Then alternate between 0 and 1 from x

        groups[x] = 0;

        int curr = (x % n) + 1;

        int val = 1;

        

        while (curr != y) {

            groups[curr] = val;

            val = 1 - val;  // Alternate between 0 and 1

            curr = (curr % n) + 1;

        }

        

        // Print result

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

            cout << groups[i] << " ";

        }

        cout << "\n";

    }

    return 0;

}

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

using namespace std;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        

        vector<int> groups(n + 1);

        

        // Start with filling most positions with alternating 0s and 1s

        int curr_val = 0;

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

            if (i == y) {

                groups[i] = 2;

            } else {

                groups[i] = curr_val;

                curr_val = 1 - curr_val;

            }

        }

        

        // Then adjust values working backwards from y to ensure MEX property holds

        int curr = y;

        while (curr != x) {

            curr = (curr == 1) ? n : curr - 1;

            if (curr == x) break;

            

            // Get next value (considering circular array)

            int next = (curr == n) ? 1 : curr + 1;

            

            // If next is y, get the value after y

            if (next == y) {

                next = (next == n) ? 1 : next + 1;

            }

            

            // Adjust current position to maintain MEX property

            groups[curr] = (groups[next] + 1) % 2;

        }

        

        // Ensure x position has value 0

        groups[x] = 0;

        

        // Print result

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

            cout << groups[i] << " ";

        }

        cout << "\n";

    }

    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;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        

        vector<int> groups(n + 1, -1);  // Initialize with -1

        groups[x] = 0;  // Start point

        

        // Forward direction

        int curr = x;

        while (curr != y) {

            curr = (curr % n) + 1;  // Move to next number (1 to n)

            if (curr == y) break;

            

            int prev = (curr == 1) ? n : curr - 1;

            groups[curr] = (groups[prev] == 0) ? 1 : 0;

        }

        

        // Backward direction

        curr = x;

        while (curr != y) {

            curr = (curr == 1) ? n : curr - 1;  // Move to previous number

            if (curr == y) break;

            

            int next = (curr % n) + 1;

            if (groups[curr] == -1) {  // Only fill if not already set

                groups[curr] = (groups[next] == 0) ? 1 : 0;

            }

        }

        

        groups[y] = 2;  // End point

        

        // Output

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

            cout << groups[i] << " ";

        }

        cout << "\n";

    }

    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;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        

        vector<int> groups(n + 1);

        

        // Start with filling most positions with alternating 0s and 1s

        int curr_val = 0;

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

            if (i == y) {

                groups[i] = 2;

            } else {

                groups[i] = curr_val;

                curr_val = 1 - curr_val;

            }

        }

        

        // Then adjust values working backwards from y to ensure MEX property holds

        int curr = y;

        while (curr != x) {

            curr = (curr == 1) ? n : curr - 1;

            if (curr == x) break;

            

            // Get next value (considering circular array)

            int next = (curr == n) ? 1 : curr + 1;

            

            // If next is y, get the value after y

            if (next == y) {

                next = (next == n) ? 1 : next + 1;

            }

            

            // Adjust current position to maintain MEX property

            groups[curr] = (groups[next] + 1) % 2;

        }

        

        // Ensure x position has value 0

        groups[x] = 0;

        

        // Print result

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

            cout << groups[i] << " ";

        }

        cout << "\n";

    }

    return 0;

}

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

using namespace std;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        --x;

        --y;



        vector<int> groups(n);



        groups[x] = 0;



        for (int i = (x + 1 + n) % n; i != y; i = (i + 1 + n) % n){

            groups[i] = (groups[(i-1) % n] + 1) % 2;



        }

    

        for (int i = (x - 1 + n) % n; i != y; i = (i - 1 + n) % n){

            groups[i] = (groups[(i+1) % n] + 1) % 2;



        }





        groups[y] = 2;



        for (auto g : groups){

            cout << g << " ";

        }

        cout << '\n';

    }

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



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        

        vector<int> groups(n + 1, -1);  // Initialize with -1

        groups[x] = 0;  // Start point

        

        // Forward direction

        int curr = x;

        while (curr != y) {

            curr = (curr % n) + 1;  // Move to next number (1 to n)

            if (curr == y) break;

            

            int prev = (curr == 1) ? n : curr - 1;

            groups[curr] = (groups[prev] == 0) ? 1 : 0;

        }

        

        // Backward direction

        curr = x;

        while (curr != y) {

            curr = (curr == 1) ? n : curr - 1;  // Move to previous number

            if (curr == y) break;

            

            int next = (curr % n) + 1;

            if (groups[curr] == -1) {  // Only fill if not already set

                groups[curr] = (groups[next] == 0) ? 1 : 0;

            }

        }

        

        groups[y] = 2;  // End point

        

        // Output

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

            cout << groups[i] << " ";

        }

        cout << "\n";

    }

    return 0;

}

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

using namespace std;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        

        vector<int> groups(n + 1);

        

        // First, set all values to 0

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

            if (i == y) {

                groups[i] = 2;  // The MEX position is always 2

            } else {

                groups[i] = 1;  // Start with all 1s except y

            }

        }

        

        // Then alternate between 0 and 1 from x

        groups[x] = 0;

        int curr = (x % n) + 1;

        int val = 1;

        

        while (curr != y) {

            groups[curr] = val;

            val = 1 - val;  // Alternate between 0 and 1

            curr = (curr % n) + 1;

        }

        

        // Print result

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

            cout << groups[i] << " ";

        }

        cout << "\n";

    }

    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;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        --x;

        --y;



        vector<int> groups(n);



        groups[x] = 0;



        for (int i = (x + 1 + n) % n; i != y; i = (i + 1 + n) % n){

            groups[i] = (groups[(i-1) % n] + 1) % 2;



        }

    

        for (int i = (x - 1 + n) % n; i != y; i = (i - 1 + n) % n){

            groups[i] = (groups[(i+1) % n] + 1) % 2;



        }





        groups[y] = 2;



        for (auto g : groups){

            cout << g << " ";

        }

        cout << '\n';

    }

}

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

using namespace std;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        --x;

        --y;



        vector<int> groups(n);



        groups[x] = 0;



        for (int i = (x + 1 + n) % n; i != y; i = (i + 1 + n) % n){

            groups[i] = (groups[(i-1) % n] + 1) % 2;



        }

    

        for (int i = (x - 1 + n) % n; i != y; i = (i - 1 + n) % n){

            groups[i] = (groups[(i+1) % n] + 1) % 2;



        }



        if (groups[(y - 1) % n] == 1 || groups[(y+1) % n] == 1) groups[y] = 2;

        else{

            groups[y] = 1;

        }

        for (auto g : groups){

            cout << g << " ";

        }

        cout << '\n';

    }

}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


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

int n;
int cnt;
const int N = 20005;

typedef struct node
{
	int code;
	int du;
}node;

struct compare
{
	bool operator()(const node& a, const node& b)
	{
		return a.du < b.du;
	}
};
vector<node> d(N);

typedef struct graph
{
	int V;//顶点数
	vector<list<int>> adj;
	graph(int V) :V(n+1), adj(n+1) {};
}graph;

void dfsvisit(int s, vector<bool>& visit, vector<list<int>> adj)
{
	visit[s] = true;
	for (int v : adj[s])
	{
		if (!visit[v])
		{
			dfsvisit(v, visit, adj);
		}
	}
}

void dfs(vector<list<int>> adj, node n1, node n2)
{
	vector<bool> visit(N, false);
	list<int> tmp1 = adj[n1.code];
	list<int> tmp2 = adj[n2.code];
	while (!adj[n1.code].empty()) adj[n1.code].pop_back();
	while (!adj[n2.code].empty()) adj[n2.code].pop_back();
	visit[n1.code] = true, visit[n2.code] = true;

	for (int i = 1; i <= n; i++)
	{
		if (!visit[i])
		{
			//printf("visit[%d]\n", i);
			cnt++;
			dfsvisit(i, visit, adj);
		}
	}
	adj[n1.code] = tmp1;
	adj[n2.code] = tmp2;
}

bool check(vector<list<int>> adj, node n1, node n2)
{
	for (int i : adj[n1.code])
	{
		if (i == n2.code)
		{
			return true;
		}
	}
	for (int i : adj[n2.code])
	{
		if (i == n1.code)
			return true;
	}
	return false;
}

void solve()
{
	cin >> n;
	graph G(n);

	for (int i = 1; i <= n; i++)
	{
		d[i].du = 0;
		d[i].code = i;
	}

	int u, v;
	for (int i = 1; i < n; i++)
	{
		cin >> u >> v;
		G.adj[u].push_back(v);
		G.adj[v].push_back(u);
		d[u].du++, d[v].du++;
	}
	if (n <= 2)
	{
		cout << 0 << endl;
		return;
	}
	priority_queue<node, vector<node>, compare> pq;
	for (int i = 1; i <= n; i++)
	{
		pq.push(d[i]);
	}
	node n1 = pq.top(); pq.pop();
	int m = 0;
	while (!pq.empty())
	{
		node n2 = pq.top(); pq.pop();
		//printf("log:n1(%d)=%d,n2(%d)=%d\n", n1.code, n1.du, n2.code, n2.du);
		dfs(G.adj, n1, n2);
		//cout << "cnt=" << cnt << endl;
		m = max(m, cnt);
		cnt = 0;
	}
	
	cout << m << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 8):
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n);
    
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> first(a.begin(), a.begin() + l - 1);
    // cout << "first size: " << first.size() << endl;
    vector<int> second(a.begin() + l - 1, a.begin() + r);
    // cout << "second size: " << second.size() << endl;
    vector<int> last(a.begin() + r, a.end());
    // cout << "last size: " << last.size() << endl;

    sort(first.begin(), first.end());
    sort(second.begin(), second.end(), greater<int>());
    sort(last.begin(), last.end());

    // cout << "first: ";
    // for (int x : first) cout << x << " ";
    // cout << endl;

    // cout << "second: ";
    // for (int x : second) cout << x << " ";
    // cout << endl;

    // cout << "last: ";
    // for (int x : last) cout << x << " ";
    // cout << endl;

    int initial_sum = 0;
    for (int x: second) initial_sum += x;


    int left_delta = 0;
    for (int i = 0; i < min(first.size(), second.size()); i++){
        if (first[i] > second[i]){
            break;
        }
        else{
            left_delta +=  first[i] - second[i] ;
        }
    }

    int right_delta = 0;
    for (int i = 0; i < min(last.size(), second.size()); i++){
        if (last[i] > second[i]){
            break;
        }
        else{
            right_delta -= second[i] - last[i];
        }
    }

    int res = initial_sum + min(left_delta, right_delta);
    // cout << "left delta: " << left_delta <<  " right delta: " << right_delta << endl;

    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
        solve();
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <climits>

using namespace std;

void solve() {
    int n;
    cin >> n;

    unordered_map<int, set<int> > graph;
    unordered_map<int, int> neighbors;

    for (int edge = 0; edge < n-1; edge++) {
        int u, v;
        cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        neighbors[u]++;
        neighbors[v]++;
    }

    vector<pair<int, int> > nodes;
    for (const auto& entry : neighbors) {
        nodes.push_back(make_pair(entry.second, entry.first));
    }

    sort(nodes.begin(), nodes.end(), greater<pair<int, int> >());

    // for (const auto& node : nodes) {
    //     cout << "Node " << node.second << " has " << node.first << " neighbors." << endl;
    // }

    int max_neighbors = nodes[0].first;
    vector<int> max_nodes;

    for (const auto& node : nodes) {
        if (node.first == max_neighbors) {
            max_nodes.push_back(node.second);
        } else {
            break;
        }
    }

    int res = 1;
    res += nodes[0].first - 1;
    // cout << "after deleting max: " << res << endl;
    if (max_nodes.size() == 1) {
        max_neighbors = nodes[1].first;

        max_nodes.clear();
        for (int i = 1; i < nodes.size(); ++i) {
            if (nodes[i].first == max_neighbors) {
                max_nodes.push_back(nodes[i].second);
            } else {
                break;
            }
        }
        int add = max_neighbors - 2;
        for (const auto& node : max_nodes) {
            if (graph[node].find(nodes[0].second) == graph[node].end()) {
                add += 1;
                break;
            } 
        }
        res += add;
        cout << res << endl;
        return;
        
    }
    if (max_nodes.size() == 2) {
        int add = nodes[0].first - 1;
        for (const auto& node : max_nodes) {
            if (graph[node].find(nodes[0].second) == graph[node].end()) {
            add -= 1;
            break;
            }
        }
        res += add;
        cout << res << endl;
        return;
    }

   
    cout << res + nodes[0].first - 1<< endl;
  
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
        solve();
    
    return 0;
}