def last(arr,x,n):
    
    low = 0
    high = n - 1
    res = -1  
    while (low <= high):
        mid = (low + high) // 2 
        if arr[mid] > x:
            high = mid - 1
        elif arr[mid] < x:
            low = mid + 1
        else:
            res = mid
            low = mid + 1
    return res
def last(arr, x, n):
    low = 0
    high = n - 1
    res = -1
    while low <= high:
        low2 = (low + high) // 2
        if arr[low2] > x:
           
            high = low2 - 1
        elif arr[low2] < x:
            low = low2 + 1
        else:
            res = low2
            low = low2 + 1
    return res