alexjercan/bugnet huggingface dataset:
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n, s;
  while (cin >> n && n > 0) {
    int large = 0;
    int small = 1000;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      cin >> s;
      sum = sum + s;
      if (large < s) {
        large = s;
      }
      if (small > s) {
        small = s;
      }
    }
    int ans = 0;
    ans = (sum - large - small) / (n - 2);
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, s;
  while (cin >> n && n > 0) {
    int large = 0;
    int small = 1000;
    int sum = 0;
    for (int i = 0; i > n; ++i) {
      cin >> s;
      sum = sum + s;
      if (large < s) {
        large = s;
      }
      if (small > s) {
        small = s;
      }
    }
    int ans = 0;
    ans = (sum - large - small) / (n - 2);
    cout << ans << endl;
  }
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, s[120], count;
  ;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    count = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      count += s[i];
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (s[j] < s[j - 1]) {
          int tmp = s[j];
          s[j] = s[j - 1];
          s[j - 1] = tmp;
        }
      }
    }
    count -= s[0];
    count -= s[n - 1];
    cout << count / (n - 2) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, s[120], count;
  ;
  while (true) {
    cin >> n;
    count = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      count += s[i];
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (s[j] < s[j - 1]) {
          int tmp = s[j];
          s[j] = s[j - 1];
          s[j - 1] = tmp;
        }
      }
    }
    count -= s[0];
    count -= s[n - 1];
    cout << count / (n - 2) << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long i64;
int main() {
  while (true) {
    int n;
    vector<int> a;
    cin >> n;
    if (n == 0)
      break;
    rep(i, n) {
      int b;
      cin >> b;
      a.push_back(b);
    }
    sort(a.begin(), a.end());
    int total = 0;
    repi(i, 1, n - 1) { total += a[i]; }
    cout << total / (n - 2) << endl;
    ;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long i64;
int main() {
  while (true) {
    int n;
    vector<int> a;
    cin >> n;
    rep(i, n) {
      int b;
      cin >> b;
      a.push_back(b);
    }
    sort(a.begin(), a.end());
    int total = 0;
    repi(i, 1, n - 1) { total += a[i]; }
    cout << total / (n - 2) << endl;
    ;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define INF (2 << 29)
using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  for (;;) {
    int a, n, s = 0, max = 0, min = INF;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a;
      s += a;
      if (max < a)
        max = a;
      if (min > a)
        min = a;
    }
    cout << (s - max - min) / (n - 2) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a, n;
  for (;;) {
    vector<int> num;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a;
      num.push_back(a);
    }
    sort(num.begin(), num.end());
    num.erase(num.begin());
    num.pop_back();
    int sum = 0;
    for (int x : num) {
      sum += x;
    }
    sum /= num.size();
    cout << sum << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

void QSort(int x[], int left, int right);
void Swap(int x[], int i, int j);

void QSort(int x[], int left, int right) {
  int i, j;
  int pivot;

  i = left;
  j = right;

  pivot = x[(left + right) / 2];
  while (1) {

    while (x[i] < pivot)
      i++;

    while (pivot < x[j])
      j--;
    if (i >= j)
      break;

    Swap(x, i, j);
    i++;
    j--;
  }

  if (left < i - 1)
    QSort(x, left, i - 1);
  if (j + 1 < right)
    QSort(x, j + 1, right);
}

void Swap(int x[], int i, int j) {
  int temp;

  temp = x[i];
  x[i] = x[j];
  x[j] = temp;
}

int main(void) {
  int i;
  int j;
  int k;
  int n;
  int d[20];
  int p[100];
  int sum;
  int ave;

  j = 0;
  while (1) {

    scanf("%d", &n);
    if (n == 0)
      break;

    for (i = 0; i < n; i++) {
      scanf("%d", &p[i]);
    }

    QSort(p, 0, n - 1);

    sum = 0;
    for (i = 1; i < n - 1; i++) {
      sum += p[i];
    }

    d[j] = sum / (n - 2);
    j++;
  }

  for (k = 0; k < j; k++)
    printf("%d\\n", d[k]);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

void sort(int p[], int n);

void sort(int p[], int n) {
  int i, j, temp;

  for (i = 0; i < n - 1; i++) {
    for (j = n - 1; j > i; j--) {
      if (p[j - 1] > p[j]) {
        temp = p[j];
        p[j] = p[j - 1];
        p[j - 1] = temp;
      }
    }
  }
}

int main(void) {
  int i;
  int j;
  int k;
  int m;
  int n;
  int d[20];
  int p[100];
  int sum;
  int ave;

  while (m) {

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%d", &p[i]);
    }

    sort(p, n);

    sum = 0;
    for (i = 1; i < n - 1; i++)
      sum += p[i];

    j = 0;
    d[j] = sum / (n - 2);
    j++;

    scanf("%d", &m);
  }

  for (k = 0; k < j; k++) {
    printf("%d", d[k]);
  }

  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)), (x).end())

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const int MOD = 1000000007;

void solve(void) {
  while (1) {
    int N;
    scanf("%d\\n", &N);
    if (N == 0)
      break;
    vector<int> ps;
    int ans = 0;
    rep(N, i) {
      int p;
      scanf("%d\\n", &p);
      ps.pb(p);
      ans += p;
    }
    sort(all(ps));
    ans -= ps[0] + ps[N - 1];
    printf("%d\\n", ans / (N - 2));
  }
}

int main(void) {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)), (x).end())

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const int MOD = 1000000007;

void solve(void) {
  while (1) {
    int N;
    scanf("%d\\n", &N);
    if (N == 0)
      break;
    vector<int> ps;
    rep(N, i) {
      int p;
      scanf("%d\\n", &p);
      ps.pb(p);
    }
    sort(all(ps));
    int ans = -ps[0] - ps[N - 1];
    for (int t : ps)
      ans += t;
    printf("%d\\n", ans / (N - 2));
  }
}

int main(void) {
  solve();
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int n;

int main() {
  int ave;
  while (cin >> n && (n > 0)) {
    int a[100];
    int sum = 0;
    for (int i = 0; i <= n - 1; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    for (int j = 1; j <= n - 2; j++) {
      sum += a[j];
    }
    ave = floor(sum / (n - 2));
    cout << ave << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int n;

int main() {
  int ave;
  while (cin >> n) {
    int a[20];
    int sum = 0;
    for (int i = 0; i <= n - 1; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    for (int j = 1; j <= n - 2; j++) {
      sum += a[j];
    }
    ave = floor(sum / (n - 2));
    cout << ave << endl;
  }
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int x[100], i, j = 0, n = 1, sum[100];
  while (1) {
    sum[j] = 0;
    cin >> n;
    if (n == 0)
      break;

    for (i = 0; i < n; i++) {
      cin >> x[i];
    }
    sort(x, x + n);
    for (i = 1; i < n - 1; i++) {
      sum[j] += x[i];
    }
    sum[j] = sum[j] / (n - 2);
    j++;
  }
  for (i = 0; i < j; i++) {
    cout << sum[i] << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int x[20], y, i, j, n, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x[i];
    sum += x[i];
  }
  sort(x, x + n);

  cout << (sum - x[0] - x[n - 1]) / (n - 2);
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int n, s[100] = {0};
  int max, min, max1, min1;
  int sum, i;

  scanf("%d", &n);

  do {
    max = 0;
    min = 100000;
    sum = 0;
    sum = 0;
    max1 = 0;
    min1 = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      if (s[i] > max) {
        max = s[i];
        max1 = i;
      }
      if (s[i] < min) {
        min = s[i];
        min1 = i;
      }
    }
    for (i = 0; i < n; i++) {
      if (i != max1 && i != min1) {
        sum += s[i];
      }
    }
    printf("%d\\n", sum / (n - 2));
    scanf("%d", &n);
  } while (n != 0);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int n, s[100] = {0};
  int max, min, max1, min1;
  int sum, i;

  // scanf("%d",&n);

  while (scanf("%d", &n) != 0) {
    max = 0;
    printf("%d\\n", scanf("%d", &n));
    min = 100000;
    sum = 0;
    sum = 0;
    max1 = 0;
    min1 = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      if (s[i] > max) {
        max = s[i];
        max1 = i;
      }
      if (s[i] < min) {
        min = s[i];
        min1 = i;
      }
    }
    for (i = 0; i < n; i++) {
      if (i != max1 && i != min1) {
        sum += s[i];
      }
    }
    printf("%d\\n", sum / (n - 2));
    // scanf("%d",&n);
  } // while (n!=0);
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int a[100];
  int b, sum = 0, point;
  while (1) {
    cin >> b;
    if (b == 0)
      break;
    for (int i = 0; i < b; i++) {
      cin >> a[i];
    }
    sort(a, a + b);
    for (int j = 1; j < b - 1; j++) {
      sum += a[j];
    }
    point = sum / (b - 2);
    cout << point << endl;
    sum = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int a[20];
  int b, sum = 0, point;
  while (1) {
    cin >> b;
    if (b == 0)
      break;
    for (int i = 0; i < b; i++) {
      cin >> a[i];
    }
    sort(a, a + b);
    for (int j = 1; j < b - 1; j++) {
      sum += a[j];
    }
    point = sum / (b - 2);
    cout << point << endl;
    sum = 0;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  int point[100], average;

  while (1) {
    average = 0;
    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      cin >> point[i];
    }
    sort(point, point + n);
    for (int i = 1; i < n - 1; i++) {
      average += point[i];
    }
    average /= (n - 2);
    cout << average << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  int point[20], average;

  while (1) {
    average = 0;
    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      cin >> point[i];
    }
    sort(point, point + n);
    for (int i = 1; i < n - 1; i++) {
      average += point[i];
    }
    average /= (n - 2);
    cout << average << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;

  while (true) {
    vector<int> point;
    int data;
    int ave = 0;

    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> data;
      point.push_back(data);
    }
    sort(point.begin(), point.end());
    for (int i = 1; i < point.size() - 1; i++) {
      ave += point[i];
    }
    cout << ave / (point.size() - 2) << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;

  while (!cin.eof()) {
    vector<int> point;
    int data;
    int ave = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> data;
      point.push_back(data);
    }
    sort(point.begin(), point.end());
    for (int i = 1; i < point.size() - 1; i++) {
      ave += point[i];
    }
    cout << ave / (point.size() - 2) << endl;
  }

  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int n, a[100], i, max = 0, min = 1000, c;
  while (1) {
    c = 0;
    max = 0;
    min = 1000;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (max < a[i])
        max = a[i];
      if (min > a[i])
        min = a[i];
    }
    for (i = 0; i < n; i++) {
      c += a[i];
    }
    c -= max + min;
    printf("%d\\n", c / (n - 2));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int n, a[100], i, max = 0, min = 1000, c;
  while (1) {
    c = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (max < a[i])
        max = a[i];
      if (min > a[i])
        min = a[i];
    }
    for (i = 0; i < n; i++) {
      if (max == a[i])
        a[i] = 0;
      if (min == a[i])
        a[i] = 0;
      c += a[i];
    }
    printf("%d\\n", c / (n - 2));
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, s[100], num, max, min, a;

  while (true) {
    num = 0;

    cin >> n;
    if (n == 0)
      break;

    cin >> s[0];
    max = s[0];
    min = s[0];
    num = s[0];

    for (int i = 1; i < n; i++) {
      cin >> s[i];

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

      num += s[i];
    }
    a = (num - max - min) / (n - 2);

    cout << a << endl;
  }
  return 0;
}


Error: -8

Fixed submission:

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

int main() {
  int n, s[100], num, max = s[0], min = s[0];

  do {
    cin >> n;
    num = 0;

    for (int i = 0; i < n; i++) {
      cin >> s[i];

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

      num += s[i];
    }
    num = (num - max - min) / n;
    cout << num << endl;

  } while (n != 0);
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, a[101], b[101];
  while (1) {

    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int max = 0, min = 10001;
    for (int i = 0; i < n; i++) {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
    }
    sum -= (max + min);

    cout << sum / (n - 2) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, a[21], b[21];
  while (1) {

    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int max = 0, min = 10001;
    for (int i = 0; i < n; i++) {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
    }
    sum -= (max + min);

    cout << sum / (n - 2) << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    if (!n)
      break;

    vector<int> scr(n);
    for (int i = 0; i < n; i++) {
      cin >> scr[i];
    }

    int sum = 0;
    int _max = scr[0];
    int _min = scr[0];

    for (int s : scr) {
      sum += s;
      _min = min(_min, s);
      _max = max(_max, s);
    }

    sum -= _max;
    sum -= _min;

    cout << sum / (n - 2) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

int main() {
  int n;

  while (cin >> n && n) {
    vector<int> scr(n);
    for (int i = 0; i < n; i++) {
      cin >> scr[i];
    }

    int sum = 0;
    int _max = scr[0];
    int _min = scr[0];

    for (int s : scr) {
      sum += s;
      _min = min(_min, s);
      _max = max(_max, s);
    }

    sum -= _max;
    sum -= _min;

    cout << sum / (n - 2) << endl;
  }

  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> array;
  vector<int> ans;
  int i, x, max, min, sum, n;

  while (1) {
    cin >> n;
    max = 0;
    min = 1000;
    if (n == 0) {
      for (i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
      }

      break;
    }
    array.clear();
    sum = 0;

    for (i = 0; i < n; i++) {
      cin >> x;
      array.push_back(x);
    }
    for (i = 0; i < n; i++) {
      if (max < array[i]) {
        max = array[i];
      }
    }
    for (i = 0; i < n; i++) {
      if (min > array[i]) {
        min = array[i];
      }
    }
    for (i = 0; i < n; i++) {
      sum += array[i];
    }
    sum = sum - max - min;
    ans.push_back(sum / (n - 2)); // 2ひいた分だけ割る数を減らす
  }
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> array;
  vector<int> ans;
  int i, x, max, min, sum, n;
  max = 0;
  min = 1000;

  while (1) {
    cin >> n;
    if (n == 1) {
      for (i = 0; i < sizeof(ans); i++) {
        cout << ans[i] << endl;
      }

      break;
    }
    array.clear();
    sum = 0;

    for (i = 0; i < n; i++) {
      cin >> x;
      array.push_back(x);
    }
    for (i = 0; i < n; i++) {
      if (max < array[i]) {
        max = array[i];
      }
    }
    for (i = 0; i < n; i++) {
      if (min > array[i]) {
        min = array[i];
      }
    }
    for (i = 0; i < n; i++) {
      sum += array[i];
    }
    sum = sum - max - min;
    ans.push_back(sum / (n - 2)); // 2ひいた分だけ割る数を減らす
  }
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
    if (m == 0) {
      break;
    }
    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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
  int n, s[1000], i, max = 0, min = 1000, sum = 0;

  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }

    sum = 0;
    max = 0;
    min = 1000;

    for (i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      sum += s[i];
    }

    for (i = 0; i < n; i++) {
      if (max <= s[i]) {
        max = s[i];
      }
    }

    for (i = 0; i < n; i++) {
      if (min >= s[i]) {
        min = s[i];
      }
    }

    printf("%d\\n", (sum - max - min) / (n - 2));
  }

  return 0;
}

Error: -11

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
  int n, s[1000], i, max = 0, min = 1000, sum = 0, lastsum;

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