ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
#define int long long
#define f(i, n1, n2) for (int i = n1; i < n2; i++)
#define fi(n1, n2) for (int i = n1; i < n2; i++)
#define ri(n1) for (int i = n1 - 1; i >= 0; i--)
#define in(nam) cin >> nam;
#define nin(nam) int nam; cin >> nam;
#define e endl;
#define out(nam) cout << nam << e
#define outar(n) for(auto it:n)cout<<it<<" "; 
#define v(n, i) vector<int> n(i);
#define vi(n) vector<int> n;
#define vin(nam)for(auto &i:nam)cin>>i;
#define map(name) map<int, int> name;
#define yon(ans) cout << ((ans) ? "YES" : "NO") << "\n";
#define all(a) a.begin(), a.end()
#define sorta(a) sort(a.begin(), a.end());
#define sortre(a) sort(a.rbegin(), a.rend());
using namespace std;
const int mod = 1e9 + 7;

void chance() {
    string s;
    in(s);
    // nin(n)
    // if(n%9==0){
    //     yon(1)
    //     return;
    // }

    int sum=0,no2=0,no6=0;
    // while(tem>0){
    //     int dig = tem%10;
    //     sum += dig; 
    //     if(dig==2)no2++;   
    //     if(dig==3)no6++;   
    //     tem/=10;
    // }
    for(auto c:s){
        int dig = c-'0';
        sum += dig; 
        if(dig==2)no2++;   
        if(dig==3)no6++;   
    }

    fi(0,no2+1){
        f(j,0,no6+1) {
            int nsum = sum+ i*2+j*6;
            if (nsum%9==0) {
                yon(1) 
                return;
            }
        }
    }
    yon(0)
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1;
    in(t) // when t
    while (t--) {
        chance();
    }
    return 0;
}


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

int main() {
	int t;
	cin>>t;
	while(t--){
		string n;
		cin>>n;
		int sum = 0;
		for(char c: n)
			sum+= c - '0';

		vector<bool> dp(9, false);
		dp[sum%9] = true;

		for(char c: n){
			int num = c - '0';
			vector<bool> newDP(9, false);
			for(int i=0; i<9; i++){
				if(!dp[i])
					continue;

				newDP[i] = true;

				if(num<=3){
					int newMod = (i - num + num*num + 9)%9;
					newDP[newMod] = true;
				}
			}

			dp = newDP;
		}

		if(dp[0] == true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;

	}
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <algorithm>
#include <bits/stdc++.h>
#include <iterator>
#include <iostream>
using namespace std;
typedef long long int ll; 
const int N = 5e3 + 5;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
ll binpow(ll a, ll b) {
    if (b == 0)
        return 1;
    ll res = binpow(a, b / 2);
    if (b % 2)  
        return res * res * a;
    else
        return res * res;
}
string a, b, c;
int dp[N][N];
int rec(int i, int j){
    if (i == a.size() && j == b.size()){
        return 0;
    }
    auto &ret = dp[i][j];
    if (ret != -1){
        return ret;
    }
    ret = MAXN;
    if (i < a.size()){
        ret = min(ret, rec(i + 1, j) + (a[i] != c[i + j]));
    }
    if (j < b.size()){
        ret = min(ret, rec(i, j + 1) + (b[j] != c[i + j]));
    }

    return ret;
}
void solve(int test){ 
    cin >> a >> b >> c; 
    for (int i = 0; i <= a.size(); i++){
        for (int j = 0; j <= b.size(); j++){
            dp[i][j] = -1;
        }
    }
    cout << rec(0, 0) << endl;
}
int main(){
    int t = 1;
    cin >> t;
    for (int test = 1; test <= t; test++){
        solve(test);
    }
    
    return 0;
}



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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pii>
#define F first
#define S second
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7;
const int INF = 1e9;

int solve(string &a,string &b,string &c,int i,int j,vector<vi> &dp){

    // if(k>=c.size()){
    //     return 0;
    // }

    int k = i+j;

    if (i == a.size() && j == b.size())
        return 0;

    if(dp[i][j]!=-1){
        return dp[i][j];
    }

    int left = INT_MAX;
    int right = INT_MAX;

    if(i<a.size() && a[i]==c[k]){
        left = solve(a,b,c,i+1,j,dp);
    }
    else if(i<a.size() && a[i]!=c[k]) {
        left = 1+solve(a,b,c,i+1,j,dp);
    }

    if(j<b.size() && b[j]==c[k]){
        right = solve(a,b,c,i,j+1,dp);
    }
    else if(j<b.size() && b[j]!=c[k]){
        right = 1+solve(a,b,c,i,j+1,dp);
    }

    return dp[i][j] = min(left,right);

}

void solve() {

    string a,b,c;
    cin>>a>>b>>c;

    vector<vector<int>> dp(a.size()+1,vector<int> (b.size()+1,-1));

    cout<<solve(a,b,c,0,0,dp)<<endl;
    
}

int main() {
    fast_io;

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

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

#define ll long long
#define vtr vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define arg sort(v.begin(),v.end())
#define Lrg sort(v.rbegin(),v.rend())
#define lm(a,b) for(int i=a; i<b; i++)
#define tst int t; cin >> t; while(t--)
#define nl

using namespace std;
void slayer()
{
    string s;
    cin >> s;
    int sum=0,two=0,three=0;
    lm(0,s.size()){
        if(s[i]=='2'){
            two++;
        }
        if(s[i]=='3'){
            three++;
        }
        sum+=(s[i]-'0');
        sum%=9;
    }
    for(int i=0; i<=three; i++){
        for(int j=0; j<=two; j++){
            ll temp = sum;
            temp+=j*2+i*6;
            if(temp%9==0){
                yes;
                return;
            }
        }
    }
    no;
    return;
}
int main()
{
    tst{
        slayer();
    }

    return 0;
}



Solution 2 (runtime: 61 ms):
#include <fstream>
#include <iostream>
using namespace std;



int main() {
    istream& fin = cin;
    ostream& fout = cout;

    int t;
    fin >> t;
    int two, three;
    long long sum;
    string number;
    int temp;
    int offset = int('0');
    for (int i=0; i<t; i++) {
        two = three = 0;
        sum = 0;
        fin >> number;
        for (char ch: number) {
            if (ch == '\n') break;
            temp = int(ch) - offset;
            if (temp == 2) two++;
            if (temp == 3) three++;
            sum += temp;
        }
        bool possible = sum % 9 == 0;
        sum %= 9;
        // fout << (sum % 9) << " " << two << " " << three << " " << endl;
        for (int j=0; j<=two; j++) {
            if (possible) break;
            if (j == 9) break;
            for (int k=0; k<=three; k++) {
                if (possible) break;
                if (k == 9) break;
                if ((sum + 2*j + 6*k) % 9 == 0) possible = true;
            }
        }
        fout << (possible ? "YES" : "NO") << "\n";
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;

void solve() {
    ll n;
    cin>>n;
    vll ve(n);
    for (int i=0; i<n; ++i) cin>>ve[i];
    ll j=0;
    for (ll i=1; i<n; i++) {
        if (ve[i-1]>ve[i]) j=i;
    }
    if (j==0) {
        cout<<"YES\n";
        return;
    }
    auto fop=[&](ll i) {
        ll mini=min(ve[i],ve[i+1]);
        ve[i]-=mini;
        ve[i+1]-=mini;
    };
    for (ll i=0; i<j; i++) {
        fop(i);
    }
    cout<<(is_sorted(ve.begin(),ve.end())?"YES":"NO")<<"\n";
}

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


Solution 2 (runtime: 93 ms):
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <utility>
#define ll long long
#define PII pair<int,int>
#define N 15
using namespace std;
void solve(){
	int n;
	cin >> n;
	vector<int>a(n+5);
	for (int i = 1; i <= n; i++) cin >> a[i];
	bool yes = true;
	for(int i = 1; i < n; i++){
		if (a[i] > a[i+1]){
			yes = false;
			break;
		}
		int tmp = min(a[i],a[i+1]);
		a[i] -= tmp;
		a[i+1] -= tmp;
	}
	if (yes) cout << "YES\n";
	else cout << "NO\n";
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) solve();
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
 #include<bits/stdc++.h>
#include<algorithm>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define nl cout<<"\n"
#define all(a) a.begin(),a.end()
#define ivec(vec) for(int i=0;i<vec.size();i++){cin>>vec[i];}
#define ovec(vec) for(int i=0;i<vec.size();i++){cout<<vec[i]<<" ";}
#define pb push_back
using ll=long long;
using ull=unsigned long long;
const int mod=1e9+7;
using namespace std;
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0;
    ll b=0;
    ll c=0;
    int ind=0;
    c=l;
    for(int i=30;i>=0;i--){
        int shi=(1<<i);
        if(((l&shi)>0) && ((r&shi)>0)){
            a=a|(shi);
            b=b|(shi);
        }
        else if ((r&shi)>0){
            a=a|shi;
            ind=i;
            break;
        }
        else if ((l&shi)>0){
            a=a|shi;
            ind=i;
            break;
        }
    }
    for(int j=0;j<ind;j++){
        b=b|(1<<j);
    }
    if (b==l || a==l){
        c=r;
    }
    for(int i=0;i<30;i++){
        if ((l&(1<<i))>0 && (r&(1<<i))>0){
            c=c|(1<<i);
        }
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
}

Solution 2 (runtime: 62 ms):
#include <iostream>				// Hello 2025 C
#include <vector>
#include <map>
#define ll long long
using namespace std;

int bit(ll x) {
	ll num = 0, cnt = 0;
	while (x >= pow(2, cnt))
		cnt++;
	return cnt;
}

void solve() {
	ll l, r, sum = 0;
	cin >> l >> r;
	int tmp;
	for (int i = bit(r) - 1; i >= 0; i--) {
		if (l >> i != r >> i) {
			tmp = i;
			sum = r >> (tmp + 1) << (tmp + 1);
			break;
		}
	}
	//cout << tmp << " " << sum << endl << endl;
	if (r == (1 << tmp) + sum) {
		cout << r << " " << r - 1 << " " << r - 2 << endl;
	}
	else {
		ll ans = (1 << tmp) + sum;
		cout << ans + 1 << " " << ans  << " " << ans - 1 << endl;
	}
}

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

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

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

    for (int i = 1; i < n; i++) {
        long long common = min(a[i - 1], a[i]); 
        a[i - 1] -= common;
        a[i] -= common;
        if (a[i - 1] > a[i]) { 
            cout << "NO\n";
            return;
        }
    }

    cout << "YES\n";
}

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

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

    return 0;
}


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

using namespace std;

typedef long long ll;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        vector<int> arr(n);

        for (auto &i : arr) {

            cin >> i;

        }

        if(is_sorted(arr.begin(),arr.end())){

            cout<<"YES"<<endl;

            continue;

        }

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

            int minm = min(arr[i],arr[i+1]);

            arr[i] -= minm;

            arr[i+1] -= minm;

        }

        if(is_sorted(arr.begin(),arr.end())){

            cout<<"YES"<<endl;

            continue;

        }

        cout<<"NO"<<endl;

    }

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using ll = long long;

void solve(){
    int n;
    cin >> n;
    vector<int> v(n);
    int mx = 0;
    for(int i = 0; i < n; ++i){
        cin >> v[i];
        mx = max(v[i], mx);
    }
    bool ok = true;
    for(int i = 0; i < n-1; ++i){
        if(v[i] <= v[i + 1]){
            int tmp = min(v[i], v[i+1]);
            v[i] -= tmp; v[i+1] -= tmp;
        }else{
            ok = false;
        }
    }
    cout << (ok ? "YES\n" : "NO\n");
}   

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
}

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



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d(x);

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

            cin>>d[i];

        }

        int v=1;

        for(int i=0;i<x-1;i++){

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
#define ll long long 
const int N=2e5+10;
using namespace std;
void solve()
{
	string a,b,c;
	cin>>a>>b>>c;	int n=a.length(),m=b.length();
	int dp[m+1][n+1];
	dp[0][0]=0;
	//fill(dp)
	for(int i=1;i<=a.length();i++)
	{
		dp[0][i]=dp[0][i-1]+(a[i-1]!=c[i-1]);
	}
	for(int i=1;i<=b.length();i++)
	{
		dp[i][0]=dp[i-1][0]+(b[i-1]!=c[i-1]);
	}
	for(int i=1;i<=b.length();i++)
	{
		for(int j=1;j<=a.length();j++)
		{
			dp[i][j]=min(dp[i-1][j]+(b[i-1]!=c[j+i-1]),dp[i][j-1]+(a[j-1]!=c[i+j-1]));
		}
	}
//	for(int i=0;i<=b.length();i++){
//		for(int j=0; j <= n; j++){
//			cout<<dp[i][j]<<' ';
//		}
//		cout<<'\n'<<endl;
//	}
		
		
	cout<<dp[b.length()][a.length()]<<endl;
	
}
int main()
{
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
 } 

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

static const int infinity = 1e9;

void solve() {
  std::string a, b, res;
  std::cin >> a >> b >> res;

  int n = (int)a.size(), m = (int)b.size();
  int dp[n + 1][m + 1];
  std::fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), infinity);
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = dp[i][0] + (a[i] != res[i]);
  }
  for (int j = 0; j < m; j++) {
    dp[0][j + 1] = dp[0][j] + (b[j] != res[j]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = std::min(dp[i - 1][j] + (a[i - 1] != res[i + j - 1]),
                          dp[i][j - 1] + (b[j - 1] != res[i + j - 1]));
    }
  }
  std::cout << dp[n][m] << std::endl;
}

int main() {
  int tests;
  std::cin >> tests;
  while (tests--) {
    solve();
  }
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 296 ms):
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

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

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

  reverse(racers.begin(), racers.end());
  vector<int> sim(n);
  for (int i = 0; i < n; ++i) {
    sim[i] = n-i;
  }

  vector<pair<int, int>> overtakes;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n-1; ++j) {
      if (sim[j] == racers[i]) {
        overtakes.push_back({sim[j], sim[j+1]});
        swap(sim[j], sim[j+1]);
      }
    }

    for (int j = n-1; j > i; --j) {
      overtakes.push_back({sim[j-1], sim[j]});
      swap(sim[j-1], sim[j]);
    }
  }

  cout << overtakes.size() << "\n";
  for (auto &[a, b] : overtakes) {
    cout << a << " " << b << "\n";
  }
}


Solution 2 (runtime: 249 ms):
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ns;
vector<int> cur;
vector<int> pos;
vector<int> x;
vector<vector<bool>> v;
bool d = false;

void f(int it, int y, int j){
    int co = 0;
    it--;
    if(it != - 1){
        while((cur[it] <= j && !v[cur[it]][cur[it+1]] && !v[cur[it+1]][cur[it]]) || (d && it >= y)){
            v[cur[it+1]][cur[it]] = true;
            ns.push_back({cur[it+1], cur[it]});
            swap(cur[it], cur[it+1]);
            it--;
            if(it == -1){
                break;
            }
        }
    }
    it++;
    while(it < y){
        v[cur[it+1]][cur[it]] = true;
        ns.push_back({cur[it+1], cur[it]});
        swap(cur[it], cur[it+1]);
        it++;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    v.resize(n+1, vector<bool>(n+1));
    x.resize(n);
    pos.resize(n+1);
    for(int i = 0; i < n; i++){
        cin >> x[i];
        pos[x[i]] = i;
    }
    cur.resize(n);
    for(int i = 0; i < n; i++){
        cur[i] = i+1;
    }
    for(int y = 0; y < n; y++){
        int it = 0;
        for(int i = 0; i < n; i++){
            if(cur[i] == x[y]){
                it = i;
                break;
            }
        }
        for(int i = y; i <= it; i++){
            d = false;
            if(i == it){
                d = true;
            }
            f(i, y, cur[i]);
        }
    }
    cout << ns.size() << "\n";
    for(int y = 0; y < ns.size(); y++){
        cout << ns[y].first << " " << ns[y].second << "\n";
    }
    return 0;
}

//3 1 4 2
//1 2 3 4
//2 1 3 4
//2 3 1 4
//3 2 1 4
//3 1 2 4
//3 1 4 2
//3 4 1 2
//4 3 1 2
//3 4 1 2
//3 1 4 2
Problem: 2050D - Digital string maximization
Language: c++17 

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


void solve (vector<int> &t){

  int iter = 0;
  for (int j = 0; j < t.size() - 1; j++){
      if ((t[j+1] - 1)  > t[j]) {
      iter++;
      auto aux = t[j];
      t[j] = t[j+1] -1;
      t[j+1] = aux;
    }
  }

  if (iter > 0) {
    solve(t);
  }

}

int main() {

    int t;
    cin >> t;
    vector<vector<int>> v(t);
    for (int i = 0; i < t; i++) {
      string s;
      cin >> s;
      for (auto c : s)
        v[i].push_back(c - '0');
        
    }


    for (int i = 0; i < v.size(); ++i){
      solve(v[i]);

    }

    for (int i = 0; i < t; i++) {
        for (int num : v[i]) {
            cout << num;
        }
        cout << endl;
    }


    return 0;
}

Solution 2 (runtime: 77 ms):
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char a[N];
void solve()
{
	int n;
	cin >> a + 1;
	n = strlen(a + 1);
	for(int i = 1; i <= n; i++)
	{
		int k = i;
		while(k > 1 && a[k] - a[k - 1] >= 2)
		{
			a[k]--;
			swap(a[k], a[k - 1]);
			k--;
		}
	}
	cout << a + 1 << "\n";
}
int main()
{
	int T;
	cin >> T;
	while(T--) solve();
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 92 ms):
#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template<class K> using ordered_set =  tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T> using ordered_multiset = tree<pair<T, int>, null_type, less<pair<T, int>>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define uint unsigned int
#define pii pair <int , int>
#define pis pair <int, string>
#define mii map<int,int>
#define mmi map<int,map<int,int>>
#define mll map<long long, long long>
#define vi vector <int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second

#define forn(i, n) for (int i = 0; i < n; ++i)
#define foru(i, a, b) for (int i = a; i <= b; ++i)
#define ford(i, a, b) for (int i = a; i >= b; --i)
#define w(t) while(t--)

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 1e9 +1;
const ll MXX =  1e18 + 1;
using namespace std;

void solve(){
    int l,r;
    cin>>l>>r;
    int x=r^l;
    int i=1;
    while(i<=x)i<<=1;
    i>>=1;
    i--;
    i=(~i);
    int f=i&r;
    int g=f-1;
    int k;
    if(f==r)k=f-2;
    else k=r;
    cout<<k<<' '<<f<<' '<<g<<endl;

}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    w(T) {
        solve();
    }

    return 0;
}

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

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {

        ll l, r;
        cin >> l >> r;

        ll a = 0, b = 0;
        bool found = false;

        for (int i = 31; i >= 0; i--)
        {

            if (((l & (1 << i)) == (r & (1 << i))) && (l & (1 << i)))
            {

                a += (1 << i);
                b += (1 << i);
            }
            else if(((l & (1 << i)) != (r & (1 << i))))
            {

                a += (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    b += (1 << j);
                break;
            }
        }

        ll c;
        for(int i=r;i>=l;i--){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << c << " " << b << endl;
    }
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<iostream>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; 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--)
	{
		solve();
	}

}

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

#include <vector>

#include <algorithm>

#include <bits/stdc++.h>

using namespace std;

// #define int long long

#define INF __builtin_inf()

#define endl '\n'

#define couthi cout <<'h'<<'i'<<endl;

#define hi(i) cout <<'h'<<'i'<<i<<endl;

#define vin(a) for(auto&XX:a)cin>>XX;

#define vout(v) for (auto XX: v)cout<<XX;cout<<endl;

#define ignore_kroo_ise ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);



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



void solve() 

{

    string s;

    cin >> s;

    stack<int> stk;

    stack<int> temp;

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

        char c = s[i]-48;

        while(!stk.empty() && c>stk.top()+1){            

            temp.push(stk.top());

            stk.pop();

            c--;

        }

        stk.push(c);

        while(!temp.empty()){

            stk.push(temp.top());

            temp.pop();

        }

    }

    vector<int> answer;

    while(!stk.empty()){

        answer.push_back(stk.top());

        stk.pop();

    }

    reverse(answer.begin(), answer.end());

    vout(answer);

}



int32_t main()

{

    ignore_kroo_ise

    int t = 1;

    cin >> t;

    int answers[t];

    while (t--)

    {

        solve();

    }

    return 0;

}