N=int(input())
x=int(input())
suma=x
maksi=x
mini=x
for i in range(N-1):
x=int(input())
if x>maksi: maksi=x
if x<mini: mini=x
else: suma+=x
print(suma-maksi-mini)
Tj1pbnQoaW5wdXQoKSkKeD1pbnQoaW5wdXQoKSkKc3VtYT14Cm1ha3NpPXgKbWluaT14CmZvciBpIGluIHJhbmdlKE4tMSk6Cgl4PWludChpbnB1dCgpKQoJaWYgeD5tYWtzaTogbWFrc2k9eAoJaWYgeDxtaW5pOiBtaW5pPXgKCWVsc2U6IHN1bWErPXgKcHJpbnQoc3VtYS1tYWtzaS1taW5pKQo=