ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 437 ms):
t = int(input())
for i in range(t):
    s = [int(x) for x in list(input())]
    sm = sum(s)
    sm %= 9
    cnt2 = s.count(2)
    cnt3 = s.count(3)
    flag = False
    for j in range(min(10, cnt2+1)):
        if flag:
            break
        for k in range(min(10, cnt3+1)):
            if (sm + j * 2 + k * 6) % 9 == 0:
                print('Yes')
                flag = True
                break
    if not flag:
        print('No')









Solution 2 (runtime: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 437 ms):
t = int(input())
for i in range(t):
    s = [int(x) for x in list(input())]
    sm = sum(s)
    sm %= 9
    cnt2 = s.count(2)
    cnt3 = s.count(3)
    flag = False
    for j in range(min(10, cnt2+1)):
        if flag:
            break
        for k in range(min(10, cnt3+1)):
            if (sm + j * 2 + k * 6) % 9 == 0:
                print('Yes')
                flag = True
                break
    if not flag:
        print('No')









Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

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

    x = sum(s)

    twos = 0

    threes = 0

    for i in s:

        if i == 2:

            twos += 1

        elif i == 3:

            threes += 1

        if twos > 8 and threes > 8:

            break



    ans = 'NO'



    for i in range(twos + 1):

        for j in range(threes + 1):

            if (2 * i + 6 * j + x) % 9 == 0:

                ans = 'YES'

                break 

    

    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
def sol() -> bool:
    s = str(input())

    numTwos = 0
    numThrees = 0
    sum = 0

    for c in s:
        x = int(c)
        # print(x)
        if x == 2:
            numTwos += 1
        if x == 3:
            numThrees += 1
        sum += x
    
    m = min(8, numTwos)
    n = min(3, numThrees)

    for j in range(m+1):
        for k in range(n+1):
            # print(sum + j * 2 + k * 6)
            if (sum + j * 2 + k * 6) % 9 == 0:
                return True
    
    return False

t = int(input())

for i in range(t):
    print("YES") if sol() else print("NO")

Solution 2 (runtime: 156 ms):
import sys

input = sys.stdin.readline





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

    s = input()[:-1]

    a, b = 0, 0

    c = 0

    for i in s:

        if i == '2':

            a += 1

        elif i == '3':

            b += 1

        c += int(i)

    c %= 9

    ew = 0

    for i in range(min(10, b+1)):

        for j in range(min(10, a+1)):

            if (c + 6*i + 2*j) % 9 == 0:

                ew = 1

                break

        if ew:

            break

    print(['NO','YES'][ew])
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
def sol() -> bool:
    s = str(input())

    numTwos = 0
    numThrees = 0
    sum = 0

    for c in s:
        x = int(c)
        # print(x)
        if x == 2:
            numTwos += 1
        if x == 3:
            numThrees += 1
        sum += x
    
    m = min(8, numTwos)
    n = min(3, numThrees)

    for j in range(m+1):
        for k in range(n+1):
            # print(sum + j * 2 + k * 6)
            if (sum + j * 2 + k * 6) % 9 == 0:
                return True
    
    return False

t = int(input())

for i in range(t):
    print("YES") if sol() else print("NO")

Solution 2 (runtime: 186 ms):
import sys, math

from functools import cmp_to_key

from operator import itemgetter

from bisect import bisect_left, bisect_right

from collections import Counter, defaultdict, deque



input = sys.stdin.readline



def iinp(): return (int(input()))

def linp(): return (list(map(int, input().split())))

def sinp(): return (input().strip())

def minp(): return (map(int, input().split()))

def debug(*args):

    print("DEBUG:", *args, file=sys.stderr)





def solve():

	# n = iinp()

	s = sinp()

	Sum = sum([int(num) for num in s])

	count_2 = s.count('2')

	count_3 = s.count('3')

	if Sum%9==0:

		print("YES")

		return

	target = (9 - Sum%9)%9 

	for i in range(count_3+1):

		new_target = (target - 6*i)%9

		if new_target<0:

			new_target +=9

		requied = (5*new_target)%9

		if requied<=count_2:

			print("YES")

			return

		

	print('NO')

		



def main():

	t = 1

	t = int(input())

	for i in range(t):

		solve()

	

if __name__ == "__main__":

	main()
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
def sol() -> bool:
    s = str(input())

    numTwos = 0
    numThrees = 0
    sum = 0

    for c in s:
        x = int(c)
        # print(x)
        if x == 2:
            numTwos += 1
        if x == 3:
            numThrees += 1
        sum += x
    
    m = min(8, numTwos)
    n = min(3, numThrees)

    for j in range(m+1):
        for k in range(n+1):
            # print(sum + j * 2 + k * 6)
            if (sum + j * 2 + k * 6) % 9 == 0:
                return True
    
    return False

t = int(input())

for i in range(t):
    print("YES") if sol() else print("NO")

Solution 2 (runtime: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
def sol() -> bool:
    s = str(input())

    numTwos = 0
    numThrees = 0
    sum = 0

    for c in s:
        x = int(c)
        # print(x)
        if x == 2:
            numTwos += 1
        if x == 3:
            numThrees += 1
        sum += x
    
    m = min(8, numTwos)
    n = min(3, numThrees)

    for j in range(m+1):
        for k in range(n+1):
            # print(sum + j * 2 + k * 6)
            if (sum + j * 2 + k * 6) % 9 == 0:
                return True
    
    return False

t = int(input())

for i in range(t):
    print("YES") if sol() else print("NO")

Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

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

    x = sum(s)

    twos = 0

    threes = 0

    for i in s:

        if i == 2:

            twos += 1

        elif i == 3:

            threes += 1

        if twos > 8 and threes > 8:

            break



    ans = 'NO'



    for i in range(twos + 1):

        for j in range(threes + 1):

            if (2 * i + 6 * j + x) % 9 == 0:

                ans = 'YES'

                break 

    

    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 156 ms):
import sys

input = sys.stdin.readline





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

    s = input()[:-1]

    a, b = 0, 0

    c = 0

    for i in s:

        if i == '2':

            a += 1

        elif i == '3':

            b += 1

        c += int(i)

    c %= 9

    ew = 0

    for i in range(min(10, b+1)):

        for j in range(min(10, a+1)):

            if (c + 6*i + 2*j) % 9 == 0:

                ew = 1

                break

        if ew:

            break

    print(['NO','YES'][ew])

Solution 2 (runtime: 186 ms):
import sys, math

from functools import cmp_to_key

from operator import itemgetter

from bisect import bisect_left, bisect_right

from collections import Counter, defaultdict, deque



input = sys.stdin.readline



def iinp(): return (int(input()))

def linp(): return (list(map(int, input().split())))

def sinp(): return (input().strip())

def minp(): return (map(int, input().split()))

def debug(*args):

    print("DEBUG:", *args, file=sys.stderr)





def solve():

	# n = iinp()

	s = sinp()

	Sum = sum([int(num) for num in s])

	count_2 = s.count('2')

	count_3 = s.count('3')

	if Sum%9==0:

		print("YES")

		return

	target = (9 - Sum%9)%9 

	for i in range(count_3+1):

		new_target = (target - 6*i)%9

		if new_target<0:

			new_target +=9

		requied = (5*new_target)%9

		if requied<=count_2:

			print("YES")

			return

		

	print('NO')

		



def main():

	t = 1

	t = int(input())

	for i in range(t):

		solve()

	

if __name__ == "__main__":

	main()
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 156 ms):
import sys

input = sys.stdin.readline





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

    s = input()[:-1]

    a, b = 0, 0

    c = 0

    for i in s:

        if i == '2':

            a += 1

        elif i == '3':

            b += 1

        c += int(i)

    c %= 9

    ew = 0

    for i in range(min(10, b+1)):

        for j in range(min(10, a+1)):

            if (c + 6*i + 2*j) % 9 == 0:

                ew = 1

                break

        if ew:

            break

    print(['NO','YES'][ew])

Solution 2 (runtime: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 156 ms):
import sys

input = sys.stdin.readline





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

    s = input()[:-1]

    a, b = 0, 0

    c = 0

    for i in s:

        if i == '2':

            a += 1

        elif i == '3':

            b += 1

        c += int(i)

    c %= 9

    ew = 0

    for i in range(min(10, b+1)):

        for j in range(min(10, a+1)):

            if (c + 6*i + 2*j) % 9 == 0:

                ew = 1

                break

        if ew:

            break

    print(['NO','YES'][ew])

Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

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

    x = sum(s)

    twos = 0

    threes = 0

    for i in s:

        if i == 2:

            twos += 1

        elif i == 3:

            threes += 1

        if twos > 8 and threes > 8:

            break



    ans = 'NO'



    for i in range(twos + 1):

        for j in range(threes + 1):

            if (2 * i + 6 * j + x) % 9 == 0:

                ans = 'YES'

                break 

    

    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
import sys, math

from functools import cmp_to_key

from operator import itemgetter

from bisect import bisect_left, bisect_right

from collections import Counter, defaultdict, deque



input = sys.stdin.readline



def iinp(): return (int(input()))

def linp(): return (list(map(int, input().split())))

def sinp(): return (input().strip())

def minp(): return (map(int, input().split()))

def debug(*args):

    print("DEBUG:", *args, file=sys.stderr)





def solve():

	# n = iinp()

	s = sinp()

	Sum = sum([int(num) for num in s])

	count_2 = s.count('2')

	count_3 = s.count('3')

	if Sum%9==0:

		print("YES")

		return

	target = (9 - Sum%9)%9 

	for i in range(count_3+1):

		new_target = (target - 6*i)%9

		if new_target<0:

			new_target +=9

		requied = (5*new_target)%9

		if requied<=count_2:

			print("YES")

			return

		

	print('NO')

		



def main():

	t = 1

	t = int(input())

	for i in range(t):

		solve()

	

if __name__ == "__main__":

	main()

Solution 2 (runtime: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
import sys, math

from functools import cmp_to_key

from operator import itemgetter

from bisect import bisect_left, bisect_right

from collections import Counter, defaultdict, deque



input = sys.stdin.readline



def iinp(): return (int(input()))

def linp(): return (list(map(int, input().split())))

def sinp(): return (input().strip())

def minp(): return (map(int, input().split()))

def debug(*args):

    print("DEBUG:", *args, file=sys.stderr)





def solve():

	# n = iinp()

	s = sinp()

	Sum = sum([int(num) for num in s])

	count_2 = s.count('2')

	count_3 = s.count('3')

	if Sum%9==0:

		print("YES")

		return

	target = (9 - Sum%9)%9 

	for i in range(count_3+1):

		new_target = (target - 6*i)%9

		if new_target<0:

			new_target +=9

		requied = (5*new_target)%9

		if requied<=count_2:

			print("YES")

			return

		

	print('NO')

		



def main():

	t = 1

	t = int(input())

	for i in range(t):

		solve()

	

if __name__ == "__main__":

	main()

Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

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

    x = sum(s)

    twos = 0

    threes = 0

    for i in s:

        if i == 2:

            twos += 1

        elif i == 3:

            threes += 1

        if twos > 8 and threes > 8:

            break



    ans = 'NO'



    for i in range(twos + 1):

        for j in range(threes + 1):

            if (2 * i + 6 * j + x) % 9 == 0:

                ans = 'YES'

                break 

    

    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")



Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

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

    x = sum(s)

    twos = 0

    threes = 0

    for i in s:

        if i == 2:

            twos += 1

        elif i == 3:

            threes += 1

        if twos > 8 and threes > 8:

            break



    ans = 'NO'



    for i in range(twos + 1):

        for j in range(threes + 1):

            if (2 * i + 6 * j + x) % 9 == 0:

                ans = 'YES'

                break 

    

    print(ans)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (runtime: 187 ms):
for _ in range(int(input())):
  s=list(map(int,input()[::-1]))
  a=[]
  while s:
    m=s[-1]
    x=-1
    for i in range(-1,max(-11,-len(s)-1),-1):
      if x-m==9:
        break
      if s[i]+i+1>m:
        m=s[i]+i+1
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (runtime: 233 ms):
import sys 
from math import*
from collections import*
I=lambda: map(int,input())
for i in range(int(input())):
    a=list(I())
    n=len(a)
    for j in range(n):
        for k in range(j,max(0,j-10,),-1):
            if a[k-1]+1<a[k]:
                a[k],a[k-1]=a[k-1],a[k]-1
                
    print(*a,sep="")
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (runtime: 296 ms):
def fun(s):
    for i in range(1, len(s)):
        while i!=0 and s[i]-1 > s[i-1]:
            s[i], s[i-1] = s[i-1], s[i]-1
            i-=1
            
    return ''.join(map(str, s))
    
if __name__ == "__main__":
    for _ in range(int(input())):
        n=list(map(int, input()))
        rs=fun(n)
        print(rs)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (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="")
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


Solution 2 (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='')
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


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: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


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: 265 ms):
t=int(input())
for _ in range(t):
    s=input()
    l = list(map(int, s))
    maxx=max(l)
    for i in range(1,len(s)):
        k=i
        while(k>0 and l[k]>l[k-1]+1):
            l[k],l[k-1]=l[k-1],l[k]-1
            k-=1
    result = ''.join(map(str, l))
    print(result)


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())