Go: package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	for n != 0 {
		arr := make([]int, n)
		for i := range arr {
			fmt.Scan(&arr[i])
		}
		sort.Ints(arr)

		sum := 0
		for i := 1; i < len(arr)-1; i++ {
			sum += arr[i]
		}
		fmt.Println(sum / (n - 2))
		fmt.Scan(&n)
	}
}

C++: 37
569
772
159
963
959
312
458
29
159
449
215
63
562
893
520
30
550
586
753
237
558
357
352
778
665
507
443
256
916
584
629
145
706
338
521
697
963
73
824
188
934
83
691
821
267
393
31
551
585
660
66
103
640
186
448
23
701
477
344
97
921
335
72
606
751
201
237
332
13
584
926
780
650
712
570
899
56
313
711
890
628
624
532
510
689
31
797
393
894
305
151
48
139
279
426
906
160
741
831
744
266
181
886
362
898
423
154
985
251
696
45
31
776
463
677
532
999
115
861
331
555
234
762
965
313
344
224
242
599
791
799
107
181
145
530
647
969
932
177
724
461
579
107
3
321
638
974
98
204
740
521
587
790
291
429
584
517
396
610
461
125
115
176
398
955
461
158
10
363
932
384
598
459
318
197
440
823
860
960
998
847
265
632
699
629
969
370
529
90
810
909
710
900
284
596
508
837
854
208
320
59
286
421
120
869
31
774
648
616
649
438
890
587
395
554
299
306
182
871
981
289
195
204
480
646
128
873
29
93
291
440
689
701
162
199
397
821
642
552
703
985
156
10
636
647
1000
100
663
480
65
492
278
813
559
150
569
413
730
241
250
802
920
887
468
697
354
822
981
685
317
662
253
2
456
956
778
921
609
453
607
609
363
349
968
437
547
713
39
399
496
584
109
865
267
356
340
120
821
980
39
604
120
705
547
392
455
890
412
175
664
560
792
910
155
359
85
764
326
62
706
310
377
532
904
233
830
448
305
876
806
465
924
858
289
989
942
527
920
715
792
44
536
918
454
86
452
805
3
801
201
531
14
895
942
531
87
707
766
790
746
889
942
77
889
677
672
43
326
613
304
328
377
532
841
713
116
933
367
768
354
215
805
980
255
513
593
442
3
386
165
741
167
687
736
30
129
389
847
600
403
396
512
4
546
906
605
595
651
227
367
3
879
833
440
100
670
910
488
53
611
163
528
17
298
608
663
914
448
19
795
841
396
637
332
244
85
355
525
918
968
768
268
723
220
820
893
121
994
113
936
75
810
315
232
150
105
450
144
713
634
328
149
747
864
529
725
935
542
957
522
307
803
52
835
7
758
240
37
288
763
438
650
83
570
730
202
551
927
572
803
251
910
173
429
462
615
511
737
757
608
428
106
60
218
968
255
34
959
537
628
452
722
360
443
937
34
905
245
650
74
9
616
762
552
252
301
108
54
830
338
638
749
362
724
430
719
208
374
705
1000
569
313
399
721
680
424
458
732
494
9
63
256
521
726
80
351
777
427
574
875
563
68
495
760
614
918
22
707
793
599
592
343
220
932
357
859
949
53
777
964
519
142
54
442
615
594
698
343
160
871
420
46
353
30
768
345
991
882
352
552
865
701
298
432
879
334
994
827
538
402
372
79
500
565
75
323
223
286
295
688
612
272
994
888
450
449
197
694
286
729
140
245
941
97
582
525
273
661
827
647
251
325
421
374
220
673
175
300
43
982
21
208
196
929
409
472
651
740
746
158
477
3
56
612
163
718
846
129
205
54
865
816
637
931
686
179
466
610
474
622
908
109
356
573
564
690
272
773
891
1000
60
791
401
564
773
651
378
337
799
44
97
407
884
598
135
373
394
459
452
688
14
951
110
677
757
483
274
992
601
741
742
543
836
726
765
411
852
469
531
467
105
759
866
427
967
674
933
214
219
175
978
607
141
505
349
855
837
312
746
595
433
76
383
359
60
256
438
506
606
682
964
347
622
842
210
931
901
484
343
479
830
993
708
797
631
274
287
603
717
183
613
774
665
757
268
108
986
561
202
341
14
623
898
509
65
457
308
360
197
924
395
626
301
461
408
141
246
505
541
865
926
179
889
999
383
642
910
805
785
5
521
462
637
955
843
558
454
999
0

C++: #include <bits/stdc++.h>
using namespace std;

int main(){

    int n;
    while(1){

        int sum=0,avg=0;
     
        cin>>n;

        if( n == 0) break;

        vector<int>  point(n);

        for(int i=0; i<n; i++){

            cin>>point.at(i);
        }

        sort(point.begin(),point.end());



        for(int i = 0; i<n; i++){

         sum += point.at(i);

        }
        
        avg = (sum - point.at(0) - point.at(n-1) ) / (n -2);

        cout<<avg<<endl;
    }


    return 0;

}

C++: #include<stdio.h>

int INF = 1e9;

int main(){
	int n;
	int s[100];
	
	
	while(1){
		scanf("%d",&n);
		if(n == 0)break;
		int sum = 0;
		int avg = 0;
		int min = INF;
		int max = 0;
		for(int i = 0;i < n;i++){
			scanf("%d",&s[i]);
			sum += s[i];
			if(max < s[i]) {max = s[i];}
			if(min > s[i]) {min = s[i];}
		}
		sum = sum - min - max;
		avg = sum / (n - 2);
		printf("%d\n", avg);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
  int n, s[100];
  int sam = 0, ave[100];
  int min, max;
  int kmin = 0, kmax = 0;
  int k = 0;
  
  while(true){
    cin >> n;
    if(n == 0) break;
    sam = 0;
    
    for(int i = 0; i < n; ++i){
      cin >> s[i];
      sam += s[i];

      if(i == 0){
	min = s[i];
	max = s[i];
      }
      
      if(min > s[i]) min = s[i];
      if(max < s[i]) max = s[i];

      if(min == s[i] && kmin == 0) ++kmin;
      if(max == s[i] && kmax == 0) ++kmax;
    }
    ave[k] = (sam - min - max) / (n - kmin - kmax);
    ++k;
  }

  for(int f = 0; f < k; ++f){
    cout << ave[f] << endl;
  }
  
    
  return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
    int n,input;
    while (1){
        scanf("%d", &n);
        if (n==0){
            break;
        }
        int sum=0,max=0,min=1001;
        for (int i;i<n;i++) {
            cin >> input;
            sum = sum+input;
            if (max < input) max = input;
            if (min > input) min = input;
        }
        printf("%d\n", (sum-max-min)/(n-2));
    }
}

C++: #include <iostream>
using namespace std;

int main(){
  int n, s, sum, max, min;
  while(1){
    cin >> n;
    if(n == 0) break;
    sum = 0;
    cin >> s;
    sum += s;
    max = s;
    cin >> s;
    sum += s;
    if(max < s){
      max = s;
    }else{
      min = s;
    }
    for(int i = 2; i < n; i++){
      cin >> s;
      sum += s;
      if(max < s){
	max = s;
      }else if{
	(min > s) min = s;
      }
    }
    sum -= max;
    sum -= min;
    int ave = sum / (n-2);

    cout << ave << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <numeric>

#define FOR(i,l,n) for(int i=(l);i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define MAX_JUDGE 100
using namespace std;

int main(){
  int n,score[MAX_JUDGE];
  while(cin>>n,n){
    REP(i,n)cin>>score[i];
    sort(score,score+n);
    int sum = accumulate(score+1,score+n-1,0);
    cout << sum/(n-2) <<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
	int n[100];
	int max[2]={0,-1},min[2]={1000,-1},sum=0;
	int m;
	while(true){
		cin>>m;
		max[0]=0;
		max[1]=-1;
		min[0]=1000;
		min[1]=-1;
		sum=0;
		for(int i=0;i<m;i++){
			cin>>n[i];
			if(n[i]>max[0]){
				max[1]=i;
				max[0]=n[i];
			}
			if(n[i]<min[0]){
				min[1]=i;
				min[0]=n[i];
			}
		}
		for(int i=0;i<m;i++){
			if(max[1]!=i && min[1]!=i){
				sum += n[i];
			}
		}
		cout<<sum/(m-2)<<endl;
	}
    return 0;
}