when i compiled this program in VSCode, I got IndexError. Is there any other solution?
#here is my sample code
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    x = len(arr)
    arr.sort()
    for i in range(0, x-1):
        #removing redundant values
        if arr[i] == max(arr):
            arr.remove(arr[i])
    arr.remove(max(arr))
    print(max(arr))
 
     
     
     
    