alexjercan/bugnet huggingface dataset:
Problem p00726 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int pos, n;
string s;
string f();
string expr() {
  string a = f();
  while (isdigit(s[pos]) || isalpha(s[pos])) {
    if (a.size() > n)
      break;
    a += f();
  }
  return a;
}
string f() {
  string t = "", p;
  if (isdigit(s[pos])) {
    int ret = 0, i = 0;
    for (; isdigit(s[pos]); pos++) {
      ret *= 10;
      ret += s[pos] - '0';
    }
    p = f();
    for (; i < ret; i++) {
      t += p;
      if (t.size() > n)
        break;
    }
  } else if (s[pos] == '(') {
    pos++;
    t = expr();
    pos++;
  } else {
    for (; isalpha(s[pos]); pos++) {
      t += s[pos];
      if (t.size() > n)
        break;
    }
  }
  return t;
}
int main() {
  while (cin >> s >> n, s != "0" || n) {
    pos = 0;
    s += "#";
    string t = expr();
    if (t.size() - 1 < n)
      cout << 0 << endl;
    else
      cout << t[n] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int pos, n;
string s, t, p;
string f();
string expr() {
  string a = f();
  while (isdigit(s[pos]) || isalpha(s[pos])) {
    if (a.size() > n)
      break;
    a += f();
  }
  return a;
}
string f() {
  t = "";
  if (isdigit(s[pos])) {
    int ret = 0, i = 0;
    for (; isdigit(s[pos]); pos++) {
      ret *= 10;
      ret += s[pos] - '0';
    }
    p = f();
    for (; i < ret; i++) {
      t += p;
      if (t.size() > n)
        break;
    }
  } else if (s[pos] == '(') {
    pos++;
    t = expr();
    pos++;
  } else {
    for (; isalpha(s[pos]); pos++) {
      t += s[pos];
      if (t.size() > n)
        break;
    }
  }
  return t;
}
int main() {
  while (cin >> s >> n, s != "0" || n) {
    pos = 0;
    s += "#";
    string t = expr();
    if (t.size() - 1 < n)
      cout << 0 << endl;
    else
      cout << t[n] << endl;
  }
  return 0;
}
Problem p00726 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cctype>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

typedef string::const_iterator Iter;
typedef ostringstream SS;

string express(Iter &p);
string factor(Iter &p);
string term(Iter &p);
int number(Iter &p);

int N;

string express(Iter &p) {
  SS r;
  while (isalpha(*p) || isdigit(*p)) {
    string rs = term(p);
    r << rs;
    if (r.str().length() > N)
      break;
  }

  return r.str();
}

string term(Iter &p) {
  if (isdigit(*p)) {
    SS r;
    int num = number(p);
    if (*p == '(') {
      p++;
      string rs = express(p);
      p++;

      for (int i = 0; i < num; i++) {
        r << rs;
        if (r.str().size() > N)
          break;
      }
      return r.str();
    } else {
      char c = *p;
      p++;

      for (int i = 0; i < num; i++) {
        r << c;
        if (r.str().size() > N)
          break;
      }
      return r.str();
    }
  } else {
    return factor(p);
  }
}

string factor(Iter &p) {
  SS r;
  while (isalpha(*p)) {
    r << *p;
    p++;
    if (r.str().size() > N)
      break;
  }
  return r.str();
}

int number(Iter &p) {
  int r = 0;
  while (isdigit(*p)) {
    r *= 10;
    r += (*p) - '0';
    p++;
  }
  return r;
}

int main() {
  for (;;) {
    string line;
    int i;
    cin >> line >> i;
    N = i;
    if (line == "0" && i == 0)
      break;
    string source = line + "|";
    Iter begin = source.begin();
    string s = express(begin);
    if (i >= s.length())
      cout << 0 << endl;
    else
      cout << s[i] << endl;
  }
}

Error: MLE

Fixed submission:

#include <cctype>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

typedef string::const_iterator Iter;
typedef ostringstream SS;

string express(Iter &p);
string factor(Iter &p);
string term(Iter &p);
int number(Iter &p);

string express(Iter &p) {
  SS r;
  while (isalpha(*p) || isdigit(*p)) {
    string rs = term(p);
    r << rs;
  }

  return r.str();
}

string term(Iter &p) {
  if (isdigit(*p)) {
    SS r;
    int num = number(p);
    if (*p == '(') {
      p++;
      string rs = express(p);
      p++;

      for (int i = 0; i < num; i++)
        r << rs;
      return r.str();
    } else {
      char c = *p;
      p++;

      for (int i = 0; i < num; i++) {
        r << c;
      }
      return r.str();
    }
  } else {
    return factor(p);
  }
}

string factor(Iter &p) {
  SS r;
  while (isalpha(*p)) {
    r << *p;
    p++;
  }
  return r.str();
}

int number(Iter &p) {
  int r = 0;
  while (isdigit(*p)) {
    r *= 10;
    r += (*p) - '0';
    p++;
  }
  return r;
}

int main() {
  for (;;) {
    string line;
    int i;
    cin >> line >> i;
    if (line == "0" && i == 0)
      break;
    string source = line + "|";
    Iter begin = source.begin();
    string s = express(begin);
    cerr << "-----" << endl;
    cerr << s << endl;
    cerr << "-----" << endl;
    if (i >= s.length())
      cout << 0 << endl;
    else
      cout << s[i] << endl;
  }
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<int> v;
    int a;
    rep(i, n) {
      cin >> a;
      v.push_back(a);
    }
    sort(ALL(v));

    int sum = 0;
    for (int i = 1; i < n - 1; i++) {
      sum += v[i];
    }
    sum = sum / (n - 2);
    cout << sum << endl;
  }
}


Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    int n;
    cin >> n;
    vector<int> v;
    int a;
    rep(i, n) {
      cin >> a;
      v.push_back(a);
    }
    sort(ALL(v));

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

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


Error: 0

Fixed submission:

#include <cstdio>
int main() {
  int n, s[20], i;
  int max, min, ava, sum;
  while (1) {
    max = 0;
    min = 1000;
    sum = 0;
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      if (max < s[i]) {
        max = s[i];
      }
      if (min > s[i]) {
        min = s[i];
      }
      sum += s[i];
    }
    sum -= max;
    sum -= min;
    ava = sum / (n - 2);
    printf("%d\\n", ava);
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <utility>
#include <vector>

#define REP(i, a, n) for (int i = a; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define vsort(v) sort(v.begin(), v.end())
#define asort(a, n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int N;
  int ans;
  int cnt;
  vi vec(100);
  while (true) {
    vec.assign(100, -1);
    ans = 0;
    cnt = 0;
    cin >> N;
    if (N == 0)
      return 0;
    rep(i, N) { cin >> vec[i]; }
    vsort(vec);
    REP(i, 101 - N, 99) {
      ans += vec[i];
      cnt++;
    }
    cout << (int)(ans / cnt) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <utility>
#include <vector>

#define REP(i, a, n) for (int i = a; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define vsort(v) sort(v.begin(), v.end())
#define asort(a, n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int N;
  int ans;
  int cnt;
  vi vec(20);
  while (true) {
    vec.assign(20, -1);
    ans = 0;
    cnt = 0;
    cin >> N;
    if (N == 0)
      return 0;
    rep(i, N) { cin >> vec[i]; }
    vsort(vec);
    REP(i, 21 - N, 19) {
      ans += vec[i];
      cnt++;
    }
    cout << (int)(ans / cnt) << endl;
  }

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

#include <iostream>
using namespace std;
int N, S;

int main() {
  while (cin >> N &&
         N > 0) { // N??????????????????????????????????????§while????????????
    int sum = 0;
    int min = 1001; // min????°?????????¨?????????
    int max = -1;
    int average = -1;

    for (int i = 0; i < N; i++) {
      cin >> S;
      sum += S;
      if (S > max)
        max = S;
      if (S < min)
        min = S;
    }

    average =
        (sum - min - max) /
        (N -
         2); //???N-2?????§???????????¨?????¨??????????????????????????¨????????????????????????

    cout << average << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int N, S;

int main() {
  while (cin >> N &&
         N > 0) { // N??????????????????????????????????????§while????????????
    int sum = 0;
    int min = 0;
    int max = 0;
    // int average = 0;

    for (int i = 0; i < N; cin >> S) {
      sum += S;
      if (S > max)
        max = S;
      else if (S < min)
        min = S;
    }

    sum -= min + max;
    sum /= N - 2;

    // average = sum - min - max / N - 2; //???N-2?????§???????????¨?????¨??????

    cout << sum << endl;
  }

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

#include <iostream>

using namespace std;

int main() {
  int n, s[1000], i;
  while (cin >> n && n > 0) {
    int sum = 0, maximum = 0, minimum = 10000;
    for (i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    for (i = 0; i < n; i++) {
      maximum = max(maximum, s[i]);
      minimum = min(minimum, s[i]);
    }
    cout << (sum - maximum - minimum) / (n - 2) << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, s[1000], i;
  while (cin >> n && n > 0) {
    int sum = 0, maximum = 0, minimum = 10000;
    for (i = 0; i > n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    for (i = 0; i > n; i++) {
      maximum = max(maximum, s[i]);
      minimum = min(minimum, s[i]);
    }
    cout << (sum - maximum - minimum) / (n - 2) << endl;
  }
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int in, a, maxer = 0, miner = 1000;
  int sum = 0;
  int i = 0;
  double ave = 0.0;
  while (cin >> in, in) {
    for (i = 0; i < in; i++) {
      cin >> a;
      maxer = max(a, maxer);
      miner = min(a, miner);
      sum += a;
    }
    sum = sum - maxer - miner;
    ave = sum / (in - 2);
    cout << floor(ave) << endl;
    sum = maxer = ave = 0;
    miner = 1000;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int in, a, maxer = 0, miner = 1000;
  int sum = 0;
  int i = 0;
  double ave = 0.0;
  while (scanf("%d", &in) != 0) {
    for (i = 0; i < in; i++) {
      cin >> a;
      maxer = max(a, maxer);
      miner = min(a, miner);
      sum += a;
    }
    sum = sum - maxer - miner;
    ave = sum / (in - 2);
    cout << floor(ave) << endl;
    sum = maxer = ave = 0;
    miner = 1000;
  }
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  int n;
  int x;
  while (1) {
    int max = -1, min = 1001;
    int S = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (min > x) {
        min = x;
      }
      if (max < x) {
        max = x;
      }
      S = S + x;
    }
    cout << (S - (max + min)) / (n - 2) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  int n;
  int x[21];
  while (1) {
    int max = -1, min = 1001;
    int S = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> x[i];
      if (min > x[i]) {
        min = x[i];
      }
      if (max < x[i]) {
        max = x[i];
      }
      S = S + x[i];
    }
    cout << (S - (max + min)) / (n - 2) << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#define S 100

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

  for (;;) {
    max = 0, min = 1000, sum = 0;

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

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

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define S 20

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

  for (;;) {
    max = 0, min = 1000, sum = 0;

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

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

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

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

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

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

#include <algorithm>
#include <iostream>

#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 = 0;
    FOR(i, 1, n - 1) sum += score[i];
    cout << sum / (n - 2) << endl;
  }
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> score(n);
    for (int i = 0; i < n; i++)
      cin >> score[i];

    vector<int>::iterator minIt = min_element(score.begin(), score.end());
    int minIndex = distance(score.begin(), minIt);
    score.erase(score.begin() + minIndex - 1);

    vector<int>::iterator maxIt = max_element(score.begin(), score.end());
    int maxIndex = distance(score.begin(), maxIt);
    score.erase(score.begin() + maxIndex - 1);

    int sum = accumulate(score.begin(), score.end(), 0);
    cout << sum / score.size() << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int main(int argc, char *argv[]) {
  int ninzu = 0;
  while (cin >> ninzu, ninzu) {
    int ans = 0;
    int i = 0;
    int temp = 0;
    int a = 0;

    vector<int> s;

    for (i = 0; i < ninzu; i++) {
      cin >> a;
      if (temp < a) {
        temp = a;
      }
      s.push_back(a);
    }

    sort(ALL(s));

    for (i = 0; i < s.size() - 1; i++)
      ans += s[i];

    ans = (ans - s[0]) / (i - 1);

    cout << ans << endl;
    ans = 0;
  }

  return 0;
}

Error: -11

Fixed submission:


#include <algorithm>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int main(int argc, char *argv[]) {
  int ninzu = 0;
  while (cin >> ninzu) {
    int ans = 0;
    int i = 0;
    int temp = 0;
    int a = 0;

    vector<int> s;

    for (i = 0; i < ninzu; i++) {
      cin >> a;
      if (temp < a) {
        temp = a;
      }
      s.push_back(a);
    }

    sort(ALL(s));

    for (i = 0; i < s.size() - 1; i++)
      ans += s[i];

    ans = (ans - s[0]) / (i - 1);

    cout << ans << endl;
    ans = 0;
  }

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

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

int main() {
  int n;
  int s[100];
  int sum;

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

    sort(s, s + n);

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

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

  return 0;
}

Error: 0

Fixed submission:

/*** ICPC??????????¨???????????????§??¢ ***/

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

int main() {
  int n;
  int s[20];
  int sum;

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

    sort(s, s + n);

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

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

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

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

int main() {
  int a, b, c;
  vector<int> d;
  while (1) {
    d.clear();
    c = 0;
    cin >> a;
    if (a == 0)
      break;
    for (int i = 0; i < a; i++) {
      cin >> b;
      d.push_back(b);
    }
    sort(d.begin(), d.end());
    for (int i = 1; i < d.size() - 1; i++) {
      c += d[i];
    }
    cout << c / (d.size() - 2) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int i, n, x, y, a[20], ans;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    x = 0;
    y = 0;
    ans = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (a[x] < a[i])
        x = i;
      if (a[y] > a[i])
        y = i;
      ans += a[i];
    }
    ans = ans - a[x] - a[y];
    ans = ans / (n - 2);
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, a[101], t;

  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    t = 0;
    for (int i = 1; i < n - 1; i++) {
      t += a[i];
    }

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, a[21], t;

  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    t = 0;
    for (int i = 1; i < n - 1; i++) {
      t += a[i];
    }

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

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

#include <algorithm>
#include <iostream>
using namespace std;
int n1;
int main() {
  while (true) {
    cin >> n1;
    int a[n1];
    if (n1 <= 0)
      break;
    for (int i = 0; i < n1; i++) {
      cin >> a[i];
    }
    sort(a, a + n1);
    a[0] = {0};
    a[n1 - 1] = {0};
    for (int i2 = 1; i2 < n1; i2++) {
      a[0] += a[i2];
    }
    cout << a[0] / (n1 - 2) << endl;
  }
  return 0;
}


Error: 3

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n1;
  cin >> n1;
  if (n1 > 0) {
    int a[100000] = {0};
    for (int i = 0; i < n1; i++) {
      cin >> a[i];
    }
    sort(a, a + n1);
    a[0] = {0};
    a[n1 - 1] = {0};
    for (int i2 = 1; i2 < n1; i2++) {
      a[0] += a[i2];
    }
    cout << a[0] / (n1 - 2) << endl;

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

#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  vector<int> vc;
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int tmp;
    vc.clear();
    REP(i, n) {
      cin >> tmp;
      vc.push_back(tmp);
    }
    sort(vc.begin(), vc.end());
    vc.erase(vc.begin());
    vc.erase(--vc.end());
    int sum = 0;
    vector<int>::iterator it = vc.begin();
    while (it != vc.end()) {
      sum += (*it);
      it++;
    }
    cout << sum / (n - 2) << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  vector<int> vc;
  int n;
  while (cin >> n) {
    int tmp;
    vc.clear();
    REP(i, n) {
      cin >> tmp;
      vc.push_back(tmp);
    }
    sort(vc.begin(), vc.end());
    vc.erase(vc.begin());
    vc.erase(--vc.end());
    int sum = 0;
    vector<int>::iterator it = vc.begin();
    while (it != vc.end()) {
      sum += (*it);
      it++;
    }
    cout << sum / (n - 2) << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

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

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

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