ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int j = 1;
    bool possible = true;

    for (int i = 0; i < n - 1; i++) {
        if (j >= n) break;
        if (a[i] > a[j]) {
            a[i] = a[i] - a[j];
            a[j] = 0;
        } else {
            a[j] = a[j] - a[i];
            a[i] = 0;
        }
        j++;
    }

    for (int i = 0; i < n-1; i++) {
        if (a[i] != 0) {
            possible = false;
            break;
        }
    }

    cout << (possible ? "YES" : "NO") << endl;
}

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


Solution 2 (runtime: 109 ms):
#include <iostream>

#include <vector>

#include <cmath>

#include <map>

#include <set>

#include <algorithm>

#include <string>

using namespace std;

typedef long long ll;



void Refra1n()

{

ll n;cin>>n;

vector<ll>a(n+1);

ll last=0;

bool flag=0;

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

{

cin>>a[i];

if(i>=2)

{

ll ma=min(a[i],a[i-1]);

a[i]-=ma;

a[i-1]-=ma;

}

}

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

{

if(a[i]<a[i-1])

{

flag=1;

break;

}

}

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

else cout<<"NO"<<endl;

}



int main()

{

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int t;cin>>t;

while(t--)

Refra1n();

//cout<<"copyright Refea1n"<<endl;

return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 187 ms):
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long t; cin>>t;
	while(t--){
		long long n, l, r; cin>>n>>l>>r;
		vector<long long> v1, v2;
		for(long long i=0;i<n;i++){
			int x; cin >>x;
			if(i<=r-1){
				v1.push_back(x);
			}
			if(i>=l-1){
				v2.push_back(x);
			}
		}
		sort(v1.begin(),v1.end());
		sort(v2.begin(),v2.end());
		long long len = r-l+1;
		long long res = LLONG_MAX;
		long long ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v1[i];
		}
		res = min(res,ans);
		ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v2[i];
		}
		res = min(res,ans);
		cout<<res <<endl;
	}
	return 0;
}

Solution 2 (runtime: 484 ms):
#include<bits/stdc++.h>

using namespace std;

#define int long long

int t,n,l,r,a[100005],b[100005];

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--){

		int cnt=0,cnt1=0;

		memset(a,0,sizeof(a));

		memset(b,0,sizeof(b));

		cin>>n>>l>>r;

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

			cin>>a[i];

			b[i]=a[i];

		}

		sort(a+1,a+r+1);

		sort(b+l,b+n+1);

		for(int i=1;i<=r-l+1;i++){

			cnt+=a[i];

		}

		for(int i=l;i<=r;i++){

			cnt1+=b[i];

		}

		cout<<min(cnt,cnt1)<<endl;

	}

	return 0;

}

//1 1 4 5 1 4

//1 1 4 5 1 4 1 9 1 9 8 1 0
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    int a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2')a++;
        else if(s[i]=='3')b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<=a;i++){
         for(int j=0;j<=b;j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
           
         }
           if(f)break;
      }
      if(!f)cout<<"NO"<<endl;


    }
}

Solution 2 (runtime: 92 ms):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

       long long n,x=0,sum=0,c2=0,c3=0,num=0,diff=0,i,f=0,j,temp=0;

       string s;

       cin>>s;

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

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

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

            c2++;

        }

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

            c3++;

        }

       }

       if(sum%9==0){

           cout<<"YES"<<endl;

           continue;

       }

       else if(c3==s.length()){

           cout<<"YES"<<endl;

           continue;

       }

       else{

          x=sum/9;

          num=(x+1)*9;

          diff=abs(num-sum);

        for(i=0;i<=c2;i++){

            temp=0;

            if(i*2>99){

                break;

            }

            else{

            for(j=0;j<=c3;j++){

                temp=i*2+j*6;

                if(temp>99){

                    break;

                }

                else if((temp+sum)%9==0){

                    f=1;

                    break;

                 }

             }

             if(f==1){

                 break;

             }

            }

             

        }



        if(f==0){

            cout<<"NO"<<endl;

        }

        else{

            cout<<"YES"<<endl;

        }



       

    }

  }  



    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 202 ms):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k; cin>>n>>k;
    
    vector<int> arr(n);
    for(int i = 0; i < n; ++i) cin>>arr[i];
    sort(arr.begin(), arr.end());

    int l = 0, r  = 0;
    // 1 1 2 2 2
    priority_queue<int, vector<int>, greater<int>> s;
    while(l < n)
    {
        while(r < n && arr[r] == arr[l]) ++r;
        s.push((r-l));
        l = r;
        // ++cnt; 
    }
    // cout << s.size() << endl;
    
    while(s.size() > 1)
    {
        auto it = s.top();
        if(it <= k) 
        {
            k -= it;
            s.pop();
        }
        else break;
    }
    // while(s.size())
    // {
    //     cout << s.top() << ' ';
    //     s.pop();
    // }
    // cout << endl;
   cout << s.size()<< endl;
    
   



    // adjust k times

    // remove the minimum elements of a subarray

    //  2 1 3 2 1 1 


    // count freq
    // 1, 4
    // 2, 2
    // 4, 3 
    // 5, 1
}
int main()
{
    int t; cin>>t;for(int i = 0; i < t; ++i) solve();
}

Solution 2 (runtime: 265 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n, k, x;
        cin >> n >> k;

        unordered_map<long long, long long> freq;
        vector<long long> v;
        
        for (int i = 0; i < n; i++) {
            cin >> x;
            v.push_back(x);
            freq[x]++;
        }

        vector<pair<long long, long long>> freqVec;
        for (int i = 0; i < n; i++) {
            if (freq[v[i]] > 0) {
                freqVec.push_back({freq[v[i]], v[i]});
                freq[v[i]] = 0;  
            }
        }

        sort(freqVec.begin(), freqVec.end());

        long long mostFreqElement = freqVec[freqVec.size() - 1].second;
        long long changed = 0;
        long long distinct = freqVec.size();

        for (int i = 0; i < freqVec.size(); i++) {
            if (k >= freqVec[i].first) {
                k -= freqVec[i].first;
                distinct--;
            } else {
                break;
            }
        }

        cout << distinct << endl;
    }
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int even= (n+1)/2;
        int odd= n/2;
        long long x,y;
        x=0;
        y=0;
        for(int i=0;i<n;i++){
            if(i%2==0){
                x+=a[i];
            }
            else{
                y+=a[i];
            }
        }
        if(y%odd==0 && x%even==0 && x/even==y/odd ){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
 
    return 0;
}

Solution 2 (runtime: 343 ms):
#include<iostream>

#include<vector>

using namespace std;



void Solve(){

    int n;

    cin>>n;

    vector<long long> vec(n);

    long long sodd=0,seven=0,countodd=0,counteven=0;

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

        cin>>vec[i];

        if(i%2==0){

            sodd+=vec[i];

            countodd++;

        }

        else{

            seven+=vec[i];

            counteven++;

        }

    }

    if((seven*countodd)==(sodd*counteven) && ((seven+sodd)%(countodd+counteven))==0){

        cout<<"YES"<<endl;

    }else{cout<<"NO"<<endl;}

}



int main(){

    int t;

    cin>>t;

    while(t--){

        Solve();

    }

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<map>
using namespace std;
long long summ(vector<long long> & v){

    long long sum = 0;
    for(int i=0;i<v.size();i++){
        sum+=v[i];
    }
    return abs(sum);
}
int main(){
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        long long n;
        cin>>n;
        vector<long long> v(n);
        long long maxsum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        for(int i=0;i<n;i++){
            maxsum+=v[i];
        }
        while(v.size()>1){
            vector<long long> newv;
            for(int i=0;i<v.size()-1;i++){
                newv.push_back(v[i+1]-v[i]);
            }
            v = newv;

            maxsum = max(maxsum,summ(v));
        }
        cout<<maxsum<<endl;
    }
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll t;
    cin >> t;
    // t = 1;
    while (t--)
    {
        ll n, k = 1;
        ll i = 0, j = 0;
        ll cnt = 0, sum = 0;
        ll mx = 0;
        cin >> n;

        ll v[n];
        for (auto &u : v)
        {
            cin >> u;
            sum += u;
        }
        if(n==1)mx=v[0];
        mx = max(sum, mx);
        sum = 0;
        for (i = 1; i < n; i++)
        {

            for (j = n-1 ; j >=i; j--)
            {
                v[j] = v[j] - v[j - 1];
            }
            sum = 0;
            for (j = i; j < n; j++)
            {
                sum += v[j];
            }
           // cout<<sum<<endl;
            mx = max(mx, abs(sum));
            if (sum < 0)
            {
                reverse(v + i, v + n);
                for (j = i; j < n; j++)
                {
                    v[j] = -v[j];
                }
            }
           // for(auto u : v) cout<<u<< " ";cout<<endl;
        }
        // for(auto u : r) cout<<u<< " ";cout<<endl;

        cout << mx << endl;

    }
}
/*

ll ar[n], br[n];

map<ll,ll>mp;

vector<ll>v;

i = 0;

while (i < n) {
    cin >> ar[i]; i++;
}

i = 0;
while (i < n) {
    cin >> br[i]; // mp[br[i]];
    i++;
}

if (p == 1) cout << "YES" << endl;
else cout << "NO" << endl;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

// ll mn = 1000000000000000000, mx = 0;

*/
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#include <vector>
using namespace std;

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

    int t;
    cin >> t;
    // Number of test cases
    while(t--){
        int n;
        cin>>n;
        long long maxsum=0;
        vector<long long>v(n);
        for(int i=0;i<n;i++){
            cin>>v[i];
            maxsum+=v[i];
        }
        if(n==1){
            cout<<maxsum<<"\n";
            continue;
        }
       
        while(n!=1){
            long long sum=0;
            int i=0;
            while(i!=(n-1)){
                v[i]=v[i+1]-v[i];
                sum+=v[i];
                i++;
            }
            maxsum=max(maxsum,abs(sum));
            n--;
            
        }
        cout<<maxsum<<"\n";
        
        
      

    }
}


Solution 2 (runtime: 61 ms):
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define N 1000000
#define int long long int



int32_t main(){
  int tc=1; 
  cin>>tc;
  while(tc--){
    int n; cin >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int ans = -1e18;
    int now = n;
    for(int i = 0; i < n; i++){
      int sum = 0;
      for(int j = 0; j < now; j++){
        sum += a[j];
      }
      if(i == 0){
        ans = max(ans, sum);
      }
      else{
        ans = max(ans, max(sum, (-sum)));
      }
      
      for(int i = 0; i < now - 1; i++){
        a[i] = a[i+1] - a[i]; 
      }
      now--;
    }
    cout << ans << '\n';
    
    

       
     }
   
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 218 ms):
#include<bits/stdc++.h>
#define ll long long
#define db double
#define inf 2e9
using namespace std;
int n,k,a[114514],tot,s[114514];
map<int,int>mp;
void solve()
{
	mp.clear();
	tot=0;
	cin>>n>>k;
	for(int i=0;i<=n;i++)
	{
		s[i]=0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(mp.count(a[i])==0)mp[a[i]]=++tot;
		a[i]=mp[a[i]];
		s[a[i]]++;
	}
	sort(s+1,s+n+1);
	int i=1,ans=0;
	while(s[i]==0)i++;
	for(i;i<n;i++)
	{
		if(k>=s[i])
		{
			ans++;
			k-=s[i];
		}
	}
	cout<<tot-ans<<"\n";
	
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Solution 2 (runtime: 218 ms):
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define ll long long
#define endl '\n'
using namespace std;
int a[200000];
map <int, int> freq;
set<pair<int, int>> s;
int main() {
  fast
  int t; cin >> t;
  while(t--){
      int n, k; cin >> n >> k;
      for(int i = 0; i < n; i++){
        cin >> a[i]; freq[a[i]]++;
      }
      for(int i = 0; i < n; i++) s.insert({freq[a[i]], a[i]});

      for(auto i = s.begin(); i != s.end();){
            if((i -> first) <= k){
                k -= (i -> first);
                s.erase(i);
                i = s.begin();
            }
            else{
                k -= (i -> first);
                i++;
            }
            if(k <= 0) break;
      }

      if(s.size() == 0) cout << 1 << endl;
      else cout << s.size() << endl;
      s.clear();
      freq.clear();
  }
  return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 312 ms):
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define pb push_back
#define eb emplace_back
#define endl '\n'

using namespace std;

const int MOD = 1000000007;

#ifdef KRISHNA
#include "handle_debug.hpp"
#define debug(...)                    \
    cout << '[';                      \
    debug_print(#_VA_ARGS, VA_ARGS_); \
    cout << "]\n";
#else
#define debug(...)
#endif

ll gcd(ll a, ll b)
{
    while (b)
    {
        ll t = a % b;
        a = b;
        b = t;
    }
    return a;
}

bool isPrime(ll n)
{
    if (n <= 1)
    {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}

int isSubstring(string s1, string s2)
{
    if (s2.find(s1) != string::npos)
        return s2.find(s1);
    return -1;
}

ll fac(ll n)
{
    ll f = 1;
    if (n == 0 || n == 1)
        return 1;
    else
    {
        for (ll i = 2; i <= n; i++)
        {
            f *= i;
        }
        return f;
    }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> vec(n,0);
        for(int i=0; i<n; i++){
            cin>>vec[i];
        }
        int flag=1;
        for (int i = 0; i < n-1; i++)
        {
           int k=min(vec[i], vec[i+1]);
           vec[i]=vec[i]-k;
           vec[i+1]=vec[i+1]-k;

           if(vec[i]>vec[i+1]){
            flag=0;
            break;
           }
        }

        if(flag) cout<<"YES"<<endl;
        else{
            cout<<"NO"<<endl;
        }
        


    }
    return 0;
}

Solution 2 (runtime: 109 ms):
 #include <bits/stdc++.h>

#define ll long long

#define yes std::cout << "YES"<<endl

#define no std::cout << "NO"<<endl

#define ff first

#define se second

#define pb push_back

#define pf push_front

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

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

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

#define fo(n) for(int i=0;i<n;i++)

#define lw lower_bound

#include <iostream>



ll inf=LLONG_MAX;

  using namespace std;

//freopen("input.txt","r",stdin);

//freopen("output.txt","w",stdout);

 int main()

{

 fast;



ll t;

cin>>t;

while(t--)

{

    ll n,f=0,mn;

    cin>>n;

    ll a[n];

    fo(n) cin>>a[i];

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

    { mn=min(a[i-1],a[i]);

        a[i-1]-=mn;

        a[i]-=mn;

        if(a[i-1]>a[i])

        {

            f=1; break;

        }

     }

  if(f) no;

  else yes;

}



}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 202 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> v(n);
        for(ll i=0; i<n; i++){
            cin>>v[i];            
        }      
        sort(v.begin(), v.end());
        vector<int> hash = {1};
        for(ll i=1; i<n; i++){
            if(v[i]==v[i-1]){
                hash.back()++;
            } else {
                hash.push_back(1);
            }
        }
        bool isDone = true;
        sort(hash.begin(), hash.end());
        for(int i=0; i<hash.size()-1; i++){
            if(k>=hash[i]) k=k-hash[i];
            else {
                cout<<hash.size()-i<<endl;
                isDone=false;
                break;
            }
        }
        if(isDone){
            cout<<1<<endl;
        }
    }    
    return 0;
}

Solution 2 (runtime: 124 ms):
#include<bits/stdc++.h>

using namespace std;

inline int read();
template <typename T> inline void write(T x);

const int N = 1e5 + 5;
 
int n, k;

int main(){
	int t = read();
	while(t--)
	{
		bool f = 0;
		n = read(), k = read();
		
		map<int, int> t;
		vector<int> a(n + 5);
		a.clear();
		for(register int i = 1; i <= n; ++i)
			t[read()]++;
		
		for(auto x: t)
			a.push_back(x.second);
		
		sort(a.begin(), a.end());

		for(int i = 0; i < (int) t.size(); ++i)
		{
			int x = a[i];
			if(k >= x) k -= x;
			else {write(t.size() - i); puts(""); f = 1; break;}
		}
		
		if(!f) write(1), puts("");
	}
	
	return 0;
}

inline int read()
{
	int x = 0, f = 1;
	char c = getchar();
	while (c > '9'|| c <'0')
	{
		if (c == '-') f = 0;
		c = getchar();
	}
	while (c >= '0'&& c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f? x: (~ (x - 1));
}

template <typename T> inline void write(T x)
{
	if (x < 0) x = ~(x - 1), putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + 48);
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 874 ms):
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(12);

	int t;
	cin >> t;

	while (t--) {
		int n;
		cin >> n;

		vector<set<int>> g(n + 1);
		for (int i = 0; i < n - 1; ++i) {
			int u, v;
			cin >> u >> v;

			g[u].insert(v);
			g[v].insert(u);
		}
		multiset<int> s;
		for (int i = 1; i < n + 1; ++i)
			s.insert(g[i].size());
		int ans = 0;
		for (int i = 1; i < n + 1; ++i) {
			int now = g[i].size();
			s.erase(s.find(now));
			for (int v: g[i]) {
				int nownow = g[v].size();
				s.erase(s.find(nownow));
				s.insert(nownow-1);
			}
			ans = max(ans, now - 1 + *(--s.end()));
			s.insert(now);
			for (int v: g[i]) {
				int nownow = g[v].size();
				s.erase(s.find(nownow - 1));
				s.insert(nownow);
			}
		}

		cout << ans << "\n";
	}
}

Solution 2 (runtime: 718 ms):
#include<bits/stdc++.h>
using namespace std;
#define N 200010

int read(){
	int res=0;char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9'){
		res=(res<<1)+(res<<3)+(c^48);
		c=getchar();
	}
	return res;
}

multiset<int> s;
int n,d[N],sum=0,ans;
vector<int> e[N];

void init(){
	s.clear();
	for(int i=1;i<=n;i++){
		e[i].clear();
		d[i]=0;
	}
}

int main(){
	int t=read();
	while(t--){
		n=read();ans=0;
		init();
		for(int i=1;i<n;i++){
			int a=read(),b=read();
			++d[a];++d[b];
			e[a].push_back(b);
			e[b].push_back(a);
		}
		
		for(int i=1;i<=n;i++) s.insert(d[i]);
		
		for(int i=1;i<=n;i++){
			sum=1;
			s.erase(s.find(d[i]));
			for(int j=0;j<e[i].size();j++){
				s.erase(s.find(d[e[i][j]]));
				s.insert(d[e[i][j]]-1);
			}
			sum+=d[i]-1;
			sum+=*s.rbegin()-1;
			ans=max(ans,sum);
			s.insert(d[i]);
			for(int j=0;j<e[i].size();j++){
				s.erase(s.find(d[e[i][j]]-1));
				s.insert(d[e[i][j]]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
string solve_case(const string &s) {
  int n = (int)s.size();
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = s[i] - '0';
  }
  for (int i = 1; i < n; i++) {
    int j = i;
    while (j > 0 && a[j] > 0 && (a[j] - 1) > a[j - 1]) {
      int temp = a[j - 1];
      a[j - 1] = a[j] - 1;
      a[j] = temp;
      j--;
    }
  }
  string ans(n, '0');
  for (int i = 0; i < n; i++) {
    ans[i] = char(a[i] + '0');
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    cout << solve_case(s) << "\n";
  }
}


Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>

using namespace std;



string canMakeDivisibleBy9(string s) {

    int n=s.length();

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

        if(s[i]==0) continue;

        for(int j=i;j>0 && s[j]-s[j-1]>1;j--){

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

        }

        

    }

    return s;

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;  

        cout << (canMakeDivisibleBy9(s)) << endl;

    }

    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define endl "\n"
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
#define int long long
typedef pair<int,int> pii;
typedef double db;
typedef long long LL;
const int N = 1e6+10;



void solve(){
    int l, r;
    cin >> l >> r;
    int op = 1;
    for (int i = 1 ; i <= 30; i  ++){
        op *= 2;
    }
    int t = r;
    while(op){
        if(r / op && (l / op) == 0 ){
            //cout << "h" << endl;
            t /= op * 2;
            t *= op * 2;
            if(r != op){
                    op += t;
                cout << op   + 1<< " " << op << " " <<  op - 1  << endl;
            }
            else {
                op += t;
                cout << op << " " << op - 1 << " " << op - 2 << endl;
            }
            return ;
        }
        if(r /op && l / op){
            r %= op;
            l %= op;
        }
        //cout << op << " " << r / op << " " << (l / op) << endl;
        op /= 2;
    }

}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin.tie(0);

    int _ = 1;
    cin>>_;
    while(_--)
    {
        solve();
    }

    return 0;
}


Solution 2 (runtime: 77 ms):
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
#define ll long long
int main()
{
    ll t;
    cin>>t;
    for(ll k1=1;k1<=t;k1++)
    {
        ll i,j,k,cnt1=0,cnt2=0,l,r;
        cin>>l>>r;
        ll base=r;
        while(base>0) base/=2,cnt1++;
        ll a=0,b=0,c=0;
        a=pow(2,cnt1-1);
        while(cnt1>0)
        {
            if(b<l) b+=pow(2,cnt1-1);
            cnt1--;
            if(a+pow(2,cnt1-1)<=r) a+=pow(2,cnt1-1);
        }
        if(a-1==b) cout<<a<<" "<<b<<" "<<b-1<<endl;
        else cout<<a<<" "<<b<<" "<<a-1<<endl;
    }
}