ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: C++20 (GCC 13-64)


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

using namespace std;



#define ll long long

#define vi vector<int>

#define vll vector<long long>

#define vvi vector<vector<int>> 

#define pb push_back

#define all(x) begin(x), end(x)

#define rall(v) v.rbegin(), v.rend()

#define sz(x) (int)(x).size()

#define ull unsigned long long

#define fr(i, a, b) for (long long i = a; i < b; i++)

#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)



// Debugging function

template <typename Arg1>

void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; }

template <typename Arg1, typename... Args>

void __f(const char *names, Arg1 &&arg1, Args &&...args) {

    const char *comma = strchr(names + 1, ',');

    cout.write(names, comma - names) << " : " << arg1 << " | ";

    __f(comma + 1, args...);

}



// Input and Output Overloads for Vectors

template <typename T>

istream &operator>>(istream &istream, vector<T> &vec) {

    for (auto &a : vec) cin >> a;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, const vector<T> &vec) {

    for (auto &a : vec) cout << a << " ";

    return ostream;

}





void to_lower(string &s) { transform(all(s), s.begin(), ::tolower); }





void to_upper(string &s) { transform(all(s), s.begin(), ::toupper); }





string helper(string a, string b) {

    if (a + b != b + a) return ""; 

    int Gcd_len = __gcd(a.size(), b.size());

    return a.substr(0, Gcd_len);

}

//-----------------------------------------------------------------





vi factors(int n) {

    vi ans;

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

        if (n % i == 0) {

            ans.pb(i);

            if (i != n / i) ans.pb(n / i);

        }

    }

    return ans;

}

 

 bool bit(int mask, int pos){

        return (mask >> pos ) &1;

 } 

  

 bool check(int k , vi &v ,int h){   

    vi tmp;

       fr(i,0,k){

            tmp.pb(v[i]);

       }

       sort(all(tmp));

       reverse(all(tmp));



       int t = 0;

          for(int i = 0 ; i < k ;i+=2) t += tmp[i];

      return t <= h;

 }

 

 

 

   

 void solve() {

    int n;

    cin >> n;

    vi v(n);

    for (int &x : v) cin >> x;



    

    int Odd_sum = 0, Even_sum = 0;

    

     

    fr(i,0,n){ 



          if(i &1) Odd_sum += v[i];

          else Even_sum += v[i];

    }



    int odd = n/2, eve = n/2;



    if( n&1) eve++;

   

   if(Odd_sum % odd == 0 && Even_sum % eve == 0 && Odd_sum/odd == Even_sum/eve ){

      cout << "YES" << endl;

   }

   else{

     cout << "NO" << endl;

   }







 }

  







signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int tc; cin >> tc;

    while(tc--){

    solve();

    }

    return 0;

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


Submission (verdict: Wrong answer on test 1):
#include <algorithm>

#include <array>

#include <bitset>

#include <cassert>

#include <chrono>

#include <climits>

#include <cmath>

#include <complex>

#include <cstring>

#include <functional>

#include <iomanip>

#include <iostream>

#include <map>

#include <numeric>

#include <queue>

#include <random>

#include <set>

#include <vector>

using namespace std;



#define ll long long

#define forn(i, s, n) for (int i = s; i < n; i++)

#define bforn(i, s) for (int i = s; i >= 0; i--)

// for pairs

#define s second

#define f first 

const int M = 2e5 + 1;

const char nl = '\n';



void solve(){

    string s; cin >> s;

    int n = s.size(); 



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

        int ind = INT_MAX;

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

            int sj = s[j] - '0';

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

            if (sj - (j - i) > si) {

                ind = min(j, ind);

            }

        }

        //cout << "ind: " << ind << nl;

        if (ind == INT_MAX) continue;

        while (ind != i) {

            char temp = s[ind - 1];

            s[ind - 1] = s[ind] - 1;

            s[ind] = temp;

            ind--;

        }

        //cout << s << nl;

    }

    cout << s << nl;

}

// if you are unsure of how to do a problem by hand

// the solution is most likely somewhat brute force (i.e binsearch)

// if input is limited to 0-9 or a-z, usually you will loop through all combinations

// of letters or numbers

// constructive problems : start with 1 when constructing

// :%y+ to copy all lines

// rearrange math expressions

// difference array? (a[i] - b[i])

// debugging : reread the problem statement-every word is important!

// debugging : print important variables!

// think brute force sol first

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    int t; cin >> t;

    for (int tt = 0; tt < t; tt++) solve();

}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define forn(i, s, n) for (int i = s; i < n; i++)
#define bforn(i, s) for (int i = s; i >= 0; i--)
// for pairs
#define s second
#define f first 
const int M = 2e5 + 1;
const char nl = '\n';

void solve(){
    ll l, r; cin >> l >> r;
    int k = 0;
    int at = 0;
    while (true) {
        if (r / (1 << at) == 0) {
            break;
        }
        if ((l >> at) % 2 != (r >> at) % 2) {
            k = at;
        }
        at++;
    }
    cout << (l | (1 << k)) << ' ' << ((l | (1 << k)) - 1) << ' ' << (((l | (1 << k)) == l) ? r : l) << nl;
}
// if you are unsure of how to do a problem by hand
// the solution is most likely somewhat brute force (i.e binsearch)
// if input is limited to 0-9 or a-z, usually you will loop through all combinations
// of letters or numbers
// constructive problems : start with 1 when constructing
// :%y+ to copy all lines
// rearrange math expressions
// difference array? (a[i] - b[i])
// debugging : reread the problem statement-every word is important!
// debugging : print important variables!
// think brute force sol first
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t; cin >> t;
    for (int tt = 0; tt < t; tt++) solve();
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0,count2=0,count3=0;
        for(char ch:n){
            int digit=ch-'0';
            sum+=digit;
            if(ch=='2') count2++;
            else if(ch=='3') count3++;
        }

        long long digitSum=0;
        int ans=0;
        for(int i=0;i<=count2;i++){
            for(int j=0;j<=count3;j++){
                digitSum=(long long)sum%9+(long long)(2*i+6*j);
                if(digitSum%9==0){
                    ans=1;
                    break;
                }
            }
        }

        if(ans){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0,count2=0,count3=0;
        for(char ch:n){
            int digit=ch-'0';
            sum+=digit;
            if(ch=='2') count2++;
            else if(ch=='3') count3++;
        }

        long long digitSum=0;
        int ans=0;
        for(int i=0;i<=count2;i++){
            for(int j=0;j<=count3;j++){
                digitSum=(long long)sum%9+(long long)(2*i+6*j);
                if(digitSum%9==0){
                    ans=1;
                    break;
                }
            }
            if(ans==1) break;
        }

        if(ans){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 1):
#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;

unordered_map<string,int> mpp;

bool f(string s){
    if(stoi(s)%9==0) return true;
    if(mpp.find(s)!=mpp.end()) return mpp[s];

    bool result=false;
    for(int i=0;i<s.size();i++){
        string original=s;
        int digit=s[i]-'0';
        digit*=digit;
        if(digit!=0 && digit<10){
            s[i]=digit+'0';
            if(f(s)){
                result=true;
                break;
            }
        }
        s=original;
    }
    return mpp[s]=result;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s=to_string(n);
        if(f(s)){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 1):
#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;

unordered_map<string,int> mpp;

bool f(string s){
    if(stoi(s)%9==0) return true;
    if(mpp.find(s)!=mpp.end()) return mpp[s];

    bool result=false;
    for(int i=0;i<s.size();i++){
        string original=s;
        int digit=s[i]-'0';
        digit*=digit;
        if(digit!=0 && digit<10){
            s[i]=digit+'0';
            if(f(s)){
                result=true;
                break;
            }
        }
        s=original;
    }
    return mpp[s]=result;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s=to_string(n);
        if(f(s)){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}

Submission (verdict: Runtime error on test 1):
#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;

unordered_map<string,int> memo;

bool f(string s){
    if(stoi(s)%9==0) return true;
    if(memo.find(s)!=memo.end()) return memo[s];

    bool result=false;
    for(int i=0;i<s.size();i++){
        string original=s;
        int digit=s[i]-'0';
        if(digit==2 || digit==3){
            digit*=digit;
            s[i]=digit+'0';
            if(f(s)){
                result=true;
                break;
            }
        }
        s=original;
    }
    return memo[s]=result;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s=to_string(n);
        memo.clear();
        if(f(s)){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 1):
#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;

unordered_map<string,int> memo;

bool f(string s){
    if(stoi(s)%9==0) return true;
    if(memo.find(s)!=memo.end()) return memo[s];

    bool result=false;
    for(int i=0;i<s.size();i++){
        string original=s;
        int digit=s[i]-'0';
        if(digit==2 || digit==3){
            digit*=digit;
            s[i]=digit+'0';
            if(f(s)){
                result=true;
                break;
            }
        }
        s=original;
    }
    return memo[s]=result;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s=to_string(n);
        memo.clear();
        if(f(s)){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}

Submission (verdict: Memory limit exceeded on test 4):
#include<iostream>
#include<vector>
using namespace std;

bool f(int two,int three,int sum,vector<vector<int>>& dp){
    sum%=9;
    if(!sum) return true;
    if(!two && !three) return false;
    if(dp[two][three]!=-1) return dp[two][three];

    bool take2=0,take3=0,take23=0;
    if(two>0) take2=f(two-1,three,sum+2,dp);
    if(three>0) take3=f(two,three-1,sum+6,dp);
    if(two>0 && three>0) take23=f(two-1,three-1,sum+8,dp);

    return dp[two][three]=take2||take3||take23;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0,count2=0,count3=0;
        for(char ch:n){
            int digit=ch-'0';
            sum+=digit;
            if(ch=='2') count2++;
            else if(ch=='3') count3++;
        }
        vector<vector<int>> dp(count2+1,vector<int>(count3+1,-1));

        if(f(count2,count3,sum%9,dp)){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Memory limit exceeded on test 4):
#include<iostream>
#include<vector>
using namespace std;

bool f(int two,int three,int sum,vector<vector<int>>& dp){
    sum%=9;
    if(!sum) return true;
    if(!two && !three) return false;
    if(dp[two][three]!=-1) return dp[two][three];

    bool take2=0,take3=0,take23=0;
    if(two>0) take2=f(two-1,three,sum+2,dp);
    if(three>0) take3=f(two,three-1,sum+6,dp);
    if(two>0 && three>0) take23=f(two-1,three-1,sum+8,dp);

    return dp[two][three]=take2||take3||take23;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0,count2=0,count3=0;
        for(char ch:n){
            int digit=ch-'0';
            sum+=digit;
            if(ch=='2') count2++;
            else if(ch=='3') count3++;
        }
        vector<vector<int>> dp(count2+1,vector<int>(count3+1,-1));

        if(f(count2,count3,sum%9,dp)){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 5):
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0,count2=0,count3=0;
        for(char ch:n){
            int digit=ch-'0';
            sum+=digit;
            if(ch=='2') count2++;
            else if(ch=='3') count3++;
        }

        long long digitSum=0;
        int ans=0;
        for(int i=0;i<=count2;i++){
            for(int j=0;j<=count3;j++){
                digitSum=(long long)sum%9+(long long)(2*i+6*j);
                if(digitSum%9==0){
                    ans=1;
                    break;
                }
            }
        }

        if(ans){
            cout<<"yes";
        }else{
            cout<<"no";
        }
        cout<<endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;



//Type aliasesa

typedef long long ll;

typedef unsigned long long ull;

typedef double db;



//Constants

const int MOD = 1e9+7;



//Macros

#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr);

#define pb push_back

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define ff first

#define ss second

#define vi vector<ll>

#define vpi vector<pair<ll,ll>>

#define vvi vector<vector<ll>>

#define mp make_pair



//Loops

#define fr(i, a, b) for (ll i = (a); i < (b); ++i)

#define frd(i, a, b) for (ll i = (a); i >= (b); --i)



//Helpers

template <typename T> void read_vector(vector<T> &v) {

    for (auto &x : v) cin >> x;

}



void solve(){

    ll n,l,r;

    cin>>n>>l>>r;

    vi a(n);

    read_vector(a);

    sort(all(a));

    ll sum=0;

    fr(i,0,r-l+1){

        sum+=a[i];

    }

    cout<<sum<<endl;

}



int main() {

    fast_io();

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}



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

using namespace std;



//Type aliasesa

typedef long long ll;

typedef unsigned long long ull;

typedef double db;



//Constants

const int MOD = 1e9+7;



//Macros

#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr);

#define pb push_back

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define ff first

#define ss second

#define vi vector<ll>

#define vpi vector<pair<ll,ll>>

#define vvi vector<vector<ll>>

#define mp make_pair



//Loops

#define fr(i, a, b) for (ll i = (a); i < (b); ++i)

#define frd(i, a, b) for (ll i = (a); i >= (b); --i)



//Helpers

template <typename T> void read_vector(vector<T> &v) {

    for (auto &x : v) cin >> x;

}



void solve(){

    ll n,l,r;

    cin>>n>>l>>r;

    vi a(n);

    read_vector(a);

    vi s1,s2;

    fr(i,0,r+1){

        s1.pb(a[i]);

    }

    fr(i,l,n){

        s2.pb(a[i]);

    }

    sort(all(s1));

    sort(all(s2));

    ll ans1=0,ans2=0;

    fr(i,0,r-l+1){

        ans1+=s1[i];

        ans2+=s2[i];

    }

    cout<<min(ans1,ans2)<<endl;

}



int main() {

    fast_io();

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;



//Type aliasesa

typedef long long ll;

typedef unsigned long long ull;

typedef double db;



//Constants

const int MOD = 1e9+7;



//Macros

#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr);

#define pb push_back

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define ff first

#define ss second

#define vi vector<ll>

#define vpi vector<pair<ll,ll>>

#define vvi vector<vector<ll>>

#define mp make_pair



//Loops

#define fr(i, a, b) for (ll i = (a); i < (b); ++i)

#define frd(i, a, b) for (ll i = (a); i >= (b); --i)



//Helpers

template <typename T> void read_vector(vector<T> &v) {

    for (auto &x : v) cin >> x;

}



void solve(){

    ll n,l,r;

    cin>>n>>l>>r;

    vi a(n);

    read_vector(a);

    vi s1,s2;

    fr(i,0,r+1){

        s1.pb(a[i]);

    }

    fr(i,l,n){

        s2.pb(a[i]);

    }

    sort(all(s1));

    sort(all(s2));

    ll ans1=0,ans2=0;

    fr(i,0,r-l+1){

        ans1+=s1[i];

        ans2+=s2[i];

    }

    cout<<min(ans1,ans2)<<endl;

}



int main() {

    fast_io();

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}



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

using namespace std;



//Type aliasesa

typedef long long ll;

typedef unsigned long long ull;

typedef double db;



//Constants

const int MOD = 1e9+7;



//Macros

#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr);

#define pb push_back

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define ff first

#define ss second

#define vi vector<ll>

#define vpi vector<pair<ll,ll>>

#define vvi vector<vector<ll>>

#define mp make_pair



//Loops

#define fr(i, a, b) for (ll i = (a); i < (b); ++i)

#define frd(i, a, b) for (ll i = (a); i >= (b); --i)



//Helpers

template <typename T> void read_vector(vector<T> &v) {

    for (auto &x : v) cin >> x;

}



void solve(){

    ll n,l,r;

    cin>>n>>l>>r;

    vi a(n);

    read_vector(a);

    vi s1,s2;

    fr(i,0,r){

        s1.pb(a[i]);

    }

    fr(i,l-1,n){

        s2.pb(a[i]);

    }

    sort(all(s1));

    sort(all(s2));

    ll ans1=0,ans2=0;

    fr(i,0,r-l+1){

        ans1+=s1[i];

        ans2+=s2[i];

    }

    cout<<min(ans1,ans2)<<endl;

}



int main() {

    fast_io();

    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 2):
#include <bits/stdc++.h>

using namespace std;



//Type aliasesa

typedef long long ll;

typedef unsigned long long ull;

typedef double db;



//Constants

const int MOD = 1e9+7;



//Macros

#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr);

#define pb push_back

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define ff first

#define ss second

#define vi vector<ll>

#define vpi vector<pair<ll,ll>>

#define vvi vector<vector<ll>>

#define mp make_pair



//Loops

#define fr(i, a, b) for (ll i = (a); i < (b); ++i)

#define frd(i, a, b) for (ll i = (a); i >= (b); --i)



//Helpers

template <typename T> void read_vector(vector<T> &v) {

    for (auto &x : v) cin >> x;

}



void solve(){

    ll n,l,r;

    cin>>n>>l>>r;

    vi a(n);

    read_vector(a);

    sort(all(a));

    ll sum=0;

    fr(i,0,r-l+1){

        sum+=a[i];

    }

    cout<<sum<<endl;

}



int main() {

    fast_io();

    int t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

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

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
#define int int64_t


using namespace std;

void update (int pos, std::string& input_d) {
    int max_ = input_d[pos];
    int max_idx_ = pos;
    for (int i = 1; (i < 8) && (pos + i < input_d.size()); ++i) {
        if (input_d[pos + i] - i > max_) {
            max_ = input_d[pos + i] - i;
            max_idx_ = pos + i;
        }
    }
    for (int i = max_idx_; i > pos; --i) {
        input_d[i] = input_d[i - 1];
    }
    input_d[pos] = max_;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string input_d;
        cin >> input_d;
        for (int i = 0; i + 1 < input_d.size(); ++i){
            update(i, input_d);
        }
        cout << input_d << endl;
    }
}

Submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include <vector>
#define int int64_t


using namespace std;

bool compare_vv(vector<char>& a, vector<char>& b) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] < b[i]) {
            return true;
        }
        if (a[i] > b[i]) {
            return false;
        }
    }
    return false;
}

void update (int pos, std::string& input_d) {
    int max_ = input_d[pos];
    int max_idx_ = pos;
    vector<vector<char>> to_compare;


 
    for (int swap_idx = pos; 
        (swap_idx < (pos + 9)) && (swap_idx < input_d.size());
        ++swap_idx) {

        vector<char> to_push;
        to_push.push_back(input_d[swap_idx] - (swap_idx - pos));

        for (int i = pos; (i < (pos + 9)) && (i < input_d.size()); ++i) {
            if (i == swap_idx) {
                continue;
            } else {
                to_push.push_back(input_d[i]);
            }
        }
        to_compare.push_back(to_push);
    }
    
    vector<char> max_v = to_compare[0];
    max_idx_ = 0;
    for (int i = 1; i < to_compare.size(); ++i) {
        if (compare_vv(max_v, to_compare[i])) {
            max_v = to_compare[i];
            max_idx_ = i;
        }
    }
    
    max_ = input_d[pos + max_idx_] - max_idx_;

    for (int i = pos+max_idx_; i > pos; --i) {
        input_d[i] = input_d[i - 1];
    }
    input_d[pos] = max_;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string input_d;
        cin >> input_d;
        bool updated = true;
        while (updated) {
            updated = false;
            for (int i = 0; i + 1< input_d.size(); ++i)  {
                if (input_d[i] < input_d[i + 1] - 1) {
                    char x = input_d[i];
                    input_d[i] = input_d[i + 1] - 1;
                    input_d[i + 1] = x;
                    updated = true;
                    break;
                }; 
            }
        }
        cout << input_d << endl;
    }
}