Dsa Learning constant

help with this code i don’t know what is missing. as i already executed this in another ide which gave me correct output
problem name Smart Phone
problem code - ZCO140003

x=int(input())
list1=[]
for i in range(x):
    y=int(input())
    list1.append(y)
list1.sort(reverse=True)
for j in range(1,len(list1)):
    if (list1[j-1]*j)>(list1[j]*(j+1)):
        print(list1[j-1]*j)
        break
    elif list1[-1]*len(list1)>list1[-2]*(len(list1)-1):
        print(list1[-1]*len(list1))
        break