ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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



using namespace std;



int main(){

ios_base :: sync_with_stdio(false);

cin.tie(NULL);

int t, x, y, k;

cin >> t;

string s;

string aux;

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

cin >> s;

aux = s;

for(int j=1; j < s.length(); j++){

if(s[j]=='0' || s[j] == '1'){

continue;

}

x = int(s[k]) - '0';

for(int k=j; k>0 && k>=(j-x); k--){

x = int(s[k]) - '0';

if(x==0){

break;

}

y = int(s[k-1]) - '0';

if((x-1)>y){

x = (x - 1) + '0';



aux[k] = char(x);

s[k-1] = aux[k];

s[k] = aux[k-1];

aux = s;

} else {

break;

}

}

}

cout << s << "\n";



}

}

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

using namespace std;



bool podeTrocar(const string &texto, int i) {

return (i < (int)texto.size() && texto[i] > '0' && (texto[i] - 1) > texto[i - 1]);

}



int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t, k;

char valor, aux;

cin >> t;

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

string s;

cin >> s;

int tamanho = s.size();

deque<int> fila;

for (int j = 1; j < tamanho; j++) {

if (podeTrocar(s, j))

fila.push_back(j);

}

while (!fila.empty()) {

k = fila.front();

fila.pop_front();

if (k < tamanho && podeTrocar(s, k)) {

valor = s[k] - 1;

aux = s[k - 1];

s[k - 1] = valor;

s[k] = aux;

if (k - 1 > 0 && podeTrocar(s, k - 1))

fila.push_back(k - 1);

if (k < tamanho && podeTrocar(s, k))

fila.push_back(k);

if (k + 1 < tamanho && podeTrocar(s, k + 1))

fila.push_back(k + 1);

}

}



cout << s << "\n";

}

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

Previous submission (verdict: Wrong answer on test 6):
 #include <bits/stdc++.h>
 #define F first
 #define S second
 #define ll long long
 #define all(v) v.begin() , v.end()
 #define allr(v) v.rbegin() , v.rend()
 #define pb push_back
 using namespace std;
 #define endl "\n"
 #include <ext/pb_ds/assoc_container.hpp>
 #include <ext/pb_ds/tree_policy.hpp>
 using namespace __gnu_pbds;
 int mod = 998244353;
 typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedS;
 //order_of_key, __builtin_popcountll(n)
 void fast() {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
}
vector <ll> calc (vector <ll> v){
    vector <ll> cp;
    int n = v.size();
    for (int i = 1; i < n; i++){
        cp.pb (v[i] - v[i - 1]);
    }
    return cp;
}

void solve (){
    int n; cin >> n;
    vector <ll>v (n);
    ll mx = 0;
    for (int i = 0; i < n; i++){
        cin >> v[i];
        mx += v[i];
    }
    if (n == 1){
        cout << v[0] << endl;
        return;
    }

    // (9 -7 8) -> -16 , 15
    // (8 -7 9) -> -15 , 16
    //v[n - 1] - v[n - 2] > v[1] - v[0]

    while (n > 2){
        v = calc(v);
        n--;
        if (v[n - 1] < v[0]){
            reverse(all(v));
        }
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += v[i];
        }
        mx = max (mx , sm);
    }
    mx = max (mx , max (v[0] - v[1] , v[1] - v[0]));
    cout << mx << endl;

}
 int main() {
     fast();
     int t = 1;
     cin >> t;
     while (t--) {
         solve();
     }
     return 0;
 }


Submission (verdict: Accepted):
 #include <bits/stdc++.h>
 #define F first
 #define S second
 #define ll long long
 #define all(v) v.begin() , v.end()
 #define allr(v) v.rbegin() , v.rend()
 #define pb push_back
 using namespace std;
 #define endl "\n"
 #include <ext/pb_ds/assoc_container.hpp>
 #include <ext/pb_ds/tree_policy.hpp>
 using namespace __gnu_pbds;
 int mod = 998244353;
 typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedS;
 //order_of_key, __builtin_popcountll(n)
 void fast() {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
}
vector <ll> calc (vector <ll> v){
    vector <ll> cp;
    int n = v.size();
    for (int i = 1; i < n; i++){
        cp.pb (v[i] - v[i - 1]);
    }
    return cp;
}

void solve (){
    int n; cin >> n;
    vector <ll>v (n);
    ll mx = 0;
    for (int i = 0; i < n; i++){
        cin >> v[i];
        mx += v[i];
    }
    if (n == 1){
        cout << v[0] << endl;
        return;
    }

    // (9 -7 8) -> -16 , 15
    // (8 -7 9) -> -15 , 16
    //v[n - 1] - v[n - 2] > v[1] - v[0]

    while (n > 2){
        if (v[n - 1] < v[0]){
            reverse(all(v));
        }
        v = calc(v);
        n--;
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += v[i];
        }
        mx = max (mx , sm);
    }
    mx = max (mx , max (v[0] - v[1] , v[1] - v[0]));
    cout << mx << endl;

}
 int main() {
     fast();
     int t = 1;
     cin >> t;
     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>
 #define F first
 #define S second
 #define ll long long
 #define all(v) v.begin() , v.end()
 #define allr(v) v.rbegin() , v.rend()
 #define pb push_back
 using namespace std;
 #define endl "\n"
 #include <ext/pb_ds/assoc_container.hpp>
 #include <ext/pb_ds/tree_policy.hpp>
 using namespace __gnu_pbds;
 int mod = 998244353;
 typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedS;
 //order_of_key, __builtin_popcountll(n)
 void fast() {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
}
vector <int> calc (vector <int> v){
    vector <int> cp;
    int n = v.size();
    for (int i = 1; i < n; i++){
        cp.pb (v[i] - v[i - 1]);
    }
    return cp;
}

void solve (){
    int n; cin >> n;
    vector <int>v (n);
    int mx = 0;
    for (int i = 0; i < n; i++){
        cin >> v[i];
        mx += v[i];
    }
    if (n == 1){
        cout << v[0] << endl;
        return;
    }

    // (9 -7 8) -> -16 , 15
    // (8 -7 9) -> -15 , 16
    //v[n - 1] - v[n - 2] > v[1] - v[0]

    while (n > 2){
        int f = v[1] - v[0];
        int b = v[n - 1] - v[n - 2];
        if (b < f){
            reverse(all(v));
        }
        v = calc(v);
        n--;
        int sm = 0;
        for (int i = 0; i < n; i++){
            sm += v[i];
        }
        mx = max (mx , sm);
    }
    mx = max (mx , max (v[0] - v[1] , v[1] - v[0]));
    cout << mx << endl;

}
 int main() {
     fast();
     int t = 1;
     cin >> t;
     while (t--) {
         solve();
     }
     return 0;
 }
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {

                int x=s[i]-'0';

                int y=s[i-1]-'0';

                if(x>y+1 && s[i]!=0) {

                    s[i]-='0';

                    s[i]-=1;

                    s[i]+='0';

                    swap(s[i],s[i-1]);



                    flag = true;

                    break;

                }

            }

        }





        cout << s << endl;















    }



    return 0;

}



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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {



                if(s[i]-s[i-1]>1 && s[i]!=0) {

                    s[i]--;

                    swap(s[i],s[i-1]);



                    flag = true;

                    break;

                }

            }

        }





        cout << s << endl;















    }



    return 0;

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


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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        //19

        //81

        //1709

        //6109

        //6180

        //6710

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {

                int x=s[i]-'0';

                int y=s[i-1]-'0';

                if(x>y+1) {

                    s[i]-='0';

                    s[i]-=1;

                    s[i]+='0';

                    swap(s[i],s[i-1]);



                    flag = true;

                    break;

                }

            }

        }





        cout << s << endl;















    }



    return 0;

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

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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {



                if(s[i]-s[i-1]>1 && s[i]!=0) {

                    s[i]--;

                    swap(s[i],s[i-1]);



                    flag = true;

                    break;

                }

            }

        }





        cout << s << endl;















    }



    return 0;

}



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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        //19

        //81

        //1709

        //6109

        //6180

        //6710

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {

                int x=s[i]-'0';

                int y=s[i-1]-'0';

                if(x>y+1) {

                    s[i]-='0';

                    s[i]-=1;

                    s[i]+='0';

                    swap(s[i],s[i-1]);



                    flag = true;

                   

                }

            }

        }





        cout << s << endl;















    }



    return 0;

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

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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        //19

        //81

        //1709

        //6109

        //6180

        //6710

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {

                int x=s[i]-'0';

                int y=s[i-1]-'0';

                if(x>y+1) {

                    s[i]-='0';

                    s[i]-=1;

                    s[i]+='0';

                    swap(s[i],s[i-1]);



                    flag = true;

                    break;

                }

            }

        }





        cout << s << endl;















    }



    return 0;

}



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

using namespace std;

#define int long long



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    /* int t;

     cin >> t;

    while (t--) {

        int a,b,c;

        cin >> a >> b >> c;

        if( b==(a+c)/2){

            int x=abs((a+c)-(2*b));

            cout << x << endl;

        }

    }*/



//abc

//cba

   int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        bool flag = true;

        while (flag) {

            flag = false;

            for (int i = 1; i < s.length(); i++) {

                int x=s[i]-'0';

                int y=s[i-1]-'0';

                if(x>y+1 && s[i]!=0) {

                    s[i]-='0';

                    s[i]-=1;

                    s[i]+='0';

                    swap(s[i],s[i-1]);



                    flag = true;

                    break;

                }

            }

        }





        cout << s << endl;















    }



    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


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

using namespace std;



#define int long long



void solve(vector<int> v1,vector<int> v2,int sum,bool &ans,int index,int n){

    if(index==n){

        return;

    }

    if(sum%9==0){

        ans = true;

    }

    int sm = sum - v1[index];

    sm += v2[index];

    if(sm%9==0){

        ans = true;

    }

    index++;

    solve(v1, v2, sum, ans, index, n);

    solve(v1, v2, sm, ans, index, n);

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        vector<int> v1;

        vector<int> v2;

        int n=s.size();

        int sum = 0;

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

            int x = s[i] - '0';

            v1.push_back(x);

            if(x*x<10){

                v2.push_back(x*x);

            }

            else{

                v2.push_back(x);

            }

            sum+=x;

        }

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

        //     cout << v1[i] << " ";

        // }

        // cout << endl;

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

        //     cout << v2[i] << " ";

        // }

        // cout << endl;

        bool ans = false;

        int index = 0;

        // cout << sum << endl;

        solve(v1,v2,sum,ans,index,n);



        if(ans){

            cout << "YES" << endl;

        }

        else{

            cout << "NO" << endl;

        }

    }

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

using namespace std;



#define int long long



// void solve(vector<int> v1,vector<int> v2,int sum,bool &ans,int index,int n){

//     if(index==n){

//         return;

//     }

//     if(sum%9==0){

//         ans = true;

//     }

//     int sm = sum - v1[index];

//     sm += v2[index];

//     if(sm%9==0){

//         ans = true;

//     }

//     index++;

//     solve(v1, v2, sum, ans, index, n);

//     solve(v1, v2, sm, ans, index, n);

// }



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.length();

        int sum = 0;

        vector<int> a;

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

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

                a.push_back(2);

            }

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

                a.push_back(6);

            }

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

        }

        int m = a.size();

        int M = (1 << m) - 1;

        bool ans = false;

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

            int sm = 0;

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

                if(i& (1<<j)){

                    sm += a[j];

                }

            }

            if((sm+sum)%9==0){

                ans=true;

                break;

            }

        }

        // cout << sum << endl;

        // for (int i = 0; i < m;i++){

        //     cout<<a[i]<<" ";

        // }

        if (ans){

            cout << "YES" << endl;

        }

        else{

            cout << "NO" << endl;

        }    

    }

}

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

using namespace std;



#define int long long



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.size();

        int n2=0;

        int n6 = 0;

        int sum = 0;

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

            if(s[i] == '2') n2++;

            if(s[i] == '3') n6++;

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

        }

        if(sum%9==0){

            cout << "YES" << endl;

            continue;

        }

        else{

            int num = 9 - (sum % 9);

            bool flag = false;

            for (int i = num;;i+=9){

                if(i>(n6*6 + n2*2)){

                    break;

                }

                if(n6*6>=i){

                    i %= 6;

                    if(i%2==0 && n2>=i/2){

                        flag = true;

                        break;

                    }

                }

                else{

                    i -= (n6 * 6);

                    if(i%2==0 && n2>=i/2){

                        flag = true;

                        break;

                    }

                }

            }

            if(flag) cout << "YES" << endl;

            else cout << "NO" << endl;

        }

    }

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

using namespace std;



#define int long long



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.size();

        int n2=0;

        int n6 = 0;

        int sum = 0;

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

            if(s[i] == '2') n2++;

            if(s[i] == '3') n6++;

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

        }

        if(sum%9==0){

            cout << "YES" << endl;

            continue;

        }

        else{

            int num = 9 - (sum % 9);

            bool flag = false;

            for (int i = num;;i+=9){

                if(i>(n6*6 + n2*2)){

                    break;

                }

                if(n6*6>=i){

                    i %= 6;

                    if(i%2==0 && n2>=i/2){

                        flag = true;

                        break;

                    }

                }

                else{

                    i -= (n6 * 6);

                    if(i%2==0 && n2>=i/2){

                        flag = true;

                        break;

                    }

                }

            }

            if(flag) cout << "YES" << endl;

            else cout << "NO" << endl;

        }

    }

}

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

using namespace std;



#define int long long



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.size();

        int n2=0;

        int n6 = 0;

        int sum = 0;

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

            if(s[i] == '2') n2++;

            if(s[i] == '3') n6++;

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

        }

        if(sum%9==0){

            cout << "YES" << endl; 

            continue;

        }

        else{

            int num = 9 - (sum % 9);

            bool flag = false;

            int maximum = ((n6 * 6) + (n2 * 2));

            for (int i = num;i<=maximum;i+=9){

                int k = i;

                if((n6*6)>=k){

                    k %= 6;

                    if(k%2==0 && n2>=(k/2)){

                        flag = true;

                        break;

                    }

                }

                else{

                    k -= (n6 * 6);

                    if(k%2==0 && n2>=(k/2)){

                        flag = true;

                        break;

                    }

                }

            }

            if(flag) cout << "YES" << endl;

            else cout << "NO" << endl;

        }

    }

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        char s[200001];
        scanf("%s", s);

        for(int i = 0; s[i] != '\0'; i++)
        {
            if(s[i + 1] - s[i] > 1)
            {
                s[i + 1]--;
                s[i] ^= s[i + 1];
                s[i + 1] ^= s[i];
                s[i] ^= s[i + 1];
                i = -1;
            }
        }
        puts(s);
    }

    return 0;
}

Submission (verdict: Accepted):
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        char s[200001];
        scanf("%s", s);

        for(int i = 0; s[i] != '\0'; )
        {
            if(s[i + 1] - s[i] > 1)
            {
                s[i + 1]--;
                s[i] ^= s[i + 1];
                s[i + 1] ^= s[i];
                s[i] ^= s[i + 1];
                if(i)
                    i--;
                else
                    i++;
                continue;
            }
            i++;
        }
        puts(s);
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 6):
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        char s[20001];
        scanf("%s", s);

        for(int i = 0; s[i] != '\0'; i++)
        {
            if(s[i + 1] - s[i] > 1)
            {
                s[i + 1]--;
                s[i] ^= s[i + 1];
                s[i + 1] ^= s[i];
                s[i] ^= s[i + 1];
                i = -1;
            }
        }
        puts(s);
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        char s[200001];
        scanf("%s", s);

        for(int i = 0; s[i] != '\0'; i++)
        {
            if(s[i + 1] - s[i] > 1)
            {
                s[i + 1]--;
                s[i] ^= s[i + 1];
                s[i + 1] ^= s[i];
                s[i] ^= s[i + 1];
                i = -1;
            }
        }
        puts(s);
    }

    return 0;
}