def binary_search(nums,key):
if len(nums)<1:
return -1
high=len(nums)-1
low=0
while low<=high:
mid=(low+high)//2
if low<=high and nums[mid]>key:
high=mid-1
elif low<=high and nums[mid]<key:
low=mid+1
else:
return mid
return low

nums=[10, 9, 2, 5, 3, 7, 101, 18]
target=[]
target.append(nums[0])
maxs = 0
tmp = []
for i in range(1,len(nums)):
if nums[i]>=target[-1]:
target.append(nums[i])
else:
position=binary_search(target, nums[i])
target[position]=nums[i]
target = target[:position+1]
maxs = max(maxs,len(target))
tmp = target if len(target)>len(tmp) else tmp
print(len(target))
print(tmp)