Problem A: ICPC Score Totalizer Software

The International Clown and Pierrot Competition (ICPC) is a prestigious and popular event in show business. The contest involves a large number of judges, sometimes up to one hundred, who score contestants' performances. Each contestant may have a different number of judges, as judges with any relationship to a specific contestant are temporarily excluded from scoring. 

Contestants' scores are calculated by averaging the judges' scores, excluding the highest and lowest scores to mitigate the influence of extreme viewpoints. If multiple judges give the same highest or lowest score, only one is ignored. The average, possibly containing fractions, is truncated to obtain the final integer score.

The task is to write a program that computes performance scores based on judges' scores, to expedite the event for television.

Input:
The input consists of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets. Each dataset begins with an integer "n" (3 ≤ n ≤ 100), representing the number of judges. The following "n" lines contain integral scores marked by judges (0 ≤ s ≤ 1000). The input ends with a line containing a single zero.

Output:
For each dataset, output a single decimal integer indicating the score for the corresponding performance.

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

# Buggy version:
j = 0
lists = []
flag = 0
cnt = 0
while 1:
    n = int(input())
    if n == 0:
        break
    for i in range(n):
        s = int(input())
        lists.append(s)
    for i in range(n):
        if lists[i] == max(lists):
            flag += 1
            pass
        elif lists[i] == min(lists):
            flag += 1
            pass
        else:
            cnt += lists[i]
    if flag >= 2:
        n -= 2
    print(cnt // n)



# Fixed version:
j = 0
lists = []
flag = 0
cnt = 0
while 1:
    cnt = 0
    flag_max = 0
    flag_min = 0
    lists = []
    n = int(input())
    if n == 0:
        break
    for i in range(n):
        s = int(input())
        lists.append(s)
    for i in range(n):
        if lists[i] == max(lists):
            flag_max += 1
            pass
        elif lists[i] == min(lists):
            flag_min += 1
            pass
        else:
            cnt += lists[i]
    n -= 2
    if flag_max >= 2:
        cnt += max(lists)
    elif flag_min >= 2:
        cnt += min(lists)
    print(cnt // n)

# Buggy version:
while True:
    n = int(input())
    if n == 0:
        exit()
    score = []
    for i in range(n):
        score.append(int(input()))
    print((sorted(score)[1:-1])//(n-2))

# Fixed version:
while True:
    n = int(input())
    if n == 0:
        exit()
    score = []
    for i in range(n):
        score.append(int(input()))
    print(sum(sorted(score)[1:-1])//(n-2))

# Buggy version:
averages = []

while True:
    amount = int(input())
    if amount == 0:
        break
    scores = [int(input()) for i in range(amount)]
    scores.remove(max(scores))
    scores.remove(min(scores))
    averages.append(sum(scores) // amount)

for i in range(len(averages)):
    print(averages[i])

# Fixed version:
averages = []

while True:
    amount = int(input())
    if amount == 0:
        break
    scores = [int(input()) for i in range(amount)]
    scores.remove(max(scores))
    scores.remove(min(scores))
    averages.append(sum(scores) // (amount - 2))

for i in range(len(averages)):
    print(averages[i])

# Buggy version:
import statistics

while True:
    n = int(input())
    if n == 0: break
    s = [int(input()) for i in range(n)]
    ave = statistics.mean(sorted(s[1:-1]))
    print(int(ave))

# Fixed version:
import statistics

while True:
    n = int(input())
    if n == 0: break
    s = [int(input()) for i in range(n)]
    ave = statistics.mean(sorted(s)[1:-1])
    print(int(ave))

# Buggy version:
while True:
    n=int(input())
    points=[]
    for i in range(n):
        points.append(int(input()))
    points.remove(max(points))
    points.remove(min(points))
    print(int(sum(points)/len(points)))
    if int(input())==0:break

# Fixed version:
while True:
    n=int(input())
    if n==0:break
    points=[]
    for i in range(n):
        points.append(int(input()))
    points.remove(max(points))
    points.remove(min(points))
    print(int(sum(points)/len(points)))

# Buggy version:
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    
    if n == 0:
        break
        
    scores = [int(sys.stdin.readline().rstrip()) for i in range(n)]
    result = (sum(scores) - (min(scores) + max(scores)) // n - 2)
    
    print(result)

# Fixed version:
import sys

while True:
    n = int(sys.stdin.readline().rstrip())

    if n == 0:
        break

    scores = [int(sys.stdin.readline().rstrip()) for i in range(n)]
    result = (sum(scores) - (max(scores) + min(scores))) // (n - 2)

    print(result)

# Buggy version:
while True:
    try:
        n = int(input())
        MIN = 1000
        MAX = 0
        points = 0
        for i in range(n):
            p = int(input())
            if MIN > p:
                MIN = p
            if MAX < p:
                MAX = p
            points += p
        print((points - MIN - MAX) // (n - 2))
    except:
        break



# Fixed version:
while True:
    n = int(input())
    if n == 0:
        break
    MIN = 1000
    MAX = 0
    points = 0
    for i in range(n):
        p = int(input())
        if MIN > p:
            MIN = p
        if MAX < p:
            MAX = p
        points += p
    print((points - MIN - MAX) // (n - 2))

# Buggy version:
import bisect
while True:
    n = int(input())
    if n+1:
        break
    score = []
    for _ in range(n):
        s = int(input())
        bisect.insort(score, s)
    print(sum(score[1:-1])//(len(score)-2))

# Fixed version:
import bisect
while True:
    n = int(input())
    if n == 0:
        break
    score = []
    for _ in range(n):
        s = int(input())
        bisect.insort(score, s)
    print(sum(score[1:-1])//(len(score)-2))

# Buggy version:
import math

def main():
    r = []
    while True:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m)/(n-2))))
    res = ''
    for j in r:
        print(j)

main()



# Fixed version:
import math

def main():
    r = []
    while True:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m))/(n-2)))
    for j in r:
        print(j)

main()

# Buggy version:
i = int(input())
while i == 0:
    i = 0
    p = 0
    k[20][100] = [[0]]
    ma = 0
    mi = 1000
    for i in range(i):
        l = int(input())
        k[p][i] = l
        ma = max(ma,l)
        mi = min(mi,l)
    su = sum(k[p]) - ma - mi
    print(su // (i-2))
    p += 1
    i = int(input()) 


# Fixed version:
i = int(input())
p = 0
while i != 0:
    k =[ [0]*100]*20
    ma = 0
    mi = 1000
    for pp in range(i):
        l = int(input())
        k[p][pp] = l
        ma = max(ma,l)
        mi = min(mi,l)
    su = sum(k[p]) - ma - mi
    l = i -2
    print(su // l)
    p += 1
    i = int(input())

# Buggy version:
while True:
    N = int(input())
    if 3
    N == 0:
        break
    S = []
    for i in range(N):
        S.append(int(input()))
    print((sum(S) - max(S) - min(S))//(len(S)-2))


# Fixed version:
while True:
    N = int(input())
    if N == 0:
        break
    S = []
    for i in range(N):
        S.append(int(input()))
    a = sum(S)-max(S)-min(S)
    print(int(a/(N-2)))