ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 249 ms):
for _ in range(int(input())):
    a = list(map(int, list(input())))
    for i in range(1, len(a)):
        for j in range(i, 0, -1):
            if a[j] - 1 > a[j - 1]:
                a[j], a[j - 1] = a[j - 1], a[j] - 1
            else:
                break
    print(*a, sep="")

Solution 2 (runtime: 265 ms):
for _ in range(int(input())):

s = list(map(int,input()))

for i in range(9):

for j in range(len(s)-1):

if s[j] < s[j+1] - 1:

s[j],s[j+1] = s[j+1]-1,s[j]

print(*s,sep= '')
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 1264 ms):
for _ in range(int(input())):
    s = list(map(int,input()))
    i = 1
    while i<len(s):
        if i > 0 and s[i] > s[i-1] + 1 :
            s[i],s[i-1] = s[i-1],s[i]-1
            i -= 1
        else:
            i += 1
    print(''.join(str(i) for i in s))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 202 ms):
t=int(input())
for _ in range(t):
  n=input()
  l=[]
  for i in n:
    l.append(int(i))
  for i in range(1,len(l)):
    j=i
    while j>=1 and l[j]-1>l[j-1]:
      l[j-1],l[j]=l[j]-1,l[j-1]
      j-=1
  print("".join(map(str,l)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 858 ms):
def solution():
    a = list(map(int, list(input())))
    for i in range(len(a)):
        _, j = max((a[j]-(j-i), -j) for j in range(i, min(i+9+1, len(a))))
        j = -j
        for k in reversed(range(i+1, j+1)):
            a[k-1], a[k] = a[k]-1, a[k-1]
    return "".join(map(str, a))

for _ in range(int(input())):
    print(solution())
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 296 ms):
def highest_var(x):
    while True:
        max_n = max(x)  
        check = False   
        while max_n > 1:
            for i in range(1, len(x)):  
                if x[i] == max_n and x[i - 1] < max_n - 1:
                    x[i - 1], x[i] = x[i] - 1, x[i - 1]  
                    check = True  
            max_n -= 1
        if not check:  
            break
    return x


t = int(input())
ab_res = []
for _ in range(t):
    s = input().strip()
    x = list(map(int, s))  
    x = highest_var(x)
    ab_res.append(''.join(map(str, x)))

print('\n'.join(ab_res))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 218 ms):
import sys
input = sys.stdin.readline
 
t = int(input())
for _ in range(t):
    s = list(input().strip())
    n = len(s)
 
    i = n - 1
    while i > 0:
        while True:
            if s[i] > '0' and ord(s[i]) - ord(s[i - 1]) > 1:
                s[i] = chr(ord(s[i]) - 1)
                s[i], s[i - 1] = s[i - 1], s[i]
                if i < n - 1:
                    i += 1
            else:
                break
        i -= 1
    print(''.join(s))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 203 ms):

import sys

#input=sys.stdin.readline

def solve():
    s = input()
    n = len(s)
    l = [int(c) for c in s]
    for i in range(n):
        best = l[i]
        id = i
        j = i+1
        while(j<i+10 and j<n):
            if ( l[j] - (j-i) > best):
                id = j 
                best = l[j] - (j-i)
            j+=1
        while(id>i):
            l[id],l[id-1] = l[id-1],l[id]-1
            id-=1
        l[i] = str(l[i])
    
    sol = ''.join(l)
    print(sol)
    

t = int(input())
for _ in range(t):
    solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 140 ms):
import sys

input = sys.stdin.readline
write = sys.stdout.write


def solve():
    # make left as big as possible
    # if curr > left + 1
    # always swap, repeatedly too
    s = [int(x) for x in input().strip()]
    for i in range(1, len(s)):
        for j in range(i, 0, -1):  # at most ~9 iterations
            if not (s[j - 1] < s[j] - 1):
                break
            s[j - 1], s[j] = s[j] - 1, s[j - 1]

    write("".join(map(str, s)) + "\n")


if __name__ == "__main__":
    t = int(input())
    for i in range(t):
        solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 734 ms):
def lists(L, X):
    for i in range(len(L)):
        max1 = int(L[i])
        index = i
        for j in range(i, min(i + 10, len(L))):
            if int(L[j]) - (j - i) > max1:
                max1 = int(L[j]) - (j - i)
                index = j
        while index > i:
            L[index], L[index - 1] = L[index - 1], L[index]
            index -= 1
        X.append(max1)

n = int(input())
for _ in range(n):
    L = [int(j) for j in input().strip()]
    X = []
    lists(L, X)
    y = ''.join(map(str, X))
    print(y)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 515 ms):

def solve(s):
	if type(s) is str: s = [*map(int,iter(s))]
	s.reverse()
	i = len(s)-1
	o = []
	while i >= 0:
		b = 0
		for j in range(1,min(i+1,10)):
			if s[i-j] - j > s[i-b] - b:
				b = j
		o.append(s[i-b]-b)
		del s[i-b]
		i -= 1
	return o

for _ in range(int(input())):
	print("".join(map(str,solve(input()))))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 187 ms):

t=int(input())
for _ in range(t):
    s =[int(x) for x in list(input())]
    n=len(s)
    for i in range(1,n):
        if s[i] !=0 and s[i] !=1:
            for j in range(i-1,-1,-1):
                if s[j]<s[j+1]-1:
                    temp=s[j+1]-1
                    s[j+1]=s[j]
                    s[j]=temp
                else:
                    break
        else:
            continue
    for x in s:
        print(x, end="")
    print()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 218 ms):
for _ in range(int(input())):
    s = list(map(int, list(input())))
    n = len(s)
    

    for i in range(1, n):
        if s[i] == 0:
            continue
        for j in range(max(0, i - 9), i):
            if s[j] < s[i] - (i - j):
                new_head_value = s[i] - (i - j)
                idx = i - 1
                while idx != j - 1:
                    s[idx], s[idx + 1] = s[idx + 1], s[idx]
                    idx -= 1
                s[j] = new_head_value
                break


    for i in range(n):
        print(s[i], end='')
    print()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 359 ms):
def recursive(a,begin):
    if begin==len(a):
        return
    max_val = a[begin]
    max_index = begin
    for i in range(begin, min(len(a), begin+9)):
        if max_val<(a[i] - (i-begin)):
            max_val= a[i]-i+begin
            max_index = i
    while max_index !=begin:
        a[max_index], a[max_index-1] = a[max_index-1],a[max_index]-1
        max_index-=1
def solve():
    n = input()
    a = list(map(int,n))
    begin = 0
    while begin<len(a):
        recursive(a,begin)
        begin+=1
    print(''.join(map(str, a)))
x = int(input())
for i in range(x):
    solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 218 ms):
def f(arr):
    i=0
    while i<len(arr):
        l=i+1
        r=min(i+8,len(arr)-1)
        max_eff=-1
        ind=-1
        for k in range(l,r+1):
            eff=arr[k]-(k-i)
            if eff>max_eff:
                ind=k
                max_eff=eff
        if max_eff>arr[i]:
            for k in range(ind,i,-1):
                temp=arr[k]
                arr[k]=arr[k-1]
                arr[k-1]=temp
            arr[i]=max_eff
        i+=1
    return arr



if __name__=="__main__":
    t=int(input())
    for i in range(t):
        s=input()
        arr=[int(i) for i in s]
        ans=f(arr)
        print("".join(map(str,ans)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 171 ms):
for _ in range(int(input())):
    s = list(map(int,input()))

    for i in range(10):
        for j in range(len(s)-1):
            if s[j] + 1 < s[j+1]:
                s[j], s[j+1] = s[j+1] - 1, s[j]

    print("".join(map(str, s)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 327 ms):
from sys import stdin

def solve():
    s = list(stdin.readline()[:-1])
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - j + i > best:
                best = int(s[j]) - j + i
                pos = j
        
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], str(int(s[pos])-1)
            pos -= 1
        
    return "".join(s)

for _ in range(int(stdin.readline())): print(solve())
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 202 ms):
t=int(input())
for _ in range(t):
    l=list(map(int,list(input())))
    for i in range(len(l)-1):
        mx=l[i]
        ind=i
        for j in range(i+1,min(i+10,len(l))):
            if l[j]-(j-i)>mx:
                mx=l[j]-(j-i)
                ind=j
        first=l[i]
        for j in range(ind,i,-1):
            l[j]=l[j-1]
        l[i]=mx
        # print(l)
    print(*l, sep='')
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 624 ms):
def func():
    tests = int(input())
    for i in range(tests):
        x = input()
        arr = []
        for c in x:
            arr.append(int(c))
        for i in range(len(arr)-1):
            c = arr[i]
            maxx = 0
            idx = 0
            for j in range(1,9-c):
                if i+j >= len(arr):
                    break
                if maxx < arr[i+j] - c - j:
                    maxx = arr[i+j] - c - j
                    idx = j
            if maxx > 0:
                tmp = arr[i+idx] - idx
                for k in range(idx,0,-1):
                    arr[i+k] = arr[i+k-1]
                arr[i] = tmp
        ans = ""
        for a in arr:
            ans += str(a)
        print(ans)
    return  

if __name__ == '__main__':
    func()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 202 ms):
#Question :
#Link to the question: 

"""Author : Nishant Kumar"""

def solve():
    s= input().strip()
    digit = [int(ch) for ch in s]
    n = len(digit)
    for i in range(n):
        copy_i = i 
        while copy_i >0 and digit[copy_i]>0 and digit[copy_i]-1>digit[copy_i-1]:
            val = digit[copy_i]
            digit[copy_i]=digit[copy_i-1]
            digit[copy_i-1]=val-1
            if copy_i>0:
                copy_i-=1
            else:
                break
    print("".join(map(str,digit)))



for _ in range(int(input())):
    solve()

"""Author : Nishant Kumar"""
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 717 ms):
# cook your dish here
testcases = int(input())
for testcase in range(testcases):
    s = str(input())
    digits = []
    for d in s:
        digits.append(int(d))
    for i in range(len(s)):
        curr = digits[i]
        idx = -1
        maxx = curr
        limit = min(len(s), i + 9 - curr)
        for j in range(i + 1, limit):
            if maxx < digits[j] - (j - i):
                idx = j 
                maxx = digits[j] - (j - i)
        if idx != -1:
            for k in range(idx, i, -1):
                digits[k] = digits[k - 1]
        digits[i] = maxx
    ans = [str(d) for d in digits]
    print("".join(ans))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 1108 ms):
def solve():
    number = list(input())
    for i in range(len(number)):
        count = 0
        for i in range(0,len(number)-1):
            if(int(number[i])+1<int(number[i+1])):
                count +=1
                temp = number[i]
                number[i]=str(int(number[i+1])-1)
                number[i+1] = temp
        if count==0:
            return ''.join(number)
        

t = int(input())
for _ in range(t):
    print(solve())
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 1077 ms):
import sys

data = sys.stdin.read().strip().splitlines()
t = int(data[0])
results = []

for case in range(1, t + 1):
    s = list(data[case])  # Convert string to a list for mutability
    n = len(s)
    
    for i in range(n):
        b = int(s[i])
        p = i
        
        for j in range(i, min(i + 10, n)):
            if int(s[j]) - (j - i) > b:
                b = int(s[j]) - (j - i)
                p = j
        
        while p > i:
            s[p], s[p - 1] = s[p - 1], s[p]  # Swap elements in the list
            p -= 1
        
        s[i] = str(b)  # Update the current position with the best value
    
    results.append(''.join(s))  # Join the list back into a string

for result in results:
    print(result)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 281 ms):
def f(n):
    # for i in range(1,len(n)):
    i = 0
    while i < (len(n) - 1):
        i += 1
        #print(n, i)
        while i > 0 and n[i] != '0' and int(str(int(n[i]) - 1) + n[i-1]) > int(n[i-1] + n[i]):
            old = n[i - 1]
            n[i-1] = str(int(n[i]) - 1)
            n[i] = old
            i -= 1
    return ''.join(n)

for i in range(int(input())):
    print(f(list(input())))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 155 ms):
from sys import stdin
from typing import Any
import math
input = stdin.readline
def ri(): return int(input())
def rl(v_type=int,output=list): return output(map(v_type, input().split()))
def rs(): return input().rstrip()
def out(x, sep='\n'): print(sep.join(x))


def solve():
    s = rs()
    n = len(s)
    a = list(map(int,s))
    for i in range(1,n):
        for j in range(i -1,max(-1,i - 11),-1):
            if a[j] + 1 < a[j + 1]:
                a[j],a[j+1] = a[j+1] - 1, a[j]
            else:
                break 

        
    return "".join(map(str,a))



output = []
for _ in range(ri()):
    output.append(str(solve()))
out(output)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 171 ms):
def solve():
    s = input()
    s = list(s)  # Преобразуем строку в список символов для удобства работы
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            current_score = int(s[j]) - (j - i)
            if current_score > best:
                best = current_score
                pos = j
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], s[pos]
            pos -= 1
        s[i] = str(best)
    print("".join(s))

if __name__ == "__main__":
    tests = int(input())
    for _ in range(tests):
        solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 218 ms):
t = int(input())
for _ in range(t):
    num = list(input())  # Convert string to list for mutable operations
    n = len(num)
    for i in range(n - 1):
        j = i + 1
        while j < n and (int(num[j]) - 1 > int(num[j - 1])):
            temp = str(int(num[j]) - 1)
            num[j] = num[j - 1]
            num[j - 1] = temp
            j -= 1  # Move backward to recheck the order
            if j <= 0:  # Prevent going out of bounds
                break
    print(''.join(num))  # Convert list back to string for output
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 187 ms):
t = int(input())
for _ in range(t):
    s = input().strip()
    l = [int(c) for c in s]
    i = 1
    while i < len(l):
        if l[i] > l[i - 1]+1 and l[i] != 0:
            l[i] -= 1
            l[i - 1], l[i] = l[i], l[i - 1]
            if i > 1:
                i -= 1
        else:
            i += 1
    print("".join(map(str, l)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')


Solution 2 (runtime: 358 ms):
n = int(input())
for _ in range(n):
    n1 = list(input())  # Convert input to a list for mutability
    length = len(n1)

    for i in range(length):
        best = int(n1[i])
        pos = i

        # Optimize the inner loop to minimize recalculations
        for j in range(i, min(i + 9, length)):
            value = int(n1[j]) - (j - i)
            if value > best:
                best = value
                pos = j

        # Perform swaps to bring the best element to the correct position
        while pos > i:
            n1[pos], n1[pos - 1] = n1[pos - 1], n1[pos]
            pos -= 1

        n1[i] = str(best)

    print("".join(n1))