Smartphone problem .problem 4 in time complexity analysis section.i am solving this question in o(n).but it is giving me an error.any help will be great

try:
n=int(input())
array=[]
sum=0
price=0
profit=0
for i in range(n):
inp=int(input())
array.append(inp)
sum+=inp
average=math.floor(sum/n)
max_price=max(array)
for i in range(n):
if array[i]>=average and array[i]<max_price :
price=array[i]
max_price=price
for i in range(n):
if array[i]>=price:
profit+=price
print(profit)
except:pass