Contest Code:LP2TO303 Problem Code:STACKS- code is not accepted please some one help

import sys
input=sys.stdin.readline
def inp():
return int(input())
def st():
return input().rstrip(’\n’)
def lis():
return list(map(int,input().split()))
def ma():
return map(int,input().split())

t=inp()
stack = []
def check(a):
r,l = 0,len(stack)-1
min_i = l

while(r<=l):
    mid = (l+r)//2
    #print(l,r,mid,len(stack))
    
    if stack[mid]>a:
        l=mid-1 
        min_i=mid
    else:
        r = mid+1
return min_i

while(t):
t-=1
n = inp()
arr = lis()

for a in arr:
    if(len(stack)==0 or stack[-1]<a):
        stack.append(a)
    else:
        index = check(a)
        stack[index] = a
    #print(stack)
        
print(len(stack),end=" ")
for s in stack:
    print(s,end=" ")
print()
stack=[]

Check the following solution of the problem using the bisect_right library function.

Accepted