Problem:
Problem A: ICPC Score Totalizer Software The International Clown and Pierrot Competition (ICPC), is one of the
most distinguished and also the most popular events on earth in the
show business. One of the unique features of this contest is the great number of
judges that sometimes counts up to one hundred.  The number of judges
may differ from one contestant to another, because judges with any
relationship whatsoever with a specific contestant are temporarily
excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges
are averaged to decide his/her score.  To avoid letting judges with
eccentric viewpoints too much influence the score, the highest and the
lowest scores are set aside in this calculation.  If the same highest
score is marked by two or more judges, only one of them is ignored.
The same is with the lowest score.  The average, which may contain
fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of
performances, given the scores of all the judges, to speed up the event
to be suited for a TV program. Input The input consists of a number of datasets, each corresponding to a
contestant's performance.  There are no more than 20 datasets in the input. A dataset begins with a line with an integer n , the number of
judges participated in scoring the performance (3 ≤ n ≤
100).  Each of the n lines following it has an integral
score s (0 ≤ s ≤ 1000) marked by a judge.  No
other characters except for digits to express these numbers are in the
input.  Judges' names are kept secret. The end of the input is indicated by a line with a single zero in it. Output For each dataset, a line containing a single decimal integer
indicating the score for the corresponding performance should be
output.  No other characters should be on the output line. Sample Input 3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0 Output for the Sample Input 342
7
300
326

Solution (Python):
while True:
    n=int(input())
    if n == 0: break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n = int(input())
    a = []
    if n == 0:
        break
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    A=[int(input()) for i in range(n)]
    B=((sum(A)-max(A)-min(A))//(n-2))
    print(B)

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n == 0: break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break

    s = [int(input()) for i in range(n)]
    s.sort()
    score = sum(s) - s[0] - s[-1]
    print(score // (n - 2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while 1:
    n=int(input())
    if n==0:break
    score=[]
    for i in range(n):
        score.append(int(input()))
    score.sort()
    score=score[1:-1]
    print(sum(score)//len(score))

Solution (Python):
while True:
    n=int(input())
    if n<3:
        break
    lst=[int(input()) for i in range(n)]
    a=sum(lst)
    b=min(lst)
    c=max(lst)
    avg=(a-b-c)//(n-2)
    print(avg)

Solution (Python):



while True:
    n=int(input())
    if n==0:
        break
    a=[int(input()) for _ in range(n)]
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
x=[]
while True:
    n=int(input())
    if n==0:
        break
    else:
        for i in range(n):
            s=int(input())
            x.append(s)
        S1=sum(x)-max(x)-min(x)
        S2=n-2
        print(int(S1/S2))
        x.clear()

Solution (Python):
while True:
    mylist = []
    n = input()
    n = int(n)
    if n ==0:
        break
    for i in range(0,n):
        mylist.append(int(input()))
    mylistz = sorted(mylist)
    del mylistz[0]
    del mylistz[n-2]
    print(int(sum(mylistz))//(n-2))

Solution (Python):
while True:
    n = int(input())
    max = 0
    min = 1000
    sum = 0
    if n == 0:
       break
    for i in range(n):

        s = int(input())
        sum += s
        if s < min:
            min = s
        if max < s:
            max = s
    ave = (sum - min - max) // (n - 2)
    print(ave)

Solution (Python):



while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))

Solution (Python):
s=[]
while True:
    N=int(input())
    if N==0:
        break
    else:
        tmp=[int(input()) for _ in range(N)]
        tmp.sort()
        tmp=tmp[1:-1]
        s.append(tmp)

for si in s:
    N=len(si)
    ans=0
    for sij in si:
        ans+=sij
    ans//=N
    print(ans)

Solution (Python):

while True:
    n=int(input())
    
    if n==0:
        break
    
    s=[int(input()) for i in range(n)]
    
    a=max(s)
    b=min(s)
    c=sum(s)
    y=(c-a-b)//(n-2)
    
    print(y)

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    
    a = [int(input()) for i in range(n)]
    a.sort()
    x = sum(a) - a[0] - a[-1]
    print(x // ( n- 2))

Solution (Python):
import math
while True:
    n = int(input())
    scores = [int(input()) for i in range(n)]
    scores.sort()
    
    if n == 0:
        break
    total = 0
    
    for i in range(1, n - 1):
        total += scores[i]
        
    print(math.floor(total / (n - 2)))

Solution (Python):
while True :
    N = int(input())
    if N == 0 :
        break
    data = list(int(input()) for i in range(N))
    
    data.sort()
    del data[0]
    del data[-1]
    
    data_ave = sum(data)/len(data)
    print(int(data_ave))

Solution (Python):
while True:
	n = int(input())
	if n == 0:
	    break
	data=[]
	for i in range(n):
	    a=int(input())
	    data.append(a)
	print((sum(data)-max(data)-min(data))//(n-2))

Solution (Python):
while True :
    n = int(input())
    if n == 0 :
        break
    
    s = [int(input()) for i in range (n)]
    s.sort()
    score = sum(s) - s[0] - s[-1]
    print(score//(n-2))

Solution (Python):


while True:
    n=int(input())
    
    x=[]
    for i in range(n):
        s=int(input())
        x.append(s)
    
    x1=sorted(x)
    if n==0:
        break
    else:
        sum1=sum(x1)
        sum1-=x1[0]+x1[n-1]
        y=sum1//(n-2)
        
        print(y)

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    a=[int(input()) for i in range(n)]
    print((sum(a)-max(a)-min(a))//(n-2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break

    s = [int(input()) for i in range(n)]
    s.sort()
    score = sum(s) - s[0] - s[-1]
    print(score // (n - 2))

Solution (Python):
while True:
    n = int(input())
    max = 0
    min = 1000
    sum = 0
    ave = 0
    if n == 0:
        break
    for i in range(n):
        s = int(input())
        sum += s
        if s < min:
            min = s
        if max < s:
            max = s
    ave = (sum - min - max) // (n - 2)
    print(ave)

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    else:
        lst=[]
        for i in range(n):
            s = int(input())
            lst.append(s)
        print((sum(lst)-max(lst)-min(lst))//(n-2))

Solution (Python):
while True:
  n=int(input())
  if n==0:
    break
  else:
    max_s=0
    min_s=2000
    sum_s=0
    for i in range(n):
      s=int(input())
      sum_s=sum_s+s
      if s<min_s:
        min_s=s
      if s>max_s:
        max_s=s
    print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        max_s=0
        min_s=2000
        sum_s=0
        for i in range(n):
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
        print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
import math

while True:
    n = int(input())
    scores = [int(input()) for i in range(n)]
    scores.sort()

    if n == 0:
        break

    total = 0

    for i in range(1, n - 1):
        total += scores[i]
    
    print(math.floor(total / (n - 2)))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        max_s=0
        min_s=2000
        sum_s=0
        for i in range(n):
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
        print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n == 0:
        break
    a=[]
    for i in range(n):
        s=int(input())
        a.append(s)
    
    print((sum(a)-max(a)-min(a))//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    x=[]
    for i in range(n):
        a=int(input())
        x.append(a)
    y=sorted(x)
    sum=0
    for j in range(1,len(y)-1):
        sum+=y[j]
    ave=sum//((len(y))-2)
    print(ave)

Solution (Python):
while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    else:
        list=[]
        for i in range(n):
            list.append(int(input()))
            list.sort()
    print(sum(list[1:n-1])//(n-2))

Solution (Python):
while True:
  n = int(input())
  if n == 0:
    break
  print(sum(sorted([int(input()) for _ in range(n)])[1:-1]) // (n - 2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break

    s = [int(input()) for i in range(n)]

    s.sort()
    ans = sum(s[1:n - 1]) // (n - 2)
    print(ans)

Solution (Python):
while True:
  N=int(input())
  if N==0:
    break
  s=list(int(input())for i in range(N))

  s.sort()
  del s[0]
  del s[-1]

  s_ave=sum(s)/len(s)
  print(int(s_ave))

Solution (Python):
while True:
      n=int(input())
      if n == 0:
            break
      a=[]
      for i in range (n):
            a.append(int(input()))
      print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
def calc_score(list):
    list.remove(max(list))
    list.remove(min(list))
    return int(sum(list) / len(list))

while True:
  grader = int(input())
  if grader == 0:
      break
  scores = [int(input()) for _ in range(grader)]
  print(calc_score(scores))

Solution (Python):
while True:
    n=int(input())
    x=[]
    if n==0:
        break
    else:
        for i in range(n):
            s=int(input())
            x.append(s)
        a=min(x)
        b=max(x)
        ave=(sum(x)-a-b)/(n-2)
        print(int(ave))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break

    s = [int(input()) for i in range(n)]
    s.sort()
    score = sum(s) - s[0] - s[-1]
    print(score // (n - 2))

Solution (Python):
while True:
    x = int(input())
    if x == 0: break
    y = []
    for i in range(x):
        y.append(int(input()))
    print((sum(y)-max(y)-min(y))//(len(y)-2))

Solution (Python):
import math

while True:
    n=int(input())
    if n==0:
        break
    x= [int(input()) for i in range(n)]
    y=(sum(x)-max(x)-min(x))/(n-2)
    print(math.floor(y))

Solution (Python):
while True:
    n=int(input())
    if n==0:break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(n-2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    
    s = []
    for i in range(n):
        s.append(int(input()))

    s.sort()
    s.pop(0)
    s.pop()
    
    print(int(sum(s)/len(s)))

Solution (Python):
while True:
    n=int(input())
    if n==0:break
    a=[]
    for i in range (n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))
    
    if n==0:break

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True :
    N = int(input())
    if N == 0 :
        break
    data = list(int(input()) for i in range(N))
    
    data.sort()
    del data[0]
    del data[-1]
    
    data_ave = sum(data)/len(data)
    print(int(data_ave))

Solution (Python):
while True:
    n= int(input())
    if n==0 :
        break
    a=[]
    for i in range(n):
         a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n= int(input())
    if n==0 :
        break
    a=[]
    for i in range(n):
         a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n= int(input())
    if n==0 :
        break
    a=[]
    for i in range(n):
         a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    N = int(input())
    if N == 0:
        break
    S = []
    for _ in range(N):
        S.append(int(input()))
    S.sort()
    S = S[1:N-1]
    ans = sum(S)//len(S)
    print(ans)

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):


while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):

while True:
    n=int(input())
    if n==0: break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):
while True:
    a=0
    ma=0
    mi=99999
    n = int(input())
    if n == 0:
        break
    else:
        for i in range(n):
            b=int(input())
            a=a+b
            if ma<b:
                ma=b
            if mi>b:
                mi=b
        answer=(a-ma-mi)//(n-2)
        print(answer)

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
    a = []
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Solution (Python):

while True:
    a = int(input())
    if a == 0:
        break
    else:
        li = [0]*a
        for i in range(a):
            li[i] = int(input())
        li_sort = sorted(li)
        del li_sort[0]
        del li_sort[-1]
        print(int(sum(li_sort)/len(li_sort)))

Solution (Python):
for i in range(20):
    n = int(input())
    
    if n == 0:
        break
    
    data = list()
    for j in range(n):
        a = int(input())
        data.extend([a])
    
    
    x = sum(data) - min(data) - max(data)
    
    print(x // (n-2) )

Solution (Python):
while True:
    x=int(input())
    if x==0:
        break
    a=[]
    for i in range(x):
        a.append(int(input()))
    A=max(a)
    B=min(a)
    C=sum(a)
    D=len(a)
    E=C-A-B
    F=D-2
    print(E//F)

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    
    a=[]
    for i in range(n):
        a.append(int(input()))
    A=max(a)
    B=min(a)
    C=sum(a)
    D=len(a)
    E=C-A-B
    F=D-2
    print(E//F)

Solution (Python):
while True:
	n = int(input())
	if n == 0: 
            break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))

Solution (Python):
while True: 
    n = int(input())
    S = []
    if n==0:
        break
    for i in range(n):
        S.append(int(input()))
    
    S.sort()
    
    S.pop(0)
    S.pop()
    

    print(sum(S)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n == 0:
        break
    b=[]
    for i in range(n):
        a=int(input())
        b.append(a)
    c=sorted(b)
    if n == 3:
        print(c[1])
    elif n >= 4:
        d=sum(c)-c[0]-c[n-1]
        e=n-2
        print(d//e)

Solution (Python):
while True:
	n = int(input())
	if n == 0:
	   break
	s, vn, vx = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vn = min(vn, a)
		vx = max(vx, a)
		s += a
	print((s-vn-vx)//(n-2))

Solution (Python):
while True :
    n = int(input())
    if n == 0 :
        break
    
    s = [int(input()) for i in range (n)]
    s.sort()
    score = sum(s) - s[0] - s[-1]
    print(score//(n-2))

Solution (Python):


"""
Problems 1157
Problem A: ICPC 得点集計ソフトウェア
"""
while True:
    n = int(input())
    if  n == 0:
        break
    sum, s_min, s_max = 0, 1001, -1
    for i in range(n):
        score = int(input())
        s_min = min(s_min, score)
        s_max = max(s_max, score)
        sum += score
    print((sum-s_min-s_max)//(n-2))

Solution (Python):
import sys
import math
input = sys.stdin.readline


num_score = int(input().rstrip())
while num_score != 0:
    scores = []
    for _ in range(num_score):
        scores.append(int(input().rstrip()))
    total = sum(scores) - max(scores) - min(scores)
    average = math.floor(total / (len(scores) - 2))
    print(average)
    num_score = int(input().rstrip())

Solution (Python):
while True:
    n=int(input())
    min=1000
    max=0
    sum=0
    if n==0:
        break
    for i in range(n):
        tennsuu=int(input())
        sum+=tennsuu
        if tennsuu<min:
            min=tennsuu
        if tennsuu>max:
            max=tennsuu
    print((sum-min-max)//(n-2))

Solution (Python):
a=[]
i=0
while True:
    
    N=int(input())
    if N==0:
        break
    else:
        for i in range(N):
            n=int(input())
            a.append(n)
        a.sort()
        a.pop()     
        a.pop(0)    
        print(sum(a) // len(a))
        a.clear()

Solution (Python):
while True:
    P = []
    n = int(input())
    if n == 0:
        exit()
    for i in range(n):
        P.append(int(input()))
    print(sum(sorted(P)[1:-1]) // (n-2))

Solution (Python):
import math
for i in range(30):
    n = int(input())
    if n == 0:
        break
    else:
        ls = []
        for i in range(n):
            ls.append(int(input()))
        ls.sort()
        ls.remove(ls[0])
        ls.remove(ls[-1])
        print(math.floor(sum(ls)/len(ls)))

Solution (Python):
while True:
    p=int(input())
    
    if p==0:
        break
    else:
        list1=[]

        for i in range(p):
            a=int(input())
            list1.append(a)
            i+=1

        min1=min(list1)
        max1=max(list1)

        list1.remove(min1)
        list1.remove(max1)

        sum1=sum(list1)

        men=p-2
        print(sum1//men)

Solution (Python):
while True:
    n=int(input())
    if n>0:
        l=list()
        for i in range(n):
            s=int(input())
        
            l.append(s)
        l.remove(max(l))
        l.remove(min(l))
        x=sum(l)
        y=len(l)
        print(int(x/y))
    if n==0:
        break

Solution (Python):
while True:
    N = int(input())
    if N == 0:
        break
    
    s = [0 for i in range(N)]
    for i in range(N):
        s[i] = int(input())
    print((sum(s) - max(s) - min(s)) // (N - 2))

Solution (Python):
while True:
    min = 1000
    max = 0
    sum = 0
    
    n=int(input())
    if n ==0:
        break
    for i in range(n):
        s=int(input())
        if s < min:
            min = s
        if s > max:
            max = s
        sum += s
    print((sum - min - max)//(n - 2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
            break
    a=[int(input()) for i in range(n)]
    print((sum(a)-max(a)-min(a))//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    s=[int(input()) for i in range(n)]
    a=max(s)
    b=min(s)
    c=sum(s)
    d=(c-a-b)//(n-2)
    print(d)

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        li=[0]*n
        for i in range(n):
            li[i]=int(input())
        print((sum(li)-max(li)-min(li))//(len(li)-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        max_s=0
        min_s=2000
        sum_s=0
        for i in range(n):
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
        print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
while True: 
 n = int(input()) 
 if n == 0:
          break 
 else:
      max_s=0
      min_s=2000
      sum_s=0
      for i in range(n): 
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
      print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
while True:
  n = int(input())
  if n ==0:
    break
  else:
    list1=[0]*n
    for i in range(n):
      list1[i]=int(input())
    print( (sum(list1)-max(list1)-min(list1))//(len(list1)-2) )

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        max_s=0
        min_s=2000
        sum_s=0
        for i in range(n):
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
        print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        A=[]
        i=1
        while i <=n:
            a=int(input())
            A.append(a)
            i=i+1
        b=(sum(A)-max(A)-min(A))//(n-2)
        print(b)

Solution (Python):
while True:
    n=int(input())
    if n == 0:
        break
    else:
        maxs=0
        mins=2000
        sums=0
        for i in range(n):
            s=int(input())
            sums=sums+s
            if s<mins:
                mins=s
            if s>maxs:
                maxs=s
        print((sums-maxs-mins)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        max_s=0
        min_s=2000
        sum_s=0
        for i in range(n):
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
        print((sum_s-max_s-min_s)//(n-2))

Solution (Python):
while True:
    n = int(input())
    if n ==0:
        break
    else:
        list0=[]
        i=0
        for i in range(n):
            list0.append(int(input()))    
        list0.remove(max(list0))
        list0.remove(min(list0))
        s=sum(list0)
        a = n-2
        print(s//a)
        i=i+1

Solution (Python):
while True:
    n=int(input())
    a=[]
    if n==0:
        break
    else:
        for i in range(n):
            a.append(int(input()))
    k=sorted(a)
    del k[0]
    del k[n-2]
    s=sum(k)
    print(int(s/(n-2)))

Solution (Python):
while True:
    n = int(input())
    numbers = []

    if n == 0:
        break

    for i in range(0, n):
        numbers.append(int((input())))

    maxValue = max(numbers)
    minValue = min(numbers)
    totalScore = sum(numbers)

    print(str(int((totalScore - maxValue - minValue) / (len(numbers) - 2))))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    else:
        list=[]
        for i in range(n):
            a=int(input())
            list.append(a)
    print((sum(list)-max(list)-min(list))//(n-2))

Solution (Python):
while 1:
    n=int(input())
    if n==0:
        break
    x=[int(input())for i in range(n)]
    x.sort()
    s=sum(x)-(x[0]+x[-1])
    print(s//(n-2))

Solution (Python):

while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        listA=[] 
        for i in range(n):
            listA.append(int(input()))
        print((sum(listA)-max(listA)-min(listA))//(n-2))

Solution (Python):
while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        list=[]
        for i in range(n):
            temp=int(input())
            list.append(temp)
    list.remove(max(list))
    list.remove(min(list))
    a=sum(list)//(n-2)
    print(a)

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    else: 
        list=[]
        for i in range(n):
            list.append(int(input()))
            list.sort()
    print(sum(list[1:n-1])//(n-2))

Solution (Python):
while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=int(input())
        max=a
        min=a
        sum=a
        for i in range(1,n):
            b=int(input())
            sum=sum+b
            if max<b:
                max=b
            elif min>b:
                min=b
        print(int((sum-max-min)/(n-2)))

Solution (Python):
while True:
    n = int(input())
    if n==0: 
        break
    l = []
    for i in range(n):
        x = int(input())
        l.append(x)
    l.sort()
    a = sum(l)-(max(l)+min(l))
    print(a//(n-2))

Solution (Python):
while True:
  n=int(input())
  if n==0:
    break
  m=10000
  M=0
  sum=0
  for i in range(n):
    s=int(input())
    m=min(m,s)
    M=max(M,s)
    sum=sum+s
  print((sum-M-m)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    m=10000
    M=0
    sum=0
    for i in range(n):
        s=int(input())
        m=min(m,s)
        M=max(M,s)
        sum+=s
    print((sum-M-m)//(n-2))

Solution (Python):
while True:
    n=int(input())
    if n == 0:
        break
    else:
        li1=[0]*n
    
        
        for t in range(n):  
            li1[t]=int(input())
        s=int((sum(li1)-max(li1)-min(li1))/(n-2))
        print(s)

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        score=[0]*n
    for i in range(n):
        score[i]=int(input())
    max=score[0]
    min=score[0]
    for i in range(1,n):
        if max<score[i]:
            max=score[i]
        if min>score[i]:
            min=score[i]
    print(int((sum(score)-max-min)/(n-2)))

Solution (Python):
list1=[]
while True: 
    n = int(input())
    if n == 0:
        break 
    else:
        for i in range(n):
            j=int(input())
            list1.append(j)
        list1.remove(max(list1))
        list1.remove(min(list1))
        print(sum(list1)//len(list1))
        list1=[]

Solution (Python):
while True:
  goukei=0
  max=0
  min=1000

  n=int(input())
  if n==0:
     break
  else:
   for i in range (n):
     i=int(input())
     if i>max:
         max=i
     if i<min:
         min=i
     goukei=goukei+i 
     heikin=(goukei-max-min)//(n-2)
   print(heikin)

Solution (Python):
while True:
    n = int(input())
    if n == 0: 
        break
    a, smin, smax=0, 1001, -1
    for i in range(n):
        s = int(input())
        a += s
        if s < smin:
            smin = s
        if s > smax:
            smax = s
        
    print((a-smin-smax)//(n-2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    else:
        intlist = []
        minval = 1001
        maxval = -1
        for i in range(n): 
            a = int(input())
            if a >= maxval:
                maxval = a
            if a <= minval:
                minval = a
            intlist.append(a)
        total = 0
        mincheck = False
        maxcheck = False
        for i in range(len(intlist)): 
            if(intlist[i] == minval and mincheck == False): 
                mincheck = True
            elif(intlist[i] == maxval and maxcheck == False): 
                maxcheck = True
            else:
                total += intlist[i]
        print(total//(len(intlist) - 2))

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    else :
        lista = [0]*n
        for i in range (n):
            lista[i] = int(input())
        lista.remove(max(lista))
        lista.remove(min(lista))
        print(sum(lista)//len(lista))

Solution (Python):
while True:
    n=int(input())
    if n==0:
        break
    else:
        li=[]
        for i in range(n):
            li.append(int(input()))
        b=sum(li)-min(li)-max(li)
        c=n-2
        print(b//c)

Solution (Python):
import math
while True:
  n=int(input())
  if n==0:
    break
  else:
    S_list=[]
    for i in range(n):
      score=int(input())
      S_list.append(score)
    S_list.remove(max(S_list))
    S_list.remove(min(S_list))
    print(math.floor(sum(S_list)/len(S_list)))

Solution (Python):
while True:
    n =int(input())
    if n == 0:
        break 
    else: 
        A=[]
        for i in range(n): 
            A.append(int(input()))
    print((sum(A)-max(A)-min(A))//(n-2))

Solution (Python):
while True:    
    n=int(input())
    if n == 0:
        break 
    else:
        A=[]
        for i in range(n):
            A.append(int(input()))
        print((sum(A)-max(A)-min(A))//(n-2))

Solution (Python):
while True:    
    n=int(input())
    if n == 0:  break 
    else:  
        d=[]
        for i in range(n): 
            d.append(int(input()))
        print((sum(d)-max(d)-min(d))//(n-2))

Solution (Python):
result = []
while True:
    no_referee = int(input())
    if no_referee == 0:
        break
    else:
        sum_score = 0
        max_score = 0
        min_score = 1000
        for i in range(no_referee):
            score = int(input())
            sum_score += score
            if score > max_score:
                max_score = score
            if score < min_score:
                min_score = score
        sum_score = sum_score - max_score - min_score
        result.append(int(sum_score/(no_referee-2)))

for r in result:
    print(str(r))

Solution (Python):
while True:
    n=int(input())
    s=[]
    if n==0:
        break
    else:
        for i in range(n):
            s.append(int(input()))
        s.sort()
        del(s[0])
        del(s[-1])
        
        print(f'{sum(s)//(n-2)}')

Solution (Python):
while True:
    n=int(input())
    x=[]
    if n==0:
        break
    else:
        for i in range(n):
            s=int(input())
            x.append(s)
        
        a=min(x)
        b=max(x)
        
        ave=(sum(x)-a-b)/(n-2)
        print(int(ave))